Skip to content

Commit a5c825c

Browse files
committed
Auto merge of #155292 - JonathanBrouwer:rollup-AJQWqfn, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #154049 (delegation: Track more precise spans for glob delegations) - #155134 (Replace custom trim_ascii_start with the standard library method) - #155235 (add the `fma4` x86 target feature) - #155218 (coroutines: Skip the closure signature annotation check for tainted bodies) - #155274 (limit duplicate-profiler-builtins test to targets that can do dynamic linking) - #155276 (`#[rustc_must_match_exhaustively]` detect let else) - #155281 (Revert "allow `windows-gnu` targets to embed gdb visualizer scripts")
2 parents 12f35ad + 2d27fe6 commit a5c825c

37 files changed

Lines changed: 346 additions & 112 deletions

File tree

compiler/rustc_ast/src/ast.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,12 +3901,17 @@ pub struct Delegation {
39013901
pub from_glob: bool,
39023902
}
39033903

3904+
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
3905+
pub enum DelegationSuffixes {
3906+
List(ThinVec<(Ident, Option<Ident>)>),
3907+
Glob(Span),
3908+
}
3909+
39043910
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
39053911
pub struct DelegationMac {
39063912
pub qself: Option<Box<QSelf>>,
39073913
pub prefix: Path,
3908-
// Some for list delegation, and None for glob delegation.
3909-
pub suffixes: Option<ThinVec<(Ident, Option<Ident>)>>,
3914+
pub suffixes: DelegationSuffixes,
39103915
pub body: Option<Box<Block>>,
39113916
}
39123917

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ macro_rules! common_visitor_and_walkers {
430430
Defaultness,
431431
Delegation,
432432
DelegationMac,
433+
DelegationSuffixes,
433434
DelimArgs,
434435
DelimSpan,
435436
EnumDef,

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ impl<'a> State<'a> {
444444
&item.vis,
445445
&deleg.qself,
446446
&deleg.prefix,
447-
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
447+
match &deleg.suffixes {
448+
ast::DelegationSuffixes::List(s) => DelegationKind::List(s),
449+
ast::DelegationSuffixes::Glob(_) => DelegationKind::Glob,
450+
},
448451
&deleg.body,
449452
),
450453
}
@@ -651,7 +654,10 @@ impl<'a> State<'a> {
651654
vis,
652655
&deleg.qself,
653656
&deleg.prefix,
654-
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
657+
match &deleg.suffixes {
658+
ast::DelegationSuffixes::List(s) => DelegationKind::List(s),
659+
ast::DelegationSuffixes::Glob(_) => DelegationKind::Glob,
660+
},
655661
&deleg.body,
656662
),
657663
}

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3232
return;
3333
}
3434

35+
// If the MIR body was constructed via `construct_error` (because an
36+
// earlier pass like match checking failed), its args may not match
37+
// the user-provided signature (e.g. a coroutine with too many
38+
// parameters). Bail out as this can cause panic,
39+
// see <https://github.com/rust-lang/rust/issues/139570>.
40+
if self.body.tainted_by_errors.is_some() {
41+
return;
42+
}
43+
3544
let user_provided_poly_sig = self.tcx().closure_user_provided_sig(mir_def_id);
3645

3746
// Instantiate the canonicalized variables from user-provided signature

compiler/rustc_errors/src/markdown/parse.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn parse_heading(buf: &[u8]) -> ParseResult<'_> {
252252
fn parse_unordered_li(buf: &[u8]) -> Parsed<'_> {
253253
let (txt, rest) = get_indented_section(&buf[2..]);
254254
let ctx = Context { .. };
255-
let stream = parse_recursive(trim_ascii_start(txt), ctx);
255+
let stream = parse_recursive(txt.trim_ascii_start(), ctx);
256256
(MdTree::UnorderedListItem(stream), rest)
257257
}
258258

@@ -261,7 +261,7 @@ fn parse_ordered_li(buf: &[u8]) -> Parsed<'_> {
261261
let (num, pos) = ord_list_start(buf).unwrap(); // success tested in caller
262262
let (txt, rest) = get_indented_section(&buf[pos..]);
263263
let ctx = Context { .. };
264-
let stream = parse_recursive(trim_ascii_start(txt), ctx);
264+
let stream = parse_recursive(txt.trim_ascii_start(), ctx);
265265
(MdTree::OrderedListItem(num, stream), rest)
266266
}
267267

@@ -578,12 +578,6 @@ fn trim_extra_ws(mut txt: &str) -> &str {
578578
&txt[..txt.len() - end_ws]
579579
}
580580

581-
/// If there is more than one whitespace char at start, trim the extras
582-
fn trim_ascii_start(buf: &[u8]) -> &[u8] {
583-
let count = buf.iter().take_while(|ch| ch.is_ascii_whitespace()).count();
584-
&buf[count..]
585-
}
586-
587581
#[cfg(test)]
588582
#[path = "tests/parse.rs"]
589583
mod tests;

compiler/rustc_errors/src/markdown/tests/parse.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,24 @@ fn test_codeblock_trailing_whitespace() {
377377
assert_eq!(t, MdTree::CodeBlock { txt: "code\n```abc\nrest", lang: Some("rust") });
378378
assert_eq!(r, b"");
379379
}
380+
381+
#[test]
382+
fn test_list_item_leading_whitespace() {
383+
// extra spaces after marker
384+
let buf = "- hello";
385+
let (t, r) = parse_unordered_li(buf.as_bytes());
386+
assert_eq!(t, MdTree::UnorderedListItem(vec![MdTree::PlainText("hello")].into()));
387+
assert_eq!(r, b"");
388+
389+
// tab after the marker space
390+
let buf = "- \thello";
391+
let (t, r) = parse_unordered_li(buf.as_bytes());
392+
assert_eq!(t, MdTree::UnorderedListItem(vec![MdTree::PlainText("hello")].into()));
393+
assert_eq!(r, b"");
394+
395+
// ordered list
396+
let buf = "1. hello";
397+
let (t, r) = parse_ordered_li(buf.as_bytes());
398+
assert_eq!(t, MdTree::OrderedListItem(1, vec![MdTree::PlainText("hello")].into()));
399+
assert_eq!(r, b"");
400+
}

