-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #115229 - iSwapna:issue-115222-fix, r=estebank
On method chain expression failure, look for missing method in earlier segments of the chain This PR tries to fix the issue: #115222 As suggested by `@estebank` , I did the following: 1. Add new test `tests/ui/structs/method-chain-expression-failure.rs` 2. In `compiler/rusct_hir_tycheck/src/method/suggest.rs` walking up the method chain and calling `probe_for_name` with the method name. But the call fails to return `Ok`.
- Loading branch information
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
struct A; | ||
struct B; | ||
struct C; | ||
struct D; | ||
struct E; | ||
|
||
impl A { | ||
fn b(&self) -> B { B } | ||
fn foo(&self) {} | ||
} | ||
|
||
impl B { | ||
fn c(&self) -> C { C } | ||
} | ||
|
||
impl C { | ||
fn d(&self) -> D { D } | ||
fn foo(&self) {} | ||
} | ||
|
||
impl D { | ||
fn e(&self) -> E { E } | ||
} | ||
|
||
impl E { | ||
fn f(&self) {} | ||
} | ||
fn main() { | ||
A.b().c().d().e().foo(); | ||
//~^ ERROR no method named `foo` found for struct `E` in the current scope | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0599]: no method named `foo` found for struct `E` in the current scope | ||
--> $DIR/method-chain-expression-failure.rs:29:23 | ||
| | ||
LL | struct E; | ||
| -------- method `foo` not found for this struct | ||
... | ||
LL | A.b().c().d().e().foo(); | ||
| - --- ^^^ method not found in `E` | ||
| | | | ||
| | method `foo` is available on `&C` | ||
| method `foo` is available on `&A` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters