Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d929a42

Browse files
committedJun 25, 2024
Auto merge of rust-lang#125741 - petrochenkov:atvisord, r=davidtwco
ast: Standardize visiting order for attributes and node IDs This should only affect `macro_rules` scopes and order of diagnostics. Also add a deprecation lint for `macro_rules` called outside of their scope, like in rust-lang#124535.
2 parents c2d2bb3 + c4c7859 commit d929a42

21 files changed

+412
-186
lines changed
 

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ pub fn noop_flat_map_pat_field<T: MutVisitor>(
429429
) -> SmallVec<[PatField; 1]> {
430430
let PatField { attrs, id, ident, is_placeholder: _, is_shorthand: _, pat, span } = &mut fp;
431431
vis.visit_id(id);
432+
visit_attrs(attrs, vis);
432433
vis.visit_ident(ident);
433434
vis.visit_pat(pat);
434435
vis.visit_span(span);
435-
visit_attrs(attrs, vis);
436436
smallvec![fp]
437437
}
438438

@@ -443,8 +443,8 @@ fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
443443
UseTreeKind::Simple(rename) => visit_opt(rename, |rename| vis.visit_ident(rename)),
444444
UseTreeKind::Nested { items, .. } => {
445445
for (tree, id) in items {
446-
vis.visit_use_tree(tree);
447446
vis.visit_id(id);
447+
vis.visit_use_tree(tree);
448448
}
449449
}
450450
UseTreeKind::Glob => {}
@@ -454,8 +454,8 @@ fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
454454

455455
pub fn noop_flat_map_arm<T: MutVisitor>(mut arm: Arm, vis: &mut T) -> SmallVec<[Arm; 1]> {
456456
let Arm { attrs, pat, guard, body, span, id, is_placeholder: _ } = &mut arm;
457-
visit_attrs(attrs, vis);
458457
vis.visit_id(id);
458+
visit_attrs(attrs, vis);
459459
vis.visit_pat(pat);
460460
visit_opt(guard, |guard| vis.visit_expr(guard));
461461
visit_opt(body, |body| vis.visit_expr(body));
@@ -548,10 +548,10 @@ pub fn noop_flat_map_variant<T: MutVisitor>(
548548
visitor: &mut T,
549549
) -> SmallVec<[Variant; 1]> {
550550
let Variant { ident, vis, attrs, id, data, disr_expr, span, is_placeholder: _ } = &mut variant;
551+
visitor.visit_id(id);
552+
visit_attrs(attrs, visitor);
551553
visitor.visit_ident(ident);
552554
visitor.visit_vis(vis);
553-
visit_attrs(attrs, visitor);
554-
visitor.visit_id(id);
555555
visitor.visit_variant_data(data);
556556
visit_opt(disr_expr, |disr_expr| visitor.visit_anon_const(disr_expr));
557557
visitor.visit_span(span);
@@ -565,8 +565,8 @@ fn noop_visit_ident<T: MutVisitor>(Ident { name: _, span }: &mut Ident, vis: &mu
565565
fn noop_visit_path<T: MutVisitor>(Path { segments, span, tokens }: &mut Path, vis: &mut T) {
566566
vis.visit_span(span);
567567
for PathSegment { ident, id, args } in segments {
568-
vis.visit_ident(ident);
569568
vis.visit_id(id);
569+
vis.visit_ident(ident);
570570
visit_opt(args, |args| vis.visit_generic_args(args));
571571
}
572572
visit_lazy_tts(tokens, vis);
@@ -620,6 +620,7 @@ fn noop_visit_parenthesized_parameter_data<T: MutVisitor>(
620620
fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
621621
let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut();
622622
vis.visit_id(id);
623+
visit_attrs(attrs, vis);
623624
vis.visit_pat(pat);
624625
visit_opt(ty, |ty| vis.visit_ty(ty));
625626
match kind {
@@ -634,7 +635,6 @@ fn noop_visit_local<T: MutVisitor>(local: &mut P<Local>, vis: &mut T) {
634635
}
635636
vis.visit_span(span);
636637
visit_opt(colon_sp, |sp| vis.visit_span(sp));
637-
visit_attrs(attrs, vis);
638638
visit_lazy_tts(tokens, vis);
639639
}
640640

@@ -894,9 +894,9 @@ fn noop_visit_coroutine_kind<T: MutVisitor>(coroutine_kind: &mut CoroutineKind,
894894
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
895895
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id }
896896
| CoroutineKind::AsyncGen { span, closure_id, return_impl_trait_id } => {
897-
vis.visit_span(span);
898897
vis.visit_id(closure_id);
899898
vis.visit_id(return_impl_trait_id);
899+
vis.visit_span(span);
900900
}
901901
}
902902
}
@@ -932,8 +932,8 @@ fn noop_visit_precise_capturing_arg<T: MutVisitor>(arg: &mut PreciseCapturingArg
932932
vis.visit_lifetime(lt);
933933
}
934934
PreciseCapturingArg::Arg(path, id) => {
935-
vis.visit_path(path);
936935
vis.visit_id(id);
936+
vis.visit_path(path);
937937
}
938938
}
939939
}
@@ -944,11 +944,11 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
944944
) -> SmallVec<[GenericParam; 1]> {
945945
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param;
946946
vis.visit_id(id);
947+
visit_attrs(attrs, vis);
947948
vis.visit_ident(ident);
948949
if let Some(colon_span) = colon_span {
949950
vis.visit_span(colon_span);
950951
}
951-
visit_attrs(attrs, vis);
952952
visit_vec(bounds, |bound| noop_visit_param_bound(bound, vis));
953953
match kind {
954954
GenericParamKind::Lifetime => {}
@@ -1015,16 +1015,16 @@ fn noop_visit_variant_data<T: MutVisitor>(vdata: &mut VariantData, vis: &mut T)
10151015
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
10161016
}
10171017
VariantData::Tuple(fields, id) => {
1018-
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
10191018
vis.visit_id(id);
1019+
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
10201020
}
10211021
VariantData::Unit(id) => vis.visit_id(id),
10221022
}
10231023
}
10241024

10251025
fn noop_visit_trait_ref<T: MutVisitor>(TraitRef { path, ref_id }: &mut TraitRef, vis: &mut T) {
1026-
vis.visit_path(path);
10271026
vis.visit_id(ref_id);
1027+
vis.visit_path(path);
10281028
}
10291029

