Skip to content

Commit 2c36833

Browse files
Edvin BryntessonBryntet
authored andcommitted
remove duplicate error in check_rustc_legacy_const_generics
1 parent 2022cce commit 2c36833

File tree

3 files changed

+12
-54
lines changed

3 files changed

+12
-54
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
213213
self.check_macro_export(hir_id, *span, target)
214214
},
215215
Attribute::Parsed(AttributeKind::RustcLegacyConstGenerics{attr_span, fn_indexes}) => {
216-
self.check_rustc_legacy_const_generics(hir_id, span, target, item, *attr_span, fn_indexes)
216+
self.check_rustc_legacy_const_generics(item, *attr_span, fn_indexes)
217217
},
218218
Attribute::Parsed(AttributeKind::Doc(attr)) => self.check_doc_attrs(attr, hir_id, target),
219219
Attribute::Parsed(
@@ -1178,29 +1178,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11781178
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
11791179
fn check_rustc_legacy_const_generics(
11801180
&self,
1181-
hir_id: HirId,
1182-
span: Span,
1183-
target: Target,
11841181
item: Option<ItemLike<'_>>,
11851182
attr_span: Span,
11861183
index_list: &ThinVec<(u128, Span)>,
11871184
) {
1188-
let is_function = matches!(target, Target::Fn);
1189-
if !is_function {
1190-
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
1191-
attr_span,
1192-
defn_span: span,
1193-
on_crate: hir_id == CRATE_HIR_ID,
1194-
});
1195-
return;
1196-
}
1197-
11981185
let Some(ItemLike::Item(Item {
11991186
kind: ItemKind::Fn { sig: FnSig { decl, .. }, generics, .. },
12001187
..
12011188
})) = item
12021189
else {
1203-
bug!("should be a function item");
1190+
// No error here, since it's already given by the parser
1191+
return;
12041192
};
12051193

12061194
for param in generics.params {

tests/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn foo4<const X: usize>() {}
1616
fn foo5<const X: usize, const Y: usize, const Z: usize, const W: usize>() {}
1717

1818
#[rustc_legacy_const_generics(0)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on structs
19-
//~^ ERROR attribute should be applied to a function definition
2019
struct S;
2120

2221
#[rustc_legacy_const_generics(0usize)]
@@ -26,7 +25,6 @@ fn foo6<const X: usize>() {}
2625

2726
extern "C" {
2827
#[rustc_legacy_const_generics(1)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on foreign functions
29-
//~^ ERROR attribute should be applied to a function definition
3028
fn foo7<const X: usize>(); //~ ERROR foreign items may not have const parameters
3129
}
3230

@@ -35,7 +33,6 @@ fn foo8<X>() {}
3533

3634
impl S {
3735
#[rustc_legacy_const_generics(0)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on inherent methods
38-
//~^ ERROR attribute should be applied to a function definition
3936
fn foo9<const X: usize>() {}
4037
}
4138

tests/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ LL | #[rustc_legacy_const_generics(0)]
2525
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
2626

2727
error: suffixed literals are not allowed in attributes
28-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:22:31
28+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:21:31
2929
|
3030
LL | #[rustc_legacy_const_generics(0usize)]
3131
| ^^^^^^
3232
|
3333
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
3434

3535
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
36-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:22:1
36+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:21:1
3737
|
3838
LL | #[rustc_legacy_const_generics(0usize)]
3939
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^
@@ -42,23 +42,23 @@ LL | #[rustc_legacy_const_generics(0usize)]
4242
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
4343

4444
error: `#[rustc_legacy_const_generics]` attribute cannot be used on foreign functions
45-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:28:5
45+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:27:5
4646
|
4747
LL | #[rustc_legacy_const_generics(1)]
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949
|
5050
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
5151

5252
error: `#[rustc_legacy_const_generics]` attribute cannot be used on inherent methods
53-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:5
53+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:35:5
5454
|
5555
LL | #[rustc_legacy_const_generics(0)]
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5757
|
5858
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
5959

6060
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
61-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:42:1
61+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:39:1
6262
|
6363
LL | #[rustc_legacy_const_generics]
6464
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -67,7 +67,7 @@ LL | #[rustc_legacy_const_generics]
6767
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
6868

6969
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
70-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:45:1
70+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:42:1
7171
|
7272
LL | #[rustc_legacy_const_generics = 1]
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^
@@ -95,50 +95,23 @@ error: index exceeds number of arguments
9595
LL | #[rustc_legacy_const_generics(2)]
9696
| ^ there are only 2 arguments
9797

98-
error: attribute should be applied to a function definition
99-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:18:1
100-
|
101-
LL | #[rustc_legacy_const_generics(0)]
102-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103-
LL |
104-
LL | struct S;
105-
| --------- not a function definition
106-
10798
error: #[rustc_legacy_const_generics] functions must only have const generics
108-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:1
99+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:31:1
109100
|
110101
LL | #[rustc_legacy_const_generics(0)]
111102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112103
LL | fn foo8<X>() {}
113104
| - non-const generic parameter
114105

115-
error: attribute should be applied to a function definition
116-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:5
117-
|
118-
LL | #[rustc_legacy_const_generics(0)]
119-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120-
LL |
121-
LL | fn foo9<const X: usize>() {}
122-
| ---------------------------- not a function definition
123-
124-
error: attribute should be applied to a function definition
125-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:28:5
126-
|
127-
LL | #[rustc_legacy_const_generics(1)]
128-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129-
LL |
130-
LL | fn foo7<const X: usize>();
131-
| -------------------------- not a function definition
132-
133106
error[E0044]: foreign items may not have const parameters
134-
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:30:5
107+
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:28:5
135108
|
136109
LL | fn foo7<const X: usize>();
137110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have const parameters
138111
|
139112
= help: replace the const parameters with concrete consts
140113

141-
error: aborting due to 17 previous errors
114+
error: aborting due to 14 previous errors
142115

143116
Some errors have detailed explanations: E0044, E0539.
144117
For more information about an error, try `rustc --explain E0044`.

0 commit comments

Comments
 (0)