Skip to content

Commit 396022b

Browse files
committed
Visit more targets when checking attrs
1 parent ea09825 commit 396022b

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

compiler/rustc_hir/src/target.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub enum Target {
5454
ForeignTy,
5555
GenericParam(GenericParamKind),
5656
MacroDef,
57+
Param,
5758
}
5859

5960
impl Display for Target {
@@ -96,6 +97,7 @@ impl Display for Target {
9697
GenericParamKind::Const => "const parameter",
9798
},
9899
Target::MacroDef => "macro def",
100+
Target::Param => "function param",
99101
}
100102
)
101103
}

compiler/rustc_passes/src/check_attr.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -1101,17 +1101,6 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
11011101
intravisit::walk_arm(self, arm);
11021102
}
11031103

1104-
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
1105-
self.check_attributes(
1106-
macro_def.hir_id,
1107-
&macro_def.attrs,
1108-
&macro_def.span,
1109-
Target::MacroDef,
1110-
None,
1111-
);
1112-
intravisit::walk_macro_def(self, macro_def);
1113-
}
1114-
11151104
fn visit_foreign_item(&mut self, f_item: &'tcx ForeignItem<'tcx>) {
11161105
let target = Target::from_foreign_item(f_item);
11171106
self.check_attributes(
@@ -1157,6 +1146,23 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
11571146
self.check_attributes(variant.id, variant.attrs, &variant.span, Target::Variant, None);
11581147
intravisit::walk_variant(self, variant, generics, item_id)
11591148
}
1149+
1150+
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
1151+
self.check_attributes(
1152+
macro_def.hir_id,
1153+
macro_def.attrs,
1154+
&macro_def.span,
1155+
Target::MacroDef,
1156+
None,
1157+
);
1158+
intravisit::walk_macro_def(self, macro_def);
1159+
}
1160+
1161+
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
1162+
self.check_attributes(param.hir_id, param.attrs, &param.span, Target::Param, None);
1163+
1164+
intravisit::walk_param(self, param);
1165+
}
11601166
}
11611167

11621168
fn is_c_like_enum(item: &Item<'_>) -> bool {

src/test/ui/proc-macro/ambiguous-builtin-attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#![feature(decl_macro)] //~ ERROR `feature` is ambiguous
44

55
extern crate builtin_attrs;
6-
use builtin_attrs::{test, bench};
76
use builtin_attrs::*;
7+
use builtin_attrs::{bench, test};
88

99
#[repr(C)] //~ ERROR `repr` is ambiguous
1010
struct S;

src/test/ui/proc-macro/ambiguous-builtin-attrs.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | #[repr(C)]
1212
|
1313
= note: `repr` could refer to a built-in attribute
1414
note: `repr` could also refer to the attribute macro imported here
15-
--> $DIR/ambiguous-builtin-attrs.rs:7:5
15+
--> $DIR/ambiguous-builtin-attrs.rs:6:5
1616
|
1717
LL | use builtin_attrs::*;
1818
| ^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | #[cfg_attr(all(), repr(C))]
2626
|
2727
= note: `repr` could refer to a built-in attribute
2828
note: `repr` could also refer to the attribute macro imported here
29-
--> $DIR/ambiguous-builtin-attrs.rs:7:5
29+
--> $DIR/ambiguous-builtin-attrs.rs:6:5
3030
|
3131
LL | use builtin_attrs::*;
3232
| ^^^^^^^^^^^^^^^^
@@ -40,7 +40,7 @@ LL | fn non_macro_expanded_location<#[repr(C)] T>() {
4040
|
4141
= note: `repr` could refer to a built-in attribute
4242
note: `repr` could also refer to the attribute macro imported here
43-
--> $DIR/ambiguous-builtin-attrs.rs:7:5
43+
--> $DIR/ambiguous-builtin-attrs.rs:6:5
4444
|
4545
LL | use builtin_attrs::*;
4646
| ^^^^^^^^^^^^^^^^
@@ -54,7 +54,7 @@ LL | #[repr(C)]
5454
|
5555
= note: `repr` could refer to a built-in attribute
5656
note: `repr` could also refer to the attribute macro imported here
57-
--> $DIR/ambiguous-builtin-attrs.rs:7:5
57+
--> $DIR/ambiguous-builtin-attrs.rs:6:5
5858
|
5959
LL | use builtin_attrs::*;
6060
| ^^^^^^^^^^^^^^^^
@@ -82,7 +82,7 @@ LL | #![feature(decl_macro)]
8282
|
8383
= note: `feature` could refer to a built-in attribute
8484
note: `feature` could also refer to the attribute macro imported here
85-
--> $DIR/ambiguous-builtin-attrs.rs:7:5
85+
--> $DIR/ambiguous-builtin-attrs.rs:6:5
8686
|
8787
LL | use builtin_attrs::*;
8888
| ^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)