Skip to content

Commit 6769f69

Browse files
committed
Auto merge of #156097 - jhpratt:rollup-haL7A1y, r=jhpratt
Rollup of 5 pull requests Successful merges: - #155666 (Interning cleanups) - #155940 (refactor rustc_on_unimplemented's filtering) - #156065 (Remove unused spans from AttributeKind) - #156079 (Move and rename the `clone-never.rs` test) - #156091 (change field `tools` on `AttributeParser` to hold `&'tcx RegisteredTools`)
2 parents 44860d3 + bd8d026 commit 6769f69

65 files changed

Lines changed: 317 additions & 381 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,6 +3586,7 @@ dependencies = [
35863586
"rustc_feature",
35873587
"rustc_hir",
35883588
"rustc_lexer",
3589+
"rustc_lint_defs",
35893590
"rustc_macros",
35903591
"rustc_parse",
35913592
"rustc_parse_format",

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
10631063
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
10641064

10651065
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
1066-
let mut coroutine_kind = find_attr!(attrs, Coroutine(_) => hir::CoroutineKind::Coroutine(Movability::Movable));
1066+
let mut coroutine_kind =
1067+
find_attr!(attrs, Coroutine => hir::CoroutineKind::Coroutine(Movability::Movable));
10671068

10681069
// FIXME(contracts): Support contracts on closures?
10691070
let body_id = this.lower_fn_body(decl, None, |this| {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ struct LoweringContext<'a, 'hir> {
164164

165165
impl<'a, 'hir> LoweringContext<'a, 'hir> {
166166
fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>) -> Self {
167-
let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
168167
Self {
169168
tcx,
170169
resolver,
@@ -220,7 +219,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
220219
attribute_parser: AttributeParser::new(
221220
tcx.sess,
222221
tcx.features(),
223-
registered_tools,
222+
tcx.registered_tools(()),
224223
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
225224
),
226225
delayed_lints: Vec::new(),

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_errors = { path = "../rustc_errors" }
1313
rustc_feature = { path = "../rustc_feature" }
1414
rustc_hir = { path = "../rustc_hir" }
1515
rustc_lexer = { path = "../rustc_lexer" }
16+
rustc_lint_defs = { path = "../rustc_lint_defs" }
1617
rustc_macros = { path = "../rustc_macros" }
1718
rustc_parse = { path = "../rustc_parse" }
1819
rustc_parse_format = { path = "../rustc_parse_format" }

compiler/rustc_attr_parsing/src/attributes/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pub(crate) struct CoroutineParser;
77
impl NoArgsAttributeParser for CoroutineParser {
88
const PATH: &[Symbol] = &[sym::coroutine];
99
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Closure)]);
10-
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
10+
const CREATE: fn(rustc_span::Span) -> AttributeKind = |_| AttributeKind::Coroutine;
1111
}

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl NoArgsAttributeParser for ColdParser {
5454
Allow(Target::ForeignFn),
5555
Allow(Target::Closure),
5656
]);
57-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
57+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::Cold;
5858
}
5959

6060
pub(crate) struct CoverageParser;
@@ -94,7 +94,7 @@ impl SingleAttributeParser for CoverageParser {
9494
}
9595
};
9696

97-
Some(AttributeKind::Coverage(cx.attr_span, kind))
97+
Some(AttributeKind::Coverage(kind))
9898
}
9999
}
100100

@@ -156,7 +156,7 @@ impl SingleAttributeParser for RustcObjcClassParser {
156156
cx.emit_err(NullOnObjcClass { span: nv.value_span });
157157
return None;
158158
}
159-
Some(AttributeKind::RustcObjcClass { classname, span: cx.attr_span })
159+
Some(AttributeKind::RustcObjcClass { classname })
160160
}
161161
}
162162

@@ -183,7 +183,7 @@ impl SingleAttributeParser for RustcObjcSelectorParser {
183183
cx.emit_err(NullOnObjcSelector { span: nv.value_span });
184184
return None;
185185
}
186-
Some(AttributeKind::RustcObjcSelector { methname, span: cx.attr_span })
186+
Some(AttributeKind::RustcObjcSelector { methname })
187187
}
188188
}
189189

