Skip to content

Commit 46c86ae

Browse files
committed
Auto merge of #152025 - jhpratt:rollup-Kxb6k3Y, r=jhpratt
Rollup of 11 pull requests Successful merges: - #151378 (Codegen tests for Arm Cortex-R82) - #151936 (Move the `fingerprint_style` special case into `DepKindVTable` creation) - #152018 (Move bigint helper tracking issues) - #151958 (Add codegen test for SLP vectorization) - #151974 (Update documentation for `Result::ok()`) - #151975 (Work around rustfmt giving up on a large expression) - #151990 (Fix missing unused_variables lint when using a match guard) - #151995 (stabilize ptr_as_ref_unchecked) - #151999 (attribute parsing: pass recovery mode to Parser.) - #152009 (Port rustc_preserve_ub_checks to attr parser) - #152022 (rustc-dev-guide subtree update) Failed merges: - #151968 (Remove `HasDepContext` by merging it into `QueryContext`)
2 parents 5ac8ece + 3b8a503 commit 46c86ae

File tree

62 files changed

+825
-521
lines changed

Some content is hidden

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

62 files changed

+825
-521
lines changed

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_feature::{
1010
use rustc_hir::attrs::CfgEntry;
1111
use rustc_hir::lints::AttributeLintKind;
1212
use rustc_hir::{AttrPath, RustcVersion, Target};
13-
use rustc_parse::parser::{ForceCollect, Parser};
13+
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
1414
use rustc_parse::{exp, parse_in};
1515
use rustc_session::Session;
1616
use rustc_session::config::ExpectedValues;
@@ -360,8 +360,10 @@ fn parse_cfg_attr_internal<'a>(
360360
) -> PResult<'a, (CfgEntry, Vec<(ast::AttrItem, Span)>)> {
361361
// Parse cfg predicate
362362
let pred_start = parser.token.span;
363-
let meta =
364-
MetaItemOrLitParser::parse_single(parser, ShouldEmit::ErrorsAndLints { recover: true })?;
363+
let meta = MetaItemOrLitParser::parse_single(
364+
parser,
365+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
366+
)?;
365367
let pred_span = pred_start.with_hi(parser.token.span.hi());
366368