10301030
fn noop_visit_poly_trait_ref<T: MutVisitor>(p: &mut PolyTraitRef, vis: &mut T) {
@@ -1039,12 +1039,12 @@ pub fn noop_flat_map_field_def<T: MutVisitor>(
10391039
visitor: &mut T,
10401040
) -> SmallVec<[FieldDef; 1]> {
10411041
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
1042+
visitor.visit_id(id);
1043+
visit_attrs(attrs, visitor);
10421044
visitor.visit_span(span);
10431045
visit_opt(ident, |ident| visitor.visit_ident(ident));
10441046
visitor.visit_vis(vis);
1045-
visitor.visit_id(id);
10461047
visitor.visit_ty(ty);
1047-
visit_attrs(attrs, visitor);
10481048
smallvec![fd]
10491049
}
10501050

@@ -1053,11 +1053,11 @@ pub fn noop_flat_map_expr_field<T: MutVisitor>(
10531053
vis: &mut T,
10541054
) -> SmallVec<[ExprField; 1]> {
10551055
let ExprField { ident, expr, span, is_shorthand: _, attrs, id, is_placeholder: _ } = &mut f;
1056+
vis.visit_id(id);
1057+
visit_attrs(attrs, vis);
10561058
vis.visit_ident(ident);
10571059
vis.visit_expr(expr);
1058-
vis.visit_id(id);
10591060
vis.visit_span(span);
1060-
visit_attrs(attrs, vis);
10611061
smallvec![f]
10621062
}
10631063

@@ -1429,6 +1429,8 @@ pub fn noop_visit_expr<T: MutVisitor>(
14291429
Expr { kind, id, span, attrs, tokens }: &mut Expr,
14301430
vis: &mut T,
14311431
) {
1432+
vis.visit_id(id);
1433+
visit_attrs(attrs, vis);
14321434
match kind {
14331435
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
14341436
ExprKind::ConstBlock(anon_const) => {
@@ -1449,8 +1451,8 @@ pub fn noop_visit_expr<T: MutVisitor>(
14491451
args: call_args,
14501452
span,
14511453
}) => {
1452-
vis.visit_ident(ident);
14531454
vis.visit_id(id);
1455+
vis.visit_ident(ident);
14541456
visit_opt(seg_args, |args| vis.visit_generic_args(args));
14551457
vis.visit_method_receiver_expr(receiver);
14561458
visit_thin_exprs(call_args, vis);
@@ -1601,9 +1603,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
16011603
ExprKind::TryBlock(body) => vis.visit_block(body),
16021604
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err(_) | ExprKind::Dummy => {}
16031605
}
1604-
vis.visit_id(id);
16051606
vis.visit_span(span);
1606-
visit_attrs(attrs, vis);
16071607
visit_lazy_tts(tokens, vis);
16081608
}
16091609

@@ -1645,8 +1645,8 @@ fn noop_flat_map_stmt_kind<T: MutVisitor>(kind: StmtKind, vis: &mut T) -> SmallV
16451645
StmtKind::Empty => smallvec![StmtKind::Empty],
16461646
StmtKind::MacCall(mut mac) => {
16471647
let MacCallStmt { mac: mac_, style: _, attrs, tokens } = mac.deref_mut();
1648-
vis.visit_mac_call(mac_);
16491648
visit_attrs(attrs, vis);
1649+
vis.visit_mac_call(mac_);
16501650
visit_lazy_tts(tokens, vis);
16511651
smallvec![StmtKind::MacCall(mac)]
16521652
}
@@ -1657,8 +1657,8 @@ fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
16571657
match &mut visibility.kind {
16581658
VisibilityKind::Public | VisibilityKind::Inherited => {}
16591659
VisibilityKind::Restricted { path, id, shorthand: _ } => {
1660-
vis.visit_path(path);
16611660
vis.visit_id(id);
1661+
vis.visit_path(path);
16621662
}
16631663
}
16641664
vis.visit_span(&mut visibility.span);

‎compiler/rustc_ast/src/visit.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ pub trait Visitor<'ast>: Sized {
298298
}
299299

300300
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
301-
walk_list!(visitor, visit_item, &krate.items);
302301
walk_list!(visitor, visit_attribute, &krate.attrs);
302+
walk_list!(visitor, visit_item, &krate.items);
303303
V::Result::output()
304304
}
305305

@@ -462,25 +462,25 @@ pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) -
462462
where
463463
V: Visitor<'a>,
464464
{
465+
walk_list!(visitor, visit_attribute, &variant.attrs);
465466
try_visit!(visitor.visit_ident(variant.ident));
466467
try_visit!(visitor.visit_vis(&variant.vis));
467468
try_visit!(visitor.visit_variant_data(&variant.data));
468469
visit_opt!(visitor, visit_variant_discr, &variant.disr_expr);
469-
walk_list!(visitor, visit_attribute, &variant.attrs);
470470
V::Result::output()
471471
}
472472

473473
pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
474+
walk_list!(visitor, visit_attribute, &f.attrs);
474475
try_visit!(visitor.visit_expr(&f.expr));
475476
try_visit!(visitor.visit_ident(f.ident));
476-
walk_list!(visitor, visit_attribute, &f.attrs);
477477
V::Result::output()
478478
}
479479

480480
pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
481+
walk_list!(visitor, visit_attribute, &fp.attrs);
481482
try_visit!(visitor.visit_ident(fp.ident));
482483
try_visit!(visitor.visit_pat(&fp.pat));
483-
walk_list!(visitor, visit_attribute, &fp.attrs);
484484
V::Result::output()
485485
}
486486

@@ -722,8 +722,8 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(
722722
visitor: &mut V,
723723
param: &'a GenericParam,
724724
) -> V::Result {
725-
try_visit!(visitor.visit_ident(param.ident));
726725
walk_list!(visitor, visit_attribute, &param.attrs);
726+
try_visit!(visitor.visit_ident(param.ident));
727727
walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound);
728728
match &param.kind {
729729
GenericParamKind::Lifetime => (),
@@ -882,10 +882,10 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
882882
ctxt: AssocCtxt,
883883
) -> V::Result {
884884
let &Item { id: _, span: _, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
885+
walk_list!(visitor, visit_attribute, attrs);
885886
try_visit!(visitor.visit_vis(vis));
886887
try_visit!(visitor.visit_ident(ident));
887888
try_visit!(kind.walk(item, ctxt, visitor));
888-
walk_list!(visitor, visit_attribute, attrs);
889889
V::Result::output()
890890
}
891891

@@ -898,10 +898,10 @@ pub fn walk_struct_def<'a, V: Visitor<'a>>(
898898
}
899899

900900
pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result {
901+
walk_list!(visitor, visit_attribute, &field.attrs);
901902
try_visit!(visitor.visit_vis(&field.vis));
902903
visit_opt!(visitor, visit_ident, field.ident);
903904
try_visit!(visitor.visit_ty(&field.ty));
904-
walk_list!(visitor, visit_attribute, &field.attrs);
905905
V::Result::output()
906906
}
907907

@@ -918,8 +918,8 @@ pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V:
918918
StmtKind::Empty => {}
919919
StmtKind::MacCall(mac) => {
920920
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
921-
try_visit!(visitor.visit_mac_call(mac));
922921
walk_list!(visitor, visit_attribute, attrs);
922+
try_visit!(visitor.visit_mac_call(mac));
923923
}
924924
}
925925
V::Result::output()
@@ -1141,10 +1141,10 @@ pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::R
11411141
}
11421142

11431143
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result {
1144+
walk_list!(visitor, visit_attribute, &arm.attrs);
11441145
try_visit!(visitor.visit_pat(&arm.pat));
11451146
visit_opt!(visitor, visit_expr, &arm.guard);
11461147
visit_opt!(visitor, visit_expr, &arm.body);
1147-
walk_list!(visitor, visit_attribute, &arm.attrs);
11481148
V::Result::output()
11491149
}
11501150

‎compiler/rustc_lint/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
604604
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
605605
.suggestion = use pat_param to preserve semantics
606606
607+
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in this scope
608+
.help = import `macro_rules` with `use` to make it callable above its definition
609+
607610
lint_overflowing_bin_hex = literal out of range for `{$ty}`
608611
.negative_note = the literal `{$lit}` (decimal `{$dec}`) does not fit into the type `{$ty}`
609612
.negative_becomes_note = and the value `-{$lit}` will become `{$actually}{$ty}`

‎compiler/rustc_lint/src/context/diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,8 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
434434
lints::InnerAttributeUnstable::CustomInnerAttribute
435435
}
436436
.decorate_lint(diag),
437+
BuiltinLintDiag::OutOfScopeMacroCalls { path } => {
438+
lints::OutOfScopeMacroCalls { path }.decorate_lint(diag)
439+
}
437440
}
438441
}

‎compiler/rustc_lint/src/lints.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,3 +2911,10 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion {
29112911
#[suggestion_part(code = ")")]
29122912
pub right: Span,
29132913
}
2914+
2915+
#[derive(LintDiagnostic)]
2916+
#[diag(lint_out_of_scope_macro_calls)]
2917+
#[help]
2918+
pub struct OutOfScopeMacroCalls {
2919+
pub path: String,
2920+
}

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4945,3 +4945,42 @@ declare_lint! {
49454945
reference: "issue #123757 <https://github.com/rust-lang/rust/issues/123757>",
49464946
};
49474947
}
4948+
4949+
declare_lint! {
4950+
/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
4951+
/// above their definition, which may happen in key-value attributes.
4952+
///
4953+
/// ### Example
4954+
///
4955+
/// ```rust
4956+
/// #![doc = in_root!()]
4957+
///
4958+
/// macro_rules! in_root { () => { "" } }
4959+
///
4960+
/// fn main() {}
4961+
/// ```
4962+
///
4963+
/// {{produces}}
4964+
///
4965+
/// ### Explanation
4966+
///
4967+
/// The scope in which a `macro_rules` item is visible starts at that item and continues
4968+
/// below it. This is more similar to `let` than to other items, which are in scope both above
4969+
/// and below their definition.
4970+
/// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
4971+
/// above their definition. The lint catches such cases.
4972+
/// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
4973+
/// with `use`.
4974+
///
4975+
/// This is a [future-incompatible] lint to transition this to a
4976+
/// hard error in the future.
4977+
///
4978+
/// [future-incompatible]: ../index.md#future-incompatible-lints
4979+
pub OUT_OF_SCOPE_MACRO_CALLS,
4980+
Warn,
4981+
"detects out of scope calls to `macro_rules` in key-value attributes",
4982+
@future_incompatible = FutureIncompatibleInfo {
4983+
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
4984+
reference: "issue #124535 <https://github.com/rust-lang/rust/issues/124535>",
4985+
};
4986+
}

‎compiler/rustc_lint_defs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,9 @@ pub enum BuiltinLintDiag {
744744
InnerAttributeUnstable {
745745
is_macro: bool,
746746
},
747+
OutOfScopeMacroCalls {
748+
path: String,
749+
},
747750
}
748751

749752
/// Lints that are buffered up early on in the `Session` before the

‎compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{Determinacy, ExternPreludeEntry, Finalize, Module, ModuleKind, Modul
1414
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, ResolutionError};
1515
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, Used, VisResolutionError};
1616

17-
use rustc_ast::visit::{self, AssocCtxt, Visitor};
17+
use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind};
1818
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
1919
use rustc_ast::{Block, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
2020
use rustc_attr as attr;
@@ -1313,7 +1313,17 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
13131313
_ => {
13141314
let orig_macro_rules_scope = self.parent_scope.macro_rules;
13151315
self.build_reduced_graph_for_item(item);
1316-
visit::walk_item(self, item);
1316+
match item.kind {
1317+
ItemKind::Mod(..) => {
1318+
// Visit attributes after items for backward compatibility.
1319+
// This way they can use `macro_rules` defined later.
1320+
self.visit_vis(&item.vis);
1321+
self.visit_ident(item.ident);
1322+
item.kind.walk(item, AssocCtxt::Trait, self);
1323+
visit::walk_list!(self, visit_attribute, &item.attrs);
1324+
}
1325+
_ => visit::walk_item(self, item),
1326+
}
13171327
match item.kind {
13181328
ItemKind::Mod(..) if self.contains_macro_use(&item.attrs) => {
13191329
self.parent_scope.macro_rules
@@ -1514,7 +1524,10 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
15141524
if krate.is_placeholder {
15151525
self.visit_invoc_in_module(krate.id);
15161526
} else {
1517-
visit::walk_crate(self, krate);
1527+
// Visit attributes after items for backward compatibility.
1528+
// This way they can use `macro_rules` defined later.
1529+
visit::walk_list!(self, visit_item, &krate.items);
1530+
visit::walk_list!(self, visit_attribute, &krate.attrs);
15181531
self.contains_macro_use(&krate.attrs);
15191532
}
15201533
}

‎compiler/rustc_resolve/src/macros.rs

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::errors::CannotDetermineMacroResolution;
55
use crate::errors::{self, AddAsNonDerive, CannotFindIdentInThisScope};
66
use crate::errors::{MacroExpectedFound, RemoveSurroundingDerive};
77
use crate::Namespace::*;
8-
use crate::{BindingKey, BuiltinMacroState, Determinacy, MacroData, Used};
8+
use crate::{BindingKey, BuiltinMacroState, Determinacy, MacroData, NameBindingKind, Used};
99
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
1010
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment, ToNameBinding};
1111
use rustc_ast::expand::StrippedCfgItem;
@@ -18,15 +18,18 @@ use rustc_errors::{Applicability, StashKey};
1818
use rustc_expand::base::{Annotatable, DeriveResolution, Indeterminate, ResolverExpand};
1919
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
2020
use rustc_expand::compile_declarative_macro;
21-
use rustc_expand::expand::{AstFragment, Invocation, InvocationKind, SupportsMacroExpansion};
21+
use rustc_expand::expand::{
22+
AstFragment, AstFragmentKind, Invocation, InvocationKind, SupportsMacroExpansion,
23+
};
2224
use rustc_hir::def::{self, DefKind, Namespace, NonMacroAttrKind};
2325
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
2426
use rustc_middle::middle::stability;
2527
use rustc_middle::ty::RegisteredTools;
2628
use rustc_middle::ty::{TyCtxt, Visibility};
27-
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
28-
use rustc_session::lint::builtin::{LEGACY_DERIVE_HELPERS, SOFT_UNSTABLE};
29-
use rustc_session::lint::builtin::{UNUSED_MACROS, UNUSED_MACRO_RULES};
29+
use rustc_session::lint::builtin::{
30+
LEGACY_DERIVE_HELPERS, OUT_OF_SCOPE_MACRO_CALLS, SOFT_UNSTABLE,
31+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_MACROS, UNUSED_MACRO_RULES,
32+
};
3033
use rustc_session::lint::BuiltinLintDiag;
3134
use rustc_session::parse::feature_err;
3235
use rustc_span::edit_distance::edit_distance;
@@ -289,6 +292,16 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
289292
let parent_scope = &ParentScope { derives, ..parent_scope };
290293
let supports_macro_expansion = invoc.fragment_kind.supports_macro_expansion();
291294
let node_id = invoc.expansion_data.lint_node_id;
295+
// This is a heuristic, but it's good enough for the lint.
296+
let looks_like_invoc_in_mod_inert_attr = self
297+
.invocation_parents
298+
.get(&invoc_id)
299+
.or_else(|| self.invocation_parents.get(&eager_expansion_root))
300+
.map(|&(mod_def_id, _)| mod_def_id)
301+
.filter(|&mod_def_id| {
302+
invoc.fragment_kind == AstFragmentKind::Expr
303+
&& self.tcx.def_kind(mod_def_id) == DefKind::Mod
304+
});
292305
let (ext, res) = self.smart_resolve_macro_path(
293306
path,
294307
kind,
@@ -299,6 +312,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
299312
force,
300313
soft_custom_inner_attributes_gate(path, invoc),
301314
deleg_impl,
315+
looks_like_invoc_in_mod_inert_attr,
302316
)?;
303317

304318
let span = invoc.span();
@@ -521,6 +535,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
521535
force: bool,
522536
soft_custom_inner_attributes_gate: bool,
523537
deleg_impl: Option<LocalDefId>,
538+
invoc_in_mod_inert_attr: Option<LocalDefId>,
524539
) -> Result<(Lrc<SyntaxExtension>, Res), Indeterminate> {
525540
let (ext, res) = match self.resolve_macro_or_delegation_path(
526541
path,
@@ -529,6 +544,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
529544
true,
530545
force,
531546
deleg_impl,
547+
invoc_in_mod_inert_attr.map(|def_id| (def_id, node_id)),
532548
) {
533549
Ok((Some(ext), res)) => (ext, res),
534550
Ok((None, res)) => (self.dummy_ext(kind), res),
@@ -683,20 +699,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
683699
trace: bool,
684700
force: bool,
685701
) -> Result<(Option<Lrc<SyntaxExtension>>, Res), Determinacy> {
686-
self.resolve_macro_or_delegation_path(path, kind, parent_scope, trace, force, None)
702+
self.resolve_macro_or_delegation_path(path, kind, parent_scope, trace, force, None, None)
687703
}
688704

689705
fn resolve_macro_or_delegation_path(
690706
&mut self,
691-
path: &ast::Path,
707+
ast_path: &ast::Path,
692708
kind: Option<MacroKind>,
693709
parent_scope: &ParentScope<'a>,
694710
trace: bool,
695711
force: bool,
696712
deleg_impl: Option<LocalDefId>,
713+
invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>,
697714
) -> Result<(Option<Lrc<SyntaxExtension>>, Res), Determinacy> {
698-
let path_span = path.span;
699-
let mut path = Segment::from_path(path);
715+
let path_span = ast_path.span;
716+
let mut path = Segment::from_path(ast_path);
700717

701718
// Possibly apply the macro helper hack
702719
if deleg_impl.is_none()
@@ -762,6 +779,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
762779

763780
let res = binding.map(|binding| binding.res());
764781
self.prohibit_imported_non_macro_attrs(binding.ok(), res.ok(), path_span);
782+
self.report_out_of_scope_macro_calls(
783+
ast_path,
784+
parent_scope,
785+
invoc_in_mod_inert_attr,
786+
binding.ok(),
787+
);
765788
res
766789
};
767790

@@ -1014,6 +1037,45 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10141037
}
10151038
}
10161039

1040+
fn report_out_of_scope_macro_calls(
1041+
&mut self,
1042+
path: &ast::Path,
1043+
parent_scope: &ParentScope<'a>,
1044+
invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>,
1045+
binding: Option<NameBinding<'a>>,
1046+
) {
1047+
if let Some((mod_def_id, node_id)) = invoc_in_mod_inert_attr
1048+
&& let Some(binding) = binding
1049+
// This is a `macro_rules` itself, not some import.
1050+
&& let NameBindingKind::Res(res) = binding.kind
1051+
&& let Res::Def(DefKind::Macro(MacroKind::Bang), def_id) = res
1052+
// And the `macro_rules` is defined inside the attribute's module,
1053+
// so it cannot be in scope unless imported.
1054+
&& self.tcx.is_descendant_of(def_id, mod_def_id.to_def_id())
1055+
{
1056+
// Try to resolve our ident ignoring `macro_rules` scopes.
1057+
// If such resolution is successful and gives the same result
1058+
// (e.g. if the macro is re-imported), then silence the lint.
1059+
let no_macro_rules = self.arenas.alloc_macro_rules_scope(MacroRulesScope::Empty);
1060+
let fallback_binding = self.early_resolve_ident_in_lexical_scope(
1061+
path.segments[0].ident,
1062+
ScopeSet::Macro(MacroKind::Bang),
1063+
&ParentScope { macro_rules: no_macro_rules, ..*parent_scope },
1064+
None,
1065+
false,
1066+
None,
1067+
);
1068+
if fallback_binding.ok().and_then(|b| b.res().opt_def_id()) != Some(def_id) {
1069+
self.tcx.sess.psess.buffer_lint(
1070+
OUT_OF_SCOPE_MACRO_CALLS,
1071+
path.span,
1072+
node_id,
1073+
BuiltinLintDiag::OutOfScopeMacroCalls { path: pprust::path_to_string(path) },
1074+
);
1075+
}
1076+
}
1077+
}
1078+
10171079
pub(crate) fn check_reserved_macro_name(&mut self, ident: Ident, res: Res) {
10181080
// Reserve some names that are not quite covered by the general check
10191081
// performed on `Resolver::builtin_attrs`.

‎src/tools/clippy/tests/ui/cfg_attr_cargo_clippy.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
error: `feature = "cargo-clippy"` was replaced by `clippy`
2-
--> tests/ui/cfg_attr_cargo_clippy.rs:5:12
2+
--> tests/ui/cfg_attr_cargo_clippy.rs:3:13
33
|
4-
LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
4+
LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
66
|
77
= note: `-D clippy::deprecated-clippy-cfg-attr` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::deprecated_clippy_cfg_attr)]`
99

10+
error: `feature = "cargo-clippy"` was replaced by `clippy`
11+
--> tests/ui/cfg_attr_cargo_clippy.rs:5:12
12+
|
13+
LL | #[cfg_attr(feature = "cargo-clippy", derive(Debug))]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
15+
1016
error: `feature = "cargo-clippy"` was replaced by `clippy`
1117
--> tests/ui/cfg_attr_cargo_clippy.rs:6:16
1218
|
@@ -37,11 +43,5 @@ error: `feature = "cargo-clippy"` was replaced by `clippy`
3743
LL | #[cfg(all(feature = "cargo-clippy"))]
3844
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
3945

40-
error: `feature = "cargo-clippy"` was replaced by `clippy`
41-
--> tests/ui/cfg_attr_cargo_clippy.rs:3:13
42-
|
43-
LL | #![cfg_attr(feature = "cargo-clippy", doc = "a")]
44-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `clippy`
45-
4646
error: aborting due to 7 previous errors
4747

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
error: using tabs in doc comments is not recommended
2-
--> tests/ui/tabs_in_doc_comments.rs:10:9
2+
--> tests/ui/tabs_in_doc_comments.rs:6:5
33
|
4-
LL | /// - First String:
5-
| ^^^^ help: consider using four spaces per tab
4+
LL | /// - first one
5+
| ^^^^ help: consider using four spaces per tab
66
|
77
= note: `-D clippy::tabs-in-doc-comments` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::tabs_in_doc_comments)]`
99