@@ -264,10 +264,18 @@ impl AttributeParser for NakedParser {
264264

265265
let span = self.span?;
266266

267+
let Some(tools) = cx.tools else {
268+
unreachable!("tools required while parsing attributes");
269+
};
270+
267271
// only if we found a naked attribute do we do the somewhat expensive check
268272
'outer: for other_attr in cx.all_attrs {
269273
for allowed_attr in ALLOW_LIST {
270-
if other_attr.segments().next().is_some_and(|i| cx.tools.contains(&i.name)) {
274+
if other_attr
275+
.segments()
276+
.next()
277+
.is_some_and(|i| tools.iter().any(|tool| tool.name == i.name))
278+
{
271279
// effectively skips the error message being emitted below
272280
// if it's a tool attribute
273281
continue 'outer;
@@ -436,9 +444,9 @@ impl AttributeParser for UsedParser {
436444
// If a specific form of `used` is specified, it takes precedence over generic `#[used]`.
437445
// If both `linker` and `compiler` are specified, use `linker`.
438446
Some(match (self.first_compiler, self.first_linker, self.first_default) {
439-
(_, Some(span), _) => AttributeKind::Used { used_by: UsedBy::Linker, span },
440-
(Some(span), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
441-
(_, _, Some(span)) => AttributeKind::Used { used_by: UsedBy::Default, span },
447+
(_, Some(_), _) => AttributeKind::Used { used_by: UsedBy::Linker },
448+
(Some(_), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler },
449+
(_, _, Some(_)) => AttributeKind::Used { used_by: UsedBy::Default },
442450
(None, None, None) => return None,
443451
})
444452
}

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ impl SingleAttributeParser for RecursionLimitParser {
8484
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
8585
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
8686

87-
Some(AttributeKind::RecursionLimit {
88-
limit: cx.parse_limit_int(nv)?,
89-
attr_span: cx.attr_span,
90-
limit_span: nv.value_span,
91-
})
87+
Some(AttributeKind::RecursionLimit { limit: cx.parse_limit_int(nv)? })
9288
}
9389
}
9490

@@ -102,11 +98,7 @@ impl SingleAttributeParser for MoveSizeLimitParser {
10298
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
10399
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
104100

105-
Some(AttributeKind::MoveSizeLimit {
106-
limit: cx.parse_limit_int(nv)?,
107-
attr_span: cx.attr_span,
108-
limit_span: nv.value_span,
109-
})
101+
Some(AttributeKind::MoveSizeLimit { limit: cx.parse_limit_int(nv)? })
110102
}
111103
}
112104

@@ -121,11 +113,7 @@ impl SingleAttributeParser for TypeLengthLimitParser {
121113
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
122114
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
123115

124-
Some(AttributeKind::TypeLengthLimit {
125-
limit: cx.parse_limit_int(nv)?,
126-
attr_span: cx.attr_span,
127-
limit_span: nv.value_span,
128-
})
116+
Some(AttributeKind::TypeLengthLimit { limit: cx.parse_limit_int(nv)? })
129117
}
130118
}
131119

@@ -139,11 +127,7 @@ impl SingleAttributeParser for PatternComplexityLimitParser {
139127
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
140128
let nv = cx.expect_name_value(args, cx.attr_span, None)?;
141129

142-
Some(AttributeKind::PatternComplexityLimit {
143-
limit: cx.parse_limit_int(nv)?,
144-
attr_span: cx.attr_span,
145-
limit_span: nv.value_span,
146-
})
130+
Some(AttributeKind::PatternComplexityLimit { limit: cx.parse_limit_int(nv)? })
147131
}
148132
}
149133

@@ -152,7 +136,7 @@ pub(crate) struct NoCoreParser;
152136
impl NoArgsAttributeParser for NoCoreParser {
153137
const PATH: &[Symbol] = &[sym::no_core];
154138
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
155-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoCore;
139+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoCore;
156140
}
157141

158142
pub(crate) struct NoStdParser;
@@ -161,7 +145,7 @@ impl NoArgsAttributeParser for NoStdParser {
161145
const PATH: &[Symbol] = &[sym::no_std];
162146
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
163147
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
164-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoStd;
148+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
165149
}
166150

167151
pub(crate) struct NoMainParser;
@@ -178,7 +162,7 @@ pub(crate) struct RustcCoherenceIsCoreParser;
178162
impl NoArgsAttributeParser for RustcCoherenceIsCoreParser {
179163
const PATH: &[Symbol] = &[sym::rustc_coherence_is_core];
180164
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
181-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
165+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcCoherenceIsCore;
182166
}
183167

184168
pub(crate) struct WindowsSubsystemParser;
@@ -204,7 +188,7 @@ impl SingleAttributeParser for WindowsSubsystemParser {
204188
}
205189
};
206190

207-
Some(AttributeKind::WindowsSubsystem(kind, cx.attr_span))
191+
Some(AttributeKind::WindowsSubsystem(kind))
208192
}
209193
}
210194

@@ -314,7 +298,7 @@ pub(crate) struct RegisterToolParser;
314298
impl CombineAttributeParser for RegisterToolParser {
315299
const PATH: &[Symbol] = &[sym::register_tool];
316300
type Item = Ident;
317-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::RegisterTool;
301+
const CONVERT: ConvertFn<Self::Item> = |tools, _span| AttributeKind::RegisterTool(tools);
318302
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
319303
const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]);
320304

compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ impl SingleAttributeParser for DoNotRecommendParser {
4040
return None;
4141
}
4242

