Skip to content

Commit 3ce01f7

Browse files
authored
Rollup merge of #94686 - ChayimFriedman2:issue-94629, r=jackh726
Do not allow `#[rustc_legacy_const_generics]` on methods It caused an ICE since `item` was `None`. Fixes #94629.
2 parents d365d5e + 96515f4 commit 3ce01f7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ impl CheckAttrVisitor<'_> {
13451345
target: Target,
13461346
item: Option<ItemLike<'_>>,
13471347
) -> bool {
1348-
let is_function = matches!(target, Target::Fn | Target::Method(..));
1348+
let is_function = matches!(target, Target::Fn);
13491349
if !is_function {
13501350
self.tcx
13511351
.sess

src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ extern {
2929
#[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have
3030
fn foo8<X>() {}
3131

32+
impl S {
33+
#[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function
34+
fn foo9<const X: usize>() {}
35+
}
36+
3237
#[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute
3338
fn bar1() {}
3439

src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ LL | #[rustc_legacy_const_generics(0usize)]
77
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
88

99
error: malformed `rustc_legacy_const_generics` attribute input
10-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:32:1
10+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:1
1111
|
1212
LL | #[rustc_legacy_const_generics]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
1414

1515
error: malformed `rustc_legacy_const_generics` attribute input
16-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:35:1
16+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:40:1
1717
|
1818
LL | #[rustc_legacy_const_generics = 1]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
@@ -66,6 +66,14 @@ LL | #[rustc_legacy_const_generics(0)]
6666
LL | fn foo8<X>() {}
6767
| - non-const generic parameter
6868

69+
error: attribute should be applied to a function
70+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:5
71+
|
72+
LL | #[rustc_legacy_const_generics(0)]
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
LL | fn foo9<const X: usize>() {}
75+
| ---------------------------- not a function
76+
6977
error: attribute should be applied to a function
7078
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5
7179
|
@@ -82,6 +90,6 @@ LL | fn foo7<const X: usize>();
8290
|
8391
= help: replace the const parameters with concrete consts
8492

85-
error: aborting due to 12 previous errors
93+
error: aborting due to 13 previous errors
8694

8795
For more information about this error, try `rustc --explain E0044`.

0 commit comments

Comments
 (0)