Skip to content

error message for inherent impl on type that is external could be more explanatory #141679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cyrgani opened this issue May 28, 2025 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented May 28, 2025

Code

use std::rc::Rc;
pub struct Foo;

pub type Function = Rc<Foo>;

impl Function {
    
}

Current output

error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
 --> src/lib.rs:6:1
  |
6 | impl Function {
  | ^^^^^^^^^^^^^ impl for type defined outside of crate
  |
  = note: define and implement a trait or new type instead

Desired output

error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
 --> src/lib.rs:6:1
  |
6 | impl Function {
  | ^^^^^^^^^^^^^ impl for type defined outside of crate
  |
  = note: define and implement a trait or new type instead (`pub struct Function(Rc<Foo>);`)
  = note: `type` does not define a new type, only a type alias
  = note: `Function` is actually `Rc<Foo>`, a type not defined in the current crate

Rationale and extra context

To a beginner, it looks as if Function was a new type, so the error message should be a bit more explanatory why it is not.

Other cases

Rust Version

1.89.0-nightly

(2025-05-27 45f256d9d7cffb66185c)

Anything else?

@rustbot label D-terse

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 28, 2025
@rustbot rustbot added the D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. label May 28, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants