Skip to content

Commit 105ca9c

Browse files
committed
feat: forwards-compatibility for handler visibility inheritance fix
relates to #2714
1 parent 3db7891 commit 105ca9c

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

actix-web-codegen/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ rust-version.workspace = true
1515
[lib]
1616
proc-macro = true
1717

18+
[features]
19+
default = ["force-pub"]
20+
force-pub = []
21+
1822
[dependencies]
1923
actix-router = { version = "0.5", default-features = false }
2024
proc-macro2 = "1"

actix-web-codegen/src/route.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ impl ToTokens for Route {
413413
doc_attributes,
414414
} = self;
415415

416+
#[allow(unused_variables)] // used when force-pub feature is disabled
417+
let vis = &ast.vis;
418+
419+
// TODO(v5.0): remove the force-pub backwards-compatibility feature
420+
#[cfg(feature = "force-pub")]
421+
let vis = syn::Visibility::Public(<Token![pub]>::default());
422+
416423
let registrations: TokenStream2 = args
417424
.iter()
418425
.map(|args| {
@@ -460,7 +467,7 @@ impl ToTokens for Route {
460467
let stream = quote! {
461468
#(#doc_attributes)*
462469
#[allow(non_camel_case_types, missing_docs)]
463-
pub struct #name;
470+
#vis struct #name;
464471

465472
impl ::actix_web::dev::HttpServiceFactory for #name {
466473
fn register(self, __config: &mut actix_web::dev::AppService) {

actix-web-codegen/tests/scopes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod scope_module {
4949
#[connect("/test2")]
5050
#[options("/test3")]
5151
#[trace("/test4")]
52-
async fn multiple_separate_paths() -> impl Responder {
52+
pub async fn multiple_separate_paths() -> impl Responder {
5353
HttpResponse::Ok().finish()
5454
}
5555

actix-web/Cargo.toml

+17-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ name = "actix_web"
4040
path = "src/lib.rs"
4141

4242
[features]
43-
default = ["macros", "compress-brotli", "compress-gzip", "compress-zstd", "cookies", "http2", "unicode"]
43+
default = [
44+
"macros",
45+
"compress-brotli",
46+
"compress-gzip",
47+
"compress-zstd",
48+
"cookies",
49+
"http2",
50+
"unicode",
51+
"compat-routing-macros-force-pub",
52+
]
4453

4554
# Brotli algorithm content-encoding support
4655
compress-brotli = ["actix-http/compress-brotli", "__compress"]
@@ -50,14 +59,15 @@ compress-gzip = ["actix-http/compress-gzip", "__compress"]
5059
compress-zstd = ["actix-http/compress-zstd", "__compress"]
5160

5261
# Routing and runtime proc macros
53-
macros = ["actix-macros", "actix-web-codegen"]
62+
macros = ["dep:actix-macros", "dep:actix-web-codegen"]
5463

5564
# Cookies support
56-
cookies = ["cookie"]
65+
cookies = ["dep:cookie"]
5766

5867
# Secure & signed cookies
5968
secure-cookies = ["cookies", "cookie/secure"]
6069

70+
# HTTP/2 support (including h2c).
6171
http2 = ["actix-http/http2"]
6272

6373
# TLS via OpenSSL
@@ -84,6 +94,9 @@ __compress = []
8494
# io-uring feature only available for Linux OSes.
8595
experimental-io-uring = ["actix-server/io-uring"]
8696

97+
# Opt-out forwards-compatibility for handler visibility inheritance fix.
98+
compat-routing-macros-force-pub = ["actix-web-codegen?/force-pub"]
99+
87100
[dependencies]
88101
actix-codec = "0.5"
89102
actix-macros = { version = "0.2.3", optional = true }
@@ -95,7 +108,7 @@ actix-tls = { version = "3.4", default-features = false, optional = true }
95108

96109
actix-http = { version = "3.7", features = ["ws"] }
97110
actix-router = { version = "0.5.3", default-features = false, features = ["http"] }
98-
actix-web-codegen = { version = "4.2", optional = true }
111+
actix-web-codegen = { version = "4.2", optional = true, default-features = false }
99112

100113
ahash = "0.8"
101114
bytes = "1"

0 commit comments

Comments
 (0)