Skip to content

Commit 4db537e

Browse files
committed
Auto merge of #156056 - GuillaumeGomez:rollup-6DdRYmD, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #152487 (core: drop unmapped ZSTs in array `map`) - #155940 (refactor rustc_on_unimplemented's filtering) - #156020 (Improve source code for `librustdoc/visit_ast.rs`) - #156021 (Clean up some traits) - #156028 (Add a `Local::arg(i)` helper constructor) - #156037 (Add AcceptContext::expect_no_args) - #156040 (Add missing alias to mailmap)
2 parents 67bcaa9 + cf18107 commit 4db537e

46 files changed

Lines changed: 306 additions & 304 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.

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Grzegorz Bartoszek <grzegorz.bartoszek@thaumatec.com>
260260
Guanqun Lu <guanqun.lu@gmail.com>
261261
Guillaume Gomez <contact@guillaume-gomez.fr>
262262
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume1.gomez@gmail.com>
263+
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <guillaume1.gomez@gmail.com>
263264
Guillaume Gomez <contact@guillaume-gomez.fr> ggomez <ggomez@ggo.ifr.lan>
264265
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <ggomez@ggo.ifr.lan>
265266
Guillaume Gomez <contact@guillaume-gomez.fr> Guillaume Gomez <guillaume.gomez@huawei.com>

