Skip to content

"bad" error message for inferred trait type arguments. #104784

Open
@downloadpizza

Description

@downloadpizza

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

fn main() {
    A::run();
}

pub struct A;
    
pub trait Runnable<T> {
    fn run();
}

mod hides_trait {
    use crate::{Runnable, A};
    
    struct DefinetlyNotPublic;

    impl Runnable<DefinetlyNotPublic> for A {
        fn run() {
            println!("impl");
        }
    }
}

In the above, the rust complier is smart enough to figure out that the user wants to call <A as Runnable<DefinetlyNotPublic>>::run(). It inferres that, and then notices that DefinetlyNotPublic is not public.

You then get this errors:

error: type `DefinetlyNotPublic` is private
 --> src/main.rs:2:5
  |
2 |     A::run();
  |     ^^^^^^ private type

error: could not compile `playground` due to previous error

Why do I think this is not perfect: The type DefinetlyNotPublic is mentioned, even though there is nothing in the code referring to it. Mentioning the inferred Runnable<DefinetlyNotPublic> would be enough. Something like

error: type `DefinetlyNotPublic` is private
 --> src/main.rs:2:5
  |
2 |     A::run();
  |     ^^^^^^------ calls `Runnable<DefinetlyNotPublic>::run()` but type parameter `DefinetlyNotPublic` is private.

Is this important? Not really, I just felt like reporting it since it is a small improvement.
If it is a quick fix and someone is bored go for it.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyT-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