1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-23 16:21:06 +01:00

feat: forwards-compatibility for handler visibility inheritance fix (#3391)

This commit is contained in:
Rob Ede 2024-06-09 00:10:15 +01:00 committed by GitHub
parent 7c4c26d2df
commit ebc43dcf1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 7 deletions

View File

@ -3,6 +3,7 @@
## Unreleased
- Add `#[scope]` macro.
- Add `compat-routing-macros-force-pub` crate feature which, on-by-default, which when disabled causes handlers to inherit their attached function's visibility.
- Prevent inclusion of default `actix-router` features.
- Minimum supported Rust version (MSRV) is now 1.72.

View File

@ -15,6 +15,10 @@ rust-version.workspace = true
[lib]
proc-macro = true
[features]
default = ["compat-routing-macros-force-pub"]
compat-routing-macros-force-pub = []
[dependencies]
actix-router = { version = "0.5", default-features = false }
proc-macro2 = "1"

View File

@ -413,6 +413,13 @@ impl ToTokens for Route {
doc_attributes,
} = self;
#[allow(unused_variables)] // used when force-pub feature is disabled
let vis = &ast.vis;
// TODO(breaking): remove this force-pub forwards-compatibility feature
#[cfg(feature = "compat-routing-macros-force-pub")]
let vis = syn::Visibility::Public(<Token![pub]>::default());
let registrations: TokenStream2 = args
.iter()
.map(|args| {
@ -460,7 +467,7 @@ impl ToTokens for Route {
let stream = quote! {
#(#doc_attributes)*
#[allow(non_camel_case_types, missing_docs)]
pub struct #name;
#vis struct #name;
impl ::actix_web::dev::HttpServiceFactory for #name {
fn register(self, __config: &mut actix_web::dev::AppService) {

View File

@ -49,7 +49,7 @@ mod scope_module {
#[connect("/test2")]
#[options("/test3")]
#[trace("/test4")]
async fn multiple_separate_paths() -> impl Responder {
pub async fn multiple_separate_paths() -> impl Responder {
HttpResponse::Ok().finish()
}

View File

@ -7,6 +7,8 @@
- Add `middleware::Identity` type.
- Add `CustomizeResponder::add_cookie()` method.
- Add `guard::GuardContext::app_data()` method.
- Add `compat-routing-macros-force-pub` crate feature which (on-by-default) which, when disabled, causes handlers to inherit their attached function's visibility.
- Add `compat` crate feature group (on-by-default) which, when disabled, helps with transitioning to some planned v5.0 breaking changes, starting only with `compat-routing-macros-force-pub`.
- Implement `From<Box<dyn ResponseError>>` for `Error`.
## 4.6.0

View File

@ -40,7 +40,16 @@ name = "actix_web"
path = "src/lib.rs"
[features]
default = ["macros", "compress-brotli", "compress-gzip", "compress-zstd", "cookies", "http2", "unicode"]
default = [
"macros",
"compress-brotli",
"compress-gzip",
"compress-zstd",
"cookies",
"http2",
"unicode",
"compat",
]
# Brotli algorithm content-encoding support
compress-brotli = ["actix-http/compress-brotli", "__compress"]
@ -50,14 +59,15 @@ compress-gzip = ["actix-http/compress-gzip", "__compress"]
compress-zstd = ["actix-http/compress-zstd", "__compress"]
# Routing and runtime proc macros
macros = ["actix-macros", "actix-web-codegen"]
macros = ["dep:actix-macros", "dep:actix-web-codegen"]
# Cookies support
cookies = ["cookie"]
cookies = ["dep:cookie"]
# Secure & signed cookies
secure-cookies = ["cookies", "cookie/secure"]
# HTTP/2 support (including h2c).
http2 = ["actix-http/http2"]
# TLS via OpenSSL
@ -84,6 +94,14 @@ __compress = []
# io-uring feature only available for Linux OSes.
experimental-io-uring = ["actix-server/io-uring"]
# Feature group which, when disabled, helps migrate code to v5.0.
compat = [
"compat-routing-macros-force-pub",
]
# Opt-out forwards-compatibility for handler visibility inheritance fix.
compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-force-pub"]
[dependencies]
actix-codec = "0.5"
actix-macros = { version = "0.2.3", optional = true }
@ -95,7 +113,7 @@ actix-tls = { version = "3.4", default-features = false, optional = true }
actix-http = { version = "3.7", features = ["ws"] }
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
actix-web-codegen = { version = "4.2", optional = true }
actix-web-codegen = { version = "4.2", optional = true, default-features = false }
ahash = "0.8"
bytes = "1"

View File

@ -64,7 +64,7 @@ compress-gzip = ["actix-http/compress-gzip", "__compress"]
compress-zstd = ["actix-http/compress-zstd", "__compress"]
# Cookie parsing and cookie jar
cookies = ["cookie"]
cookies = ["dep:cookie"]
# Use `trust-dns-resolver` crate as DNS resolver
trust-dns = ["trust-dns-resolver"]