Skip to content

[WIP] Delay def collection for expression-like nodes #128844

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Show nested items in rustc_dump_def_parents
  • Loading branch information
camelid committed Aug 8, 2024
commit 79a3e7a9426d86f87fcd8f9fe6f27c3071e15747
13 changes: 9 additions & 4 deletions compiler/rustc_hir_analysis/src/collect/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
self.tcx.hir()
}

fn visit_item(&mut self, i: &'tcx rustc_hir::Item<'tcx>) -> Self::Result {
self.defs.push(i.owner_id.def_id);
intravisit::walk_item(self, i)
}

fn visit_anon_const(&mut self, c: &'tcx rustc_hir::AnonConst) {
self.defs.push(c.def_id);
intravisit::walk_anon_const(self, c)
Expand All @@ -76,13 +81,13 @@ pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
// Look for any anon consts inside of this body owner as there is no way to apply
// the `rustc_dump_def_parents` attribute to the anon const so it would not be possible
// to see what its def parent is.
let mut expr_def_finder = ExprDefFinder { tcx, defs: vec![] };
let mut def_finder = ExprDefFinder { tcx, defs: vec![] };
tcx.hir()
.fn_decl_by_hir_id(tcx.local_def_id_to_hir_id(did))
.map(|decl| intravisit::walk_fn_decl(&mut expr_def_finder, decl));
intravisit::walk_expr(&mut expr_def_finder, tcx.hir().body_owned_by(did).value);
.map(|decl| intravisit::walk_fn_decl(&mut def_finder, decl));
intravisit::walk_expr(&mut def_finder, tcx.hir().body_owned_by(did).value);

for did in [did].into_iter().chain(expr_def_finder.defs) {
for did in [did].into_iter().chain(def_finder.defs) {
let span = tcx.def_span(did);

let mut diag = tcx.dcx().struct_span_err(
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_passes/src/hir_id_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
if def_parent_hir_id.owner != owner {
self.error(|| {
format!(
"inconsistent Def parent at `{:?}` for `{:?}`:\nexpected={:?}\nfound={:?}",
"inconsistent Def parent at `{:?}` for `{:?}`:\nexpected={:?}\nfound={:?} ({:?})",
self.tcx.def_span(id),
id,
owner,
def_parent_hir_id
def_parent_hir_id,
def_parent,
)
});
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/attributes/dump_def_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn bar() {
{
//~^ ERROR: rustc_dump_def_parents: DefId
fn doesnt_inhibit_dump() {
//~^ ERROR: rustc_dump_def_parents: DefId
qux::<
{
//~^ ERROR: rustc_dump_def_parents: DefId
Expand Down
35 changes: 34 additions & 1 deletion tests/ui/attributes/dump_def_parents.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,39 @@ LL | |
LL | | fn main() {}
| |____________^

error: rustc_dump_def_parents: DefId(..)
--> $DIR/dump_def_parents.rs:13:25
|
LL | fn doesnt_inhibit_dump() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: DefId(..)
--> $DIR/dump_def_parents.rs:6:9
|
LL | fn baz() {
| ^^^^^^^^
note: DefId(..)
--> $DIR/dump_def_parents.rs:5:5
|
LL | fn foo() {
| ^^^^^^^^
note: DefId(..)
--> $DIR/dump_def_parents.rs:4:1
|
LL | fn bar() {
| ^^^^^^^^
note: DefId(..)
--> $DIR/dump_def_parents.rs:2:1
|
LL | / #![feature(rustc_attrs)]
LL | |
LL | | fn bar() {
LL | | fn foo() {
... |
LL | |
LL | | fn main() {}
| |____________^

error: rustc_dump_def_parents: DefId(..)
--> $DIR/dump_def_parents.rs:15:33
|
Expand Down Expand Up @@ -184,5 +217,5 @@ LL | |
LL | | fn main() {}
| |____________^

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

Loading