Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions actix-web-codegen/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions actix-web-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion actix-web-codegen/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion actix-web-codegen/tests/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 2 additions & 0 deletions actix-web/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 22 additions & 4 deletions actix-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand All @@ -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 }
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion awc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading