Skip to content

Commit 81799cd

Browse files
committed
Auto merge of rust-lang#96495 - Dylan-DPC:rollup-9lm4tpp, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#96377 (make `fn() -> _ { .. }` suggestion MachineApplicable) - rust-lang#96397 (Make EncodeWide implement FusedIterator) - rust-lang#96421 (Less `NoDelim`) - rust-lang#96432 (not need `Option` for `dbg_scope`) - rust-lang#96466 (Better error messages when collecting into `[T; n]`) - rust-lang#96471 (replace let else with `?`) - rust-lang#96483 (Add missing `target_feature` to the list of well known cfg names) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c95346b + 89db345 commit 81799cd

File tree

34 files changed

+243
-209
lines changed

34 files changed

+243
-209
lines changed

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1542,10 +1542,10 @@ pub enum MacArgs {
15421542
}
15431543

15441544
impl MacArgs {
1545-
pub fn delim(&self) -> DelimToken {
1545+
pub fn delim(&self) -> Option<DelimToken> {
15461546
match self {
1547-
MacArgs::Delimited(_, delim, _) => delim.to_token(),
1548-
MacArgs::Empty | MacArgs::Eq(..) => token::NoDelim,
1547+
MacArgs::Delimited(_, delim, _) => Some(delim.to_token()),
1548+
MacArgs::Empty | MacArgs::Eq(..) => None,
15491549
}
15501550
}
15511551

compiler/rustc_ast_pretty/src/pprust/state.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
464464
Some(MacHeader::Path(&item.path)),
465465
false,
466466
None,
467-
delim.to_token(),
467+
Some(delim.to_token()),
468468
tokens,
469469
true,
470470
span,
@@ -530,7 +530,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
530530
None,
531531
false,
532532
None,
533-
*delim,
533+
Some(*delim),
534534
tts,
535535
convert_dollar_crate,
536536
dspan.entire(),
@@ -556,12 +556,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
556556
header: Option<MacHeader<'_>>,
557557
has_bang: bool,
558558
ident: Option<Ident>,
559-
delim: DelimToken,
559+
delim: Option<DelimToken>,
560560
tts: &TokenStream,
561561
convert_dollar_crate: bool,
562562
span: Span,
563563
) {
564-
if delim == DelimToken::Brace {
564+
if delim == Some(DelimToken::Brace) {
565565
self.cbox(INDENT_UNIT);
566566
}
567567
match header {
@@ -577,31 +577,33 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
577577
self.print_ident(ident);
578578
}
579579
match delim {
580-
DelimToken::Brace => {
580+
Some(DelimToken::Brace) => {
581581
if header.is_some() || has_bang || ident.is_some() {
582582
self.nbsp();
583583
}
584584
self.word("{");
585585
if !tts.is_empty() {
586586
self.space();
587587
}
588-
}
589-
_ => {
590-
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
591-
self.word(token_str)
592-
}
593-
}
594-
self.ibox(0);
595-
self.print_tts(tts, convert_dollar_crate);
596-
self.end();
597-
match delim {
598-
DelimToken::Brace => {
588+
self.ibox(0);
589+
self.print_tts(tts, convert_dollar_crate);
590+
self.end();
599591
let empty = tts.is_empty();
600592
self.bclose(span, empty);
601593
}
602-
_ => {
594+
Some(delim) => {
595+
let token_str = self.token_kind_to_string(&token::OpenDelim(delim));
596+
self.word(token_str);
597+
self.ibox(0);
598+
self.print_tts(tts, convert_dollar_crate);
599+
self.end();
603600
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
604-
self.word(token_str)
601+
self.word(token_str);
602+
}
603+
None => {
604+
self.ibox(0);
605+
self.print_tts(tts, convert_dollar_crate);
606+
self.end();
605607
}
606608
}
607609
}

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
2020
cx: &CodegenCx<'ll, 'tcx>,
2121
instance: Instance<'tcx>,
2222
mir: &Body<'tcx>,
23-
fn_dbg_scope: &'ll DIScope,
2423
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
2524
) {
2625
// Find all scopes with variables defined in them.
@@ -38,47 +37,49 @@ pub fn compute_mir_scopes<'ll, 'tcx>(
3837
// Nothing to emit, of course.
3938
None
4039
};
41-
40+
let mut instantiated = BitSet::new_empty(mir.source_scopes.len());
4241
// Instantiate all scopes.
4342
for idx in 0..mir.source_scopes.len() {
4443
let scope = SourceScope::new(idx);
45-
make_mir_scope(cx, instance, mir, fn_dbg_scope, &variables, debug_context, scope);
44+
make_mir_scope(cx, instance, mir, &variables, debug_context, &mut instantiated, scope);
4645
}
46+
assert!(instantiated.count() == mir.source_scopes.len());
4747
}
4848

4949
fn make_mir_scope<'ll, 'tcx>(
5050
cx: &CodegenCx<'ll, 'tcx>,
5151
instance: Instance<'tcx>,
5252
mir: &Body<'tcx>,
53-
fn_dbg_scope: &'ll DIScope,
5453
variables: &Option<BitSet<SourceScope>>,
5554
debug_context: &mut FunctionDebugContext<&'ll DIScope, &'ll DILocation>,
55+
instantiated: &mut BitSet<SourceScope>,
5656
scope: SourceScope,
5757
) {
58-
if debug_context.scopes[scope].dbg_scope.is_some() {
58+
if instantiated.contains(scope) {
5959
return;
6060
}
6161

6262
let scope_data = &mir.source_scopes[scope];
6363
let parent_scope = if let Some(parent) = scope_data.parent_scope {
64-
make_mir_scope(cx, instance, mir, fn_dbg_scope, variables, debug_context, parent);
64+
make_mir_scope(cx, instance, mir, variables, debug_context, instantiated, parent);
6565
debug_context.scopes[parent]
6666
} else {
6767
// The root is the function itself.
6868
let loc = cx.lookup_debug_loc(mir.span.lo());
6969
debug_context.scopes[scope] = DebugScope {
70-
dbg_scope: Some(fn_dbg_scope),
71-
inlined_at: None,
7270
file_start_pos: loc.file.start_pos,
7371
file_end_pos: loc.file.end_pos,
72+
..debug_context.scopes[scope]
7473
};
74+
instantiated.insert(scope);
7575
return;
7676
};
7777

7878
if let Some(vars) = variables && !vars.contains(scope) && scope_data.inlined.is_none() {
7979
// Do not create a DIScope if there are no variables defined in this
8080
// MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat.
8181
debug_context.scopes[scope] = parent_scope;
82+
instantiated.insert(scope);
8283
return;
8384
}
8485

@@ -100,7 +101,7 @@ fn make_mir_scope<'ll, 'tcx>(
100101
None => unsafe {
101102
llvm::LLVMRustDIBuilderCreateLexicalBlock(
102103
DIB(cx),
103-
parent_scope.dbg_scope.unwrap(),
104+
parent_scope.dbg_scope,
104105
file_metadata,
105106
loc.line,
106107
loc.col,
@@ -116,9 +117,10 @@ fn make_mir_scope<'ll, 'tcx>(
116117
});
117118

118119
debug_context.scopes[scope] = DebugScope {
119-
dbg_scope: Some(dbg_scope),
120+
dbg_scope,
120121
inlined_at: inlined_at.or(parent_scope.inlined_at),
121122
file_start_pos: loc.file.start_pos,
122123
file_end_pos: loc.file.end_pos,
123124
};
125+
instantiated.insert(scope);
124126
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
286286
}
287287

288288
// Initialize fn debug context (including scopes).
289-
// FIXME(eddyb) figure out a way to not need `Option` for `dbg_scope`.
290289
let empty_scope = DebugScope {
291-
dbg_scope: None,
290+
dbg_scope: self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
292291
inlined_at: None,
293292
file_start_pos: BytePos(0),
294293
file_end_pos: BytePos(0),
@@ -297,13 +296,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
297296
FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) };
298297

299298
// Fill in all the scopes, with the information from the MIR body.
300-
compute_mir_scopes(
301-
self,
302-
instance,
303-
mir,
304-
self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
305-
&mut fn_debug_context,
306-
);
299+
compute_mir_scopes(self, instance, mir, &mut fn_debug_context);
307300

308301
Some(fn_debug_context)
309302
}

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {
3939

4040
#[derive(Clone, Copy, Debug)]
4141
pub struct DebugScope<S, L> {
42-
// FIXME(eddyb) this should never be `None`, after initialization.
43-
pub dbg_scope: Option<S>,
42+
pub dbg_scope: S,
4443

4544
/// Call site location, if this scope was inlined from another function.
4645
pub inlined_at: Option<L>,
@@ -61,17 +60,12 @@ impl<'tcx, S: Copy, L: Copy> DebugScope<S, L> {
6160
cx: &Cx,
6261
span: Span,
6362
) -> S {
64-
// FIXME(eddyb) this should never be `None`.
65-
let dbg_scope = self
66-
.dbg_scope
67-
.unwrap_or_else(|| bug!("`dbg_scope` is only `None` during initialization"));
68-
6963
let pos = span.lo();
7064
if pos < self.file_start_pos || pos >= self.file_end_pos {
7165
let sm = cx.sess().source_map();
72-
cx.extend_scope_to_file(dbg_scope, &sm.lookup_char_pos(pos).file)
66+
cx.extend_scope_to_file(self.dbg_scope, &sm.lookup_char_pos(pos).file)
7367
} else {
74-
dbg_scope
68+
self.dbg_scope
7569
}
7670
}
7771
}

compiler/rustc_expand/src/base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,7 @@ pub fn parse_macro_name_and_helper_attrs(
12721272
// Once we've located the `#[proc_macro_derive]` attribute, verify
12731273
// that it's of the form `#[proc_macro_derive(Foo)]` or
12741274
// `#[proc_macro_derive(Foo, attributes(A, ..))]`
1275-
let Some(list) = attr.meta_item_list() else {
1276-
return None;
1277-
};
1275+
let list = attr.meta_item_list()?;
12781276
if list.len() != 1 && list.len() != 2 {
12791277
diag.span_err(attr.span, "attribute must have either one or two arguments");
12801278
return None;

compiler/rustc_expand/src/mbe/macro_rules.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,15 @@ fn generic_extension<'cx, 'tt>(
260260
// Merge the gated spans from parsing the matcher with the pre-existing ones.
261261
sess.gated_spans.merge(gated_spans_snapshot);
262262

263-
// Ignore the delimiters on the RHS.
264-
let rhs = match &rhses[i] {
265-
mbe::TokenTree::Delimited(_, delimited) => &delimited.tts,
263+
let (rhs, rhs_span): (&mbe::Delimited, DelimSpan) = match &rhses[i] {
264+
mbe::TokenTree::Delimited(span, delimited) => (&delimited, *span),
266265
_ => cx.span_bug(sp, "malformed macro rhs"),
267266
};
268267
let arm_span = rhses[i].span();
269268

270-
let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
269+
let rhs_spans = rhs.tts.iter().map(|t| t.span()).collect::<Vec<_>>();
271270
// rhs has holes ( `$id` and `$(...)` that need filled)
272-
let mut tts = match transcribe(cx, &named_matches, &rhs, transparency) {
271+
let mut tts = match transcribe(cx, &named_matches, &rhs, rhs_span, transparency) {
273272
Ok(tts) => tts,
274273
Err(mut err) => {
275274
err.emit();

compiler/rustc_expand/src/mbe/transcribe.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ impl MutVisitor for Marker {
2929
enum Frame<'a> {
3030
Delimited {
3131
tts: &'a [mbe::TokenTree],
32-
delim_token: token::DelimToken,
3332
idx: usize,
33+
delim_token: token::DelimToken,
3434
span: DelimSpan,
3535
},
3636
Sequence {
@@ -42,8 +42,8 @@ enum Frame<'a> {
4242

4343
impl<'a> Frame<'a> {
4444
/// Construct a new frame around the delimited set of tokens.
45-
fn new(tts: &'a [mbe::TokenTree]) -> Frame<'a> {
46-
Frame::Delimited { tts, delim_token: token::NoDelim, idx: 0, span: DelimSpan::dummy() }
45+
fn new(src: &'a mbe::Delimited, span: DelimSpan) -> Frame<'a> {
46+
Frame::Delimited { tts: &src.tts, idx: 0, delim_token: src.delim, span }
4747
}
4848
}
4949

@@ -85,17 +85,18 @@ impl<'a> Iterator for Frame<'a> {
8585
pub(super) fn transcribe<'a>(
8686
cx: &ExtCtxt<'a>,
8787
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
88-
src: &[mbe::TokenTree],
88+
src: &mbe::Delimited,
89+
src_span: DelimSpan,
8990
transparency: Transparency,
9091
) -> PResult<'a, TokenStream> {
9192
// Nothing for us to transcribe...
92-
if src.is_empty() {
93+
if src.tts.is_empty() {
9394
return Ok(TokenStream::default());
9495
}
9596

9697
// We descend into the RHS (`src`), expanding things as we go. This stack contains the things
9798
// we have yet to expand/are still expanding. We start the stack off with the whole RHS.
98-
let mut stack: SmallVec<[Frame<'_>; 1]> = smallvec![Frame::new(&src)];
99+
let mut stack: SmallVec<[Frame<'_>; 1]> = smallvec![Frame::new(&src, src_span)];
99100

100101
// As we descend in the RHS, we will need to be able to match nested sequences of matchers.
101102
// `repeats` keeps track of where we are in matching at each level, with the last element being

compiler/rustc_index/src/bit_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
17141714
}
17151715

17161716
pub fn row(&self, row: R) -> Option<&HybridBitSet<C>> {
1717-
if let Some(Some(row)) = self.rows.get(row) { Some(row) } else { None }
1717+
self.rows.get(row)?.as_ref()
17181718
}
17191719

17201720
/// Intersects `row` with `set`. `set` can be either `BitSet` or

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,16 @@ pub(crate) fn find_anon_type<'tcx>(
2525
region: Region<'tcx>,
2626
br: &ty::BoundRegionKind,
2727
) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> {
28-
if let Some(anon_reg) = tcx.is_suitable_region(region) {
29-
let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id);
30-
let Some(fn_sig) = tcx.hir().get(hir_id).fn_sig() else {
31-
return None
32-
};
28+
let anon_reg = tcx.is_suitable_region(region)?;
29+
let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id);
30+
let fn_sig = tcx.hir().get(hir_id).fn_sig()?;
3331

34-
fn_sig
35-
.decl
36-
.inputs
37-
.iter()
38-
.find_map(|arg| find_component_for_bound_region(tcx, arg, br))
39-
.map(|ty| (ty, fn_sig))
40-
} else {
41-
None
42-
}
32+
fn_sig
33+
.decl
34+
.inputs
35+
.iter()
36+
.find_map(|arg| find_component_for_bound_region(tcx, arg, br))
37+
.map(|ty| (ty, fn_sig))
4338
}
4439

4540
// This method creates a FindNestedTypeVisitor which returns the type corresponding

0 commit comments

Comments
 (0)