Skip to content

Commit

Permalink
Avoid infinite recursion on error case in get_path_res.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Sep 7, 2022
1 parent 78a891d commit 80845be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_save_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,9 @@ impl<'tcx> SaveContext<'tcx> {
if seg.res != Res::Err {
seg.res
} else {
// Avoid infinite recursion!
let parent_node = self.tcx.hir().get_parent_node(hir_id);
self.get_path_res(parent_node)
if parent_node != hir_id { self.get_path_res(parent_node) } else { Res::Err }
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/save-analysis/issue-101505.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-flags: -Zsave-analysis

// Check that this doesn't loop infinitely.

fn a(self) {} //~ ERROR `self` parameter is only allowed in associated functions

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/save-analysis/issue-101505.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: `self` parameter is only allowed in associated functions
--> $DIR/issue-101505.rs:5:6
|
LL | fn a(self) {}
| ^^^^ not semantically valid as function parameter
|
= note: associated functions are those in `impl` or `trait` definitions

error: aborting due to previous error

0 comments on commit 80845be

Please sign in to comment.