compiler/rustc_attr_parsing/src/attributes/autodiff.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
5252
cx.adcx().expected_identifier(mode.span());
5353
return None;
5454
};
55-
let Ok(()) = mode.args().no_args() else {
56-
cx.adcx().expected_identifier(mode.span());
57-
return None;
58-
};
55+
cx.expect_no_args(mode.args())?;
5956
let Some(mode) = mode.path().word() else {
6057
cx.adcx().expected_identifier(mode.span());
6158
return None;
@@ -85,11 +82,7 @@ impl SingleAttributeParser for RustcAutodiffParser {
8582
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
8683
return None;
8784
};
88-
let Ok(()) = activity.args().no_args() else {
89-
cx.adcx()
90-
.expected_specific_argument(activity.span(), DiffActivity::all_activities());
91-
return None;
92-
};
85+
cx.expect_no_args(activity.args())?;
9386
let Some(activity) = activity.path().word() else {
9487
cx.adcx()
9588
.expected_specific_argument(activity.span(), DiffActivity::all_activities());

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ pub(crate) struct NakedParser {
195195
impl AttributeParser for NakedParser {
196196
const ATTRIBUTES: AcceptMapping<Self> =
197197
&[(&[sym::naked], template!(Word), |this, cx, args| {
198-
if let Err(span) = args.no_args() {
199-
cx.adcx().expected_no_args(span);
198+
let Some(()) = cx.expect_no_args(args) else {
200199
return;
201-
}
200+
};
202201

203202
if let Some(earlier) = this.span {
204203
let span = cx.attr_span;

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,9 @@ impl CombineAttributeParser for FeatureParser {
294294
cx.adcx().expected_identifier(elem.span());
295295
continue;
296296
};
297-
if let Err(arg_span) = elem.args().no_args() {
298-
cx.adcx().expected_no_args(arg_span);
297+
let Some(()) = cx.expect_no_args(elem.args()) else {
299298
continue;
300-
}
301-
299+
};
302300
let path = elem.path();
303301
let Some(ident) = path.word() else {
304302
cx.adcx().expected_identifier(path.span());
@@ -340,10 +338,9 @@ impl CombineAttributeParser for RegisterToolParser {
340338
cx.adcx().expected_identifier(elem.span());
341339
continue;
342340
};
343-
if let Err(arg_span) = elem.args().no_args() {
344-
cx.adcx().expected_no_args(arg_span);
341+
let Some(()) = cx.expect_no_args(elem.args()) else {
345342
continue;
346-
}
343+
};
347344

348345
let path = elem.path();
349346
let Some(ident) = path.word() else {

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/doc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl DocParser {
150150

151151
match path.word_sym() {
152152
Some(sym::no_crate_inject) => {
153-
if let Err(span) = args.no_args() {
153+
if let Err(span) = args.as_no_args() {
154154
expected_no_args(cx, span);
155155
return;
156156
}
@@ -280,7 +280,7 @@ impl DocParser {
280280
args: &ArgParser,
281281
inline: DocInline,
282282
) {
283-
if let Err(span) = args.no_args() {
283+
if let Err(span) = args.as_no_args() {
284284
expected_no_args(cx, span);
285285
return;
286286
}
@@ -426,7 +426,7 @@ impl DocParser {
426426

427427
macro_rules! no_args {
428428
($ident: ident) => {{
429-
if let Err(span) = args.no_args() {
429+
if let Err(span) = args.as_no_args() {
430430
expected_no_args(cx, span);
431431
return;
432432
}
@@ -445,7 +445,7 @@ impl DocParser {
445445
}
446446
macro_rules! no_args_and_not_crate_level {
447447
($ident: ident) => {{
448-
if let Err(span) = args.no_args() {
448+
if let Err(span) = args.as_no_args() {
449449
expected_no_args(cx, span);
450450
return;
451451
}
@@ -461,7 +461,7 @@ impl DocParser {
461461
no_args_and_crate_level!($ident, |span| {});
462462
}};
463463
($ident: ident, |$span:ident| $extra_validation:block) => {{
464-
if let Err(span) = args.no_args() {
464+
if let Err(span) = args.as_no_args() {
465465
expected_no_args(cx, span);
466466
return;
467467
}

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ impl AttributeParser for MacroUseParser {
8686
cx.adcx().expected_identifier(item.span());
8787
continue;
8888
};
89-
if let Err(err_span) = item.args().no_args() {
90-
cx.adcx().expected_no_args(err_span);
89+
let Some(()) = cx.expect_no_args(item.args()) else {
9190
continue;
92-
}
91+
};
9392
let Some(item) = item.path().word() else {
9493
cx.adcx().expected_identifier(item.span());
9594
continue;
@@ -179,9 +178,7 @@ impl SingleAttributeParser for CollapseDebugInfoParser {
179178
cx.adcx().expected_not_literal(single.span());
180179
return None;
181180
};
182-
if let Err(err) = mi.args().no_args() {
183-
cx.adcx().expected_no_args(err);
184-
}
181+
let _ = cx.expect_no_args(mi.args());
185182
let path = mi.path().word_sym();
186183
let info = match path {
187184
Some(sym::yes) => CollapseMacroDebuginfo::Yes,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ impl<T: NoArgsAttributeParser> SingleAttributeParser for WithoutArgs<T> {
258258
const TEMPLATE: AttributeTemplate = template!(Word);
259259

260260
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
261-
if let Err(span) = args.no_args() {
262-
cx.adcx().expected_no_args(span);
263-
}
261+
let _ = cx.expect_no_args(args);
264262
Some(T::CREATE(cx.attr_span))
265263
}
266264
}

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn parse_derive_like(
5858
) -> Option<(Option<Symbol>, ThinVec<Symbol>)> {
5959
let Some(list) = args.as_list() else {
6060
// For #[rustc_builtin_macro], it is permitted to leave out the trait name
61-
if args.no_args().is_ok() && !trait_name_mandatory {
61+
if args.as_no_args().is_ok() && !trait_name_mandatory {
6262
return Some((None, ThinVec::new()));
6363
}
6464
let attr_span = cx.attr_span;
@@ -84,10 +84,7 @@ fn parse_derive_like(
8484
cx.adcx().expected_identifier(trait_ident.span);
8585
return None;
8686
}
87-
if let Err(e) = trait_attr.args().no_args() {
88-
cx.adcx().expected_no_args(e);
89-
return None;
90-
};
87+
cx.expect_no_args(trait_attr.args())?;
9188

9289
// Parse optional attributes
9390
let mut attributes = ThinVec::new();
@@ -108,10 +105,7 @@ fn parse_derive_like(
108105
cx.adcx().expected_identifier(attr.span());
109106
return None;
110107
};
111-
if let Err(e) = attr.args().no_args() {
112-
cx.adcx().expected_no_args(e);
113-
return None;
114-
};
108+
cx.expect_no_args(attr.args())?;
115109
let Some(ident) = attr.path().word() else {
116110
cx.adcx().expected_identifier(attr.path().span());
117111
return None;

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ impl SingleAttributeParser for RustcDumpDefPathParser {
3636
]);
3737
const TEMPLATE: AttributeTemplate = template!(Word);
3838
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
39-
if let Err(span) = args.no_args() {
40-
cx.adcx().expected_no_args(span);
41-
return None;
42-
}
39+
cx.expect_no_args(args)?;
4340
Some(AttributeKind::RustcDumpDefPath(cx.attr_span))
4441
}
4542
}
@@ -203,10 +200,7 @@ impl SingleAttributeParser for RustcDumpSymbolNameParser {
203200
]);
204201
const TEMPLATE: AttributeTemplate = template!(Word);
205202
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
206-
if let Err(span) = args.no_args() {
207-
cx.adcx().expected_no_args(span);
208-
return None;
209-
}
203+
cx.expect_no_args(args)?;
210204
Some(AttributeKind::RustcDumpSymbolName(cx.attr_span))
211205
}
212206
}

0 commit comments

Comments
 (0)