From f667e952f85911fb2983f98d0808d40242db7b47 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 5 May 2022 14:14:06 +0000 Subject: [PATCH] Check hidden types for well formedness at the definition site instead of only at the opaque type itself --- .../src/region_infer/opaque_types.rs | 1 + .../rustc_trait_selection/src/opaque_types.rs | 74 ++++++++++++++++++- .../bounds-are-checked-2.rs | 2 +- .../bounds-are-checked-2.stderr | 6 +- .../generic_duplicate_param_use.rs | 1 + .../generic_duplicate_param_use.stderr | 18 ++++- .../generic_duplicate_param_use2.rs | 2 +- .../generic_duplicate_param_use2.stderr | 6 +- .../generic_duplicate_param_use3.rs | 4 +- .../generic_duplicate_param_use3.stderr | 29 ++++---- .../generic_duplicate_param_use4.rs | 2 +- .../generic_duplicate_param_use4.stderr | 6 +- .../generic_duplicate_param_use5.rs | 7 +- .../generic_duplicate_param_use5.stderr | 50 ++++++++----- .../generic_duplicate_param_use6.rs | 5 +- .../generic_duplicate_param_use6.stderr | 44 +++++++---- .../generic_duplicate_param_use8.rs | 4 +- .../generic_duplicate_param_use8.stderr | 30 ++++---- .../generic_duplicate_param_use9.rs | 10 ++- .../generic_duplicate_param_use9.stderr | 56 ++++++++------ .../ui/type-alias-impl-trait/issue-52843.rs | 2 +- .../type-alias-impl-trait/issue-52843.stderr | 6 +- .../ui/type-alias-impl-trait/issue-60564.rs | 1 + .../type-alias-impl-trait/issue-60564.stderr | 16 +++- .../issue-68368-non-defining-use.rs | 1 + .../issue-68368-non-defining-use.stderr | 14 +++- .../ui/type-alias-impl-trait/issue-89686.rs | 2 +- .../type-alias-impl-trait/issue-89686.stderr | 6 +- .../not_a_defining_use.rs | 5 +- .../not_a_defining_use.stderr | 43 +++++++---- .../underconstrained_generic.rs | 2 +- .../underconstrained_generic.stderr | 6 +- 32 files changed, 311 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index fa07c4fa949..f3d37a6be7b 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -110,6 +110,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let remapped_type = infcx.infer_opaque_definition_from_instantiation( opaque_type_key, universal_concrete_type, + origin, ); let ty = if check_opaque_type_parameter_valid( infcx.tcx, diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 4b949ff8b95..81a90e92b4f 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -1,11 +1,15 @@ use crate::traits; +use crate::traits::error_reporting::InferCtxtExt as _; +use crate::traits::TraitEngineExt as _; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; +use rustc_hir::OpaqueTyOrigin; use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic; -use rustc_infer::infer::InferCtxt; +use rustc_infer::infer::{InferCtxt, TyCtxtInferExt as _}; +use rustc_infer::traits::{Obligation, ObligationCause, TraitEngine}; use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts}; -use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt}; +use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt}; use rustc_span::Span; pub trait InferCtxtExt<'tcx> { @@ -13,6 +17,7 @@ pub trait InferCtxtExt<'tcx> { &self, opaque_type_key: OpaqueTypeKey<'tcx>, instantiated_ty: OpaqueHiddenType<'tcx>, + origin: OpaqueTyOrigin, ) -> Ty<'tcx>; } @@ -45,6 +50,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, opaque_type_key: OpaqueTypeKey<'tcx>, instantiated_ty: OpaqueHiddenType<'tcx>, + origin: OpaqueTyOrigin, ) -> Ty<'tcx> { if self.is_tainted_by_errors() { return self.tcx.ty_error(); @@ -76,7 +82,69 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { )); debug!(?definition_ty); - definition_ty + // Only check this for TAIT. RPIT already supports `src/test/ui/impl-trait/nested-return-type2.rs` + // on stable and we'd break that. + if let OpaqueTyOrigin::TyAlias = origin { + // This logic duplicates most of `check_opaque_meets_bounds`. + // FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely. + let param_env = self.tcx.param_env(def_id); + let body_id = self.tcx.local_def_id_to_hir_id(def_id.as_local().unwrap()); + self.tcx.infer_ctxt().enter(move |infcx| { + // Require the hidden type to be well-formed with only the generics of the opaque type. + // Defining use functions may have more bounds than the opaque type, which is ok, as long as the + // hidden type is well formed even without those bounds. + let predicate = + ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into())) + .to_predicate(infcx.tcx); + let mut fulfillment_cx = >::new(infcx.tcx); + + // Require that the hidden type actually fulfills all the bounds of the opaque type, even without + // the bounds that the function supplies. + match infcx.register_hidden_type( + OpaqueTypeKey { def_id, substs: id_substs }, + ObligationCause::misc(instantiated_ty.span, body_id), + param_env, + definition_ty, + origin, + ) { + Ok(infer_ok) => { + for obligation in infer_ok.obligations { + fulfillment_cx.register_predicate_obligation(&infcx, obligation); + } + } + Err(err) => { + infcx + .report_mismatched_types( + &ObligationCause::misc(instantiated_ty.span, body_id), + self.tcx.mk_opaque(def_id, id_substs), + definition_ty, + err, + ) + .emit(); + } + } + + fulfillment_cx.register_predicate_obligation( + &infcx, + Obligation::misc(instantiated_ty.span, body_id, param_env, predicate), + ); + + // Check that all obligations are satisfied by the implementation's + // version. + let errors = fulfillment_cx.select_all_or_error(&infcx); + + let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types(); + + if errors.is_empty() { + definition_ty + } else { + infcx.report_fulfillment_errors(&errors, None, false); + self.tcx.ty_error() + } + }) + } else { + definition_ty + } } } diff --git a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.rs b/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.rs index c0359159aeb..55b4dc8dc23 100644 --- a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.rs +++ b/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.rs @@ -4,10 +4,10 @@ #![feature(type_alias_impl_trait)] type X = impl Clone; -//~^ ERROR the trait bound `T: Clone` is not satisfied fn f(t: T) -> X { t + //~^ ERROR the trait bound `T: Clone` is not satisfied } fn g(o: Option>) -> Option> { diff --git a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.stderr b/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.stderr index 5ee7c72bf73..8678e9b33b5 100644 --- a/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.stderr +++ b/src/test/ui/type-alias-impl-trait/bounds-are-checked-2.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/bounds-are-checked-2.rs:6:13 + --> $DIR/bounds-are-checked-2.rs:9:5 | -LL | type X = impl Clone; - | ^^^^^^^^^^ the trait `Clone` is not implemented for `T` +LL | t + | ^ the trait `Clone` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs index 093c1c23186..cf46add124c 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -15,6 +15,7 @@ type TwoConsts = impl Debug; fn one_ty(t: T) -> TwoTys { t //~^ ERROR non-defining opaque type use in defining scope + //~| ERROR `U` doesn't implement `Debug` } fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index b2edcc5526a..d661196e1bf 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -1,3 +1,14 @@ +error[E0277]: `U` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use.rs:16:5 + | +LL | t + | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | +help: consider restricting type parameter `U` + | +LL | type TwoTys = impl Debug; + | +++++++++++++++++ + error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_param_use.rs:16:5 | @@ -11,7 +22,7 @@ LL | type TwoTys = impl Debug; | ^ ^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:21:5 + --> $DIR/generic_duplicate_param_use.rs:22:5 | LL | t | ^ @@ -23,7 +34,7 @@ LL | type TwoLifetimes<'a, 'b> = impl Debug; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:26:5 + --> $DIR/generic_duplicate_param_use.rs:27:5 | LL | t | ^ @@ -34,5 +45,6 @@ note: constant used multiple times LL | type TwoConsts = impl Debug; | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs index 81bf9770d02..201535efe15 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs @@ -6,8 +6,8 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` fn two(t: T, _: U) -> Two { t + //~^ ERROR `T` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr index 84aa260b099..3dbfff7453f 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr @@ -1,8 +1,8 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use2.rs:8:18 + --> $DIR/generic_duplicate_param_use2.rs:11:5 | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | t + | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs index 7747626d96d..e7a25fc7240 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs @@ -6,13 +6,13 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` fn two(t: T, _: U) -> Two { t + //~^ ERROR `T` doesn't implement `Debug` } fn three(_: T, u: U) -> Two { u - //~^ ERROR concrete type differs from previous defining opaque type use + //~^ ERROR `U` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr index 88c450704bf..7bec3822071 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr @@ -1,26 +1,25 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use3.rs:16:5 - | -LL | u - | ^ expected `T`, got `U` - | -note: previous use here - --> $DIR/generic_duplicate_param_use3.rs:12:5 +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use3.rs:11:5 | LL | t - | ^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use3.rs:8:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | help: consider restricting type parameter `T` | LL | type Two = impl Debug; | +++++++++++++++++ +error[E0277]: `U` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use3.rs:16:5 + | +LL | u + | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | +help: consider restricting type parameter `U` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs index aee2550e907..d1e5a0f0198 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs @@ -6,8 +6,8 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; -//~^ ERROR `U` doesn't implement `Debug` fn three(_: T, u: U) -> Two { u + //~^ ERROR `U` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr index 0491d61030e..21a5369d9ff 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr @@ -1,8 +1,8 @@ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use4.rs:8:18 + --> $DIR/generic_duplicate_param_use4.rs:11:5 | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | u + | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | help: consider restricting type parameter `U` | diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs index 03bd00a039d..3bd1dda6331 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs @@ -6,14 +6,15 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` -//~| ERROR `U` doesn't implement `Debug` fn two(t: T, u: U) -> Two { (t, u) + //~^ ERROR `T` doesn't implement `Debug` + //~| ERROR `U` doesn't implement `Debug` } fn three(t: T, u: U) -> Two { (u, t) - //~^ concrete type differs from previous + //~^ ERROR `T` doesn't implement `Debug` + //~| ERROR `U` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr index d46a3ebe175..2768f0c3ab7 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr @@ -1,20 +1,8 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use5.rs:17:5 - | -LL | (u, t) - | ^^^^^^ expected `(T, U)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use5.rs:13:5 +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use5.rs:11:5 | LL | (t, u) - | ^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:8:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(T, U)` help: consider restricting type parameter `T` @@ -23,10 +11,10 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:8:18 + --> $DIR/generic_duplicate_param_use5.rs:11:5 | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | (t, u) + | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(T, U)` help: consider restricting type parameter `U` @@ -34,6 +22,30 @@ help: consider restricting type parameter `U` LL | type Two = impl Debug; | +++++++++++++++++ -error: aborting due to 3 previous errors +error[E0277]: `U` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use5.rs:17:5 + | +LL | (u, t) + | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(U, T)` +help: consider restricting type parameter `U` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use5.rs:17:5 + | +LL | (u, t) + | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(U, T)` +help: consider restricting type parameter `T` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs index a8c801dc887..5120925e5a4 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs @@ -6,13 +6,14 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` fn two(t: T, u: U) -> Two { (t, t) + //~^ ERROR `T` doesn't implement `Debug` } fn three(t: T, u: U) -> Two { (u, t) - //~^ ERROR concrete type differs from previous + //~^ ERROR `T` doesn't implement `Debug` + //~| ERROR `U` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr index 7e89b574b5c..c1712ca2efb 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr @@ -1,20 +1,8 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use6.rs:16:5 - | -LL | (u, t) - | ^^^^^^ expected `(T, T)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use6.rs:12:5 +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use6.rs:11:5 | LL | (t, t) - | ^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use6.rs:8:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(T, T)` help: consider restricting type parameter `T` @@ -22,6 +10,30 @@ help: consider restricting type parameter `T` LL | type Two = impl Debug; | +++++++++++++++++ -error: aborting due to 2 previous errors +error[E0277]: `U` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use6.rs:16:5 + | +LL | (u, t) + | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(U, T)` +help: consider restricting type parameter `U` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use6.rs:16:5 + | +LL | (u, t) + | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(U, T)` +help: consider restricting type parameter `T` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs index 57527e758db..3a4b5047b41 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs @@ -5,13 +5,13 @@ use std::fmt::Debug; fn main() {} type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` fn two(t: T, _: U) -> Two { (t, 4u32) + //~^ ERROR `T` doesn't implement `Debug` } fn three(_: T, u: U) -> Two { (u, 4u32) - //~^ concrete type differs from previous + //~^ ERROR `U` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr index 1a6ec3aec14..b83105c45f2 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr @@ -1,20 +1,8 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use8.rs:15:5 - | -LL | (u, 4u32) - | ^^^^^^^^^ expected `(T, u32)`, got `(U, u32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use8.rs:11:5 +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use8.rs:10:5 | LL | (t, 4u32) - | ^^^^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use8.rs:7:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(T, u32)` help: consider restricting type parameter `T` @@ -22,6 +10,18 @@ help: consider restricting type parameter `T` LL | type Two = impl Debug; | +++++++++++++++++ +error[E0277]: `U` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use8.rs:15:5 + | +LL | (u, 4u32) + | ^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(U, u32)` +help: consider restricting type parameter `U` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs index 5878ad92698..6afcdfe4d1c 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs @@ -5,9 +5,6 @@ use std::fmt::Debug; fn main() {} type Two = impl Debug; -//~^ ERROR the trait bound `A: Foo` is not satisfied -//~| ERROR `A` doesn't implement `Debug` -//~| ERROR `B` doesn't implement `Debug` trait Foo { type Bar: Debug; @@ -16,8 +13,13 @@ trait Foo { fn two(t: T, u: U) -> Two { (t, u, T::BAR) + //~^ ERROR the trait bound `A: Foo` is not satisfied + //~| ERROR `A` doesn't implement `Debug` + //~| ERROR `B` doesn't implement `Debug` } fn three(t: T, u: U) -> Two { - (t, u, 42) //~ ERROR concrete type differs from previous + (t, u, 42) + //~^ ERROR `A` doesn't implement `Debug` + //~| ERROR `B` doesn't implement `Debug` } diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr index ef7573246af..50cf982733b 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr @@ -1,20 +1,8 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use9.rs:22:5 - | -LL | (t, u, 42) - | ^^^^^^^^^^ expected `(A, B, ::Bar)`, got `(A, B, i32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use9.rs:18:5 +error[E0277]: the trait bound `A: Foo` is not satisfied + --> $DIR/generic_duplicate_param_use9.rs:15:5 | LL | (t, u, T::BAR) - | ^^^^^^^^^^^^^^ - -error[E0277]: the trait bound `A: Foo` is not satisfied - --> $DIR/generic_duplicate_param_use9.rs:7:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ the trait `Foo` is not implemented for `A` + | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A` | help: consider restricting type parameter `A` | @@ -22,10 +10,10 @@ LL | type Two = impl Debug; | +++++ error[E0277]: `A` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:7:18 + --> $DIR/generic_duplicate_param_use9.rs:15:5 | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | (t, u, T::BAR) + | ^^^^^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(A, B, _)` help: consider restricting type parameter `A` @@ -34,10 +22,10 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `B` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:7:18 + --> $DIR/generic_duplicate_param_use9.rs:15:5 | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | (t, u, T::BAR) + | ^^^^^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(A, B, _)` help: consider restricting type parameter `B` @@ -45,6 +33,30 @@ help: consider restricting type parameter `B` LL | type Two = impl Debug; | +++++++++++++++++ -error: aborting due to 4 previous errors +error[E0277]: `A` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use9.rs:22:5 + | +LL | (t, u, 42) + | ^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(A, B, i32)` +help: consider restricting type parameter `A` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error[E0277]: `B` doesn't implement `Debug` + --> $DIR/generic_duplicate_param_use9.rs:22:5 + | +LL | (t, u, 42) + | ^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(A, B, i32)` +help: consider restricting type parameter `B` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-52843.rs b/src/test/ui/type-alias-impl-trait/issue-52843.rs index b24959d7207..159d3ccd27e 100644 --- a/src/test/ui/type-alias-impl-trait/issue-52843.rs +++ b/src/test/ui/type-alias-impl-trait/issue-52843.rs @@ -1,11 +1,11 @@ #![feature(type_alias_impl_trait)] type Foo = impl Default; -//~^ ERROR: the trait bound `T: Default` is not satisfied #[allow(unused)] fn foo(t: T) -> Foo { t + //~^ ERROR: the trait bound `T: Default` is not satisfied } struct NotDefault; diff --git a/src/test/ui/type-alias-impl-trait/issue-52843.stderr b/src/test/ui/type-alias-impl-trait/issue-52843.stderr index 2463ed9c71a..acd40f9804e 100644 --- a/src/test/ui/type-alias-impl-trait/issue-52843.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-52843.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Default` is not satisfied - --> $DIR/issue-52843.rs:3:15 + --> $DIR/issue-52843.rs:7:5 | -LL | type Foo = impl Default; - | ^^^^^^^^^^^^ the trait `Default` is not implemented for `T` +LL | t + | ^ the trait `Default` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/type-alias-impl-trait/issue-60564.rs b/src/test/ui/type-alias-impl-trait/issue-60564.rs index 4fc7679311a..0aeebae639e 100644 --- a/src/test/ui/type-alias-impl-trait/issue-60564.rs +++ b/src/test/ui/type-alias-impl-trait/issue-60564.rs @@ -19,6 +19,7 @@ where fn iter_bits(self, n: u8) -> Self::BitsIter { (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap()) //~^ ERROR non-defining opaque type use in defining scope + //~| ERROR type mismatch resolving } } diff --git a/src/test/ui/type-alias-impl-trait/issue-60564.stderr b/src/test/ui/type-alias-impl-trait/issue-60564.stderr index bbc93657be3..9cb07cbbb44 100644 --- a/src/test/ui/type-alias-impl-trait/issue-60564.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-60564.stderr @@ -1,3 +1,16 @@ +error[E0271]: type mismatch resolving `<[closure@$DIR/issue-60564.rs:20:28: 20:100] as FnOnce<(u8,)>>::Output == I` + --> $DIR/issue-60564.rs:20:9 + | +LL | type IterBitsIter = impl std::iter::Iterator; + | - this type parameter +... +LL | (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found type parameter `I` + | + = note: expected type `u8` + found type parameter `I` + = note: required because of the requirements on the impl of `Iterator` for `Map>, [closure@$DIR/issue-60564.rs:20:28: 20:100]>` + error: non-defining opaque type use in defining scope --> $DIR/issue-60564.rs:20:9 | @@ -10,5 +23,6 @@ note: used non-generic type `u8` for generic parameter LL | type IterBitsIter = impl std::iter::Iterator; | ^ -error: aborting due to previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0271`. diff --git a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs index b50462bf237..bffff8787e4 100644 --- a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs +++ b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs @@ -8,6 +8,7 @@ type Alias<'a, U> = impl Trait; fn f<'a>() -> Alias<'a, ()> {} //~^ ERROR non-defining opaque type use in defining scope +//~| ERROR the trait bound `(): Trait` is not satisfied fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr index 8059621b61a..b79d638ad99 100644 --- a/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr @@ -1,3 +1,14 @@ +error[E0277]: the trait bound `(): Trait` is not satisfied + --> $DIR/issue-68368-non-defining-use.rs:9:29 + | +LL | fn f<'a>() -> Alias<'a, ()> {} + | ^^ the trait `Trait` is not implemented for `()` + | +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | type Alias<'a, U> = impl Trait where (): Trait; + | ++++++++++++++++++ + error: non-defining opaque type use in defining scope --> $DIR/issue-68368-non-defining-use.rs:9:29 | @@ -10,5 +21,6 @@ note: used non-generic type `()` for generic parameter LL | type Alias<'a, U> = impl Trait; | ^ -error: aborting due to previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.rs b/src/test/ui/type-alias-impl-trait/issue-89686.rs index f058653dde3..de070fc9deb 100644 --- a/src/test/ui/type-alias-impl-trait/issue-89686.rs +++ b/src/test/ui/type-alias-impl-trait/issue-89686.rs @@ -5,7 +5,6 @@ use std::future::Future; type G<'a, T> = impl Future; -//~^ ERROR: the trait bound `T: Trait` is not satisfied trait Trait { type F: Future; @@ -17,6 +16,7 @@ trait Trait { Self: Sized, { async move { self.f().await } + //~^ ERROR: the trait bound `T: Trait` is not satisfied } } diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.stderr b/src/test/ui/type-alias-impl-trait/issue-89686.stderr index 0df5a809ebb..b636ada8b75 100644 --- a/src/test/ui/type-alias-impl-trait/issue-89686.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-89686.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/issue-89686.rs:7:17 + --> $DIR/issue-89686.rs:18:9 | -LL | type G<'a, T> = impl Future; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` +LL | async move { self.f().await } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs b/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs index 289784ce747..fa47d13f516 100644 --- a/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs +++ b/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs @@ -5,10 +5,10 @@ use std::fmt::Debug; fn main() {} type Two = impl Debug; -//~^ ERROR `T` doesn't implement `Debug` fn three(t: T) -> Two { (t, 5i8) + //~^ ERROR `T` doesn't implement `Debug` } trait Bar { @@ -23,7 +23,8 @@ impl Bar for u32 { fn four(t: T) -> Two { (t, ::FOO) - //~^ ERROR concrete type differs from previous + //~^ ERROR `U: Bar` is not satisfied + //~| ERROR `T` doesn't implement `Debug` } fn is_sync() {} diff --git a/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr index 6068cfeb51e..a5ac38c38d4 100644 --- a/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr +++ b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr @@ -1,20 +1,8 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/not_a_defining_use.rs:25:5 - | -LL | (t, ::FOO) - | ^^^^^^^^^^^^^^^^^^^^ expected `(T, i8)`, got `(T, ::Blub)` - | -note: previous use here - --> $DIR/not_a_defining_use.rs:11:5 +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/not_a_defining_use.rs:10:5 | LL | (t, 5i8) - | ^^^^^^^^ - -error[E0277]: `T` doesn't implement `Debug` - --> $DIR/not_a_defining_use.rs:7:18 - | -LL | type Two = impl Debug; - | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | ^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | = note: required because of the requirements on the impl of `Debug` for `(T, i8)` help: consider restricting type parameter `T` @@ -22,6 +10,29 @@ help: consider restricting type parameter `T` LL | type Two = impl Debug; | +++++++++++++++++ -error: aborting due to 2 previous errors +error[E0277]: the trait bound `U: Bar` is not satisfied + --> $DIR/not_a_defining_use.rs:25:5 + | +LL | (t, ::FOO) + | ^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `U` + | +help: consider restricting type parameter `U` + | +LL | type Two = impl Debug; + | +++++ + +error[E0277]: `T` doesn't implement `Debug` + --> $DIR/not_a_defining_use.rs:25:5 + | +LL | (t, ::FOO) + | ^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` + | + = note: required because of the requirements on the impl of `Debug` for `(T, _)` +help: consider restricting type parameter `T` + | +LL | type Two = impl Debug; + | +++++++++++++++++ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/underconstrained_generic.rs b/src/test/ui/type-alias-impl-trait/underconstrained_generic.rs index 22264670f37..aa537dfc917 100644 --- a/src/test/ui/type-alias-impl-trait/underconstrained_generic.rs +++ b/src/test/ui/type-alias-impl-trait/underconstrained_generic.rs @@ -17,10 +17,10 @@ impl ProofForConversion for () { } type Converter = impl ProofForConversion; -//~^ ERROR the trait bound `T: Trait` is not satisfied fn _defining_use() -> Converter { () + //~^ ERROR the trait bound `T: Trait` is not satisfied } diff --git a/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr b/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr index 1c305abcfeb..e70916573f6 100644 --- a/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr +++ b/src/test/ui/type-alias-impl-trait/underconstrained_generic.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/underconstrained_generic.rs:19:21 + --> $DIR/underconstrained_generic.rs:22:5 | -LL | type Converter = impl ProofForConversion; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` +LL | () + | ^^ the trait `Trait` is not implemented for `T` | note: required because of the requirements on the impl of `ProofForConversion` for `()` --> $DIR/underconstrained_generic.rs:13:16