Skip to content

Change orphan hint from "only" to "any uncovered type inside..." #128391

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

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,14 @@ hir_analysis_only_current_traits_arbitrary = only traits defined in the current

hir_analysis_only_current_traits_foreign = this is not defined in the current crate because this is a foreign trait

hir_analysis_only_current_traits_label = impl doesn't use only types from inside the current crate

hir_analysis_only_current_traits_name = this is not defined in the current crate because {$name} are always foreign

hir_analysis_only_current_traits_note = define and implement a trait or new type instead

hir_analysis_only_current_traits_note_more_info = for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules

hir_analysis_only_current_traits_note_uncovered = impl doesn't have any local type before any uncovered type parameters

hir_analysis_only_current_traits_opaque = type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate

hir_analysis_only_current_traits_outside = only traits defined in the current crate can be implemented for types defined outside of the crate
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,24 +1440,27 @@ pub enum OnlyCurrentTraits {
#[diag(hir_analysis_only_current_traits_outside, code = E0117)]
Outside {
#[primary_span]
#[label(hir_analysis_only_current_traits_label)]
span: Span,
#[note(hir_analysis_only_current_traits_note_uncovered)]
#[note(hir_analysis_only_current_traits_note_more_info)]
#[note(hir_analysis_only_current_traits_note)]
note: (),
},
#[diag(hir_analysis_only_current_traits_primitive, code = E0117)]
Primitive {
#[primary_span]
#[label(hir_analysis_only_current_traits_label)]
span: Span,
#[note(hir_analysis_only_current_traits_note_uncovered)]
#[note(hir_analysis_only_current_traits_note_more_info)]
#[note(hir_analysis_only_current_traits_note)]
note: (),
},
#[diag(hir_analysis_only_current_traits_arbitrary, code = E0117)]
Arbitrary {
#[primary_span]
#[label(hir_analysis_only_current_traits_label)]
span: Span,
#[note(hir_analysis_only_current_traits_note_uncovered)]
#[note(hir_analysis_only_current_traits_note_more_info)]
#[note(hir_analysis_only_current_traits_note)]
note: (),
},
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/coherence/coherence-cow.re_a.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ty
|
LL | impl<T> Remote for Pair<T,Cover<T>> { }
| ^^^^^^^^^^^^^^^^^^^----------------
| | |
| | `Pair` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `Pair` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/coherence/coherence-cow.re_b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ty
|
LL | impl<T> Remote for Pair<Cover<T>,T> { }
| ^^^^^^^^^^^^^^^^^^^----------------
| | |
| | `Pair` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `Pair` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/coherence/coherence-cow.re_c.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ty
|
LL | impl<T,U> Remote for Pair<Cover<T>,U> { }
| ^^^^^^^^^^^^^^^^^^^^^----------------
| | |
| | `Pair` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `Pair` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/coherence/coherence-fundamental-trait-objects.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Misc for dyn Fundamental<Local> {}
| ^^^^^^^^^^^^^^----------------------
| | |
| | `dyn Fundamental<Local>` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `dyn Fundamental<Local>` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl !Send for dyn Marker2 {}
| ^^^^^^^^^^^^^^^-----------
| | |
| | `dyn Marker2` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `dyn Marker2` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | unsafe impl Send for dyn Marker2 {}
| ^^^^^^^^^^^^^^^^^^^^^-----------
| | |
| | `dyn Marker2` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `dyn Marker2` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)`
Expand Down
28 changes: 16 additions & 12 deletions tests/ui/coherence/coherence-impls-copy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Copy for &'static [NotSync] {}
| ^^^^^^^^^^^^^^------------------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for primitive types
--> $DIR/coherence-impls-copy.rs:5:1
|
LL | impl Copy for i32 {}
| ^^^^^^^^^^^^^^---
| | |
| | `i32` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `i32` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0206]: the trait `Copy` cannot be implemented for this type
Expand All @@ -41,10 +43,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Copy for (MyType, MyType) {}
| ^^^^^^^^^^^^^^----------------
| | |
| | this is not defined in the current crate because tuples are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because tuples are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0206]: the trait `Copy` cannot be implemented for this type
Expand All @@ -58,10 +61,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Copy for [MyType] {}
| ^^^^^^^^^^^^^^--------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0206]: the trait `Copy` cannot be implemented for this type
Expand Down
21 changes: 12 additions & 9 deletions tests/ui/coherence/coherence-impls-send.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | unsafe impl Send for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^^^^^^^------------------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-send.rs:16:1
|
LL | unsafe impl Send for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^^^^^^^----------------
| | |
| | this is not defined in the current crate because tuples are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because tuples are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `&'static NotSync`
Expand All @@ -31,10 +33,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | unsafe impl Send for [MyType] {}
| ^^^^^^^^^^^^^^^^^^^^^--------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 4 previous errors
Expand Down
21 changes: 12 additions & 9 deletions tests/ui/coherence/coherence-impls-sized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Sized for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^----------------
| | |
| | this is not defined in the current crate because tuples are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because tuples are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0322]: explicit impls for the `Sized` trait are not permitted
Expand All @@ -44,10 +45,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Sized for [MyType] {}
| ^^^^^^^^^^^^^^^--------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0322]: explicit impls for the `Sized` trait are not permitted
Expand All @@ -61,10 +63,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl Sized for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^------------------
| | |
| | this is not defined in the current crate because slices are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because slices are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 9 previous errors
Expand Down
21 changes: 12 additions & 9 deletions tests/ui/coherence/coherence-negative-impls-copy-bad.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
LL | impl !Copy for str {}
| ^^^^^^^^^^^^^^^---
| | |
| | `str` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `str` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-negative-impls-copy-bad.rs:7:1
|
LL | impl !Copy for fn() {}
| ^^^^^^^^^^^^^^^----
| | |
| | `fn()` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `fn()` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-negative-impls-copy-bad.rs:10:1
|
LL | impl !Copy for () {}
| ^^^^^^^^^^^^^^^--
| | |
| | this is not defined in the current crate because tuples are always foreign
| impl doesn't use only types from inside the current crate
| |
| this is not defined in the current crate because tuples are always foreign
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 3 previous errors
Expand Down
16 changes: 9 additions & 7 deletions tests/ui/coherence/coherence-orphan.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ error[E0117]: only traits defined in the current crate can be implemented for pr
|
LL | impl TheTrait<usize> for isize {}
| ^^^^^---------------^^^^^-----
| | | |
| | | `isize` is not defined in the current crate
| | `usize` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| | |
| | `isize` is not defined in the current crate
| `usize` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> $DIR/coherence-orphan.rs:17:1
|
LL | impl !Send for Vec<isize> {}
| ^^^^^^^^^^^^^^^----------
| | |
| | `Vec` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `Vec` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 2 previous errors
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/coherence/coherence-overlapping-pairs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ty
|
LL | impl<T> Remote for lib::Pair<T,Foo> { }
| ^^^^^^^^^^^^^^^^^^^----------------
| | |
| | `Pair` is not defined in the current crate
| impl doesn't use only types from inside the current crate
| |
| `Pair` is not defined in the current crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead

error: aborting due to 1 previous error
Expand Down
Loading
Loading