43-
Some(AttributeKind::DoNotRecommend { attr_span })
43+
Some(AttributeKind::DoNotRecommend)
4444
}
4545
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::ops::Range;
33
use rustc_errors::E0232;
44
use rustc_hir::AttrPath;
55
use rustc_hir::attrs::diagnostic::{
6-
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
7-
OnUnimplementedCondition, Piece, Predicate,
6+
Directive, Filter, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name,
7+
NameValue, Piece, Predicate,
88
};
99
use rustc_macros::Diagnostic;
1010
use rustc_parse_format::{
@@ -201,12 +201,11 @@ fn parse_directive_items<'p>(
201201
items: impl Iterator<Item = &'p MetaItemOrLitParser>,
202202
is_root: bool,
203203
) -> Option<Directive> {
204-
let condition = None;
205204
let mut message: Option<(Span, _)> = None;
206205
let mut label: Option<(Span, _)> = None;
207206
let mut notes = ThinVec::new();
208207
let mut parent_label = None;
209-
let mut subcommands = ThinVec::new();
208+
let mut filters = ThinVec::new();
210209

211210
for item in items {
212211
let span = item.span();
@@ -330,29 +329,27 @@ fn parse_directive_items<'p>(
330329
if is_root {
331330
let items = or_malformed!(item.args().as_list()?);
332331
let mut iter = items.mixed();
333-
let condition: &MetaItemOrLitParser = match iter.next() {
332+
let filter: &MetaItemOrLitParser = match iter.next() {
334333
Some(c) => c,
335334
None => {
336335
cx.emit_err(InvalidOnClause::Empty { span });
337336
continue;
338337
}
339338
};
340339

341-
let condition = parse_condition(condition);
340+
let filter = parse_filter(filter);
342341

343342
if items.len() < 2 {
344343
// Something like `#[rustc_on_unimplemented(on(.., /* nothing */))]`
345-
// There's a condition but no directive behind it, this is a mistake.
344+
// There's a filter but no directive behind it, this is a mistake.
346345
malformed!();
347346
}
348347

349-
let mut directive =
350-
or_malformed!(parse_directive_items(cx, mode, iter, false)?);
351-
352-
match condition {
353-
Ok(c) => {
354-
directive.condition = Some(c);
355-
subcommands.push(directive);
348+
match filter {
349+
Ok(filter) => {
350+
let directive =
351+
or_malformed!(parse_directive_items(cx, mode, iter, false)?);
352+
filters.push((filter, directive));
356353
}
357354
Err(e) => {
358355
cx.emit_err(e);
@@ -371,8 +368,7 @@ fn parse_directive_items<'p>(
371368

372369
Some(Directive {
373370
is_rustc_attr: matches!(mode, Mode::RustcOnUnimplemented),
374-
condition,
375-
subcommands,
371+
filters,
376372
message,
377373
label,
378374
notes,
@@ -513,12 +509,10 @@ fn slice_span(input: Span, Range { start, end }: Range<usize>, is_source_literal
513509
if is_source_literal { input.from_inner(InnerSpan { start, end }) } else { input }
514510
}
515511

516-
pub(crate) fn parse_condition(
517-
input: &MetaItemOrLitParser,
518-
) -> Result<OnUnimplementedCondition, InvalidOnClause> {
512+
pub(crate) fn parse_filter(input: &MetaItemOrLitParser) -> Result<Filter, InvalidOnClause> {
519513
let span = input.span();
520514
let pred = parse_predicate(input)?;
521-
Ok(OnUnimplementedCondition { span, pred })
515+
Ok(Filter { span, pred })
522516
}
523517

524518
fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnClause> {
@@ -553,7 +547,7 @@ fn parse_predicate(input: &MetaItemOrLitParser) -> Result<Predicate, InvalidOnCl
553547
return Err(InvalidOnClause::UnsupportedLiteral { span: p.args_span() });
554548
};
555549
let name = parse_name(predicate.name);
556-
let value = parse_filter(value.name);
550+
let value = parse_filter_format(value.name);
557551
let kv = NameValue { name, value };
558552
Ok(Predicate::Match(kv))
559553
}
@@ -588,7 +582,7 @@ fn parse_name(name: Symbol) -> Name {
588582
}
589583
}
590584

591-
fn parse_filter(input: Symbol) -> FilterFormatString {
585+
fn parse_filter_format(input: Symbol) -> FilterFormatString {
592586
let pieces = Parser::new(input.as_str(), None, None, false, ParseMode::Diagnostic)
593587
.map(|p| match p {
594588
RpfPiece::Lit(s) => LitOrArg::Lit(Symbol::intern(s)),

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_move.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl AttributeParser for OnMoveParser {
5151
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
5252

5353
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
54-
if let Some(span) = self.span {
55-
Some(AttributeKind::OnMove { span, directive: self.directive.map(|d| Box::new(d.1)) })
54+
if let Some(_span) = self.span {
55+
Some(AttributeKind::OnMove { directive: self.directive.map(|d| Box::new(d.1)) })
5656
} else {
5757
None
5858
}

0 commit comments

Comments
 (0)