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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ macro_rules! common_visitor_and_walkers {
}
}

fn visit_defaultness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, defaultness: &$($lt)? $($mut)? Defaultness) -> V::Result {
pub fn visit_defaultness<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, defaultness: &$($lt)? $($mut)? Defaultness) -> V::Result {
match defaultness {
Defaultness::Default(span) => visit_span(vis, span),
Defaultness::Final => {
Expand Down Expand Up @@ -807,7 +807,7 @@ macro_rules! common_visitor_and_walkers {
visit_foreign_items(vis, items)
}

fn walk_define_opaques<$($lt,)? V: $Visitor$(<$lt>)?>(
pub fn walk_define_opaques<$($lt,)? V: $Visitor$(<$lt>)?>(
visitor: &mut V,
define_opaque: &$($lt)? $($mut)? Option<ThinVec<(NodeId, Path)>>,
) -> V::Result {
Expand Down Expand Up @@ -1225,6 +1225,27 @@ macro_rules! common_visitor_and_walkers {
V::Result::output()
}

pub fn walk_stmt<$($lt,)? V: $Visitor$(<$lt>)?>(
vis: &mut V,
statement: &$($lt)? $($mut)? Stmt,
) -> V::Result {
let Stmt { id, kind, span } = statement;
try_visit!(visit_id(vis, id));
match kind {
StmtKind::Let(local) => try_visit!(vis.visit_local(local)),
StmtKind::Item(item) => try_visit!(vis.visit_item(item)),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(vis.visit_expr(expr)),
StmtKind::Empty => {}
StmtKind::MacCall(mac) => {
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &$($mut)? **mac;
walk_list!(vis, visit_attribute, attrs);
try_visit!(vis.visit_mac_call(mac));
}
}
try_visit!(visit_span(vis, span));
V::Result::output()
}

pub fn walk_path<$($lt,)? V: $Visitor$(<$lt>)?>(
vis: &mut V,
path: &$($lt)? $($mut)? Path,
Expand Down Expand Up @@ -1944,20 +1965,3 @@ fn visit_nested_use_tree<'a, V: Visitor<'a>>(
) -> V::Result {
vis.visit_nested_use_tree(nested_tree, nested_id)
}

pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
let Stmt { id, kind, span: _ } = statement;
try_visit!(visit_id(visitor, id));
match kind {
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
StmtKind::Empty => {}
StmtKind::MacCall(mac) => {
let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
walk_list!(visitor, visit_attribute, attrs);
try_visit!(visitor.visit_mac_call(mac));
}
}
V::Result::output()
}
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