1010
error: using tabs in doc comments is not recommended
11-
--> tests/ui/tabs_in_doc_comments.rs:11:9
11+
--> tests/ui/tabs_in_doc_comments.rs:6:13
1212
|
13-
LL | /// - needs to be inside here
14-
| ^^^^^^^^ help: consider using four spaces per tab
13+
LL | /// - first one
14+
| ^^^^^^^^ help: consider using four spaces per tab
1515

1616
error: using tabs in doc comments is not recommended
17-
--> tests/ui/tabs_in_doc_comments.rs:14:9
17+
--> tests/ui/tabs_in_doc_comments.rs:7:5
1818
|
19-
LL | /// - Second String:
20-
| ^^^^ help: consider using four spaces per tab
19+
LL | /// - second one
20+
| ^^^^ help: consider using four spaces per tab
2121

2222
error: using tabs in doc comments is not recommended
23-
--> tests/ui/tabs_in_doc_comments.rs:15:9
23+
--> tests/ui/tabs_in_doc_comments.rs:7:14
2424
|
25-
LL | /// - needs to be inside here
26-
| ^^^^^^^^ help: consider using four spaces per tab
25+
LL | /// - second one
26+
| ^^^^ help: consider using four spaces per tab
2727

2828
error: using tabs in doc comments is not recommended
29-
--> tests/ui/tabs_in_doc_comments.rs:6:5
29+
--> tests/ui/tabs_in_doc_comments.rs:10:9
3030
|
31-
LL | /// - first one
32-
| ^^^^ help: consider using four spaces per tab
31+
LL | /// - First String:
32+
| ^^^^ help: consider using four spaces per tab
3333

3434
error: using tabs in doc comments is not recommended
35-
--> tests/ui/tabs_in_doc_comments.rs:6:13
35+
--> tests/ui/tabs_in_doc_comments.rs:11:9
3636
|
37-
LL | /// - first one
38-
| ^^^^^^^^ help: consider using four spaces per tab
37+
LL | /// - needs to be inside here
38+
| ^^^^^^^^ help: consider using four spaces per tab
3939

4040
error: using tabs in doc comments is not recommended
41-
--> tests/ui/tabs_in_doc_comments.rs:7:5
41+
--> tests/ui/tabs_in_doc_comments.rs:14:9
4242
|
43-
LL | /// - second one
44-
| ^^^^ help: consider using four spaces per tab
43+
LL | /// - Second String:
44+
| ^^^^ help: consider using four spaces per tab
4545

4646
error: using tabs in doc comments is not recommended
47-
--> tests/ui/tabs_in_doc_comments.rs:7:14
47+
--> tests/ui/tabs_in_doc_comments.rs:15:9
4848
|
49-
LL | /// - second one
50-
| ^^^^ help: consider using four spaces per tab
49+
LL | /// - needs to be inside here
50+
| ^^^^^^^^ help: consider using four spaces per tab
5151

5252
error: aborting due to 8 previous errors
5353

‎src/tools/clippy/tests/ui/unnecessary_clippy_cfg.stderr

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
error: no need to put clippy lints behind a `clippy` cfg
2-
--> tests/ui/unnecessary_clippy_cfg.rs:13:1
2+
--> tests/ui/unnecessary_clippy_cfg.rs:4:1
33
|
4-
LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]`
4+
LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]`
66
|
77
= note: `-D clippy::unnecessary-clippy-cfg` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_clippy_cfg)]`
99

1010
error: no need to put clippy lints behind a `clippy` cfg
11-
--> tests/ui/unnecessary_clippy_cfg.rs:15:36
11+
--> tests/ui/unnecessary_clippy_cfg.rs:6:37
1212
|
13-
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^
13+
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^
1515
|
16-
= note: write instead: `#[deny(clippy::non_minimal_cfg)]`
16+
= note: write instead: `#![deny(clippy::non_minimal_cfg)]`
1717

1818
error: no need to put clippy lints behind a `clippy` cfg
19-
--> tests/ui/unnecessary_clippy_cfg.rs:17:36
19+
--> tests/ui/unnecessary_clippy_cfg.rs:8:37
2020
|
21-
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
22-
| ^^^^^^^^^^^^^^^^^^^^^^^
21+
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
22+
| ^^^^^^^^^^^^^^^^^^^^^^^
2323
|
24-
= note: write instead: `#[deny(clippy::non_minimal_cfg)]`
24+
= note: write instead: `#![deny(clippy::non_minimal_cfg)]`
2525

2626
error: no need to put clippy lints behind a `clippy` cfg
27-
--> tests/ui/unnecessary_clippy_cfg.rs:19:1
27+
--> tests/ui/unnecessary_clippy_cfg.rs:10:1
2828
|
29-
LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]`
29+
LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]`
3131

3232
error: no need to put clippy lints behind a `clippy` cfg
33-
--> tests/ui/unnecessary_clippy_cfg.rs:4:1
33+
--> tests/ui/unnecessary_clippy_cfg.rs:13:1
3434
|
35-
LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]`
35+
LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]`
3737