367369
let cfg_predicate = AttributeParser::parse_single_args(
@@ -376,7 +378,7 @@ fn parse_cfg_attr_internal<'a>(
376378
CRATE_NODE_ID,
377379
Target::Crate,
378380
features,
379-
ShouldEmit::ErrorsAndLints { recover: true },
381+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
380382
&meta,
381383
parse_cfg_entry,
382384
&CFG_ATTR_TEMPLATE,

compiler/rustc_attr_parsing/src/attributes/cfg_select.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_feature::{AttributeTemplate, Features};
55
use rustc_hir::attrs::CfgEntry;
66
use rustc_hir::{AttrPath, Target};
77
use rustc_parse::exp;
8-
use rustc_parse::parser::Parser;
8+
use rustc_parse::parser::{Parser, Recovery};
99
use rustc_session::Session;
1010
use rustc_span::{ErrorGuaranteed, Span, sym};
1111

@@ -78,9 +78,11 @@ pub fn parse_cfg_select(
7878
}
7979
}
8080
} else {
81-
let meta =
82-
MetaItemOrLitParser::parse_single(p, ShouldEmit::ErrorsAndLints { recover: true })
83-
.map_err(|diag| diag.emit())?;
81+
let meta = MetaItemOrLitParser::parse_single(
82+
p,
83+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
84+
)
85+
.map_err(|diag| diag.emit())?;
8486
let cfg_span = meta.span();
8587
let cfg = AttributeParser::parse_single_args(
8688
sess,
@@ -95,7 +97,7 @@ pub fn parse_cfg_select(
9597
// Doesn't matter what the target actually is here.
9698
Target::Crate,
9799
features,
98-
ShouldEmit::ErrorsAndLints { recover: true },
100+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
99101
&meta,
100102
parse_cfg_entry,
101103
&AttributeTemplate::default(),

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoBuiltinsParser {
274274
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
275275
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
276276
}
277+
278+
pub(crate) struct RustcPreserveUbChecksParser;
279+
280+
impl<S: Stage> NoArgsAttributeParser<S> for RustcPreserveUbChecksParser {
281+
const PATH: &[Symbol] = &[sym::rustc_preserve_ub_checks];
282+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
283+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
284+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPreserveUbChecks;
285+
}

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
77
use crate::context::Stage;
88
use crate::target_checking::AllowedTargets;
99

10-
pub(crate) struct RustcDumpUserArgs;
10+
pub(crate) struct RustcDumpUserArgsParser;
1111

12-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpUserArgs {
12+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpUserArgsParser {
1313
const PATH: &[Symbol] = &[sym::rustc_dump_user_args];
1414
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1515
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
1616
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpUserArgs;
1717
}
1818

19-
pub(crate) struct RustcDumpDefParents;
19+
pub(crate) struct RustcDumpDefParentsParser;
2020

21-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParents {
21+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParentsParser {
2222
const PATH: &[Symbol] = &[sym::rustc_dump_def_parents];
2323
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
2424
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
2525
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpDefParents;
2626
}
2727

28-
pub(crate) struct RustcDumpItemBounds;
28+
pub(crate) struct RustcDumpItemBoundsParser;
2929

30-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBounds {
30+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBoundsParser {
3131
const PATH: &[Symbol] = &[sym::rustc_dump_item_bounds];
3232
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
3333
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::AssocTy)]);
3434
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpItemBounds;
3535
}
3636

37-
pub(crate) struct RustcDumpPredicates;
37+
pub(crate) struct RustcDumpPredicatesParser;
3838

39-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicates {
39+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicatesParser {
4040
const PATH: &[Symbol] = &[sym::rustc_dump_predicates];
4141
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4242
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
@@ -49,9 +49,9 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicates {
4949
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpPredicates;
5050
}
5151

52-
pub(crate) struct RustcDumpVtable;
52+
pub(crate) struct RustcDumpVtableParser;
5353

54-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVtable {
54+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVtableParser {
5555
const PATH: &[Symbol] = &[sym::rustc_dump_vtable];
5656
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
5757
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_feature::{AttrSuggestionStyle, AttributeTemplate};
1010
use rustc_hir::attrs::AttributeKind;
1111
use rustc_hir::lints::AttributeLintKind;
1212
use rustc_hir::{AttrPath, HirId};
13+
use rustc_parse::parser::Recovery;
1314
use rustc_session::Session;
1415
use rustc_session::lint::{Lint, LintId};
1516
use rustc_span::{ErrorGuaranteed, Span, Symbol};
@@ -31,7 +32,8 @@ use crate::attributes::crate_level::{
3132
CrateNameParser, CrateTypeParser, MoveSizeLimitParser, NeedsPanicRuntimeParser,
3233
NoBuiltinsParser, NoCoreParser, NoMainParser, NoStdParser, PanicRuntimeParser,
3334
PatternComplexityLimitParser, ProfilerRuntimeParser, RecursionLimitParser,
34-
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
35+
RustcCoherenceIsCoreParser, RustcPreserveUbChecksParser, TypeLengthLimitParser,
36+
WindowsSubsystemParser,
3537
};
3638
use crate::attributes::debugger::DebuggerViualizerParser;
3739
use crate::attributes::deprecation::DeprecationParser;
@@ -71,8 +73,8 @@ use crate::attributes::rustc_allocator::{
7173
RustcDeallocatorParser, RustcReallocatorParser,
7274
};
7375
use crate::attributes::rustc_dump::{
74-
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
75-
RustcDumpVtable,
76+
RustcDumpDefParentsParser, RustcDumpItemBoundsParser, RustcDumpPredicatesParser,
77+
RustcDumpUserArgsParser, RustcDumpVtableParser,
7678
};
7779
use crate::attributes::rustc_internal::{
7880
RustcHasIncoherentInherentImplsParser, RustcHiddenTypeOfOpaquesParser, RustcLayoutParser,
@@ -294,11 +296,11 @@ attribute_parsers!(
294296
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
295297
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
296298
Single<WithoutArgs<RustcDeallocatorParser>>,
297-
Single<WithoutArgs<RustcDumpDefParents>>,
298-
Single<WithoutArgs<RustcDumpItemBounds>>,
299-
Single<WithoutArgs<RustcDumpPredicates>>,
300-
Single<WithoutArgs<RustcDumpUserArgs>>,
301-
Single<WithoutArgs<RustcDumpVtable>>,
299+
Single<WithoutArgs<RustcDumpDefParentsParser>>,
300+
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
301+
Single<WithoutArgs<RustcDumpPredicatesParser>>,
302+
Single<WithoutArgs<RustcDumpUserArgsParser>>,
303+
Single<WithoutArgs<RustcDumpVtableParser>>,
302304
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
303305
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
304306
Single<WithoutArgs<RustcLintOptTyParser>>,
@@ -311,6 +313,7 @@ attribute_parsers!(
311313
Single<WithoutArgs<RustcNounwindParser>>,
312314
Single<WithoutArgs<RustcOffloadKernelParser>>,
313315
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
316+
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
314317
Single<WithoutArgs<RustcReallocatorParser>>,
315318
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
316319
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,
@@ -385,7 +388,7 @@ impl Stage for Late {
385388
}
386389

387390
fn should_emit(&self) -> ShouldEmit {
388-
ShouldEmit::ErrorsAndLints { recover: true }
391+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }
389392
}
390393
}
391394

@@ -772,10 +775,10 @@ pub enum ShouldEmit {
772775
ErrorsAndLints {
773776
/// Whether [`ArgParser`] will attempt to recover from errors.
774777
///
775-
/// If true, it will attempt to recover from bad input (like an invalid literal). Setting
776-
/// this to false will instead return early, and not raise errors except at the top level
777-
/// (in [`ArgParser::from_attr_args`]).
778-
recover: bool,
778+
/// Whether it is allowed to recover from bad input (like an invalid literal). Setting
779+
/// this to `Forbidden` will instead return early, and not raise errors except at the top
780+
/// level (in [`ArgParser::from_attr_args`]).
781+
recovery: Recovery,
779782
},
780783
/// The operation will *not* emit errors and lints.
781784
///

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_ast_pretty::pprust;
1515
use rustc_errors::{Diag, PResult};
1616
use rustc_hir::{self as hir, AttrPath};
1717
use rustc_parse::exp;
18-
use rustc_parse::parser::{ForceCollect, Parser, PathStyle, token_descr};
18+
use rustc_parse::parser::{ForceCollect, Parser, PathStyle, Recovery, token_descr};
1919
use rustc_session::errors::create_lit_error;
2020
use rustc_session::parse::ParseSess;
2121
use rustc_span::{Ident, Span, Symbol, sym};
@@ -121,7 +121,7 @@ impl ArgParser {
121121
&args.tokens,
122122
args.dspan.entire(),
123123
psess,
124-
ShouldEmit::ErrorsAndLints { recover: false },
124+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden },
125125
) {
126126
Ok(p) => return Some(ArgParser::List(p)),
127127
Err(e) => {
@@ -373,7 +373,10 @@ fn expr_to_lit<'sess>(
373373
}
374374
Err(err) => {
375375
let err = create_lit_error(psess, err, token_lit, expr.span);
376-
if matches!(should_emit, ShouldEmit::ErrorsAndLints { recover: false }) {
376+
if matches!(
377+
should_emit,
378+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden }
379+
) {
377380
Err(err)
378381
} else {
379382
let lit = MetaItemLit {
@@ -431,7 +434,10 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
431434
if !lit.kind.is_unsuffixed() {
432435
// Emit error and continue, we can still parse the attribute as if the suffix isn't there
433436
let err = self.parser.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span });
434-
if matches!(self.should_emit, ShouldEmit::ErrorsAndLints { recover: false }) {
437+
if matches!(
438+
self.should_emit,
439+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden }
440+
) {
435441
return Err(err);
436442
} else {
437443
self.should_emit.emit_err(err)
@@ -569,6 +575,10 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
569575
should_emit: ShouldEmit,
570576
) -> PResult<'sess, MetaItemListParser> {
571577
let mut parser = Parser::new(psess, tokens, None);
578+
if let ShouldEmit::ErrorsAndLints { recovery } = should_emit {
579+
parser = parser.recovery(recovery);
580+
}
581+
572582
let mut this = MetaItemListParserContext { parser: &mut parser, should_emit };
573583

574584
// Presumably, the majority of the time there will only be one attr.

compiler/rustc_builtin_macros/src/cfg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpa
1313
use rustc_hir::attrs::CfgEntry;
1414
use rustc_hir::{AttrPath, Target};
1515
use rustc_parse::exp;
16+
use rustc_parse::parser::Recovery;
1617
use rustc_span::{ErrorGuaranteed, Span, sym};
1718

1819
use crate::errors;
@@ -42,7 +43,7 @@ fn parse_cfg(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream) -> Result<CfgEntry,
4243

4344
let meta = MetaItemOrLitParser::parse_single(
4445
&mut parser,
45-
ShouldEmit::ErrorsAndLints { recover: true },
46+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
4647
)
4748
.map_err(|diag| diag.emit())?;
4849
let cfg = AttributeParser::parse_single_args(
@@ -58,7 +59,7 @@ fn parse_cfg(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream) -> Result<CfgEntry,
5859
// Doesn't matter what the target actually is here.
5960
Target::Crate,
6061
Some(cx.ecfg.features),
61-
ShouldEmit::ErrorsAndLints { recover: true },
62+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
6263
&meta,
6364
parse_cfg_entry,
6465
&CFG_TEMPLATE,

compiler/rustc_expand/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_feature::{
2020
UNSTABLE_LANG_FEATURES,
2121
};
2222
use rustc_hir::Target;
23+
use rustc_parse::parser::Recovery;
2324
use rustc_session::Session;
2425
use rustc_session::parse::feature_err;
2526
use rustc_span::{STDLIB_STABLE_CRATES, Span, Symbol, sym};
@@ -395,7 +396,9 @@ impl<'a> StripUnconfigured<'a> {
395396
fn in_cfg(&self, attrs: &[Attribute]) -> bool {
396397
attrs.iter().all(|attr| {
397398
!is_cfg(attr)
398-
|| self.cfg_true(attr, ShouldEmit::ErrorsAndLints { recover: true }).as_bool()
399+
|| self
400+
.cfg_true(attr, ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed })
401+
.as_bool()
399402
})
400403
}
401404

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_hir::def::MacroKinds;
2626
use rustc_hir::limit::Limit;
2727
use rustc_parse::parser::{
2828
AllowConstBlockItems, AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser,
29-
RecoverColon, RecoverComma, token_descr,
29+
RecoverColon, RecoverComma, Recovery, token_descr,
3030
};
3131
use rustc_session::Session;
3232
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
@@ -2170,7 +2170,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21702170
call.span(),
21712171
self.cx.current_expansion.lint_node_id,
21722172
Some(self.cx.ecfg.features),
2173-
ShouldEmit::ErrorsAndLints { recover: true },
2173+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
21742174
);
21752175

21762176
let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
@@ -2220,7 +2220,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22202220
// Target doesn't matter for `cfg` parsing.
22212221
Target::Crate,
22222222
self.cfg().features,
2223-
ShouldEmit::ErrorsAndLints { recover: true },
2223+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
22242224
parse_cfg,
22252225
&CFG_TEMPLATE,
22262226
) else {

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,9 @@ pub enum AttributeKind {
11261126
/// Represents `#[rustc_pass_indirectly_in_non_rustic_abis]`
11271127
RustcPassIndirectlyInNonRusticAbis(Span),
11281128

1129+
/// Represents `#[rustc_preserve_ub_checks]`
1130+
RustcPreserveUbChecks,
1131+
11291132
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
11301133
RustcPubTransparent(Span),
11311134

0 commit comments

Comments
 (0)