Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,15 @@ pub(crate) struct AttributesStartingWithRustcAreReserved {
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag(
"attributes containing a segment starting with `rustc` are reserved for use by the `rustc` compiler"
)]
pub(crate) struct AttributesContainingRustcAreReserved {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Diagnostic)]
#[diag("cannot use {$article} {$descr} through an import")]
pub(crate) struct CannotUseThroughAnImport {
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

// Report errors for the resolved macro.
for segment in &path.segments {
for (idx, segment) in path.segments.iter().enumerate() {
if let Some(args) = &segment.args {
self.dcx().emit_err(errors::GenericArgumentsInMacroPath { span: args.span() });
}
if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
self.dcx().emit_err(errors::AttributesStartingWithRustcAreReserved {
span: segment.ident.span,
});
if idx == 0 {
self.dcx().emit_err(errors::AttributesStartingWithRustcAreReserved {
span: segment.ident.span,
});
} else {
self.dcx().emit_err(errors::AttributesContainingRustcAreReserved {
span: segment.ident.span,
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/feature-gates/feature-gate-rustc-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod unknown { pub macro rustc() {} }
fn f() {}

#[unknown::rustc]
//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler
//~^ ERROR attributes containing a segment starting with `rustc` are reserved for use by the `rustc` compiler
//~| ERROR expected attribute, found macro `unknown::rustc`
//~| NOTE not an attribute
fn g() {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/feature-gates/feature-gate-rustc-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error: expected attribute, found macro `rustc::unknown`
LL | #[rustc::unknown]
| ^^^^^^^^^^^^^^ not an attribute

error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
error: attributes containing a segment starting with `rustc` are reserved for use by the `rustc` compiler
--> $DIR/feature-gate-rustc-attrs.rs:14:12
|
LL | #[unknown::rustc]
Expand Down
Loading