Skip to content

Diagnostics suggest incorrect paths when inline modules are used #119521

Open
@WaffleLapkin

Description

@WaffleLapkin

I tried this code:

struct A;

mod inner {
    struct A;
    
    impl From<super::A> for A {}
    impl From<A> for super::A {}
}

I expected to see this happen: an error suggesting the following code:

struct A;

mod inner {
    struct A;
    
    impl From<super::A> for A { fn from(_: super::A) -> Self { todo!() } }
    impl From<A> for super::A { fn from(_: A) -> Self { todo!() } }
}

Instead, this happened: an error suggested the following (incorrect) code:

struct A;

mod inner {
    struct A;
    
    impl From<super::A> for A { fn from(_: A) -> Self { todo!() } }
    impl From<A> for super::A { fn from(_: inner::A) -> Self { todo!() } }
}
error[E0046]: not all trait items implemented, missing: `from`
 --> ./t.rs:6:5
  |
6 |     impl From<super::A> for A {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from` in implementation
  |
  = help: implement the missing item: `fn from(_: A) -> Self { todo!() }`

error[E0046]: not all trait items implemented, missing: `from`
 --> ./t.rs:7:5
  |
7 |     impl From<A> for super::A {}
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `from` in implementation
  |
  = help: implement the missing item: `fn from(_: inner::A) -> Self { todo!() }`

Meta

rustc --version --verbose:

rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions