Skip to content

Commit 80845be

Browse files
committed
Avoid infinite recursion on error case in get_path_res.
Fixes #101505.
1 parent 78a891d commit 80845be

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,9 @@ impl<'tcx> SaveContext<'tcx> {
600600
if seg.res != Res::Err {
601601
seg.res
602602
} else {
603+
// Avoid infinite recursion!
603604
let parent_node = self.tcx.hir().get_parent_node(hir_id);
604-
self.get_path_res(parent_node)
605+
if parent_node != hir_id { self.get_path_res(parent_node) } else { Res::Err }
605606
}
606607
}
607608

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: -Zsave-analysis
2+
3+
// Check that this doesn't loop infinitely.
4+
5+
fn a(self) {} //~ ERROR `self` parameter is only allowed in associated functions
6+
7+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `self` parameter is only allowed in associated functions
2+
--> $DIR/issue-101505.rs:5:6
3+
|
4+
LL | fn a(self) {}
5+
| ^^^^ not semantically valid as function parameter
6+
|
7+
= note: associated functions are those in `impl` or `trait` definitions
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)