compiler/rustc_expand/src/base.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,26 +1019,32 @@ impl SyntaxExtension {
10191019
pub fn glob_delegation(
10201020
trait_def_id: DefId,
10211021
impl_def_id: LocalDefId,
1022+
star_span: Span,
10221023
edition: Edition,
10231024
) -> SyntaxExtension {
10241025
struct GlobDelegationExpanderImpl {
10251026
trait_def_id: DefId,
10261027
impl_def_id: LocalDefId,
1028+
star_span: Span,
10271029
}
10281030
impl GlobDelegationExpander for GlobDelegationExpanderImpl {
10291031
fn expand(
10301032
&self,
10311033
ecx: &mut ExtCtxt<'_>,
10321034
) -> ExpandResult<Vec<(Ident, Option<Ident>)>, ()> {
1033-
match ecx.resolver.glob_delegation_suffixes(self.trait_def_id, self.impl_def_id) {
1035+
match ecx.resolver.glob_delegation_suffixes(
1036+
self.trait_def_id,
1037+
self.impl_def_id,
1038+
self.star_span,
1039+
) {
10341040
Ok(suffixes) => ExpandResult::Ready(suffixes),
10351041
Err(Indeterminate) if ecx.force_mode => ExpandResult::Ready(Vec::new()),
10361042
Err(Indeterminate) => ExpandResult::Retry(()),
10371043
}
10381044
}
10391045
}
10401046

1041-
let expander = GlobDelegationExpanderImpl { trait_def_id, impl_def_id };
1047+
let expander = GlobDelegationExpanderImpl { trait_def_id, impl_def_id, star_span };
10421048
SyntaxExtension::default(SyntaxExtensionKind::GlobDelegation(Arc::new(expander)), edition)
10431049
}
10441050

@@ -1170,6 +1176,7 @@ pub trait ResolverExpand {
11701176
&self,
11711177
trait_def_id: DefId,
11721178
impl_def_id: LocalDefId,
1179+
star_span: Span,
11731180
) -> Result<Vec<(Ident, Option<Ident>)>, Indeterminate>;
11741181

11751182
/// Record the name of an opaque `Ty::ImplTrait` pre-expansion so that it can be used

compiler/rustc_expand/src/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use rustc_ast::tokenstream::TokenStream;
88
use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list};
99
use rustc_ast::{
1010
self as ast, AssocItemKind, AstNodeWrapper, AttrArgs, AttrItemKind, AttrStyle, AttrVec,
11-
DUMMY_NODE_ID, EarlyParsedAttribute, ExprKind, ForeignItemKind, HasAttrs, HasNodeId, Inline,
12-
ItemKind, MacStmtStyle, MetaItemInner, MetaItemKind, ModKind, NodeId, PatKind, StmtKind,
13-
TyKind, token,
11+
DUMMY_NODE_ID, DelegationSuffixes, EarlyParsedAttribute, ExprKind, ForeignItemKind, HasAttrs,
12+
HasNodeId, Inline, ItemKind, MacStmtStyle, MetaItemInner, MetaItemKind, ModKind, NodeId,
13+
PatKind, StmtKind, TyKind, token,
1414
};
1515
use rustc_ast_pretty::pprust;
1616
use rustc_attr_parsing::parser::AllowExprMetavar;
@@ -2401,7 +2401,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
24012401
res
24022402
}
24032403
None if let Some((deleg, item)) = node.delegation() => {
2404-
let Some(suffixes) = &deleg.suffixes else {
2404+
let DelegationSuffixes::List(suffixes) = &deleg.suffixes else {
24052405
let traitless_qself =
24062406
matches!(&deleg.qself, Some(qself) if qself.position == 0);
24072407
let (item, of_trait) = match node.to_annotatable() {

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ declare_features! (
512512
(incomplete, field_projections, "CURRENT_RUSTC_VERSION", Some(145383)),
513513
/// Allows marking trait functions as `final` to prevent overriding impls
514514
(unstable, final_associated_functions, "1.95.0", Some(131179)),
515+
/// fma4 target feature on x86.
516+
(unstable, fma4_target_feature, "CURRENT_RUSTC_VERSION", Some(155233)),
515517
/// Controlling the behavior of fmt::Debug
516518
(unstable, fmt_debug, "1.82.0", Some(129709)),
517519
/// Allows using `#[align(...)]` on function items

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
659659
// being stalled on a coroutine.
660660
self.select_obligations_where_possible(|_| {});
661661

662-
let ty::TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
663-
else {
664-
bug!();
662+
let defining_opaque_types_and_generators = match self.typing_mode() {
663+
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
664+
defining_opaque_types_and_generators
665+
}
666+
ty::TypingMode::Coherence
667+
| ty::TypingMode::Borrowck { .. }
668+
| ty::TypingMode::PostBorrowckAnalysis { .. }
669+
| ty::TypingMode::PostAnalysis => {
670+
bug!()
671+
}
665672
};
666673

667674
if defining_opaque_types_and_generators

0 commit comments

Comments
 (0)