Skip to content

On method chain expression failure, look for missing method in earlier segments of the chain #115222

Closed
@estebank

Description

@estebank

Code

struct A;
struct B;
struct C;
struct D;

impl A {
    fn b(&self) -> B { B }
}
impl B {
    fn c(&self) -> C { C }
    fn foo(&self) {}
}
impl C {
    fn d(&self) -> D { D }
}
impl D {
    fn e(&self) {}
}

fn main() {
    A.b().c().d().foo();
}

Current output

error[E0599]: no method named `foo` found for struct `D` in the current scope
  --> src/main.rs:21:19
   |
4  | struct D;
   | -------- method `foo` not found for this struct
...
21 |     A.b().c().d().foo();
   |                   ^^^ method not found in `D`

Desired output

error[E0599]: no method named `foo` found for struct `D` in the current scope
  --> src/main.rs:21:19
   |
2  | struct B;
   | -------- method `foo` found for this struct
3  | struct C;
4  | struct D;
   | -------- method `foo` not found for this struct
...
21 |     A.b().c().d().foo();
   |     -----         ^^^ method not found in `D`
   |     |
   |     method `foo` available after this method call

Rationale and extra context

No response

Other cases

No response

Anything else?

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5d27c80570db4a4005f5ff3d4ea94e0e

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions