From 56c2886c61a2ce0586e50c05f697ed8fad09f4ac Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Sun, 14 Aug 2022 13:06:08 -0700 Subject: [PATCH 01/11] Update coherence check for projections, add test --- .../src/traits/coherence.rs | 12 ++- compiler/rustc_typeck/src/coherence/orphan.rs | 94 +++++++++++++------ .../auxiliary/coherence_projection_assoc.rs | 3 + .../coherence-projection-uncovered-ty.rs | 24 +++++ .../coherence-projection-uncovered-ty.stderr | 12 +++ 5 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 src/test/ui/coherence/auxiliary/coherence_projection_assoc.rs create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty.rs create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty.stderr diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 292787d4dbb24..8c91cf0d5b3cc 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -631,7 +631,7 @@ impl<'tcx> OrphanChecker<'tcx> { ControlFlow::CONTINUE } - fn found_param_ty(&mut self, t: Ty<'tcx>) -> ControlFlow> { + fn found_uncovered_ty(&mut self, t: Ty<'tcx>) -> ControlFlow> { if self.search_first_local_ty { ControlFlow::CONTINUE } else { @@ -672,10 +672,14 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { | ty::Slice(..) | ty::RawPtr(..) | ty::Never - | ty::Tuple(..) - | ty::Projection(..) => self.found_non_local_ty(ty), + | ty::Tuple(..) => self.found_non_local_ty(ty), - ty::Param(..) => self.found_param_ty(ty), + ty::Param(..) => self.found_uncovered_ty(ty), + + ty::Projection(..) => { + self.found_non_local_ty(ty); + self.found_uncovered_ty(ty) + } ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) => match self.in_crate { InCrate::Local => self.found_non_local_ty(ty), diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 1608550aa6ae4..98f4ea66c455e 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -277,42 +277,78 @@ fn emit_orphan_check_error<'tcx>( } 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; + + match *param_ty.kind() { + ty::Projection(..) => { + sp = self_ty_span; } - } + _ => { + for param in generics.params { + if param.name.ident().to_string() == param_ty.to_string() { + sp = param.span; + } + } + } + }; match local_type { - Some(local_type) => struct_span_err!( - 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 \ + Some(local_type) => { + let mut err = match *param_ty.kind() { + ty::Projection(..) => { + let mut err = struct_span_err!( + tcx.sess, + sp, + E0210, + "type projection `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, + local_type + ); + err.span_label( + sp, + format!( + "type projection `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, local_type + ), + ); + err + } + _ => { + let mut err = struct_span_err!( + tcx.sess, + sp, + E0210, + "type parameter `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, + local_type + ); + err.span_label( + sp, + format!( + "type parameter `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + param_ty, local_type + ), + ); + err + } + }; + + err.note( + "implementing a foreign trait is only possible if at \ least one of the types for which it is implemented is local, \ - and no uncovered type parameters appear before that first \ + and no uncovered type parameters or projections appear before that first \ local type", - ) - .note( - "in this case, 'before' refers to the following order: \ + ) + .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(), + ) + .emit() + } None => struct_span_err!( tcx.sess, sp, diff --git a/src/test/ui/coherence/auxiliary/coherence_projection_assoc.rs b/src/test/ui/coherence/auxiliary/coherence_projection_assoc.rs new file mode 100644 index 0000000000000..5213dfd273132 --- /dev/null +++ b/src/test/ui/coherence/auxiliary/coherence_projection_assoc.rs @@ -0,0 +1,3 @@ +pub trait Foreign { + type Assoc; +} diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty.rs b/src/test/ui/coherence/coherence-projection-uncovered-ty.rs new file mode 100644 index 0000000000000..35686f560cc28 --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty.rs @@ -0,0 +1,24 @@ +// Here we expect that orphan rule is violated +// because T is an uncovered parameter appearing +// before the first local (Issue #99554) + +// aux-build:coherence_projection_assoc.rs + +extern crate coherence_projection_assoc as lib; +use lib::Foreign; + +trait Id { + type Assoc; +} + +impl Id for T { + type Assoc = T; +} + +pub struct B; +impl Foreign for ::Assoc { +//~^ ERROR E0210 + type Assoc = usize; +} + +fn main() {} diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr b/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr new file mode 100644 index 0000000000000..e2d3dd3b738bb --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr @@ -0,0 +1,12 @@ +error[E0210]: type projection `::Assoc` must be covered by another type when it appears before the first local type (`B`) + --> $DIR/coherence-projection-uncovered-ty.rs:19:27 + | +LL | impl Foreign for ::Assoc { + | ^^^^^^^^^^^^^^^^ type projection `::Assoc` must be covered by another type when it appears before the first local type (`B`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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 + +For more information about this error, try `rustc --explain E0210`. From e6bf0581ca470c3ae1db46aeaee70e1d27d4eda1 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Sun, 14 Aug 2022 15:03:04 -0700 Subject: [PATCH 02/11] Blessing new error message for existing coherence tests --- src/test/ui/coherence/coherence-bigint-param.stderr | 2 +- .../impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr | 4 ++-- .../impl[t]-foreign[local]-for-fundamental[t].stderr | 4 ++-- src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/ui/coherence/coherence-bigint-param.stderr b/src/test/ui/coherence/coherence-bigint-param.stderr index e8d74c917e465..1be30146a7a9f 100644 --- a/src/test/ui/coherence/coherence-bigint-param.stderr +++ b/src/test/ui/coherence/coherence-bigint-param.stderr @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for T { } | ^ type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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[fundamental[t]_local]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr index f94f04c8df5c1..94180ec324180 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote2, Local> for u32 { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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 covered by another type when it appears before the first local type (`Local`) @@ -13,7 +13,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl<'a, T> Remote2<&'a T, Local> for u32 { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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].stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr index e68f2fe585637..b49f349f8aa6c 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for Box { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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 covered by another type when it appears before the first local type (`Local`) @@ -13,7 +13,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for &T { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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.stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr index d97e85dcb3c3e..9f041594cc212 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for T { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections 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 From 1ac08d82d92f4b87064b9e34e57c5483af11e21c Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Mon, 15 Aug 2022 15:40:30 -0700 Subject: [PATCH 03/11] Change error msg wording from type projection -> associated type, bless tests --- compiler/rustc_typeck/src/coherence/orphan.rs | 8 ++++---- src/test/ui/coherence/coherence-bigint-param.stderr | 2 +- .../ui/coherence/coherence-projection-uncovered-ty.stderr | 6 +++--- ...pl[t]-foreign[fundamental[t]_local]-for-foreign.stderr | 4 ++-- .../impl[t]-foreign[local]-for-fundamental[t].stderr | 4 ++-- src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 98f4ea66c455e..2934d6a60d231 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -299,7 +299,7 @@ fn emit_orphan_check_error<'tcx>( tcx.sess, sp, E0210, - "type projection `{}` must be covered by another type \ + "associated type `{}` must be covered by another type \ when it appears before the first local type (`{}`)", param_ty, local_type @@ -307,7 +307,7 @@ fn emit_orphan_check_error<'tcx>( err.span_label( sp, format!( - "type projection `{}` must be covered by another type \ + "associated type `{}` must be covered by another type \ when it appears before the first local type (`{}`)", param_ty, local_type ), @@ -339,8 +339,8 @@ fn emit_orphan_check_error<'tcx>( err.note( "implementing a foreign trait is only possible if at \ least one of the types for which it is implemented is local, \ - and no uncovered type parameters or projections appear before that first \ - local type", + and no uncovered type parameters or associated types appear \ + before that first local type", ) .note( "in this case, 'before' refers to the following order: \ diff --git a/src/test/ui/coherence/coherence-bigint-param.stderr b/src/test/ui/coherence/coherence-bigint-param.stderr index 1be30146a7a9f..e45b331de0f3d 100644 --- a/src/test/ui/coherence/coherence-bigint-param.stderr +++ b/src/test/ui/coherence/coherence-bigint-param.stderr @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for T { } | ^ type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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-projection-uncovered-ty.stderr b/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr index e2d3dd3b738bb..5729d36e5474f 100644 --- a/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty.stderr @@ -1,10 +1,10 @@ -error[E0210]: type projection `::Assoc` must be covered by another type when it appears before the first local type (`B`) +error[E0210]: associated type `::Assoc` must be covered by another type when it appears before the first local type (`B`) --> $DIR/coherence-projection-uncovered-ty.rs:19:27 | LL | impl Foreign for ::Assoc { - | ^^^^^^^^^^^^^^^^ type projection `::Assoc` must be covered by another type when it appears before the first local type (`B`) + | ^^^^^^^^^^^^^^^^ associated type `::Assoc` must be covered by another type when it appears before the first local type (`B`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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[fundamental[t]_local]-for-foreign.stderr b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]_local]-for-foreign.stderr index 94180ec324180..8ef1e514a9857 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote2, Local> for u32 { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 covered by another type when it appears before the first local type (`Local`) @@ -13,7 +13,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl<'a, T> Remote2<&'a T, Local> for u32 { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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].stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-fundamental[t].stderr index b49f349f8aa6c..138c9aa114181 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for Box { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 covered by another type when it appears before the first local type (`Local`) @@ -13,7 +13,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for &T { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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.stderr b/src/test/ui/coherence/impl[t]-foreign[local]-for-t.stderr index 9f041594cc212..5cc4b38d71936 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 @@ -4,7 +4,7 @@ error[E0210]: type parameter `T` must be covered by another type when it appears LL | impl Remote1 for T { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or projections appear before that first local type + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 From 7913a81ac6b537bdd30613c40931172299b5f1d1 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Mon, 15 Aug 2022 15:42:46 -0700 Subject: [PATCH 04/11] Stop adding projection found_non_local_ty, only add as uncovered --- compiler/rustc_trait_selection/src/traits/coherence.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 8c91cf0d5b3cc..0a76ed81d617f 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -674,12 +674,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { | ty::Never | ty::Tuple(..) => self.found_non_local_ty(ty), - ty::Param(..) => self.found_uncovered_ty(ty), - - ty::Projection(..) => { - self.found_non_local_ty(ty); - self.found_uncovered_ty(ty) - } + ty::Param(..) | ty::Projection(..) => self.found_uncovered_ty(ty), ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) => match self.in_crate { InCrate::Local => self.found_non_local_ty(ty), From 42347b864c3258b13a87884d351026afb6bc7c8a Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Sat, 20 Aug 2022 13:49:35 -0700 Subject: [PATCH 05/11] Check if projection have type parameters and only fail orphan check if it does --- .../rustc_trait_selection/src/traits/coherence.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 0a76ed81d617f..262b7dfe9c1e9 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -631,8 +631,23 @@ impl<'tcx> OrphanChecker<'tcx> { ControlFlow::CONTINUE } + #[instrument(skip(self), level = "debug")] fn found_uncovered_ty(&mut self, t: Ty<'tcx>) -> ControlFlow> { if self.search_first_local_ty { + return ControlFlow::CONTINUE; + }; + + // Fully concrete projections are OK, so check + // and only exit if there's generics + if let ty::Projection(proj) = *t.kind() { + for typ in proj.trait_ref(self.tcx).substs.types() { + if let ty::Param(..) = *typ.kind() { + debug!( + "found_uncovered_ty: type parameter found in projection, exit orphan check" + ); + return ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)); + } + } ControlFlow::CONTINUE } else { ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)) From d89dc3fd23e2104d7afb2f99ab33a91357e38caa Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Sun, 21 Aug 2022 10:05:41 -0700 Subject: [PATCH 06/11] Improve type param checking in projection per suggestion, add test --- .../src/traits/coherence.rs | 15 +++++------- .../coherence-projection-uncovered-ty-2.rs | 24 +++++++++++++++++++ ...coherence-projection-uncovered-ty-2.stderr | 12 ++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-2.rs create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-2.stderr diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 262b7dfe9c1e9..aab6aeeed2ffd 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -24,7 +24,7 @@ use rustc_middle::traits::specialization_graph::OverlapMode; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::visit::TypeVisitable; -use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitor}; +use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeFlags, TypeVisitor}; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; use std::fmt::Debug; @@ -640,15 +640,12 @@ impl<'tcx> OrphanChecker<'tcx> { // Fully concrete projections are OK, so check // and only exit if there's generics if let ty::Projection(proj) = *t.kind() { - for typ in proj.trait_ref(self.tcx).substs.types() { - if let ty::Param(..) = *typ.kind() { - debug!( - "found_uncovered_ty: type parameter found in projection, exit orphan check" - ); - return ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)); - } + if proj.has_type_flags(TypeFlags::HAS_TY_PARAM) { + debug!("found_uncovered_ty: type parameter found in projection, exit orphan check"); + ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)) + } else { + ControlFlow::CONTINUE } - ControlFlow::CONTINUE } else { ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)) } diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-2.rs b/src/test/ui/coherence/coherence-projection-uncovered-ty-2.rs new file mode 100644 index 0000000000000..2bd7165d95be8 --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-2.rs @@ -0,0 +1,24 @@ +// Here we expect that orphan rule is violated +// because T is an uncovered parameter appearing +// before the first local (Issue #99554) + +// aux-build:coherence_projection_assoc.rs + +extern crate coherence_projection_assoc as lib; +use lib::Foreign; + +trait Id { + type Assoc; +} + +impl Id for T { + type Assoc = T; +} + +pub struct B; +impl Foreign for > as Id>::Assoc { + //~^ ERROR E0210 + type Assoc = usize; +} + +fn main() {} diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-2.stderr b/src/test/ui/coherence/coherence-projection-uncovered-ty-2.stderr new file mode 100644 index 0000000000000..4a631b7de01bb --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-2.stderr @@ -0,0 +1,12 @@ +error[E0210]: associated type `> as Id>::Assoc` must be covered by another type when it appears before the first local type (`B`) + --> $DIR/coherence-projection-uncovered-ty-2.rs:19:27 + | +LL | impl Foreign for > as Id>::Assoc { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `> as Id>::Assoc` must be covered by another type when it appears before the first local type (`B`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 + +For more information about this error, try `rustc --explain E0210`. From 9f7b8ddf1884edda6210614b89e352c6e9001220 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Tue, 23 Aug 2022 08:15:22 -0700 Subject: [PATCH 07/11] Improve error spans --- .../src/traits/coherence.rs | 33 +++++++++++-------- compiler/rustc_typeck/src/coherence/orphan.rs | 24 +++++--------- .../coherence-projection-uncovered-ty-3.rs | 20 +++++++++++ ...coherence-projection-uncovered-ty-3.stderr | 12 +++++++ 4 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-3.rs create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-3.stderr diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index aab6aeeed2ffd..ff42436d7db1b 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -461,7 +461,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>, Option>), + UncoveredTy(Ty<'tcx>, usize, Option>), } /// Checks the coherence orphan rules. `impl_def_id` should be the @@ -588,21 +588,28 @@ fn orphan_check_trait_ref<'tcx>( } let mut checker = OrphanChecker::new(tcx, in_crate); - match trait_ref.visit_with(&mut checker) { - ControlFlow::Continue(()) => Err(OrphanCheckErr::NonLocalInputType(checker.non_local_tys)), - ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(ty)) => { - // Does there exist some local type after the `ParamTy`. - checker.search_first_local_ty = true; - if let Some(OrphanCheckEarlyExit::LocalTy(local_ty)) = - trait_ref.visit_with(&mut checker).break_value() - { - Err(OrphanCheckErr::UncoveredTy(ty, Some(local_ty))) - } else { - Err(OrphanCheckErr::UncoveredTy(ty, None)) + for (idx, arg) in trait_ref.substs.types().enumerate() { + match checker.visit_ty(arg) { + ControlFlow::Continue(()) => continue, + ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(ty)) => { + // Does there exist some local type after the `ParamTy`. + checker.search_first_local_ty = true; + + if let Some(OrphanCheckEarlyExit::LocalTy(local_ty)) = + trait_ref.visit_with(&mut checker).break_value() + { + return Err(OrphanCheckErr::UncoveredTy(ty, idx, Some(local_ty))); + } else { + return Err(OrphanCheckErr::UncoveredTy(ty, idx, None)); + } } + ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(_)) => return Ok(()), } - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(_)) => Ok(()), } + + // If no early break occured, means we didn't find a local type + // and should return Err + return Err(OrphanCheckErr::NonLocalInputType(checker.non_local_tys)); } struct OrphanChecker<'tcx> { diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 2934d6a60d231..4fe373e870d56 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -111,7 +111,7 @@ fn do_orphan_check_impl<'tcx>( tr.path.span, trait_ref.self_ty(), impl_.self_ty.span, - &impl_.generics, + &impl_.of_trait.as_ref().unwrap().path.segments.last().unwrap().args().args, err, )?, } @@ -212,7 +212,7 @@ fn emit_orphan_check_error<'tcx>( trait_span: Span, self_ty: Ty<'tcx>, self_ty_span: Span, - generics: &hir::Generics<'tcx>, + generics: &[rustc_hir::GenericArg<'tcx>], err: traits::OrphanCheckErr<'tcx>, ) -> Result { Err(match err { @@ -275,21 +275,13 @@ fn emit_orphan_check_error<'tcx>( err.note("define and implement a trait or new type instead"); err.emit() } - traits::OrphanCheckErr::UncoveredTy(param_ty, local_type) => { - let mut sp = sp; + traits::OrphanCheckErr::UncoveredTy(param_ty, idx, local_type) => { + let sp; - match *param_ty.kind() { - ty::Projection(..) => { - sp = self_ty_span; - } - _ => { - for param in generics.params { - if param.name.ident().to_string() == param_ty.to_string() { - sp = param.span; - } - } - } - }; + match idx { + 0 => sp = self_ty_span, + _ => sp = generics[idx - 1].span(), + } match local_type { Some(local_type) => { diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-3.rs b/src/test/ui/coherence/coherence-projection-uncovered-ty-3.rs new file mode 100644 index 0000000000000..a2efb04fcf29f --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-3.rs @@ -0,0 +1,20 @@ +// aux-build:coherence_projection_assoc.rs + +extern crate coherence_projection_assoc as lib; +use lib::Foreign; + +trait Id { + type Assoc; +} + +impl Id for T { + type Assoc = T; +} + +pub struct Local(T); +impl Foreign<::Assoc, Local> for () { + //~^ ERROR E0210 + type Assoc = usize; +} + +fn main() {} diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-3.stderr b/src/test/ui/coherence/coherence-projection-uncovered-ty-3.stderr new file mode 100644 index 0000000000000..ea0f98513d1c9 --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-3.stderr @@ -0,0 +1,12 @@ +error[E0210]: associated type `::Assoc` must be covered by another type when it appears before the first local type (`Local`) + --> $DIR/coherence-projection-uncovered-ty-3.rs:15:17 + | +LL | impl Foreign<::Assoc, Local> for () { + | ^^^^^^^^^^^^^^^^ associated type `::Assoc` must be covered by another type when it appears before the first local type (`Local`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 + +For more information about this error, try `rustc --explain E0210`. From ca4711f690d5ad3341564fecc32b473968e720e1 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Tue, 23 Aug 2022 08:35:32 -0700 Subject: [PATCH 08/11] Clean up error message between associated type and type param --- compiler/rustc_typeck/src/coherence/orphan.rs | 92 ++++++++----------- .../coherence-projection-uncovered-ty-4.rs | 19 ++++ ...coherence-projection-uncovered-ty-4.stderr | 12 +++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-4.rs create mode 100644 src/test/ui/coherence/coherence-projection-uncovered-ty-4.stderr diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 4fe373e870d56..2d1c98fb57687 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -283,79 +283,59 @@ fn emit_orphan_check_error<'tcx>( _ => sp = generics[idx - 1].span(), } - match local_type { - Some(local_type) => { - let mut err = match *param_ty.kind() { - ty::Projection(..) => { - let mut err = struct_span_err!( - tcx.sess, - sp, - E0210, - "associated type `{}` must be covered by another type \ - when it appears before the first local type (`{}`)", - param_ty, - local_type - ); - err.span_label( - sp, - format!( - "associated type `{}` must be covered by another type \ - when it appears before the first local type (`{}`)", - param_ty, local_type - ), - ); - err - } - _ => { - let mut err = struct_span_err!( - tcx.sess, - sp, - E0210, - "type parameter `{}` must be covered by another type \ - when it appears before the first local type (`{}`)", - param_ty, - local_type - ); - err.span_label( - sp, - format!( - "type parameter `{}` must be covered by another type \ - when it appears before the first local type (`{}`)", - param_ty, local_type - ), - ); - err - } - }; + let message = match *param_ty.kind() { + ty::Projection(..) => "associated type", + _ => "type parameter", + }; - err.note( - "implementing a foreign trait is only possible if at \ + match local_type { + Some(local_type) => struct_span_err!( + tcx.sess, + sp, + E0210, + "{} `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + message, + param_ty, + local_type + ) + .span_label( + sp, + format!( + "{} `{}` must be covered by another type \ + when it appears before the first local type (`{}`)", + message, param_ty, local_type + ), + ) + .note( + "implementing a foreign trait is only possible if at \ least one of the types for which it is implemented is local, \ and no uncovered type parameters or associated types appear \ before that first local type", - ) - .note( - "in this case, 'before' refers to the following order: \ + ) + .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() - } + ) + .emit(), + None => struct_span_err!( tcx.sess, sp, E0210, - "type parameter `{}` must be used as the type parameter for some \ + "{} `{}` must be used as the type parameter for some \ local type (e.g., `MyStruct<{}>`)", + message, param_ty, param_ty ) .span_label( sp, format!( - "type parameter `{}` must be used as the type parameter for some \ - local type", - param_ty, + "{} `{}` must be used as the type parameter for some \ + local type", + message, param_ty, ), ) .note( diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-4.rs b/src/test/ui/coherence/coherence-projection-uncovered-ty-4.rs new file mode 100644 index 0000000000000..9d17af5eadb48 --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-4.rs @@ -0,0 +1,19 @@ +// aux-build:coherence_projection_assoc.rs + +extern crate coherence_projection_assoc as lib; +use lib::Foreign; + +trait Id { + type Assoc; +} + +impl Id for T { + type Assoc = T; +} + +impl Foreign<(), Vec> for ::Assoc { +//~^ ERROR E0210 + type Assoc = usize; +} + +fn main() {} diff --git a/src/test/ui/coherence/coherence-projection-uncovered-ty-4.stderr b/src/test/ui/coherence/coherence-projection-uncovered-ty-4.stderr new file mode 100644 index 0000000000000..280cb0f026252 --- /dev/null +++ b/src/test/ui/coherence/coherence-projection-uncovered-ty-4.stderr @@ -0,0 +1,12 @@ +error[E0210]: associated type `::Assoc` must be used as the type parameter for some local type (e.g., `MyStruct<::Assoc>`) + --> $DIR/coherence-projection-uncovered-ty-4.rs:14:33 + | +LL | impl Foreign<(), Vec> for ::Assoc { + | ^^^^^^^^^^^^^^^^ associated type `::Assoc` 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 it is implemented is local + = note: only traits defined in the current crate can be implemented for a type parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0210`. From 344e225cb264986d19f5837da14bb16604923fbf Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Wed, 24 Aug 2022 17:26:25 -0700 Subject: [PATCH 09/11] Move projection type flags check to visit_ty --- .../src/traits/coherence.rs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index ff42436d7db1b..07c8d227ae4f6 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -641,18 +641,7 @@ impl<'tcx> OrphanChecker<'tcx> { #[instrument(skip(self), level = "debug")] fn found_uncovered_ty(&mut self, t: Ty<'tcx>) -> ControlFlow> { if self.search_first_local_ty { - return ControlFlow::CONTINUE; - }; - - // Fully concrete projections are OK, so check - // and only exit if there's generics - if let ty::Projection(proj) = *t.kind() { - if proj.has_type_flags(TypeFlags::HAS_TY_PARAM) { - debug!("found_uncovered_ty: type parameter found in projection, exit orphan check"); - ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)) - } else { - ControlFlow::CONTINUE - } + ControlFlow::CONTINUE } else { ControlFlow::Break(OrphanCheckEarlyExit::ParamTy(t)) } @@ -693,7 +682,15 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { | ty::Never | ty::Tuple(..) => self.found_non_local_ty(ty), - ty::Param(..) | ty::Projection(..) => self.found_uncovered_ty(ty), + ty::Param(..) => self.found_uncovered_ty(ty), + + ty::Projection(proj) => { + if proj.has_type_flags(TypeFlags::HAS_TY_PARAM) { + self.found_uncovered_ty(ty) + } else { + ControlFlow::CONTINUE + } + } ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) => match self.in_crate { InCrate::Local => self.found_non_local_ty(ty), From c3e2567bee72c037bbea916c2f4ec19e01570578 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Wed, 24 Aug 2022 18:40:07 -0700 Subject: [PATCH 10/11] Improve error message for when type param is inside fundamental type, bless tests --- compiler/rustc_typeck/src/coherence/orphan.rs | 31 ++++++++++++++----- .../ui/coherence/coherence-all-remote.stderr | 4 +-- .../coherence/coherence-bigint-param.stderr | 4 +-- .../coherence-cross-crate-conflict.stderr | 4 +-- .../coherence-lone-type-parameter.stderr | 4 +-- .../impl[t]-foreign-for-fundamental[t].rs | 2 +- .../impl[t]-foreign-for-fundamental[t].stderr | 6 ++-- ...[t]-foreign[foreign]-for-fundamental[t].rs | 6 ++-- ...foreign[foreign]-for-fundamental[t].stderr | 12 +++---- .../impl[t]-foreign[foreign]-for-t.stderr | 4 +-- ...foreign[fundamental[t]]-for-foreign.stderr | 8 ++--- ...eign[fundamental[t]]-for-fundamental[t].rs | 6 ++-- ...[fundamental[t]]-for-fundamental[t].stderr | 12 +++---- ...pl[t]-foreign[fundamental[t]]-for-t.stderr | 8 ++--- ...n[fundamental[t]_local]-for-foreign.stderr | 8 ++--- ...pl[t]-foreign[local]-for-fundamental[t].rs | 6 ++-- ...]-foreign[local]-for-fundamental[t].stderr | 12 +++---- .../impl[t]-foreign[local]-for-t.stderr | 4 +-- .../impl[t]-foreign[t]-for-foreign.stderr | 4 +-- .../impl[t]-foreign[t]-for-fundamental.rs | 6 ++-- .../impl[t]-foreign[t]-for-fundamental.stderr | 12 +++---- .../coherence/impl[t]-foreign[t]-for-t.stderr | 4 +-- 22 files changed, 96 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index 2d1c98fb57687..eded331f628c7 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -277,9 +277,21 @@ fn emit_orphan_check_error<'tcx>( } traits::OrphanCheckErr::UncoveredTy(param_ty, idx, local_type) => { let sp; + let mut param_ty_in_fundamental_ty = false; match idx { - 0 => sp = self_ty_span, + 0 => { + sp = self_ty_span; + match *self_ty.kind() { + ty::Ref(..) => { + param_ty_in_fundamental_ty = true; + } + ty::Adt(def, _) => { + param_ty_in_fundamental_ty = def.is_fundamental(); + } + _ => (), + } + } _ => sp = generics[idx - 1].span(), } @@ -288,23 +300,27 @@ fn emit_orphan_check_error<'tcx>( _ => "type parameter", }; + let fundamental_ty_msg = + if param_ty_in_fundamental_ty { "as argument to a fundamental type " } else { "" }; + match local_type { Some(local_type) => struct_span_err!( tcx.sess, sp, E0210, - "{} `{}` must be covered by another type \ + "{} `{}` {}must be covered by another type \ when it appears before the first local type (`{}`)", message, param_ty, + fundamental_ty_msg, local_type ) .span_label( sp, format!( - "{} `{}` must be covered by another type \ + "{} `{}` {}must be covered by another type \ when it appears before the first local type (`{}`)", - message, param_ty, local_type + message, param_ty, fundamental_ty_msg, local_type ), ) .note( @@ -324,18 +340,19 @@ fn emit_orphan_check_error<'tcx>( tcx.sess, sp, E0210, - "{} `{}` must be used as the type parameter for some \ + "{} `{}` {}must be used as the type parameter for some \ local type (e.g., `MyStruct<{}>`)", message, param_ty, + fundamental_ty_msg, param_ty ) .span_label( sp, format!( - "{} `{}` must be used as the type parameter for some \ + "{} `{}` {}must be used as the type parameter for some \ local type", - message, param_ty, + message, param_ty, fundamental_ty_msg ), ) .note( diff --git a/src/test/ui/coherence/coherence-all-remote.stderr b/src/test/ui/coherence/coherence-all-remote.stderr index 7eca417533954..38241a6ae9660 100644 --- a/src/test/ui/coherence/coherence-all-remote.stderr +++ b/src/test/ui/coherence/coherence-all-remote.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/coherence-all-remote.rs:6:6 + --> $DIR/coherence-all-remote.rs:6:17 | LL | impl Remote1 for isize { } - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/coherence-bigint-param.stderr b/src/test/ui/coherence/coherence-bigint-param.stderr index e45b331de0f3d..9943958b2d24d 100644 --- a/src/test/ui/coherence/coherence-bigint-param.stderr +++ b/src/test/ui/coherence/coherence-bigint-param.stderr @@ -1,8 +1,8 @@ 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 + --> $DIR/coherence-bigint-param.rs:8:29 | LL | impl Remote1 for T { } - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`BigInt`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 diff --git a/src/test/ui/coherence/coherence-cross-crate-conflict.stderr b/src/test/ui/coherence/coherence-cross-crate-conflict.stderr index 3d253d56a4565..f008b9b21e7ef 100644 --- a/src/test/ui/coherence/coherence-cross-crate-conflict.stderr +++ b/src/test/ui/coherence/coherence-cross-crate-conflict.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/coherence-cross-crate-conflict.rs:9:6 + --> $DIR/coherence-cross-crate-conflict.rs:9:17 | LL | impl Foo for A { - | ^ type parameter `A` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/coherence-lone-type-parameter.stderr b/src/test/ui/coherence/coherence-lone-type-parameter.stderr index ef5b088365381..d0f4731a21836 100644 --- a/src/test/ui/coherence/coherence-lone-type-parameter.stderr +++ b/src/test/ui/coherence/coherence-lone-type-parameter.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/coherence-lone-type-parameter.rs:6:6 + --> $DIR/coherence-lone-type-parameter.rs:6:20 | LL | impl Remote for T { } - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].rs index 6f5605a21938e..144a3a3ada74f 100644 --- a/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].rs +++ b/src/test/ui/coherence/impl[t]-foreign-for-fundamental[t].rs @@ -8,7 +8,7 @@ use std::rc::Rc; struct Local; impl Remote for Box { - //~^ ERROR type parameter `T` must be used as the type parameter for + //~^ ERROR type parameter `T` as argument to a fundamental type must be used as the type parameter for // | some local type (e.g., `MyStruct`) } 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 249a5c44c79cd..3b468c9cd9472 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 @@ -1,8 +1,8 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign-for-fundamental[t].rs:10:6 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign-for-fundamental[t].rs:10:20 | LL | impl Remote for Box { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^^ type parameter `T` as argument to a fundamental type 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs index 81044cd0529af..99d9bf3510c8d 100644 --- a/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs +++ b/src/test/ui/coherence/impl[t]-foreign[foreign]-for-fundamental[t].rs @@ -8,11 +8,13 @@ use std::rc::Rc; 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` as argument to a fundamental type + // | must be used as the type parameter for some local type } impl<'a, T> Remote1 for &'a T { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` as argument to a fundamental type + // | must be used as the type parameter for some local type } fn main() {} 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 95a20cc5b0f5c..fb356e3787e24 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 @@ -1,17 +1,17 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:10:6 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:10:26 | LL | impl Remote1 for Box { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^^ type parameter `T` as argument to a fundamental type 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 it is 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`) - --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:14:10 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:15:30 | LL | impl<'a, T> Remote1 for &'a T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^ type parameter `T` as argument to a fundamental type 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter 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 aed184767a0bd..06c464edd2cdf 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 @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[foreign]-for-t.rs:10:6 + --> $DIR/impl[t]-foreign[foreign]-for-t.rs:10:26 | LL | impl Remote1 for T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter 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 73b1e2c6ed248..54598b0339e11 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 @@ -1,17 +1,17 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:10:6 + --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:10:17 | LL | impl Remote1> for u32 { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^^ 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 it is 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`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:14:10 + --> $DIR/impl[t]-foreign[fundamental[t]]-for-foreign.rs:14:21 | LL | impl<'a, T> Remote1<&'a T> for u32 { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs index 703f25dd60a62..dcfca77de335e 100644 --- a/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs +++ b/src/test/ui/coherence/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs @@ -8,10 +8,12 @@ use std::rc::Rc; struct Local; impl<'a, T> Remote1> for &'a T { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` as argument to a fundamental type + // | must be used as the type parameter for some local type } impl<'a, T> Remote1<&'a T> for Box { - //~^ ERROR type parameter `T` must be used as the type parameter for some local type + //~^ ERROR type parameter `T` as argument to a fundamental type + // | must be used as the type parameter for some local type } fn main() {} 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 5f89a7aa469c1..cd6ecf508518e 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 @@ -1,17 +1,17 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:10:10 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:10:33 | LL | impl<'a, T> Remote1> for &'a T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^ type parameter `T` as argument to a fundamental type 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 it is 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`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:13:10 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[fundamental[t]]-for-fundamental[t].rs:14:32 | LL | impl<'a, T> Remote1<&'a T> for Box { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^^ type parameter `T` as argument to a fundamental type 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter 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 45559d8b62d37..cc0bdef9d1ccf 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 @@ -1,17 +1,17 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:10:6 + --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:10:29 | LL | impl Remote1> for T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is 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`) - --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:13:10 + --> $DIR/impl[t]-foreign[fundamental[t]]-for-t.rs:13:32 | LL | impl<'a, T> Remote1<&'a T> for T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter 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 8ef1e514a9857..df6b4c1d6d410 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,17 +1,17 @@ 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 + --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:10:17 | LL | impl Remote2, Local> for u32 { - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) + | ^^^^^^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 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 + --> $DIR/impl[t]-foreign[fundamental[t]_local]-for-foreign.rs:14:21 | LL | impl<'a, T> Remote2<&'a T, Local> for u32 { - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) + | ^^^^^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 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 7709bd9c89b6f..217067aafd2a3 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,13 @@ use std::rc::Rc; struct Local; impl Remote1 for Box { - //~^ ERROR type parameter `T` must be covered by another type + //~^ ERROR type parameter `T` as argument to a fundamental type + // | must be covered by another type when it appears before the first local type (`Local`) } impl Remote1 for &T { - //~^ ERROR type parameter `T` must be covered by another type + //~^ ERROR type parameter `T` as argument to a fundamental type + // | must be covered by another type when it appears before the first local type (`Local`) } 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 138c9aa114181..964006ec521ef 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,17 +1,17 @@ -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 +error[E0210]: type parameter `T` as argument to a fundamental type 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:28 | LL | impl Remote1 for Box { - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) + | ^^^^^^ type parameter `T` as argument to a fundamental type must be covered by another type when it appears before the first local type (`Local`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 covered by another type when it appears before the first local type (`Local`) - --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:14:6 +error[E0210]: type parameter `T` as argument to a fundamental type must be covered by another type when it appears before the first local type (`Local`) + --> $DIR/impl[t]-foreign[local]-for-fundamental[t].rs:15:28 | LL | impl Remote1 for &T { - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) + | ^^ type parameter `T` as argument to a fundamental type must be covered by another type when it appears before the first local type (`Local`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 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 5cc4b38d71936..fb3b39361594b 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,8 +1,8 @@ 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 + --> $DIR/impl[t]-foreign[local]-for-t.rs:10:28 | LL | impl Remote1 for T { - | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) + | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters or associated types 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 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 44e3b7eedb40c..d412b1c8d523a 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 @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[t]-for-foreign.rs:10:6 + --> $DIR/impl[t]-foreign[t]-for-foreign.rs:10:17 | LL | impl Remote1 for u32 { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs index 79b5aa3fc6202..fed36babfdc3b 100644 --- a/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs +++ b/src/test/ui/coherence/impl[t]-foreign[t]-for-fundamental.rs @@ -8,11 +8,13 @@ use std::rc::Rc; 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` as argument to a fundamental type + // | must be used as the type parameter for some local type } impl<'a, A, B> Remote1 for &'a B { - //~^ ERROR type parameter `B` must be used as the type parameter for some local type + //~^ ERROR type parameter `B` as argument to a fundamental type + // | must be used as the type parameter for some local type } fn main() {} 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 80fb5dbec8662..e2cb43bb38930 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 @@ -1,17 +1,17 @@ -error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:10:6 +error[E0210]: type parameter `T` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:10:24 | LL | impl Remote1 for Box { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^^^^^^ type parameter `T` as argument to a fundamental type 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 it is 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`) - --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:14:13 +error[E0210]: type parameter `B` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/impl[t]-foreign[t]-for-fundamental.rs:15:31 | LL | impl<'a, A, B> Remote1 for &'a B { - | ^ type parameter `B` must be used as the type parameter for some local type + | ^^^^^ type parameter `B` as argument to a fundamental type 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter 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 ff72969dc52ae..f28b5c3e7b0d9 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 @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/impl[t]-foreign[t]-for-t.rs:10:6 + --> $DIR/impl[t]-foreign[t]-for-t.rs:10:24 | LL | impl Remote1 for T { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter From 84e8ac29a6088aaf56e2f513fcf762672247b769 Mon Sep 17 00:00:00 2001 From: Katherine Philip Date: Wed, 24 Aug 2022 19:14:18 -0700 Subject: [PATCH 11/11] Rebase & bless more tests --- src/test/ui/coherence/issue-100191.stderr | 4 ++-- src/test/ui/error-codes/e0119/issue-28981.stderr | 4 ++-- src/test/ui/issues/issue-41974.stderr | 4 ++-- src/test/ui/orphan-check-diagnostics.stderr | 4 ++-- src/test/ui/specialization/issue-43037.stderr | 4 ++-- .../ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs | 4 +++- .../type-alias-impl-trait/incoherent-assoc-imp-trait.stderr | 6 +++--- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/test/ui/coherence/issue-100191.stderr b/src/test/ui/coherence/issue-100191.stderr index 1adb0f1e4fa7b..9bd6498a72f74 100644 --- a/src/test/ui/coherence/issue-100191.stderr +++ b/src/test/ui/coherence/issue-100191.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-100191.rs:18:6 + --> $DIR/issue-100191.rs:18:38 | LL | impl From< as Z>::Assoc> for T {} - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/error-codes/e0119/issue-28981.stderr b/src/test/ui/error-codes/e0119/issue-28981.stderr index 97b570bc7aca3..a2d0030a4e15f 100644 --- a/src/test/ui/error-codes/e0119/issue-28981.stderr +++ b/src/test/ui/error-codes/e0119/issue-28981.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `Foo` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-28981.rs:5:6 + --> $DIR/issue-28981.rs:5:21 | LL | impl Deref for Foo { } - | ^^^ type parameter `Foo` must be used as the type parameter for some local type + | ^^^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/issues/issue-41974.stderr b/src/test/ui/issues/issue-41974.stderr index e249db9df5324..aca96eb14f14d 100644 --- a/src/test/ui/issues/issue-41974.stderr +++ b/src/test/ui/issues/issue-41974.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-41974.rs:7:6 + --> $DIR/issue-41974.rs:7:18 | LL | impl Drop for T where T: A { - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/orphan-check-diagnostics.stderr b/src/test/ui/orphan-check-diagnostics.stderr index 7a7cea56307de..c37a925575912 100644 --- a/src/test/ui/orphan-check-diagnostics.stderr +++ b/src/test/ui/orphan-check-diagnostics.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/orphan-check-diagnostics.rs:11:6 + --> $DIR/orphan-check-diagnostics.rs:11:25 | LL | impl RemoteTrait for T where T: LocalTrait {} - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/specialization/issue-43037.stderr b/src/test/ui/specialization/issue-43037.stderr index 4249cd8947716..4799c63fc489d 100644 --- a/src/test/ui/specialization/issue-43037.stderr +++ b/src/test/ui/specialization/issue-43037.stderr @@ -1,8 +1,8 @@ error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-43037.rs:17:6 + --> $DIR/issue-43037.rs:17:38 | LL | impl From< as Z>::Assoc> for T {} - | ^ type parameter `T` must be used as the type parameter for some local type + | ^ 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter diff --git a/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs b/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs index 685d76ee36f33..60c12d7bc4cc8 100644 --- a/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs +++ b/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.rs @@ -8,7 +8,9 @@ trait MyTrait {} impl MyTrait for () {} impl FnOnce<()> for &F { - //~^ ERROR type parameter `F` must be used + //~^ ERROR type parameter `F` as argument to a fundamental type + // | must be used as the type parameter for some local type + // | (e.g., `MyStruct`) type Output = impl MyTrait; extern "rust-call" fn call_once(self, _: ()) -> Self::Output {} } diff --git a/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.stderr b/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.stderr index b93ea955c89f5..33dcba8ba24c1 100644 --- a/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.stderr +++ b/src/test/ui/type-alias-impl-trait/incoherent-assoc-imp-trait.stderr @@ -1,8 +1,8 @@ -error[E0210]: type parameter `F` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/incoherent-assoc-imp-trait.rs:10:6 +error[E0210]: type parameter `F` as argument to a fundamental type must be used as the type parameter for some local type (e.g., `MyStruct`) + --> $DIR/incoherent-assoc-imp-trait.rs:10:24 | LL | impl FnOnce<()> for &F { - | ^ type parameter `F` must be used as the type parameter for some local type + | ^^ type parameter `F` as argument to a fundamental type 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 it is implemented is local = note: only traits defined in the current crate can be implemented for a type parameter