3838
error: no need to put clippy lints behind a `clippy` cfg
39-
--> tests/ui/unnecessary_clippy_cfg.rs:6:37
39+
--> tests/ui/unnecessary_clippy_cfg.rs:15:36
4040
|
41-
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
42-
| ^^^^^^^^^^^^^^^^^^^^^^^
41+
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
42+
| ^^^^^^^^^^^^^^^^^^^^^^^
4343
|
44-
= note: write instead: `#![deny(clippy::non_minimal_cfg)]`
44+
= note: write instead: `#[deny(clippy::non_minimal_cfg)]`
4545

4646
error: no need to put clippy lints behind a `clippy` cfg
47-
--> tests/ui/unnecessary_clippy_cfg.rs:8:37
47+
--> tests/ui/unnecessary_clippy_cfg.rs:17:36
4848
|
49-
LL | #![cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
50-
| ^^^^^^^^^^^^^^^^^^^^^^^
49+
LL | #[cfg_attr(clippy, deny(dead_code, clippy::non_minimal_cfg))]
50+
| ^^^^^^^^^^^^^^^^^^^^^^^
5151
|
52-
= note: write instead: `#![deny(clippy::non_minimal_cfg)]`
52+
= note: write instead: `#[deny(clippy::non_minimal_cfg)]`
5353

5454
error: no need to put clippy lints behind a `clippy` cfg
55-
--> tests/ui/unnecessary_clippy_cfg.rs:10:1
55+
--> tests/ui/unnecessary_clippy_cfg.rs:19:1
5656
|
57-
LL | #![cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
58-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#![deny(clippy::non_minimal_cfg)]`
57+
LL | #[cfg_attr(clippy, deny(clippy::non_minimal_cfg))]
58+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `#[deny(clippy::non_minimal_cfg)]`
5959

6060
error: duplicated attribute
6161
--> tests/ui/unnecessary_clippy_cfg.rs:8:26
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Imports suppress the `out_of_scope_macro_calls` lint.
2+
3+
//@ check-pass
4+
//@ edition:2018
5+
6+
#![doc = in_root!()]
7+
8+
macro_rules! in_root { () => { "" } }
9+
use in_root;
10+
11+
mod macros_stay {
12+
#![doc = in_mod!()]
13+
14+
macro_rules! in_mod { () => { "" } }
15+
use in_mod;
16+
}
17+
18+
fn main() {}

‎tests/ui/attributes/key-value-expansion-scope.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#![doc = in_root!()] // FIXME, this is a bug
1+
#![doc = in_root!()] //~ WARN cannot find macro `in_root` in this scope
2+
//~| WARN this was previously accepted by the compiler
23
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
3-
#![doc = in_mod_escape!()] // FIXME, this is a bug
4+
#![doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape` in this scope
5+
//~| WARN this was previously accepted by the compiler
46
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
57

