Skip to content

Imprecise error message when Trait in qualified path is not in scope #109809

Closed
@krtab

Description

@krtab

I tried this code:

struct S {}

impl S {
    fn new() -> Self {
        S {}
    }
}


fn main() {
    <S as NonExistingTrait>::method_of_non_existing_trait();
}

I would expect the error message to be something like "cannot find trait NonExistingTrait in this scope" like I would have for

fn f<T : NonExistingTrait>(){}

Instead the error message is

error[E0433]: failed to resolve: use of undeclared type `NonExistingTrait`
  --> example.rs:12:11
   |
12 |     <S as NonExistingTrait>::method_of_non_existing_trait();
   |           ^^^^^^^^^^^^^^^^ use of undeclared type `NonExistingTrait`

Meta

rustc --version --verbose:

rustc 1.70.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.70.0-dev
LLVM version: 16.0.0

@rustbot claim

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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