Skip to content

Commit 6c4ca5e

Browse files
committed
Auto merge of #152002 - JonathanBrouwer:rollup-7XNKruy, r=JonathanBrouwer
Rollup of 4 pull requests Successful merges: - #151958 (Add codegen test for SLP vectorization) - #151974 (Update documentation for `Result::ok()`) - #151975 (Work around rustfmt giving up on a large expression) - #151999 (attribute parsing: pass recovery mode to Parser.)
2 parents f60a0f1 + 8e39986 commit 6c4ca5e

13 files changed

Lines changed: 91 additions & 36 deletions

File tree

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

Lines changed: 6 additions & 5 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};
@@ -383,7 +384,7 @@ impl Stage for Late {
383384
}
384385

385386
fn should_emit(&self) -> ShouldEmit {
386-
ShouldEmit::ErrorsAndLints { recover: true }
387+
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }
387388
}
388389
}
389390

@@ -770,10 +771,10 @@ pub enum ShouldEmit {
770771
ErrorsAndLints {
771772
/// Whether [`ArgParser`] will attempt to recover from errors.
772773
///
773-
/// If true, it will attempt to recover from bad input (like an invalid literal). Setting
774-
/// this to false will instead return early, and not raise errors except at the top level
775-
/// (in [`ArgParser::from_attr_args`]).
776-
recover: bool,
774+
/// Whether it is allowed to recover from bad input (like an invalid literal). Setting
775+
/// this to `Forbidden` will instead return early, and not raise errors except at the top
776+
/// level (in [`ArgParser::from_attr_args`]).
777+
recovery: Recovery,
777778
},
778779
/// The operation will *not* emit errors and lints.
779780
///

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_interface/src/util.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ pub(crate) fn run_in_thread_pool_with_globals<
231231
.name("rustc query cycle handler".to_string())
232232
.spawn(move || {
233233
let on_panic = defer(|| {
234-
eprintln!("internal compiler error: query cycle handler thread panicked, aborting process");
234+
// Split this long string so that it doesn't cause rustfmt to
235+
// give up on the entire builder expression.
236+
// <https://github.com/rust-lang/rustfmt/issues/3863>
237+
const MESSAGE: &str = "\
238+
internal compiler error: query cycle handler thread panicked, aborting process";
239+
eprintln!("{MESSAGE}");
235240
// We need to abort here as we failed to resolve the deadlock,
236241
// otherwise the compiler could just hang,
237242
process::abort();
@@ -244,11 +249,16 @@ pub(crate) fn run_in_thread_pool_with_globals<
244249
tls::with(|tcx| {
245250
// Accessing session globals is sound as they outlive `GlobalCtxt`.
246251
// They are needed to hash query keys containing spans or symbols.
247-
let query_map = rustc_span::set_session_globals_then(unsafe { &*(session_globals as *const SessionGlobals) }, || {
248-
// Ensure there was no errors collecting all active jobs.
249-
// We need the complete map to ensure we find a cycle to break.
250-
QueryCtxt::new(tcx).collect_active_jobs(false).expect("failed to collect active queries in deadlock handler")
251-
});
252+
let query_map = rustc_span::set_session_globals_then(
253+
unsafe { &*(session_globals as *const SessionGlobals) },
254+
|| {
255+
// Ensure there were no errors collecting all active jobs.
256+
// We need the complete map to ensure we find a cycle to break.
257+
QueryCtxt::new(tcx).collect_active_jobs(false).expect(
258+
"failed to collect active queries in deadlock handler",
259+
)
260+
},
261+
);
252262
break_query_cycles(query_map, &registry);
253263
})
254264
})

library/core/src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<T, E> Result<T, E> {
690690
/// Converts from `Result<T, E>` to [`Option<T>`].
691691
///
692692
/// Converts `self` into an [`Option<T>`], consuming `self`,
693-
/// and discarding the error, if any.
693+
/// and converting the error to `None`, if any.
694694
///
695695
/// # Examples
696696
///
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Regression test for #142519
2+
//@ only-x86_64
3+
//@ compile-flags: -O
4+
//@ min-llvm-version: 22
5+
6+
#![crate_type = "lib"]
7+
8+
// CHECK-LABEL: @mul3
9+
// CHECK: phi <4 x i8>
10+
// CHECK: load <4 x i8>
11+
// CHECK: add <4 x i8>
12+
// CHECK: store <4 x i8>
13+
14+
#[no_mangle]
15+
pub fn mul3(previous: &[[u8; 4]], current: &mut [[u8; 4]]) {
16+
let mut c_bpp = [0u8; 4];
17+
18+
for i in 0..previous.len() {
19+
current[i][0] = current[i][0].wrapping_add(c_bpp[0]);
20+
current[i][1] = current[i][1].wrapping_add(c_bpp[1]);
21+
current[i][2] = current[i][2].wrapping_add(c_bpp[2]);
22+
current[i][3] = current[i][3].wrapping_add(c_bpp[3]);
23+
24+
c_bpp = previous[i];
25+
}
26+
}

0 commit comments

Comments
 (0)