From 7e94cc37e8d4938da29def5f49ae9fec56ca7dec Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Fri, 8 Nov 2019 21:40:30 +0100 Subject: [PATCH 1/2] Update E0210 to match RFC 2451 --- src/librustc_typeck/error_codes.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index f21fc2df8b9..9417e78ebfa 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -2058,8 +2058,13 @@ fn make(&mut self) -> Foo { This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule concerns the use of type parameters in an implementation of a foreign trait (a trait defined in another crate), and -states that type parameters must be "covered" by a local type. To understand -what this means, it is perhaps easiest to consider a few examples. +states that type parameters must be "covered" by a local type. + +When implementing a foreign trait for a foreign type, +the trait must have one or more type parameters. +A type local to your crate must appear before any use of any type parameters. + +To understand what this means, it is perhaps easier to consider a few examples. If `ForeignTrait` is a trait defined in some external crate `foo`, then the following trait `impl` is an error: @@ -2117,12 +2122,17 @@ impl ForeignTrait for T0 { ... } where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn` are types. One of the types `T0, ..., Tn` must be a local type (this is another -orphan rule, see the explanation for E0117). Let `i` be the smallest integer -such that `Ti` is a local type. Then no type parameter can appear in any of the -`Tj` for `j < i`. +orphan rule, see the explanation for E0117). -For information on the design of the orphan rules, see [RFC 1023]. +Both of the folowing must be true: +1. At least one of the types T0..=Tn must be a local type. +Let Ti be the first such type. +2. No uncovered type parameters P1..=Pm may appear in T0..Ti (excluding Ti). +For information on the design of the orphan rules, +see [RFC 2451] and [RFC 1023]. + +[RFC 2451]: https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md "##, From 2db744ca9d4da28c5d0088f5d21e237e7f678abb Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sat, 9 Nov 2019 17:32:15 +0100 Subject: [PATCH 2/2] Improve coherence errors for wrong type order --- src/librustc/traits/coherence.rs | 12 +++- src/librustc_typeck/coherence/orphan.rs | 64 +++++++++++++------ src/librustc_typeck/error_codes.rs | 9 +-- .../ui/coherence/coherence-all-remote.stderr | 1 + .../coherence/coherence-bigint-param.stderr | 7 +- .../coherence-cross-crate-conflict.stderr | 1 + .../coherence-lone-type-parameter.stderr | 1 + .../impl[t]-foreign-for-fundamental[t].stderr | 1 + ...foreign[foreign]-for-fundamental[t].stderr | 2 + .../impl[t]-foreign[foreign]-for-t.stderr | 1 + ...foreign[fundamental[t]]-for-foreign.stderr | 2 + ...[fundamental[t]]-for-fundamental[t].stderr | 2 + ...pl[t]-foreign[fundamental[t]]-for-t.stderr | 2 + ...reign[fundamental[t]_local]-for-foreign.rs | 4 +- ...n[fundamental[t]_local]-for-foreign.stderr | 14 ++-- ...pl[t]-foreign[local]-for-fundamental[t].rs | 4 +- ...]-foreign[local]-for-fundamental[t].stderr | 14 ++-- .../coherence/impl[t]-foreign[local]-for-t.rs | 2 +- .../impl[t]-foreign[local]-for-t.stderr | 7 +- .../impl[t]-foreign[t]-for-foreign.stderr | 1 + .../impl[t]-foreign[t]-for-fundamental.stderr | 2 + .../coherence/impl[t]-foreign[t]-for-t.stderr | 1 + .../ui/error-codes/e0119/issue-28981.stderr | 1 + src/test/ui/issues/issue-41974.stderr | 1 + src/test/ui/orphan-check-diagnostics.stderr | 1 + 25 files changed, 110 insertions(+), 47 deletions(-) diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 1645f94535f..778bba1eef6 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -238,7 +238,7 @@ pub fn trait_ref_is_local_or_fundamental<'tcx>( pub enum OrphanCheckErr<'tcx> { NonLocalInputType(Vec<(Ty<'tcx>, bool /* Is this the first input type? */)>), - UncoveredTy(Ty<'tcx>), + UncoveredTy(Ty<'tcx>, Option>), } /// Checks the coherence orphan rules. `impl_def_id` should be the @@ -402,7 +402,15 @@ fn uncover_fundamental_ty<'tcx>( return Ok(()); } else if let ty::Param(_) = input_ty.kind { debug!("orphan_check_trait_ref: uncovered ty: `{:?}`", input_ty); - return Err(OrphanCheckErr::UncoveredTy(input_ty)) + let local_type = trait_ref + .input_types() + .flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate)) + .filter(|ty| ty_is_non_local_constructor(tcx, ty, in_crate).is_none()) + .next(); + + debug!("orphan_check_trait_ref: uncovered ty local_type: `{:?}`", local_type); + + return Err(OrphanCheckErr::UncoveredTy(input_ty, local_type)) } if let Some(non_local_tys) = non_local_tys { for input_ty in non_local_tys { diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index f066ca762c0..88fa09cc936 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -77,30 +77,58 @@ fn visit_item(&mut self, item: &hir::Item) { err.emit(); return; } - Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => { + Err(traits::OrphanCheckErr::UncoveredTy(param_ty, local_type)) => { let mut sp = sp; for param in &generics.params { if param.name.ident().to_string() == param_ty.to_string() { sp = param.span; } } - let mut err = struct_span_err!( - self.tcx.sess, - sp, - E0210, - "type parameter `{}` must be used as the type parameter for some local \ - type (e.g., `MyStruct<{}>`)", - param_ty, - param_ty - ); - err.span_label(sp, format!( - "type parameter `{}` must be used as the type parameter for some local \ - type", - param_ty, - )); - err.note("only traits defined in the current crate can be implemented for a \ - type parameter"); - err.emit(); + + match local_type { + Some(local_type) => { + struct_span_err!( + self.tcx.sess, + sp, + E0210, + "type parameter `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, + local_type + ).span_label(sp, format!( + "type parameter `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, + local_type + )).note("implementing a foreign trait is only possible if at \ + least one of the types for which is it implemented is local, \ + and no uncovered type parameters appear before that first \ + local type" + ).note("in this case, 'before' refers to the following order: \ + `impl<..> ForeignTrait for T0`, \ + where `T0` is the first and `Tn` is the last" + ).emit(); + } + None => { + struct_span_err!( + self.tcx.sess, + sp, + E0210, + "type parameter `{}` must be used as the type parameter for some \ + local type (e.g., `MyStruct<{}>`)", + param_ty, + param_ty + ).span_label(sp, format!( + "type parameter `{}` must be used as the type parameter for some \ + local type", + param_ty, + )).note("implementing a foreign trait is only possible if at \ + least one of the types for which is it implemented is local" + ).note("only traits defined in the current crate can be \ + implemented for a type parameter" + ).emit(); + } + }; return; } } diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index 9417e78ebfa..6e8ba7089cf 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -2124,10 +2124,11 @@ impl ForeignTrait for T0 { ... } are types. One of the types `T0, ..., Tn` must be a local type (this is another orphan rule, see the explanation for E0117). -Both of the folowing must be true: -1. At least one of the types T0..=Tn must be a local type. -Let Ti be the first such type. -2. No uncovered type parameters P1..=Pm may appear in T0..Ti (excluding Ti). +Both of the following must be true: +1. At least one of the types `T0..=Tn` must be a local type. +Let `Ti` be the first such type. +2. No uncovered type parameters `P1..=Pm` may appear in `T0..Ti` +(excluding `Ti`). For information on the design of the orphan rules, see [RFC 2451] and [RFC 1023]. diff --git a/src/test/ui/coherence/coherence-all-remote.stderr b/src/test/ui/coherence/coherence-all-remote.stderr index b35ae46f888..6ecfb2c5eb0 100644 --- a/src/test/ui/coherence/coherence-all-remote.stderr +++ b/src/test/ui/coherence/coherence-all-remote.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for isize { } | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-bigint-param.stderr b/src/test/ui/coherence/coherence-bigint-param.stderr index bb81d7adea2..d431c5f4b52 100644 --- a/src/test/ui/coherence/coherence-bigint-param.stderr +++ b/src/test/ui/coherence/coherence-bigint-param.stderr @@ -1,10 +1,11 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) --> $DIR/coherence-bigint-param.rs:8:6 | LL | impl Remote1 for T { } - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last error: aborting due to previous error diff --git a/src/test/ui/coherence/coherence-cross-crate-conflict.stderr b/src/test/ui/coherence/coherence-cross-crate-conflict.stderr index cb66f9b0c7f..c00751a0f23 100644 --- a/src/test/ui/coherence/coherence-cross-crate-conflict.stderr +++ b/src/test/ui/coherence/coherence-cross-crate-conflict.stderr @@ -13,6 +13,7 @@ error[E0210]: type parameter `A` must be used as the type parameter for some loc LL | impl Foo for A { | ^ type parameter `A` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/coherence-lone-type-parameter.stderr b/src/test/ui/coherence/coherence-lone-type-parameter.stderr index 3791d96302b..2c3b4fc3ad2 100644 --- a/src/test/ui/coherence/coherence-lone-type-parameter.stderr +++ b/src/test/ui/coherence/coherence-lone-type-parameter.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote for T { } | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].stderr index 69194bdaf56..8a951d407ca 100644 --- a/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].stderr +++ b/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote for Box { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr index b0f34419bb3..c5759244eff 100644 --- a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr +++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for Box { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) @@ -12,6 +13,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl<'a, T> Remote1 for &'a T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr index 002f8b7286a..e8663fd7d82 100644 --- a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr index 0c43936e6d4..639bee2b8ec 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-foreign.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1> for u32 { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) @@ -12,6 +13,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl<'a, T> Remote1<&'a T> for u32 { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr index f81f15b204b..0b6c81b53cd 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl<'a, T> Remote1> for &'a T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) @@ -12,6 +13,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl<'a, T> Remote1<&'a T> for Box { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr index 24fd492c57c..fe40490822e 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-t.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1> for T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) @@ -12,6 +13,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl<'a, T> Remote1<&'a T> for T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs index 4666e449ca9..c9e3594cd34 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs @@ -8,11 +8,11 @@ struct Local; impl Remote2, Local> for u32 { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` must be covered by another type } impl<'a, T> Remote2<&'a T, Local> for u32 { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` must be covered by another type } fn main() {} diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr index 6a1db165416..1eaef59b3f8 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr @@ -1,18 +1,20 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:10:6 | LL | impl Remote2, Local> for u32 { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:14:10 | LL | impl<'a, T> Remote2<&'a T, Local> for u32 { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs index db88c330b39..7709bd9c89b 100644 --- a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs +++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].rs @@ -8,11 +8,11 @@ struct Local; impl Remote1 for Box { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` must be covered by another type } impl Remote1 for &T { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` must be covered by another type } fn main() {} diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr index b5fdb16c2f3..4d39186d494 100644 --- a/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr +++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr @@ -1,18 +1,20 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:10:6 | LL | impl Remote1 for Box { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:14:6 | LL | impl Remote1 for &T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs index dd4110d31e6..eed3a4b5c23 100644 --- a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs +++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.rs @@ -8,7 +8,7 @@ struct Local; impl Remote1 for T { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` must be covered by another type } fn main() {} diff --git a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr index 7b65212f62a..d74be4cec72 100644 --- a/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr @@ -1,10 +1,11 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) +error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) --> $DIR/impl[t]-foreign[local]-for-t.rs:10:6 | LL | impl Remote1 for T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: only traits defined in the current crate can be implemented for a type parameter + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local, and no uncovered type parameters appear before that first local type + = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last error: aborting due to previous error diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr index 2e5ae6a8eb3..b26feb4914c 100644 --- a/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-foreign.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for u32 { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr index 3976f06947f..5e8cc552c98 100644 --- a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for Box { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error[E0210]: type parameter `B` must be used as the type parameter for some local type (e.g., `MyStruct`) @@ -12,6 +13,7 @@ error[E0210]: type parameter `B` must be used as the type parameter for some loc LL | impl<'a, A, B> Remote1 for &'a B { | ^ type parameter `B` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr index 8d858b8abee..d3226d33bee 100644 --- a/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr +++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-t.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Remote1 for T { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error diff --git a/src/test/ui/error-codes/e0119/issue-28981.stderr b/src/test/ui/error-codes/e0119/issue-28981.stderr index ec8e8144d42..2a78cc8b2db 100644 --- a/src/test/ui/error-codes/e0119/issue-28981.stderr +++ b/src/test/ui/error-codes/e0119/issue-28981.stderr @@ -14,6 +14,7 @@ error[E0210]: type parameter `Foo` must be used as the type parameter for some l LL | impl Deref for Foo { } | ^^^ type parameter `Foo` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-41974.stderr b/src/test/ui/issues/issue-41974.stderr index 12d4da71599..9f164822dea 100644 --- a/src/test/ui/issues/issue-41974.stderr +++ b/src/test/ui/issues/issue-41974.stderr @@ -21,6 +21,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl Drop for T where T: A { | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to 3 previous errors diff --git a/src/test/ui/orphan-check-diagnostics.stderr b/src/test/ui/orphan-check-diagnostics.stderr index cb21b26bba7..c84d401898c 100644 --- a/src/test/ui/orphan-check-diagnostics.stderr +++ b/src/test/ui/orphan-check-diagnostics.stderr @@ -4,6 +4,7 @@ error[E0210]: type parameter `T` must be used as the type parameter for some loc LL | impl RemoteTrait for T where T: LocalTrait {} | ^ type parameter `T` must be used as the type parameter for some local type | + = note: implementing a foreign trait is only possible if at least one of the types for which is it implemented is local = note: only traits defined in the current crate can be implemented for a type parameter error: aborting due to previous error