Skip to content

Commit

Permalink
Do not consider built-in attributes as candidates when resolving non-…
Browse files Browse the repository at this point in the history
…attribute macro invocations

This is needed to avoid regressions on stable channel
  • Loading branch information
petrochenkov committed Aug 11, 2018
1 parent d2f5637 commit e7ee6fb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 36 deletions.
5 changes: 4 additions & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
}
WhereToResolve::BuiltinAttrs => {
if is_builtin_attr_name(ident.name) {
// FIXME: Only built-in attributes are not considered as candidates for
// non-attributes to fight off regressions on stable channel (#53205).
// We need to come up with some more principled approach instead.
if is_attr && is_builtin_attr_name(ident.name) {
let binding = (Def::NonMacroAttr(NonMacroAttrKind::Builtin),
ty::Visibility::Public, ident.span, Mark::root())
.to_name_binding(self.arenas);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issue-11692-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

fn main() {
concat!(test!());
//~^ ERROR expected a macro, found built-in attribute
//~^ ERROR cannot find macro `test!` in this scope
}
2 changes: 1 addition & 1 deletion src/test/ui/issue-11692-2.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected a macro, found built-in attribute
error: cannot find macro `test!` in this scope
--> $DIR/issue-11692-2.rs:12:13
|
LL | concat!(test!());
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/macro-path-prelude-fail-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#![feature(use_extern_macros)]

#[derive(inline)] //~ ERROR expected a macro, found built-in attribute
#[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
struct S;

fn main() {
inline!(); //~ ERROR expected a macro, found built-in attribute
inline!(); //~ ERROR cannot find macro `inline!` in this scope
}
10 changes: 5 additions & 5 deletions src/test/ui/macro-path-prelude-fail-3.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: expected a macro, found built-in attribute
error: cannot find derive macro `inline` in this scope
--> $DIR/macro-path-prelude-fail-3.rs:13:10
|
LL | #[derive(inline)] //~ ERROR expected a macro, found built-in attribute
LL | #[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
| ^^^^^^

error: expected a macro, found built-in attribute
error: cannot find macro `inline!` in this scope
--> $DIR/macro-path-prelude-fail-3.rs:17:5
|
LL | inline!(); //~ ERROR expected a macro, found built-in attribute
| ^^^^^^
LL | inline!(); //~ ERROR cannot find macro `inline!` in this scope
| ^^^^^^ help: you could try the macro: `line`

error: aborting due to 2 previous errors

4 changes: 3 additions & 1 deletion src/test/ui/macro-path-prelude-shadowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ add_macro_expanded_things_to_macro_prelude!();

mod m1 {
fn check() {
inline!(); //~ ERROR `inline` is ambiguous
inline!(); // OK. Theoretically ambiguous, but we do not consider built-in attributes
// as candidates for non-attribute macro invocations to avoid regressions
// on stable channel
}
}

Expand Down
29 changes: 4 additions & 25 deletions src/test/ui/macro-path-prelude-shadowing.stderr
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
error[E0659]: `inline` is ambiguous
--> $DIR/macro-path-prelude-shadowing.rs:24:9
|
LL | inline!(); //~ ERROR `inline` is ambiguous
| ^^^^^^
|
note: `inline` could refer to the name imported here
--> $DIR/macro-path-prelude-shadowing.rs:16:5
|
LL | #[macro_use]
| ^^^^^^^^^^^^
...
LL | add_macro_expanded_things_to_macro_prelude!();
| ---------------------------------------------- in this macro invocation
note: `inline` could also refer to the name defined here
--> $DIR/macro-path-prelude-shadowing.rs:24:9
|
LL | inline!(); //~ ERROR `inline` is ambiguous
| ^^^^^^
= note: macro-expanded macro imports do not shadow

error[E0659]: `std` is ambiguous
--> $DIR/macro-path-prelude-shadowing.rs:37:9
--> $DIR/macro-path-prelude-shadowing.rs:39:9
|
LL | std::panic!(); //~ ERROR `std` is ambiguous
| ^^^^^^^^^^
|
note: `std` could refer to the name imported here
--> $DIR/macro-path-prelude-shadowing.rs:35:9
--> $DIR/macro-path-prelude-shadowing.rs:37:9
|
LL | use m2::*; // glob-import user-defined `std`
| ^^^^^
note: `std` could also refer to the name defined here
--> $DIR/macro-path-prelude-shadowing.rs:37:9
--> $DIR/macro-path-prelude-shadowing.rs:39:9
|
LL | std::panic!(); //~ ERROR `std` is ambiguous
| ^^^
= note: consider adding an explicit import of `std` to disambiguate

error: aborting due to 2 previous errors
error: aborting due to previous error

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

0 comments on commit e7ee6fb

Please sign in to comment.