68
#[doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope
@@ -16,8 +18,11 @@ fn before() {
1618

1719
macro_rules! in_root { () => { "" } }
1820

21+
#[doc = in_mod!()] //~ WARN cannot find macro `in_mod` in this scope
22+
//~| WARN this was previously accepted by the compiler
1923
mod macros_stay {
20-
#![doc = in_mod!()] // FIXME, this is a bug
24+
#![doc = in_mod!()] //~ WARN cannot find macro `in_mod` in this scope
25+
//~| WARN this was previously accepted by the compiler
2126

2227
macro_rules! in_mod { () => { "" } }
2328

@@ -28,8 +33,11 @@ mod macros_stay {
2833
}
2934

3035
#[macro_use]
36+
#[doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape` in this scope
37+
//~| WARN this was previously accepted by the compiler
3138
mod macros_escape {
32-
#![doc = in_mod_escape!()] // FIXME, this is a bug
39+
#![doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape` in this scope
40+
//~| WARN this was previously accepted by the compiler
3341

3442
macro_rules! in_mod_escape { () => { "" } }
3543

@@ -39,8 +47,9 @@ mod macros_escape {
3947
}
4048
}
4149

50+
#[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
4251
fn block() {
43-
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
52+
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
4453

4554
macro_rules! in_block { () => { "" } }
4655

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,191 @@
11
error: cannot find macro `in_mod` in this scope
2-
--> $DIR/key-value-expansion-scope.rs:2:10
2+
--> $DIR/key-value-expansion-scope.rs:3:10
33
|
44
LL | #![doc = in_mod!()]
55
| ^^^^^^
66
|
77
= help: have you added the `#[macro_use]` on the module/import?
88

99
error: cannot find macro `in_block` in this scope
10-
--> $DIR/key-value-expansion-scope.rs:4:10
10+
--> $DIR/key-value-expansion-scope.rs:6:10
1111
|
1212
LL | #![doc = in_block!()]
1313
| ^^^^^^^^
1414
|
1515
= help: have you added the `#[macro_use]` on the module/import?
1616

1717
error: cannot find macro `in_root` in this scope
18-
--> $DIR/key-value-expansion-scope.rs:6:9
18+
--> $DIR/key-value-expansion-scope.rs:8:9
1919
|
2020
LL | #[doc = in_root!()]
2121
| ^^^^^^^
2222
|
2323
= help: have you added the `#[macro_use]` on the module/import?
2424

2525
error: cannot find macro `in_mod` in this scope
26-
--> $DIR/key-value-expansion-scope.rs:7:9
26+
--> $DIR/key-value-expansion-scope.rs:9:9
2727
|
2828
LL | #[doc = in_mod!()]
2929
| ^^^^^^
3030
|
3131
= help: have you added the `#[macro_use]` on the module/import?
3232

3333
error: cannot find macro `in_mod_escape` in this scope
34-
--> $DIR/key-value-expansion-scope.rs:8:9
34+
--> $DIR/key-value-expansion-scope.rs:10:9
3535
|
3636
LL | #[doc = in_mod_escape!()]
3737
| ^^^^^^^^^^^^^
3838
|
3939
= help: have you added the `#[macro_use]` on the module/import?
4040

4141
error: cannot find macro `in_block` in this scope
42-
--> $DIR/key-value-expansion-scope.rs:9:9
42+
--> $DIR/key-value-expansion-scope.rs:11:9
4343
|
4444
LL | #[doc = in_block!()]
4545
| ^^^^^^^^
4646
|
4747
= help: have you added the `#[macro_use]` on the module/import?
4848

4949
error: cannot find macro `in_root` in this scope
50-
--> $DIR/key-value-expansion-scope.rs:11:14
50+
--> $DIR/key-value-expansion-scope.rs:13:14
5151
|
5252
LL | #![doc = in_root!()]
5353
| ^^^^^^^
5454
|
5555
= help: have you added the `#[macro_use]` on the module/import?
5656

5757
error: cannot find macro `in_mod` in this scope
58-
--> $DIR/key-value-expansion-scope.rs:12:14
58+
--> $DIR/key-value-expansion-scope.rs:14:14
5959
|
6060
LL | #![doc = in_mod!()]
6161
| ^^^^^^
6262
|
6363
= help: have you added the `#[macro_use]` on the module/import?
6464

6565
error: cannot find macro `in_mod_escape` in this scope
66-
--> $DIR/key-value-expansion-scope.rs:13:14
66+
--> $DIR/key-value-expansion-scope.rs:15:14
6767
|
6868
LL | #![doc = in_mod_escape!()]
6969
| ^^^^^^^^^^^^^
7070
|
7171
= help: have you added the `#[macro_use]` on the module/import?
7272

7373
error: cannot find macro `in_block` in this scope
74-
--> $DIR/key-value-expansion-scope.rs:14:14
74+
--> $DIR/key-value-expansion-scope.rs:16:14
7575
|
7676
LL | #![doc = in_block!()]
7777
| ^^^^^^^^
7878
|
7979
= help: have you added the `#[macro_use]` on the module/import?
8080

8181
error: cannot find macro `in_block` in this scope
82-
--> $DIR/key-value-expansion-scope.rs:43:14
82+
--> $DIR/key-value-expansion-scope.rs:50:9
83+
|
84+
LL | #[doc = in_block!()]
85+
| ^^^^^^^^
86+
|
87+
= help: have you added the `#[macro_use]` on the module/import?
88+
89+
error: cannot find macro `in_block` in this scope
90+
--> $DIR/key-value-expansion-scope.rs:52:14
8391
|
8492
LL | #![doc = in_block!()]
8593
| ^^^^^^^^
8694
|
8795
= help: have you added the `#[macro_use]` on the module/import?
8896

8997
error: cannot find macro `in_mod` in this scope
90-
--> $DIR/key-value-expansion-scope.rs:54:9
98+
--> $DIR/key-value-expansion-scope.rs:63:9
9199
|
92100
LL | #[doc = in_mod!()]
93101
| ^^^^^^
94102
|
95103
= help: have you added the `#[macro_use]` on the module/import?
96104

97105
error: cannot find macro `in_block` in this scope
98-
--> $DIR/key-value-expansion-scope.rs:56:9
106+
--> $DIR/key-value-expansion-scope.rs:65:9
99107
|
100108
LL | #[doc = in_block!()]
101109
| ^^^^^^^^
102110
|
103111
= help: have you added the `#[macro_use]` on the module/import?
104112

105113
error: cannot find macro `in_mod` in this scope
106-
--> $DIR/key-value-expansion-scope.rs:59:14
114+
--> $DIR/key-value-expansion-scope.rs:68:14
107115
|
108116
LL | #![doc = in_mod!()]
109117
| ^^^^^^
110118
|
111119
= help: have you added the `#[macro_use]` on the module/import?
112120

113121
error: cannot find macro `in_block` in this scope
114-
--> $DIR/key-value-expansion-scope.rs:61:14
122+
--> $DIR/key-value-expansion-scope.rs:70:14
115123
|
116124
LL | #![doc = in_block!()]
117125
| ^^^^^^^^
118126
|
119127
= help: have you added the `#[macro_use]` on the module/import?
120128

121-
error: aborting due to 15 previous errors
129+
warning: cannot find macro `in_root` in this scope
130+
--> $DIR/key-value-expansion-scope.rs:1:10
131+
|
132+
LL | #![doc = in_root!()]
133+
| ^^^^^^^
134+
|
135+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
136+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
137+
= help: import `macro_rules` with `use` to make it callable above its definition
138+
= note: `#[warn(out_of_scope_macro_calls)]` on by default
139+
140+
warning: cannot find macro `in_mod_escape` in this scope
141+
--> $DIR/key-value-expansion-scope.rs:4:10
142+
|
143+
LL | #![doc = in_mod_escape!()]
144+
| ^^^^^^^^^^^^^
145+
|
146+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
147+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
148+
= help: import `macro_rules` with `use` to make it callable above its definition
149+
150+
warning: cannot find macro `in_mod` in this scope
151+
--> $DIR/key-value-expansion-scope.rs:21:9
152+
|
153+
LL | #[doc = in_mod!()]
154+
| ^^^^^^
155+
|
156+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
157+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
158+
= help: import `macro_rules` with `use` to make it callable above its definition
159+
160+
warning: cannot find macro `in_mod` in this scope
161+
--> $DIR/key-value-expansion-scope.rs:24:14
162+
|
163+
LL | #![doc = in_mod!()]
164+
| ^^^^^^
165+
|
166+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
167+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
168+
= help: import `macro_rules` with `use` to make it callable above its definition
169+
170+
warning: cannot find macro `in_mod_escape` in this scope
171+
--> $DIR/key-value-expansion-scope.rs:36:9
172+
|
173+
LL | #[doc = in_mod_escape!()]
174+
| ^^^^^^^^^^^^^
175+
|
176+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
177+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
178+
= help: import `macro_rules` with `use` to make it callable above its definition
179+
180+
warning: cannot find macro `in_mod_escape` in this scope
181+
--> $DIR/key-value-expansion-scope.rs:39:14
182+
|
183+
LL | #![doc = in_mod_escape!()]
184+
| ^^^^^^^^^^^^^
185+
|
186+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
187+
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
188+
= help: import `macro_rules` with `use` to make it callable above its definition
189+
190+
error: aborting due to 16 previous errors; 6 warnings emitted
122191

‎tests/ui/feature-gates/feature-gate-optimize_attribute.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
error[E0658]: the `#[optimize]` attribute is an experimental feature
2-
--> $DIR/feature-gate-optimize_attribute.rs:7:1
2+
--> $DIR/feature-gate-optimize_attribute.rs:2:1
33
|
4-
LL | #[optimize(size)]
5-
| ^^^^^^^^^^^^^^^^^
4+
LL | #![optimize(speed)]
5+
| ^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information
88
= help: add `#![feature(optimize_attribute)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: the `#[optimize]` attribute is an experimental feature
12-
--> $DIR/feature-gate-optimize_attribute.rs:10:1
12+
--> $DIR/feature-gate-optimize_attribute.rs:4:1
1313
|
14-
LL | #[optimize(speed)]
15-
| ^^^^^^^^^^^^^^^^^^
14+
LL | #[optimize(size)]
15+
| ^^^^^^^^^^^^^^^^^
1616
|
1717
= note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information
1818
= help: add `#![feature(optimize_attribute)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the `#[optimize]` attribute is an experimental feature
22-
--> $DIR/feature-gate-optimize_attribute.rs:13:1
22+
--> $DIR/feature-gate-optimize_attribute.rs:7:1
2323
|
24-
LL | #[optimize(banana)]
25-
| ^^^^^^^^^^^^^^^^^^^
24+
LL | #[optimize(size)]
25+
| ^^^^^^^^^^^^^^^^^
2626
|
2727
= note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information
2828
= help: add `#![feature(optimize_attribute)]` to the crate attributes to enable
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

3131
error[E0658]: the `#[optimize]` attribute is an experimental feature
32-
--> $DIR/feature-gate-optimize_attribute.rs:4:1
32+
--> $DIR/feature-gate-optimize_attribute.rs:10:1
3333
|
34-
LL | #[optimize(size)]
35-
| ^^^^^^^^^^^^^^^^^
34+
LL | #[optimize(speed)]
35+
| ^^^^^^^^^^^^^^^^^^
3636
|
3737
= note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information
3838
= help: add `#![feature(optimize_attribute)]` to the crate attributes to enable
3939
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4040

4141
error[E0658]: the `#[optimize]` attribute is an experimental feature
42-
--> $DIR/feature-gate-optimize_attribute.rs:2:1
42+
--> $DIR/feature-gate-optimize_attribute.rs:13:1
4343
|
44-
LL | #![optimize(speed)]
44+
LL | #[optimize(banana)]
4545
| ^^^^^^^^^^^^^^^^^^^
4646
|
4747
= note: see issue #54882 <https://github.com/rust-lang/rust/issues/54882> for more information
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error[E0734]: stability attributes may not be used outside of the standard library
2-
--> $DIR/feature-gate-staged_api.rs:8:1
3-
|
4-
LL | #[stable(feature = "a", since = "3.3.3")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
71
error[E0734]: stability attributes may not be used outside of the standard library
82
--> $DIR/feature-gate-staged_api.rs:1:1
93
|
104
LL | #![stable(feature = "a", since = "3.3.3")]
115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126

7+
error[E0734]: stability attributes may not be used outside of the standard library
8+
--> $DIR/feature-gate-staged_api.rs:8:1
9+
|
10+
LL | #[stable(feature = "a", since = "3.3.3")]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
1313
error: aborting due to 2 previous errors
1414

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

‎tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ warning: unknown lint: `x5100`
4242
LL | #![deny(x5100)]
4343
| ^^^^^
4444

45+
warning: use of deprecated attribute `crate_id`: no longer used
46+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:84:1
47+
|
48+
LL | #![crate_id = "10"]
49+
| ^^^^^^^^^^^^^^^^^^^ help: remove this attribute
50+
|
51+
= note: `#[warn(deprecated)]` on by default
52+
53+
warning: use of deprecated attribute `no_start`: no longer used
54+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:94:1
55+
|
56+
LL | #![no_start]
57+
| ^^^^^^^^^^^^ help: remove this attribute
58+
4559
warning: unknown lint: `x5400`
4660
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:105:8
4761
|
@@ -186,20 +200,6 @@ warning: unknown lint: `x5100`
186200
LL | #[deny(x5100)] impl S { }
187201
| ^^^^^
188202

189-
warning: use of deprecated attribute `crate_id`: no longer used
190-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:84:1
191-
|
192-
LL | #![crate_id = "10"]
193-
| ^^^^^^^^^^^^^^^^^^^ help: remove this attribute
194-
|
195-
= note: `#[warn(deprecated)]` on by default
196-
197-
warning: use of deprecated attribute `no_start`: no longer used
198-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:94:1
199-
|
200-
LL | #![no_start]
201-
| ^^^^^^^^^^^^ help: remove this attribute
202-
203203
warning: `#[macro_export]` only has an effect on macro definitions
204204
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:198:1
205205
|

‎tests/ui/feature-gates/issue-43106-gating-of-stable.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error[E0734]: stability attributes may not be used outside of the standard library
2+
--> $DIR/issue-43106-gating-of-stable.rs:7:1
3+
|
4+
LL | #![stable()]
5+
| ^^^^^^^^^^^^
6+
7+
error[E0734]: stability attributes may not be used outside of the standard library
8+
--> $DIR/issue-43106-gating-of-stable.rs:10:1
9+
|
10+
LL | #[stable()]
11+
| ^^^^^^^^^^^
12+
113
error[E0734]: stability attributes may not be used outside of the standard library
214
--> $DIR/issue-43106-gating-of-stable.rs:14:9
315
|
@@ -28,18 +40,6 @@ error[E0734]: stability attributes may not be used outside of the standard libra
2840
LL | #[stable()]
2941
| ^^^^^^^^^^^
3042

31-
error[E0734]: stability attributes may not be used outside of the standard library
32-
--> $DIR/issue-43106-gating-of-stable.rs:10:1
33-
|
34-
LL | #[stable()]
35-
| ^^^^^^^^^^^
36-
37-
error[E0734]: stability attributes may not be used outside of the standard library
38-
--> $DIR/issue-43106-gating-of-stable.rs:7:1
39-
|
40-
LL | #![stable()]
41-
| ^^^^^^^^^^^^
42-
4343
error: aborting due to 7 previous errors
4444

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

‎tests/ui/feature-gates/issue-43106-gating-of-unstable.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error[E0734]: stability attributes may not be used outside of the standard library
2+
--> $DIR/issue-43106-gating-of-unstable.rs:7:1
3+
|
4+
LL | #![unstable()]
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0734]: stability attributes may not be used outside of the standard library
8+
--> $DIR/issue-43106-gating-of-unstable.rs:10:1
9+
|
10+
LL | #[unstable()]
11+
| ^^^^^^^^^^^^^
12+
113
error[E0734]: stability attributes may not be used outside of the standard library
214
--> $DIR/issue-43106-gating-of-unstable.rs:14:9
315
|
@@ -28,18 +40,6 @@ error[E0734]: stability attributes may not be used outside of the standard libra
2840
LL | #[unstable()]
2941
| ^^^^^^^^^^^^^
3042

31-
error[E0734]: stability attributes may not be used outside of the standard library
32-
--> $DIR/issue-43106-gating-of-unstable.rs:10:1
33-
|
34-
LL | #[unstable()]
35-
| ^^^^^^^^^^^^^
36-
37-
error[E0734]: stability attributes may not be used outside of the standard library
38-
--> $DIR/issue-43106-gating-of-unstable.rs:7:1
39-
|
40-
LL | #![unstable()]
41-
| ^^^^^^^^^^^^^^
42-
4343
error: aborting due to 7 previous errors
4444

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

‎tests/ui/stability-attribute/issue-106589.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0734]: stability attributes may not be used outside of the standard library
2-
--> $DIR/issue-106589.rs:6:1
2+
--> $DIR/issue-106589.rs:3:1
33
|
4-
LL | #[unstable(feature = "foo", issue = "none")]
4+
LL | #![stable(feature = "foo", since = "1.0.0")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0734]: stability attributes may not be used outside of the standard library
8-
--> $DIR/issue-106589.rs:3:1
8+
--> $DIR/issue-106589.rs:6:1
99
|
10-
LL | #![stable(feature = "foo", since = "1.0.0")]
10+
LL | #[unstable(feature = "foo", issue = "none")]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)
Please sign in to comment.