warn_msg: &'static str,
}
-// For compatibility bang macros are skipped when resolving potentially built-in attributes.
-fn macro_kind_mismatch(name: Name, requirement: Option<MacroKind>, candidate: Option<MacroKind>)
- -> bool {
- requirement == Some(MacroKind::Attr) && candidate == Some(MacroKind::Bang) &&
- (name == "test" || name == "bench" || is_builtin_attr_name(name))
+// Macro namespace is separated into two sub-namespaces, one for bang macros and
+// one for attribute-like macros (attributes, derives).
+// We ignore resolutions from one sub-namespace when searching names in scope for another.
+fn sub_namespace_mismatch(requirement: Option<MacroKind>, candidate: Option<MacroKind>) -> bool {
+ #[derive(PartialEq)]
+ enum SubNS { Bang, AttrLike }
+ let sub_ns = |kind| match kind {
+ MacroKind::Bang => Some(SubNS::Bang),
+ MacroKind::Attr | MacroKind::Derive => Some(SubNS::AttrLike),
+ MacroKind::ProcMacroStub => None,
+ };
+ let requirement = requirement.and_then(|kind| sub_ns(kind));
+ let candidate = candidate.and_then(|kind| sub_ns(kind));
+ // "No specific sub-namespace" means "matches anything" for both requirements and candidates.
+ candidate.is_some() && requirement.is_some() && candidate != requirement
}
impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
}
}
WhereToResolve::BuiltinAttrs => {
- // 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 kind == Some(MacroKind::Attr) && is_builtin_attr_name(ident.name) {
+ if is_builtin_attr_name(ident.name) {
let binding = (Def::NonMacroAttr(NonMacroAttrKind::Builtin),
ty::Visibility::Public, ident.span, Mark::root())
.to_name_binding(self.arenas);
match result {
Ok(result) => {
- if macro_kind_mismatch(ident.name, kind, result.0.macro_kind()) {
+ if sub_namespace_mismatch(kind, result.0.macro_kind()) {
continue_search!();
}
parent_scope: &ParentScope<'a>,
record_used: bool,
) -> Option<&'a NameBinding<'a>> {
- if macro_kind_mismatch(ident.name, kind, Some(MacroKind::Bang)) {
+ if sub_namespace_mismatch(kind, Some(MacroKind::Bang)) {
return None;
}
-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
-struct S;
-
fn main() {
inline!(); //~ ERROR cannot find macro `inline!` in this scope
}
-error: cannot find derive macro `inline` in this scope
- --> $DIR/macro-path-prelude-fail-3.rs:11:10
- |
-LL | #[derive(inline)] //~ ERROR cannot find derive macro `inline` in this scope
- | ^^^^^^
-
error: cannot find macro `inline!` in this scope
- --> $DIR/macro-path-prelude-fail-3.rs:15:5
+ --> $DIR/macro-path-prelude-fail-3.rs:2:5
|
LL | inline!(); //~ ERROR cannot find macro `inline!` in this scope
| ^^^^^^ help: you could try the macro: `line`
-error: aborting due to 2 previous errors
+error: aborting due to previous error