mirror of https://github.com/rust-lang/rust.git
Do not allow `#[rustc_legacy_const_generics]` on methods
It caused an ICE since `item` was `None`.
This commit is contained in:
parent
38a0b81b1c
commit
96515f421a
|
@ -1372,7 +1372,7 @@ impl CheckAttrVisitor<'_> {
|
||||||
target: Target,
|
target: Target,
|
||||||
item: Option<ItemLike<'_>>,
|
item: Option<ItemLike<'_>>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let is_function = matches!(target, Target::Fn | Target::Method(..));
|
let is_function = matches!(target, Target::Fn);
|
||||||
if !is_function {
|
if !is_function {
|
||||||
self.tcx
|
self.tcx
|
||||||
.sess
|
.sess
|
||||||
|
|
|
@ -29,6 +29,11 @@ extern {
|
||||||
#[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have
|
#[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have
|
||||||
fn foo8<X>() {}
|
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
|
#[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute
|
||||||
fn bar1() {}
|
fn bar1() {}
|
||||||
|
|
||||||
|
|
|
@ -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.)
|
= 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
|
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]
|
LL | #[rustc_legacy_const_generics]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
|
||||||
|
|
||||||
error: malformed `rustc_legacy_const_generics` attribute input
|
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]
|
LL | #[rustc_legacy_const_generics = 1]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
|
||||||
|
@ -66,6 +66,14 @@ LL | #[rustc_legacy_const_generics(0)]
|
||||||
LL | fn foo8<X>() {}
|
LL | fn foo8<X>() {}
|
||||||
| - non-const generic parameter
|
| - 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
|
error: attribute should be applied to a function
|
||||||
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5
|
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5
|
||||||
|
|
|
|
||||||
|
@ -82,6 +90,6 @@ LL | fn foo7<const X: usize>();
|
||||||
|
|
|
|
||||||
= help: replace the const parameters with concrete consts
|
= 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`.
|
For more information about this error, try `rustc --explain E0044`.
|
||||||
|
|
Loading…
Reference in New Issue