Skip to content
Open
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn emit_orphan_check_error<'tcx>(
let impl_ = item.expect_impl();
let of_trait = impl_.of_trait.unwrap();

let span = tcx.def_span(impl_def_id);
let span = impl_.self_ty.span;
let mut diag = tcx.dcx().create_err(match trait_ref.self_ty().kind() {
ty::Adt(..) => diagnostics::OnlyCurrentTraits::Outside { span, note: () },
_ if trait_ref.self_ty().is_primitive() => {
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/any/reject_manual_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ LL | impl TryAsDynCompatible<'static> for dyn Iterator<Item = u32> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `TryAsDynCompatible` not allowed

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/reject_manual_impl.rs:25:1
--> $DIR/reject_manual_impl.rs:25:38
|
LL | impl TryAsDynCompatible<'static> for dyn Iterator<Item = u32> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------------------------
| |
| `dyn Iterator<Item = u32>` is not defined in the current crate
| ^^^^^^^^^^^^^^^^^^^^^^^^ `dyn Iterator<Item = u32>` 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
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/coherence/coherence-cow.re_a.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> $DIR/coherence-cow.rs:18:1
--> $DIR/coherence-cow.rs:18:20
|
LL | impl<T> Remote for Pair<T,Cover<T>> { }
| ^^^^^^^^^^^^^^^^^^^----------------
| |
| `Pair` is not defined in 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
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/coherence/coherence-cow.re_b.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> $DIR/coherence-cow.rs:22:1
--> $DIR/coherence-cow.rs:22:20
|
LL | impl<T> Remote for Pair<Cover<T>,T> { }
| ^^^^^^^^^^^^^^^^^^^----------------
| |
| `Pair` is not defined in 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
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/coherence/coherence-cow.re_c.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> $DIR/coherence-cow.rs:26:1
--> $DIR/coherence-cow.rs:26:22
|
LL | impl<T,U> Remote for Pair<Cover<T>,U> { }
| ^^^^^^^^^^^^^^^^^^^^^----------------
| |
| `Pair` is not defined in 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
Expand Down
6 changes: 2 additions & 4 deletions tests/ui/coherence/coherence-fundamental-trait-objects.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-fundamental-trait-objects.rs:12:1
--> $DIR/coherence-fundamental-trait-objects.rs:12:15
|
LL | impl Misc for dyn Fundamental<Local> {}
| ^^^^^^^^^^^^^^----------------------
| |
| `dyn Fundamental<Local>` is not defined in 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ LL | impl !Marker2 for dyn Object {}
= note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:22:1
--> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:22:16
|
LL | impl !Send for dyn Marker2 {}
| ^^^^^^^^^^^^^^^-----------
| |
| `dyn Marker2` is not defined in 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ LL | impl Marker2 for dyn Object {}
= note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:22:1
--> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:22:22
|
LL | unsafe impl Send for dyn Marker2 {}
| ^^^^^^^^^^^^^^^^^^^^^-----------
| |
| `dyn Marker2` is not defined in 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
Expand Down
24 changes: 8 additions & 16 deletions tests/ui/coherence/coherence-impls-copy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ LL | impl Copy for &'static NotSync {}
where T: ?Sized;

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-copy.rs:33:1
--> $DIR/coherence-impls-copy.rs:33:15
|
LL | impl Copy for &'static [NotSync] {}
| ^^^^^^^^^^^^^^------------------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^^^^^^^^^^^ 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
--> $DIR/coherence-impls-copy.rs:5:15
|
LL | impl Copy for i32 {}
| ^^^^^^^^^^^^^^---
| |
| `i32` is not defined in 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
Expand All @@ -39,12 +35,10 @@ LL | impl Copy for &'static mut MyType {}
| ^^^^^^^^^^^^^^^^^^^ type is not a structure or enumeration

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-copy.rs:25:1
--> $DIR/coherence-impls-copy.rs:25:15
|
LL | impl Copy for (MyType, MyType) {}
| ^^^^^^^^^^^^^^----------------
| |
| this is not defined in the current crate because tuples are always foreign
| ^^^^^^^^^^^^^^^^ 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
Expand All @@ -57,12 +51,10 @@ LL | impl Copy for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^^ type is not a structure or enumeration

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-copy.rs:30:1
--> $DIR/coherence-impls-copy.rs:30:15
|
LL | impl Copy for [MyType] {}
| ^^^^^^^^^^^^^^--------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^ 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
Expand Down
18 changes: 6 additions & 12 deletions tests/ui/coherence/coherence-impls-send.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-send.rs:25:1
--> $DIR/coherence-impls-send.rs:25:22
|
LL | unsafe impl Send for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^^^^^^^------------------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^^^^^^^^^^^ 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
--> $DIR/coherence-impls-send.rs:16:22
|
LL | unsafe impl Send for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^^^^^^^----------------
| |
| this is not defined in the current crate because tuples are always foreign
| ^^^^^^^^^^^^^^^^ 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
Expand All @@ -29,12 +25,10 @@ LL | unsafe impl Send for &'static NotSync {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-send.rs:22:1
--> $DIR/coherence-impls-send.rs:22:22
|
LL | unsafe impl Send for [MyType] {}
| ^^^^^^^^^^^^^^^^^^^^^--------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^ 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
Expand Down
18 changes: 6 additions & 12 deletions tests/ui/coherence/coherence-impls-sized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ LL | impl Sized for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-sized.rs:20:1
--> $DIR/coherence-impls-sized.rs:20:16
|
LL | impl Sized for (MyType, MyType) {}
| ^^^^^^^^^^^^^^^----------------
| |
| this is not defined in the current crate because tuples are always foreign
| ^^^^^^^^^^^^^^^^ 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
Expand All @@ -41,12 +39,10 @@ LL | impl Sized for [MyType] {}
| ^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-sized.rs:27:1
--> $DIR/coherence-impls-sized.rs:27:16
|
LL | impl Sized for [MyType] {}
| ^^^^^^^^^^^^^^^--------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^ 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
Expand All @@ -59,12 +55,10 @@ LL | impl Sized for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-impls-sized.rs:31:1
--> $DIR/coherence-impls-sized.rs:31:16
|
LL | impl Sized for &'static [NotSync] {}
| ^^^^^^^^^^^^^^^------------------
| |
| this is not defined in the current crate because slices are always foreign
| ^^^^^^^^^^^^^^^^^^ 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
Expand Down
18 changes: 6 additions & 12 deletions tests/ui/coherence/coherence-negative-impls-copy-bad.stderr
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/coherence-negative-impls-copy-bad.rs:4:1
--> $DIR/coherence-negative-impls-copy-bad.rs:4:16
|
LL | impl !Copy for str {}
| ^^^^^^^^^^^^^^^---
| |
| `str` is not defined in 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
--> $DIR/coherence-negative-impls-copy-bad.rs:7:16
|
LL | impl !Copy for fn() {}
| ^^^^^^^^^^^^^^^----
| |
| `fn()` is not defined in 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
--> $DIR/coherence-negative-impls-copy-bad.rs:10:16
|
LL | impl !Copy for () {}
| ^^^^^^^^^^^^^^^--
| |
| this is not defined in the current crate because tuples are always foreign
| ^^ 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
Expand Down
28 changes: 12 additions & 16 deletions tests/ui/coherence/coherence-orphan-foreign-adt-diagnostic.stderr
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> $DIR/coherence-orphan-foreign-adt-diagnostic.rs:10:1
--> $DIR/coherence-orphan-foreign-adt-diagnostic.rs:10:20
|
LL | impl PartialEq for Option<u32> {
| ^^^^^---------^^^^^-----------
| | |
| | `Option` is not defined in the current crate
| --------- ^^^^^^^^^^^ `Option` is not defined in the current crate
| |
| this is not defined in the current crate because this is a foreign trait
|
= 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-foreign-adt-diagnostic.rs:27:1
--> $DIR/coherence-orphan-foreign-adt-diagnostic.rs:27:28
|
LL | impl PartialEq<String> for Option<u32> {
| ^^^^^-----------------^^^^^-----------
| | |
| | `Option` is not defined in the current crate
| ----------------- ^^^^^^^^^^^ `Option` is not defined in the current crate
| |
| this is not defined in the current crate because this is a foreign trait
|
= 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-foreign-adt-diagnostic.rs:38:1
--> $DIR/coherence-orphan-foreign-adt-diagnostic.rs:38:30
|
LL | impl PartialEq<[i32; 3]> for Option<u32> {
| ^^^^^-------------------^^^^^-----------
| | |
| | `Option` is not defined in the current crate
| ------------------- ^^^^^^^^^^^ `Option` is not defined in the current crate
| |
| this is not defined in the current crate because this is a foreign trait
|
= 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-orphan-foreign-adt-diagnostic.rs:18:1
--> $DIR/coherence-orphan-foreign-adt-diagnostic.rs:18:14
|
LL | impl Add for u32 {
| ^^^^^---^^^^^---
| | |
| | `u32` is not defined in the current crate
| --- ^^^ `u32` is not defined in the current crate
| |
| this is not defined in the current crate because this is a foreign trait
|
= note: impl doesn't have any local type before any uncovered type parameters
Expand Down
Loading
Loading