diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2022-03-07 16:31:03 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-07 16:31:03 +0000 |
| commit | 96515f421a9efe88b46091e58533c1bfe875e09e (patch) | |
| tree | 80d7cbdbdbec000e1b3d3db3fc70bdfc782ccae8 | |
| parent | 38a0b81b1c32764d6a583a5efb6f306b8c44c503 (diff) | |
| download | rust-96515f421a9efe88b46091e58533c1bfe875e09e.tar.gz rust-96515f421a9efe88b46091e58533c1bfe875e09e.zip | |
Do not allow `#[rustc_legacy_const_generics]` on methods
It caused an ICE since `item` was `None`.
3 files changed, 17 insertions, 4 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d94ad7ba71a..200bb21504e 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1372,7 +1372,7 @@ impl CheckAttrVisitor<'_> { target: Target, item: Option<ItemLike<'_>>, ) -> bool { - let is_function = matches!(target, Target::Fn | Target::Method(..)); + let is_function = matches!(target, Target::Fn); if !is_function { self.tcx .sess diff --git a/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs b/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs index 3d8478f06db..6eabd9b1015 100644 --- a/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs +++ b/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs @@ -29,6 +29,11 @@ extern { #[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have fn foo8<X>() {} +impl S { + #[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function + fn foo9<const X: usize>() {} +} + #[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute fn bar1() {} diff --git a/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr b/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr index 1f55a8e72d2..bfe7bb2e10d 100644 --- a/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr +++ b/src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr @@ -7,13 +7,13 @@ LL | #[rustc_legacy_const_generics(0usize)] = help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.) error: malformed `rustc_legacy_const_generics` attribute input - --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:32:1 + --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:1 | LL | #[rustc_legacy_const_generics] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]` error: malformed `rustc_legacy_const_generics` attribute input - --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:35:1 + --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:40:1 | LL | #[rustc_legacy_const_generics = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]` @@ -67,6 +67,14 @@ LL | fn foo8<X>() {} | - non-const generic parameter error: attribute should be applied to a function + --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:5 + | +LL | #[rustc_legacy_const_generics(0)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo9<const X: usize>() {} + | ---------------------------- not a function + +error: attribute should be applied to a function --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5 | LL | #[rustc_legacy_const_generics(1)] @@ -82,6 +90,6 @@ LL | fn foo7<const X: usize>(); | = help: replace the const parameters with concrete consts -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0044`. |
