diff --git a/actix-web-codegen/tests/trybuild.rs b/actix-web-codegen/tests/trybuild.rs index d71f9be00..1bc2bd25e 100644 --- a/actix-web-codegen/tests/trybuild.rs +++ b/actix-web-codegen/tests/trybuild.rs @@ -1,4 +1,3 @@ -#[rustversion::attr(not(stable(1.42)), ignore)] #[test] fn compile_macros() { let t = trybuild::TestCases::new(); @@ -7,7 +6,22 @@ fn compile_macros() { t.compile_fail("tests/trybuild/simple-fail.rs"); t.pass("tests/trybuild/route-ok.rs"); - t.compile_fail("tests/trybuild/route-missing-method-fail.rs"); t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs"); t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs"); + + test_route_missing_method(&t) } + +#[rustversion::stable(1.42)] +fn test_route_missing_method(t: &trybuild::TestCases) { + t.compile_fail("tests/trybuild/route-missing-method-fail-msrv.rs"); +} + +#[rustversion::not(stable(1.42))] +#[rustversion::not(nightly)] +fn test_route_missing_method(t: &trybuild::TestCases) { + t.compile_fail("tests/trybuild/route-missing-method-fail.rs"); +} + +#[rustversion::nightly] +fn test_route_missing_method(_t: &trybuild::TestCases) {} diff --git a/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.rs b/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.rs new file mode 100644 index 000000000..5c30b57ce --- /dev/null +++ b/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.rs @@ -0,0 +1,15 @@ +use actix_web::*; + +#[route("/")] +async fn index() -> impl Responder { + HttpResponse::Ok() +} + +#[actix_web::main] +async fn main() { + let srv = test::start(|| App::new().service(index)); + + let request = srv.get("/"); + let response = request.send().await.unwrap(); + assert!(response.status().is_success()); +} diff --git a/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.stderr b/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.stderr new file mode 100644 index 000000000..f59f6c27e --- /dev/null +++ b/actix-web-codegen/tests/trybuild/route-missing-method-fail-msrv.stderr @@ -0,0 +1,11 @@ +error: The #[route(..)] macro requires at least one `method` attribute + --> $DIR/route-missing-method-fail-msrv.rs:3:1 + | +3 | #[route("/")] + | ^^^^^^^^^^^^^ + +error[E0425]: cannot find value `index` in this scope + --> $DIR/route-missing-method-fail-msrv.rs:10:49 + | +10 | let srv = test::start(|| App::new().service(index)); + | ^^^^^ not found in this scope diff --git a/actix-web-codegen/tests/trybuild/route-missing-method-fail.stderr b/actix-web-codegen/tests/trybuild/route-missing-method-fail.stderr index a90f04edb..6d35ea600 100644 --- a/actix-web-codegen/tests/trybuild/route-missing-method-fail.stderr +++ b/actix-web-codegen/tests/trybuild/route-missing-method-fail.stderr @@ -3,6 +3,8 @@ error: The #[route(..)] macro requires at least one `method` attribute | 3 | #[route("/")] | ^^^^^^^^^^^^^ + | + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `index` in this scope --> $DIR/route-missing-method-fail.rs:10:49