Skip to content

Mark span parent in def_collector. #127241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 5 additions & 3 deletions compiler/rustc_ast/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ pub struct FormatPlaceholder {
#[visitable(ignore)]
pub format_trait: FormatTrait,
/// `{}` or `{:.5}` or `{:-^20}`, etc.
#[visitable(ignore)]
pub format_options: FormatOptions,
}

Expand Down Expand Up @@ -229,23 +228,26 @@ pub enum FormatTrait {
UpperHex,
}

#[derive(Clone, Encodable, Decodable, Default, Debug, PartialEq, Eq)]
#[derive(Clone, Encodable, Decodable, Default, Debug, PartialEq, Eq, Walkable)]
pub struct FormatOptions {
/// The width. E.g. `{:5}` or `{:width$}`.
pub width: Option<FormatCount>,
/// The precision. E.g. `{:.5}` or `{:.precision$}`.
pub precision: Option<FormatCount>,
/// The alignment. E.g. `{:>}` or `{:<}` or `{:^}`.
#[visitable(ignore)]
pub alignment: Option<FormatAlignment>,
/// The fill character. E.g. the `.` in `{:.>10}`.
pub fill: Option<char>,
/// The `+` or `-` flag.
#[visitable(ignore)]
pub sign: Option<FormatSign>,
/// The `#` flag.
pub alternate: bool,
/// The `0` flag. E.g. the `0` in `{:02x}`.
pub zero_pad: bool,
/// The `x` or `X` flag (for `Debug` only). E.g. the `x` in `{:x?}`.
#[visitable(ignore)]
pub debug_hex: Option<FormatDebugHex>,
}

Expand Down Expand Up @@ -275,7 +277,7 @@ pub enum FormatAlignment {
Center,
}

#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)]
pub enum FormatCount {
/// `{:5}` or `{:.5}`
Literal(u16),
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ macro_rules! common_visitor_and_walkers {
std::borrow::Cow<'_, str>,
Symbol,
u8,
u16,
usize,
);
// `Span` is only a no-op for the non-mutable visitor.
Expand Down Expand Up @@ -436,6 +437,8 @@ macro_rules! common_visitor_and_walkers {
FormatArgument,
FormatArgumentKind,
FormatArguments,
FormatCount,
FormatOptions,
FormatPlaceholder,
GenericParamKind,
Impl,
Expand Down Expand Up @@ -1067,6 +1070,7 @@ macro_rules! common_visitor_and_walkers {
pub fn walk_contract(FnContract);
pub fn walk_coroutine_kind(CoroutineKind);
pub fn walk_crate(Crate);
pub fn walk_defaultness(Defaultness);
pub fn walk_expr(Expr);
pub fn walk_expr_field(ExprField);
pub fn walk_field_def(FieldDef);
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
}
};
(op, self.lower_span(*op_sp))
(op, *op_sp)
})
.collect();

Expand Down Expand Up @@ -463,7 +463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
late: true,
expr: None,
},
self.lower_span(abi_span),
abi_span,
));
clobbered.insert(clobber);
}
Expand Down Expand Up @@ -497,12 +497,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let operands = self.arena.alloc_from_iter(operands);
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
let template_strs = self.arena.alloc_from_iter(
asm.template_strs
.iter()
.map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))),
asm.template_strs.iter().map(|(sym, snippet, span)| (*sym, *snippet, *span)),
);
let line_spans =
self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span)));
let line_spans = self.arena.alloc_from_iter(asm.line_spans.iter().copied());
let hir_asm = hir::InlineAsm {
asm_macro: asm.asm_macro,
template,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast_lowering/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::Block<'hir> {
let (stmts, expr) = self.lower_stmts(&b.stmts);
let rules = self.lower_block_check_mode(&b.rules);
hir::Block { hir_id, stmts, expr, rules, span: self.lower_span(b.span), targeted_by_break }
hir::Block { hir_id, stmts, expr, rules, span: b.span, targeted_by_break }
}

fn lower_stmts(
Expand All @@ -39,7 +39,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let local = self.lower_local(local);
self.alias_attrs(hir_id, local.hir_id);
let kind = hir::StmtKind::Let(local);
let span = self.lower_span(s.span);
let span = s.span;
stmts.push(hir::Stmt { hir_id, kind, span });
}
StmtKind::Item(it) => {
Expand All @@ -50,7 +50,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
_ => self.next_id(),
};
let kind = hir::StmtKind::Item(item_id);
let span = self.lower_span(s.span);
let span = s.span;
hir::Stmt { hir_id, kind, span }
},
));
Expand All @@ -63,7 +63,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let hir_id = self.lower_node_id(s.id);
self.alias_attrs(hir_id, e.hir_id);
let kind = hir::StmtKind::Expr(e);
let span = self.lower_span(s.span);
let span = s.span;
stmts.push(hir::Stmt { hir_id, kind, span });
}
}
Expand All @@ -72,7 +72,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let hir_id = self.lower_node_id(s.id);
self.alias_attrs(hir_id, e.hir_id);
let kind = hir::StmtKind::Semi(e);
let span = self.lower_span(s.span);
let span = s.span;
stmts.push(hir::Stmt { hir_id, kind, span });
}
StmtKind::Empty => {}
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
None
};
let span = self.lower_span(l.span);
let span = l.span;
let source = hir::LocalSource::Normal;
self.lower_attrs(hir_id, &l.attrs, l.span);
self.arena.alloc(hir::LetStmt { hir_id, super_, ty, pat, init, els, span, source })
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
item_id: NodeId,
is_in_trait_impl: bool,
) -> DelegationResults<'hir> {
let span = self.lower_span(delegation.path.segments.last().unwrap().ident.span);
let span = delegation.path.segments.last().unwrap().ident.span;
let sig_id = self.get_delegation_sig_id(item_id, delegation.id, span, is_in_trait_impl);
match sig_id {
Ok(sig_id) => {
Expand All @@ -92,9 +92,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let decl = self.lower_delegation_decl(sig_id, param_count, c_variadic, span);
let sig = self.lower_delegation_sig(sig_id, decl, span);
let body_id = self.lower_delegation_body(delegation, is_method, param_count, span);
let ident = self.lower_ident(delegation.ident);
let generics = self.lower_delegation_generics(span);
DelegationResults { body_id, sig, ident, generics }
DelegationResults { body_id, sig, ident: delegation.ident, generics }
}
Err(err) => self.generate_delegation_error(err, span),
}
Expand Down
Loading
Loading