Skip to content

Commit d091832

Browse files
Auto merge of #127241 - cjgillot:def-collector-span, r=<try>
Mark span parent in def_collector.
2 parents ce5fdd7 + d347d18 commit d091832

File tree

25 files changed

+547
-551
lines changed

25 files changed

+547
-551
lines changed

compiler/rustc_ast/src/format.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ pub struct FormatPlaceholder {
180180
#[visitable(ignore)]
181181
pub format_trait: FormatTrait,
182182
/// `{}` or `{:.5}` or `{:-^20}`, etc.
183-
#[visitable(ignore)]
184183
pub format_options: FormatOptions,
185184
}
186185

@@ -229,23 +228,26 @@ pub enum FormatTrait {
229228
UpperHex,
230229
}
231230

232-
#[derive(Clone, Encodable, Decodable, Default, Debug, PartialEq, Eq)]
231+
#[derive(Clone, Encodable, Decodable, Default, Debug, PartialEq, Eq, Walkable)]
233232
pub struct FormatOptions {
234233
/// The width. E.g. `{:5}` or `{:width$}`.
235234
pub width: Option<FormatCount>,
236235
/// The precision. E.g. `{:.5}` or `{:.precision$}`.
237236
pub precision: Option<FormatCount>,
238237
/// The alignment. E.g. `{:>}` or `{:<}` or `{:^}`.
238+
#[visitable(ignore)]
239239
pub alignment: Option<FormatAlignment>,
240240
/// The fill character. E.g. the `.` in `{:.>10}`.
241241
pub fill: Option<char>,
242242
/// The `+` or `-` flag.
243+
#[visitable(ignore)]
243244
pub sign: Option<FormatSign>,
244245
/// The `#` flag.
245246
pub alternate: bool,
246247
/// The `0` flag. E.g. the `0` in `{:02x}`.
247248
pub zero_pad: bool,
248249
/// The `x` or `X` flag (for `Debug` only). E.g. the `x` in `{:x?}`.
250+
#[visitable(ignore)]
249251
pub debug_hex: Option<FormatDebugHex>,
250252
}
251253

@@ -275,7 +277,7 @@ pub enum FormatAlignment {
275277
Center,
276278
}
277279

278-
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
280+
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)]
279281
pub enum FormatCount {
280282
/// `{:5}` or `{:.5}`
281283
Literal(u16),

compiler/rustc_ast/src/visit.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ macro_rules! common_visitor_and_walkers {
375375
std::borrow::Cow<'_, str>,
376376
Symbol,
377377
u8,
378+
u16,
378379
usize,
379380
);
380381
// `Span` is only a no-op for the non-mutable visitor.
@@ -436,6 +437,8 @@ macro_rules! common_visitor_and_walkers {
436437
FormatArgument,
437438
FormatArgumentKind,
438439
FormatArguments,
440+
FormatCount,
441+
FormatOptions,
439442
FormatPlaceholder,
440443
GenericParamKind,
441444
Impl,
@@ -1067,6 +1070,7 @@ macro_rules! common_visitor_and_walkers {
10671070
pub fn walk_contract(FnContract);
10681071
pub fn walk_coroutine_kind(CoroutineKind);
10691072
pub fn walk_crate(Crate);
1073+
pub fn walk_defaultness(Defaultness);
10701074
pub fn walk_expr(Expr);
10711075
pub fn walk_expr_field(ExprField);
10721076
pub fn walk_field_def(FieldDef);

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
237237
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
238238
}
239239
};
240-
(op, self.lower_span(*op_sp))
240+
(op, *op_sp)
241241
})
242242
.collect();
243243

@@ -463,7 +463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
463463
late: true,
464464
expr: None,
465465
},
466-
self.lower_span(abi_span),
466+
abi_span,
467467
));
468468
clobbered.insert(clobber);
469469
}
@@ -497,12 +497,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
497497
let operands = self.arena.alloc_from_iter(operands);
498498
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
499499
let template_strs = self.arena.alloc_from_iter(
500-
asm.template_strs
501-
.iter()
502-
.map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))),
500+
asm.template_strs.iter().map(|(sym, snippet, span)| (*sym, *snippet, *span)),
503501
);
504-
let line_spans =
505-
self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span)));
502+
let line_spans = self.arena.alloc_from_iter(asm.line_spans.iter().copied());
506503
let hir_asm = hir::InlineAsm {
507504
asm_macro: asm.asm_macro,
508505
template,

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2323
) -> hir::Block<'hir> {
2424
let (stmts, expr) = self.lower_stmts(&b.stmts);
2525
let rules = self.lower_block_check_mode(&b.rules);
26-
hir::Block { hir_id, stmts, expr, rules, span: self.lower_span(b.span), targeted_by_break }
26+
hir::Block { hir_id, stmts, expr, rules, span: b.span, targeted_by_break }
2727
}
2828

2929
fn lower_stmts(
@@ -39,7 +39,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3939
let local = self.lower_local(local);
4040
self.alias_attrs(hir_id, local.hir_id);
4141
let kind = hir::StmtKind::Let(local);
42-
let span = self.lower_span(s.span);
42+
let span = s.span;
4343
stmts.push(hir::Stmt { hir_id, kind, span });
4444
}
4545
StmtKind::Item(it) => {
@@ -50,7 +50,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5050
_ => self.next_id(),
5151
};
5252
let kind = hir::StmtKind::Item(item_id);
53-
let span = self.lower_span(s.span);
53+
let span = s.span;
5454
hir::Stmt { hir_id, kind, span }
5555
},
5656
));
@@ -63,7 +63,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6363
let hir_id = self.lower_node_id(s.id);
6464
self.alias_attrs(hir_id, e.hir_id);
6565
let kind = hir::StmtKind::Expr(e);
66-
let span = self.lower_span(s.span);
66+
let span = s.span;
6767
stmts.push(hir::Stmt { hir_id, kind, span });
6868
}
6969
}
@@ -72,7 +72,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7272
let hir_id = self.lower_node_id(s.id);
7373
self.alias_attrs(hir_id, e.hir_id);
7474
let kind = hir::StmtKind::Semi(e);
75-
let span = self.lower_span(s.span);
75+
let span = s.span;
7676
stmts.push(hir::Stmt { hir_id, kind, span });
7777
}
7878
StmtKind::Empty => {}
@@ -107,7 +107,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
107107
} else {
108108
None
109109
};
110-
let span = self.lower_span(l.span);
110+
let span = l.span;
111111
let source = hir::LocalSource::Normal;
112112
self.lower_attrs(hir_id, &l.attrs, l.span);
113113
self.arena.alloc(hir::LetStmt { hir_id, super_, ty, pat, init, els, span, source })

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
8383
item_id: NodeId,
8484
is_in_trait_impl: bool,
8585
) -> DelegationResults<'hir> {
86-
let span = self.lower_span(delegation.path.segments.last().unwrap().ident.span);
86+
let span = delegation.path.segments.last().unwrap().ident.span;
8787
let sig_id = self.get_delegation_sig_id(item_id, delegation.id, span, is_in_trait_impl);
8888
match sig_id {
8989
Ok(sig_id) => {
@@ -92,9 +92,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
9292
let decl = self.lower_delegation_decl(sig_id, param_count, c_variadic, span);
9393
let sig = self.lower_delegation_sig(sig_id, decl, span);
9494
let body_id = self.lower_delegation_body(delegation, is_method, param_count, span);
95-
let ident = self.lower_ident(delegation.ident);
9695
let generics = self.lower_delegation_generics(span);
97-
DelegationResults { body_id, sig, ident, generics }
96+
DelegationResults { body_id, sig, ident: delegation.ident, generics }
9897
}
9998
Err(err) => self.generate_delegation_error(err, span),
10099
}

0 commit comments

Comments
 (0)