Skip to content

Add note when inherent impl for a alias type defined outside of the crate #142415

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Jun 12, 2025

Fixes #141679

r? compiler

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 12, 2025
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/insufficient-suggestion-issue-141679.rs:6:1
|
LL | impl Function {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to point out the span of the type alias, and explain that the orphan checking rules apply to that type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion!

…rate

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Comment on lines +1 to +15
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
--> $DIR/insufficient-suggestion-issue-141679.rs:6:1
|
LL | impl Function {}
| ^^^^^^^^^^^^^ impl for type defined outside of crate
|
= note: define and implement a trait or new type instead, for more details about orphan rules, see <https://doc.rust-lang.org/reference/items/implementations.html?highlight=orphan#orphan-rules>
note: `Function` does not define a new type, just alias of `Rc<Foo>` defined here
--> $DIR/insufficient-suggestion-issue-141679.rs:4:1
|
LL | pub type Function = Rc<Foo>;
| ^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It give a link to rust reference for explaining the orphan rules. and present the span where the alias is defined.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 23, 2025

r? compiler

@rustbot rustbot assigned lcnr and unassigned BoxyUwU Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error message for inherent impl on type that is external could be more explanatory
5 participants