1
Fork 0

Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726

Ensure valid TraitRefs are created for GATs

This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`.

r? ````@jackh726````
This commit is contained in:
Dylan DPC 2021-02-18 16:57:34 +01:00 committed by GitHub
commit 66211f6657
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 542 additions and 239 deletions

View file

@ -914,6 +914,7 @@ impl<'a> State<'a> {
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) { pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
self.print_ident(constraint.ident); self.print_ident(constraint.ident);
constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
self.s.space(); self.s.space();
match &constraint.kind { match &constraint.kind {
ast::AssocTyConstraintKind::Equality { ty } => { ast::AssocTyConstraintKind::Equality { ty } => {

View file

@ -242,6 +242,7 @@ language_item_table! {
Deref, sym::deref, deref_trait, Target::Trait; Deref, sym::deref, deref_trait, Target::Trait;
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait; DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait;
DerefTarget, sym::deref_target, deref_target, Target::AssocTy;
Receiver, sym::receiver, receiver_trait, Target::Trait; Receiver, sym::receiver, receiver_trait, Target::Trait;
Fn, kw::Fn, fn_trait, Target::Trait; Fn, kw::Fn, fn_trait, Target::Trait;

View file

@ -55,6 +55,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy { pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
fn to_trace( fn to_trace(
tcx: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -178,7 +179,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where where
T: ToTrace<'tcx>, T: ToTrace<'tcx>,
{ {
let trace = ToTrace::to_trace(self.cause, a_is_expected, a, b); let trace = ToTrace::to_trace(self.infcx.tcx, self.cause, a_is_expected, a, b);
Trace { at: self, trace, a_is_expected } Trace { at: self, trace, a_is_expected }
} }
} }
@ -251,6 +252,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
impl<'tcx> ToTrace<'tcx> for Ty<'tcx> { impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
fn to_trace( fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -262,6 +264,7 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> { impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
fn to_trace( fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -273,6 +276,7 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> { impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
fn to_trace( fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -284,6 +288,7 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> { impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
fn to_trace( fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -298,6 +303,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> { impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
fn to_trace( fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>, cause: &ObligationCause<'tcx>,
a_is_expected: bool, a_is_expected: bool,
a: Self, a: Self,
@ -309,3 +315,20 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
} }
} }
} }
impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
fn to_trace(
tcx: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
let a_ty = tcx.mk_projection(a.item_def_id, a.substs);
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
TypeTrace {
cause: cause.clone(),
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
}
}
}

View file

@ -1,5 +1,6 @@
use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty::diagnostics::suggest_constraining_type_param; use crate::ty::diagnostics::suggest_constraining_type_param;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt}; use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt};
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect}; use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
use rustc_errors::{pluralize, DiagnosticBuilder}; use rustc_errors::{pluralize, DiagnosticBuilder};
@ -405,14 +406,22 @@ impl<'tcx> TyCtxt<'tcx> {
{ {
// Synthesize the associated type restriction `Add<Output = Expected>`. // Synthesize the associated type restriction `Add<Output = Expected>`.
// FIXME: extract this logic for use in other diagnostics. // FIXME: extract this logic for use in other diagnostics.
let trait_ref = proj.trait_ref(self); let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(self);
let path = let path =
self.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs); self.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs);
let item_name = self.item_name(proj.item_def_id); let item_name = self.item_name(proj.item_def_id);
let item_args = self.format_generic_args(assoc_substs);
let path = if path.ends_with('>') { let path = if path.ends_with('>') {
format!("{}, {} = {}>", &path[..path.len() - 1], item_name, p) format!(
"{}, {}{} = {}>",
&path[..path.len() - 1],
item_name,
item_args,
p
)
} else { } else {
format!("{}<{} = {}>", path, item_name, p) format!("{}<{}{} = {}>", path, item_name, item_args, p)
}; };
note = !suggest_constraining_type_param( note = !suggest_constraining_type_param(
self, self,
@ -561,7 +570,7 @@ impl<T> Trait<T> for X {
ty: Ty<'tcx>, ty: Ty<'tcx>,
) -> bool { ) -> bool {
let assoc = self.associated_item(proj_ty.item_def_id); let assoc = self.associated_item(proj_ty.item_def_id);
let trait_ref = proj_ty.trait_ref(self); let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self);
if let Some(item) = self.hir().get_if_local(body_owner_def_id) { if let Some(item) = self.hir().get_if_local(body_owner_def_id) {
if let Some(hir_generics) = item.generics() { if let Some(hir_generics) = item.generics() {
// Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`. // Get the `DefId` for the type parameter corresponding to `A` in `<A as T>::Foo`.
@ -595,6 +604,7 @@ impl<T> Trait<T> for X {
&trait_ref, &trait_ref,
pred.bounds, pred.bounds,
&assoc, &assoc,
assoc_substs,
ty, ty,
msg, msg,
) { ) {
@ -612,6 +622,7 @@ impl<T> Trait<T> for X {
&trait_ref, &trait_ref,
param.bounds, param.bounds,
&assoc, &assoc,
assoc_substs,
ty, ty,
msg, msg,
); );
@ -697,6 +708,7 @@ impl<T> Trait<T> for X {
db, db,
self.def_span(def_id), self.def_span(def_id),
&assoc, &assoc,
proj_ty.trait_ref_and_own_substs(self).1,
values.found, values.found,
&msg, &msg,
) { ) {
@ -861,6 +873,7 @@ fn foo(&self) -> Self::T { String::new() }
trait_ref: &ty::TraitRef<'tcx>, trait_ref: &ty::TraitRef<'tcx>,
bounds: hir::GenericBounds<'_>, bounds: hir::GenericBounds<'_>,
assoc: &ty::AssocItem, assoc: &ty::AssocItem,
assoc_substs: &[ty::GenericArg<'tcx>],
ty: Ty<'tcx>, ty: Ty<'tcx>,
msg: &str, msg: &str,
) -> bool { ) -> bool {
@ -870,7 +883,12 @@ fn foo(&self) -> Self::T { String::new() }
// Relate the type param against `T` in `<A as T>::Foo`. // Relate the type param against `T` in `<A as T>::Foo`.
ptr.trait_ref.trait_def_id() == Some(trait_ref.def_id) ptr.trait_ref.trait_def_id() == Some(trait_ref.def_id)
&& self.constrain_associated_type_structured_suggestion( && self.constrain_associated_type_structured_suggestion(
db, ptr.span, assoc, ty, msg, db,
ptr.span,
assoc,
assoc_substs,
ty,
msg,
) )
} }
_ => false, _ => false,
@ -884,6 +902,7 @@ fn foo(&self) -> Self::T { String::new() }
db: &mut DiagnosticBuilder<'_>, db: &mut DiagnosticBuilder<'_>,
span: Span, span: Span,
assoc: &ty::AssocItem, assoc: &ty::AssocItem,
assoc_substs: &[ty::GenericArg<'tcx>],
ty: Ty<'tcx>, ty: Ty<'tcx>,
msg: &str, msg: &str,
) -> bool { ) -> bool {
@ -895,11 +914,20 @@ fn foo(&self) -> Self::T { String::new() }
let span = Span::new(pos, pos, span.ctxt()); let span = Span::new(pos, pos, span.ctxt());
(span, format!(", {} = {}", assoc.ident, ty)) (span, format!(", {} = {}", assoc.ident, ty))
} else { } else {
(span.shrink_to_hi(), format!("<{} = {}>", assoc.ident, ty)) let item_args = self.format_generic_args(assoc_substs);
(span.shrink_to_hi(), format!("<{}{} = {}>", assoc.ident, item_args, ty))
}; };
db.span_suggestion_verbose(span, msg, sugg, MaybeIncorrect); db.span_suggestion_verbose(span, msg, sugg, MaybeIncorrect);
return true; return true;
} }
false false
} }
fn format_generic_args(self, args: &[ty::GenericArg<'tcx>]) -> String {
let mut item_args = String::new();
FmtPrinter::new(self, &mut item_args, hir::def::Namespace::TypeNS)
.path_generic_args(Ok, args)
.expect("could not write to `String`.");
item_args
}
} }

View file

@ -1289,8 +1289,22 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
self.skip_binder().projection_ty.item_def_id self.skip_binder().projection_ty.item_def_id
} }
/// Returns the `DefId` of the trait of the associated item being projected.
#[inline] #[inline]
pub fn to_poly_trait_ref(&self, tcx: TyCtxt<'tcx>) -> PolyTraitRef<'tcx> { pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
self.skip_binder().projection_ty.trait_def_id(tcx)
}
#[inline]
pub fn projection_self_ty(&self) -> Binder<Ty<'tcx>> {
self.map_bound(|predicate| predicate.projection_ty.self_ty())
}
/// Get the [PolyTraitRef] required for this projection to be well formed.
/// Note that for generic associated types the predicates of the associated
/// type also need to be checked.
#[inline]
pub fn required_poly_trait_ref(&self, tcx: TyCtxt<'tcx>) -> PolyTraitRef<'tcx> {
// Note: unlike with `TraitRef::to_poly_trait_ref()`, // Note: unlike with `TraitRef::to_poly_trait_ref()`,
// `self.0.trait_ref` is permitted to have escaping regions. // `self.0.trait_ref` is permitted to have escaping regions.
// This is because here `self` has a `Binder` and so does our // This is because here `self` has a `Binder` and so does our

View file

@ -17,7 +17,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::Idx; use rustc_index::vec::Idx;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::symbol::{kw, Symbol};
use rustc_target::abi::VariantIdx; use rustc_target::abi::VariantIdx;
use rustc_target::spec::abi; use rustc_target::spec::abi;
use std::borrow::Cow; use std::borrow::Cow;
@ -1112,36 +1112,35 @@ pub struct ProjectionTy<'tcx> {
} }
impl<'tcx> ProjectionTy<'tcx> { impl<'tcx> ProjectionTy<'tcx> {
/// Construct a `ProjectionTy` by searching the trait from `trait_ref` for the pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
/// associated item named `item_name`. tcx.associated_item(self.item_def_id).container.id()
pub fn from_ref_and_name( }
tcx: TyCtxt<'_>,
trait_ref: ty::TraitRef<'tcx>,
item_name: Ident,
) -> ProjectionTy<'tcx> {
let item_def_id = tcx
.associated_items(trait_ref.def_id)
.find_by_name_and_kind(tcx, item_name, ty::AssocKind::Type, trait_ref.def_id)
.unwrap()
.def_id;
ProjectionTy { substs: trait_ref.substs, item_def_id } /// Extracts the underlying trait reference and own substs from this projection.
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
/// then this function would return a `T: Iterator` trait reference and `['a]` as the own substs
pub fn trait_ref_and_own_substs(
&self,
tcx: TyCtxt<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
let def_id = tcx.associated_item(self.item_def_id).container.id();
let trait_generics = tcx.generics_of(def_id);
(
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, trait_generics) },
&self.substs[trait_generics.count()..],
)
} }
/// Extracts the underlying trait reference from this projection. /// Extracts the underlying trait reference from this projection.
/// For example, if this is a projection of `<T as Iterator>::Item`, /// For example, if this is a projection of `<T as Iterator>::Item`,
/// then this function would return a `T: Iterator` trait reference. /// then this function would return a `T: Iterator` trait reference.
///
/// WARNING: This will drop the substs for generic associated types
/// consider calling [Self::trait_ref_and_own_substs] to get those
/// as well.
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
// FIXME: This method probably shouldn't exist at all, since it's not let def_id = self.trait_def_id(tcx);
// clear what this method really intends to do. Be careful when ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) }
// using this method since the resulting TraitRef additionally
// contains the substs for the assoc_item, which strictly speaking
// is not correct
let def_id = tcx.associated_item(self.item_def_id).container.id();
// Include substitutions for generic arguments of associated types
let assoc_item = tcx.associated_item(self.item_def_id);
let substs_assoc_item = self.substs.truncate_to(tcx, tcx.generics_of(assoc_item.def_id));
ty::TraitRef { def_id, substs: substs_assoc_item }
} }
pub fn self_ty(&self) -> Ty<'tcx> { pub fn self_ty(&self) -> Ty<'tcx> {
@ -1493,12 +1492,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
/// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`, /// For example, if this is a projection of `exists T. <T as Iterator>::Item == X`,
/// then this function would return a `exists T. T: Iterator` existential trait /// then this function would return a `exists T. T: Iterator` existential trait
/// reference. /// reference.
pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::ExistentialTraitRef<'tcx> { pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> {
// FIXME(generic_associated_types): substs is the substs of the
// associated type, which should be truncated to get the correct substs
// for the trait.
let def_id = tcx.associated_item(self.item_def_id).container.id(); let def_id = tcx.associated_item(self.item_def_id).container.id();
ty::ExistentialTraitRef { def_id, substs: self.substs } let subst_count = tcx.generics_of(def_id).count() - 1;
let substs = tcx.intern_substs(&self.substs[..subst_count]);
ty::ExistentialTraitRef { def_id, substs }
} }
pub fn with_self_ty( pub fn with_self_ty(
@ -1517,6 +1515,20 @@ impl<'tcx> ExistentialProjection<'tcx> {
ty: self.ty, ty: self.ty,
} }
} }
pub fn erase_self_ty(
tcx: TyCtxt<'tcx>,
projection_predicate: ty::ProjectionPredicate<'tcx>,
) -> Self {
// Assert there is a Self.
projection_predicate.projection_ty.substs.type_at(0);
Self {
item_def_id: projection_predicate.projection_ty.item_def_id,
substs: tcx.intern_substs(&projection_predicate.projection_ty.substs[1..]),
ty: projection_predicate.ty,
}
}
} }
impl<'tcx> PolyExistentialProjection<'tcx> { impl<'tcx> PolyExistentialProjection<'tcx> {

View file

@ -77,6 +77,12 @@ trait DefIdVisitor<'tcx> {
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> {
self.skeleton().visit_trait(trait_ref) self.skeleton().visit_trait(trait_ref)
} }
fn visit_projection_ty(
&mut self,
projection: ty::ProjectionTy<'tcx>,
) -> ControlFlow<Self::BreakTy> {
self.skeleton().visit_projection_ty(projection)
}
fn visit_predicates( fn visit_predicates(
&mut self, &mut self,
predicates: ty::GenericPredicates<'tcx>, predicates: ty::GenericPredicates<'tcx>,
@ -101,6 +107,20 @@ where
if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) } if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) }
} }
fn visit_projection_ty(
&mut self,
projection: ty::ProjectionTy<'tcx>,
) -> ControlFlow<V::BreakTy> {
let (trait_ref, assoc_substs) =
projection.trait_ref_and_own_substs(self.def_id_visitor.tcx());
self.visit_trait(trait_ref)?;
if self.def_id_visitor.shallow() {
ControlFlow::CONTINUE
} else {
assoc_substs.iter().try_for_each(|subst| subst.visit_with(self))
}
}
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> { fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> {
match predicate.kind().skip_binder() { match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => { ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
@ -108,7 +128,7 @@ where
} }
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => { ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
ty.visit_with(self)?; ty.visit_with(self)?;
self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx())) self.visit_projection_ty(projection_ty)
} }
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => { ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
ty.visit_with(self) ty.visit_with(self)
@ -197,7 +217,7 @@ where
return ControlFlow::CONTINUE; return ControlFlow::CONTINUE;
} }
// This will also visit substs if necessary, so we don't need to recurse. // This will also visit substs if necessary, so we don't need to recurse.
return self.visit_trait(proj.trait_ref(tcx)); return self.visit_projection_ty(proj);
} }
ty::Dynamic(predicates, ..) => { ty::Dynamic(predicates, ..) => {
// All traits in the list are considered the "primary" part of the type // All traits in the list are considered the "primary" part of the type
@ -1203,10 +1223,9 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
} }
for (poly_predicate, _) in bounds.projection_bounds { for (poly_predicate, _) in bounds.projection_bounds {
let tcx = self.tcx;
if self.visit(poly_predicate.skip_binder().ty).is_break() if self.visit(poly_predicate.skip_binder().ty).is_break()
|| self || self
.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx)) .visit_projection_ty(poly_predicate.skip_binder().projection_ty)
.is_break() .is_break()
{ {
return; return;

View file

@ -6,7 +6,6 @@ use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness}; use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
use rustc_middle::ty::{ToPredicate, TypeFoldable}; use rustc_middle::ty::{ToPredicate, TypeFoldable};
use rustc_session::DiagnosticMessageId; use rustc_session::DiagnosticMessageId;
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
@ -146,11 +145,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
let normalized_ty = fulfillcx.normalize_projection_type( let normalized_ty = fulfillcx.normalize_projection_type(
&self.infcx, &self.infcx,
self.param_env, self.param_env,
ty::ProjectionTy::from_ref_and_name( ty::ProjectionTy {
tcx, item_def_id: tcx.lang_items().deref_target()?,
trait_ref, substs: trait_ref.substs,
Ident::with_dummy_span(sym::Target), },
),
cause, cause,
); );
if let Err(e) = fulfillcx.select_where_possible(&self.infcx) { if let Err(e) = fulfillcx.select_where_possible(&self.infcx) {

View file

@ -1589,8 +1589,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
self.emit_inference_failure_err(body_id, span, a.into(), vec![], ErrorCode::E0282) self.emit_inference_failure_err(body_id, span, a.into(), vec![], ErrorCode::E0282)
} }
ty::PredicateKind::Projection(data) => { ty::PredicateKind::Projection(data) => {
let trait_ref = bound_predicate.rebind(data).to_poly_trait_ref(self.tcx); let self_ty = data.projection_ty.self_ty();
let self_ty = trait_ref.skip_binder().self_ty();
let ty = data.ty; let ty = data.ty;
if predicate.references_error() { if predicate.references_error() {
return; return;

View file

@ -6,6 +6,7 @@ use rustc_errors::ErrorReported;
use rustc_infer::traits::{TraitEngine, TraitEngineExt as _, TraitObligation}; use rustc_infer::traits::{TraitEngine, TraitEngineExt as _, TraitObligation};
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::ToPredicate; use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable}; use rustc_middle::ty::{self, Binder, Const, Ty, TypeFoldable};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -633,9 +634,9 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
// only reason we can fail to make progress on // only reason we can fail to make progress on
// trait selection is because we don't have enough // trait selection is because we don't have enough
// information about the types in the trait. // information about the types in the trait.
*stalled_on = trait_ref_infer_vars( *stalled_on = substs_infer_vars(
self.selcx, self.selcx,
trait_obligation.predicate.map_bound(|pred| pred.trait_ref), trait_obligation.predicate.map_bound(|pred| pred.trait_ref.substs),
); );
debug!( debug!(
@ -663,9 +664,9 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
match project::poly_project_and_unify_type(self.selcx, &project_obligation) { match project::poly_project_and_unify_type(self.selcx, &project_obligation) {
Ok(Ok(Some(os))) => ProcessResult::Changed(mk_pending(os)), Ok(Ok(Some(os))) => ProcessResult::Changed(mk_pending(os)),
Ok(Ok(None)) => { Ok(Ok(None)) => {
*stalled_on = trait_ref_infer_vars( *stalled_on = substs_infer_vars(
self.selcx, self.selcx,
project_obligation.predicate.to_poly_trait_ref(tcx), project_obligation.predicate.map_bound(|pred| pred.projection_ty.substs),
); );
ProcessResult::Unchanged ProcessResult::Unchanged
} }
@ -678,16 +679,15 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
} }
} }
/// Returns the set of inference variables contained in a trait ref. /// Returns the set of inference variables contained in `substs`.
fn trait_ref_infer_vars<'a, 'tcx>( fn substs_infer_vars<'a, 'tcx>(
selcx: &mut SelectionContext<'a, 'tcx>, selcx: &mut SelectionContext<'a, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>, substs: ty::Binder<SubstsRef<'tcx>>,
) -> Vec<TyOrConstInferVar<'tcx>> { ) -> Vec<TyOrConstInferVar<'tcx>> {
selcx selcx
.infcx() .infcx()
.resolve_vars_if_possible(trait_ref) .resolve_vars_if_possible(substs)
.skip_binder() .skip_binder() // ok because this check doesn't care about regions
.substs
.iter() .iter()
// FIXME(eddyb) try using `skip_current_subtree` to skip everything that // FIXME(eddyb) try using `skip_current_subtree` to skip everything that
// doesn't contain inference variables, not just the outermost level. // doesn't contain inference variables, not just the outermost level.

View file

@ -292,11 +292,7 @@ fn predicate_references_self(
// //
// This is ALT2 in issue #56288, see that for discussion of the // This is ALT2 in issue #56288, see that for discussion of the
// possible alternatives. // possible alternatives.
if data.projection_ty.trait_ref(tcx).substs[1..].iter().any(has_self_ty) { if data.projection_ty.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
Some(sp)
} else {
None
}
} }
ty::PredicateKind::WellFormed(..) ty::PredicateKind::WellFormed(..)
| ty::PredicateKind::ObjectSafe(..) | ty::PredicateKind::ObjectSafe(..)

View file

@ -741,11 +741,7 @@ fn project_type<'cx, 'tcx>(
return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow)); return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow));
} }
let obligation_trait_ref = &obligation.predicate.trait_ref(selcx.tcx()); if obligation.predicate.references_error() {
debug!(?obligation_trait_ref);
if obligation_trait_ref.references_error() {
return Ok(ProjectedTy::Progress(Progress::error(selcx.tcx()))); return Ok(ProjectedTy::Progress(Progress::error(selcx.tcx())));
} }
@ -754,19 +750,19 @@ fn project_type<'cx, 'tcx>(
// Make sure that the following procedures are kept in order. ParamEnv // Make sure that the following procedures are kept in order. ParamEnv
// needs to be first because it has highest priority, and Select checks // needs to be first because it has highest priority, and Select checks
// the return value of push_candidate which assumes it's ran at last. // the return value of push_candidate which assumes it's ran at last.
assemble_candidates_from_param_env(selcx, obligation, &obligation_trait_ref, &mut candidates); assemble_candidates_from_param_env(selcx, obligation, &mut candidates);
assemble_candidates_from_trait_def(selcx, obligation, &obligation_trait_ref, &mut candidates); assemble_candidates_from_trait_def(selcx, obligation, &mut candidates);
assemble_candidates_from_object_ty(selcx, obligation, &obligation_trait_ref, &mut candidates); assemble_candidates_from_object_ty(selcx, obligation, &mut candidates);
if let ProjectionTyCandidateSet::Single(ProjectionTyCandidate::Object(_)) = candidates { if let ProjectionTyCandidateSet::Single(ProjectionTyCandidate::Object(_)) = candidates {
// Avoid normalization cycle from selection (see // Avoid normalization cycle from selection (see
// `assemble_candidates_from_object_ty`). // `assemble_candidates_from_object_ty`).
// FIXME(lazy_normalization): Lazy normalization should save us from // FIXME(lazy_normalization): Lazy normalization should save us from
// having to do special case this. // having to special case this.
} else { } else {
assemble_candidates_from_impls(selcx, obligation, &obligation_trait_ref, &mut candidates); assemble_candidates_from_impls(selcx, obligation, &mut candidates);
}; };
match candidates { match candidates {
@ -792,14 +788,12 @@ fn project_type<'cx, 'tcx>(
fn assemble_candidates_from_param_env<'cx, 'tcx>( fn assemble_candidates_from_param_env<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>, candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
) { ) {
debug!("assemble_candidates_from_param_env(..)"); debug!("assemble_candidates_from_param_env(..)");
assemble_candidates_from_predicates( assemble_candidates_from_predicates(
selcx, selcx,
obligation, obligation,
obligation_trait_ref,
candidate_set, candidate_set,
ProjectionTyCandidate::ParamEnv, ProjectionTyCandidate::ParamEnv,
obligation.param_env.caller_bounds().iter(), obligation.param_env.caller_bounds().iter(),
@ -820,7 +814,6 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>(
fn assemble_candidates_from_trait_def<'cx, 'tcx>( fn assemble_candidates_from_trait_def<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>, candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
) { ) {
debug!("assemble_candidates_from_trait_def(..)"); debug!("assemble_candidates_from_trait_def(..)");
@ -828,7 +821,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
let tcx = selcx.tcx(); let tcx = selcx.tcx();
// Check whether the self-type is itself a projection. // Check whether the self-type is itself a projection.
// If so, extract what we know from the trait and try to come up with a good answer. // If so, extract what we know from the trait and try to come up with a good answer.
let bounds = match *obligation_trait_ref.self_ty().kind() { let bounds = match *obligation.predicate.self_ty().kind() {
ty::Projection(ref data) => tcx.item_bounds(data.item_def_id).subst(tcx, data.substs), ty::Projection(ref data) => tcx.item_bounds(data.item_def_id).subst(tcx, data.substs),
ty::Opaque(def_id, substs) => tcx.item_bounds(def_id).subst(tcx, substs), ty::Opaque(def_id, substs) => tcx.item_bounds(def_id).subst(tcx, substs),
ty::Infer(ty::TyVar(_)) => { ty::Infer(ty::TyVar(_)) => {
@ -843,7 +836,6 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
assemble_candidates_from_predicates( assemble_candidates_from_predicates(
selcx, selcx,
obligation, obligation,
obligation_trait_ref,
candidate_set, candidate_set,
ProjectionTyCandidate::TraitDef, ProjectionTyCandidate::TraitDef,
bounds.iter(), bounds.iter(),
@ -863,14 +855,13 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
fn assemble_candidates_from_object_ty<'cx, 'tcx>( fn assemble_candidates_from_object_ty<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>, candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
) { ) {
debug!("assemble_candidates_from_object_ty(..)"); debug!("assemble_candidates_from_object_ty(..)");
let tcx = selcx.tcx(); let tcx = selcx.tcx();
let self_ty = obligation_trait_ref.self_ty(); let self_ty = obligation.predicate.self_ty();
let object_ty = selcx.infcx().shallow_resolve(self_ty); let object_ty = selcx.infcx().shallow_resolve(self_ty);
let data = match object_ty.kind() { let data = match object_ty.kind() {
ty::Dynamic(data, ..) => data, ty::Dynamic(data, ..) => data,
@ -890,7 +881,6 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
assemble_candidates_from_predicates( assemble_candidates_from_predicates(
selcx, selcx,
obligation, obligation,
obligation_trait_ref,
candidate_set, candidate_set,
ProjectionTyCandidate::Object, ProjectionTyCandidate::Object,
env_predicates, env_predicates,
@ -901,7 +891,6 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
fn assemble_candidates_from_predicates<'cx, 'tcx>( fn assemble_candidates_from_predicates<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>, candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
ctor: fn(ty::PolyProjectionPredicate<'tcx>) -> ProjectionTyCandidate<'tcx>, ctor: fn(ty::PolyProjectionPredicate<'tcx>) -> ProjectionTyCandidate<'tcx>,
env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>, env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
@ -921,8 +910,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
&& infcx.probe(|_| { && infcx.probe(|_| {
selcx.match_projection_projections( selcx.match_projection_projections(
obligation, obligation,
obligation_trait_ref, data,
&data,
potentially_unnormalized_candidates, potentially_unnormalized_candidates,
) )
}); });
@ -948,14 +936,13 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
fn assemble_candidates_from_impls<'cx, 'tcx>( fn assemble_candidates_from_impls<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>, selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>, candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
) { ) {
debug!("assemble_candidates_from_impls"); debug!("assemble_candidates_from_impls");
// If we are resolving `<T as TraitRef<...>>::Item == Type`, // If we are resolving `<T as TraitRef<...>>::Item == Type`,
// start out by selecting the predicate `T as TraitRef<...>`: // start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(*obligation_trait_ref); let poly_trait_ref = obligation.predicate.trait_ref(selcx.tcx()).to_poly_trait_ref();
let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate()); let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate());
let _ = selcx.infcx().commit_if_ok(|_| { let _ = selcx.infcx().commit_if_ok(|_| {
let impl_source = match selcx.select(&trait_obligation) { let impl_source = match selcx.select(&trait_obligation) {
@ -1410,25 +1397,25 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
poly_cache_entry, poly_cache_entry,
); );
let cache_trait_ref = cache_entry.projection_ty.trait_ref(infcx.tcx); let cache_projection = cache_entry.projection_ty;
let obligation_trait_ref = obligation.predicate.trait_ref(infcx.tcx); let obligation_projection = obligation.predicate;
let mut nested_obligations = Vec::new(); let mut nested_obligations = Vec::new();
let cache_trait_ref = if potentially_unnormalized_candidate { let cache_projection = if potentially_unnormalized_candidate {
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
normalize_with_depth_to( normalize_with_depth_to(
selcx, selcx,
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
cache_trait_ref, cache_projection,
&mut nested_obligations, &mut nested_obligations,
) )
}) })
} else { } else {
cache_trait_ref cache_projection
}; };
match infcx.at(cause, param_env).eq(cache_trait_ref, obligation_trait_ref) { match infcx.at(cause, param_env).eq(cache_projection, obligation_projection) {
Ok(InferOk { value: _, obligations }) => { Ok(InferOk { value: _, obligations }) => {
nested_obligations.extend(obligations); nested_obligations.extend(obligations);
assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations); assoc_ty_own_obligations(selcx, obligation, &mut nested_obligations);

View file

@ -32,6 +32,7 @@ use rustc_errors::ErrorReported;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::Constness; use rustc_hir::Constness;
use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_middle::dep_graph::{DepKind, DepNodeIndex}; use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::fast_reject; use rustc_middle::ty::fast_reject;
@ -1254,32 +1255,33 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
pub(super) fn match_projection_projections( pub(super) fn match_projection_projections(
&mut self, &mut self,
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
obligation_trait_ref: &ty::TraitRef<'tcx>, env_predicate: PolyProjectionPredicate<'tcx>,
data: &PolyProjectionPredicate<'tcx>,
potentially_unnormalized_candidates: bool, potentially_unnormalized_candidates: bool,
) -> bool { ) -> bool {
let mut nested_obligations = Vec::new(); let mut nested_obligations = Vec::new();
let projection_ty = if potentially_unnormalized_candidates { let (infer_predicate, _) = self.infcx.replace_bound_vars_with_fresh_vars(
obligation.cause.span,
LateBoundRegionConversionTime::HigherRankedType,
env_predicate,
);
let infer_projection = if potentially_unnormalized_candidates {
ensure_sufficient_stack(|| { ensure_sufficient_stack(|| {
project::normalize_with_depth_to( project::normalize_with_depth_to(
self, self,
obligation.param_env, obligation.param_env,
obligation.cause.clone(), obligation.cause.clone(),
obligation.recursion_depth + 1, obligation.recursion_depth + 1,
data.map_bound(|data| data.projection_ty), infer_predicate.projection_ty,
&mut nested_obligations, &mut nested_obligations,
) )
}) })
} else { } else {
data.map_bound(|data| data.projection_ty) infer_predicate.projection_ty
}; };
// FIXME(generic_associated_types): Compare the whole projections
let data_poly_trait_ref = projection_ty.map_bound(|proj| proj.trait_ref(self.tcx()));
let obligation_poly_trait_ref = ty::Binder::dummy(*obligation_trait_ref);
self.infcx self.infcx
.at(&obligation.cause, obligation.param_env) .at(&obligation.cause, obligation.param_env)
.sup(obligation_poly_trait_ref, data_poly_trait_ref) .sup(obligation.predicate, infer_projection)
.map_or(false, |InferOk { obligations, value: () }| { .map_or(false, |InferOk { obligations, value: () }| {
self.evaluate_predicates_recursively( self.evaluate_predicates_recursively(
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()), TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),

View file

@ -779,14 +779,11 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>
self, self,
interner: &RustInterner<'tcx>, interner: &RustInterner<'tcx>,
) -> chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>> { ) -> chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>> {
let trait_ref = self.projection_ty.trait_ref(interner.tcx); let (trait_ref, own_substs) = self.projection_ty.trait_ref_and_own_substs(interner.tcx);
chalk_solve::rust_ir::AliasEqBound { chalk_solve::rust_ir::AliasEqBound {
trait_bound: trait_ref.lower_into(interner), trait_bound: trait_ref.lower_into(interner),
associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.item_def_id), associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.item_def_id),
parameters: self.projection_ty.substs[trait_ref.substs.len()..] parameters: own_substs.iter().map(|arg| arg.lower_into(interner)).collect(),
.iter()
.map(|arg| arg.lower_into(interner))
.collect(),
value: self.ty.lower_into(interner), value: self.ty.lower_into(interner),
} }
} }

View file

@ -985,10 +985,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// //
// We want to produce `<B as SuperTrait<i32>>::T == foo`. // We want to produce `<B as SuperTrait<i32>>::T == foo`.
debug!( debug!(?hir_ref_id, ?trait_ref, ?binding, ?bounds, "add_predicates_for_ast_type_binding",);
"add_predicates_for_ast_type_binding(hir_ref_id {:?}, trait_ref {:?}, binding {:?}, bounds {:?}",
hir_ref_id, trait_ref, binding, bounds
);
let tcx = self.tcx(); let tcx = self.tcx();
let candidate = let candidate =
@ -1326,37 +1323,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("regular_traits: {:?}", regular_traits); debug!("regular_traits: {:?}", regular_traits);
debug!("auto_traits: {:?}", auto_traits); debug!("auto_traits: {:?}", auto_traits);
// Transform a `PolyTraitRef` into a `PolyExistentialTraitRef` by
// removing the dummy `Self` type (`trait_object_dummy_self`).
let trait_ref_to_existential = |trait_ref: ty::TraitRef<'tcx>| {
if trait_ref.self_ty() != dummy_self {
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
// which picks up non-supertraits where clauses - but also, the object safety
// completely ignores trait aliases, which could be object safety hazards. We
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
// disabled. (#66420)
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"trait_ref_to_existential called on {:?} with non-dummy Self",
trait_ref,
),
);
}
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
};
// Erase the `dummy_self` (`trait_object_dummy_self`) used above. // Erase the `dummy_self` (`trait_object_dummy_self`) used above.
let existential_trait_refs = let existential_trait_refs = regular_traits.iter().map(|i| {
regular_traits.iter().map(|i| i.trait_ref().map_bound(trait_ref_to_existential)); i.trait_ref().map_bound(|trait_ref: ty::TraitRef<'tcx>| {
if trait_ref.self_ty() != dummy_self {
// FIXME: There appears to be a missing filter on top of `expand_trait_aliases`,
// which picks up non-supertraits where clauses - but also, the object safety
// completely ignores trait aliases, which could be object safety hazards. We
// `delay_span_bug` here to avoid an ICE in stable even when the feature is
// disabled. (#66420)
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!(
"trait_ref_to_existential called on {:?} with non-dummy Self",
trait_ref,
),
);
}
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
})
});
let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| { let existential_projections = bounds.projection_bounds.iter().map(|(bound, _)| {
bound.map_bound(|b| { bound.map_bound(|b| {
let trait_ref = trait_ref_to_existential(b.projection_ty.trait_ref(tcx)); if b.projection_ty.self_ty() != dummy_self {
ty::ExistentialProjection { tcx.sess.delay_span_bug(
ty: b.ty, DUMMY_SP,
item_def_id: b.projection_ty.item_def_id, &format!("trait_ref_to_existential called on {:?} with non-dummy Self", b),
substs: trait_ref.substs, );
} }
ty::ExistentialProjection::erase_self_ty(tcx, b)
}) })
}); });

View file

@ -208,7 +208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}); });
// Even if we can't infer the full signature, we may be able to // Even if we can't infer the full signature, we may be able to
// infer the kind. This can occur if there is a trait-reference // infer the kind. This can occur when we elaborate a predicate
// like `F : Fn<A>`. Note that due to subtyping we could encounter // like `F : Fn<A>`. Note that due to subtyping we could encounter
// many viable options, so pick the most restrictive. // many viable options, so pick the most restrictive.
let expected_kind = self let expected_kind = self
@ -234,11 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("deduce_sig_from_projection({:?})", projection); debug!("deduce_sig_from_projection({:?})", projection);
let trait_ref = projection.to_poly_trait_ref(tcx); let trait_def_id = projection.trait_def_id(tcx);
let is_fn = tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some(); let is_fn = tcx.fn_trait_kind_from_lang_item(trait_def_id).is_some();
let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span); let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span);
let is_gen = gen_trait == trait_ref.def_id(); let is_gen = gen_trait == trait_def_id;
if !is_fn && !is_gen { if !is_fn && !is_gen {
debug!("deduce_sig_from_projection: not fn or generator"); debug!("deduce_sig_from_projection: not fn or generator");
return None; return None;
@ -256,7 +256,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
let input_tys = if is_fn { let input_tys = if is_fn {
let arg_param_ty = trait_ref.skip_binder().substs.type_at(1); let arg_param_ty = projection.skip_binder().projection_ty.substs.type_at(1);
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty); let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty); debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty);
@ -662,9 +662,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}; };
// Check that this is a projection from the `Future` trait. // Check that this is a projection from the `Future` trait.
let trait_ref = predicate.projection_ty.trait_ref(self.tcx); let trait_def_id = predicate.projection_ty.trait_def_id(self.tcx);
let future_trait = self.tcx.require_lang_item(LangItem::Future, Some(cause_span)); let future_trait = self.tcx.require_lang_item(LangItem::Future, Some(cause_span));
if trait_ref.def_id != future_trait { if trait_def_id != future_trait {
debug!("deduce_future_output_from_projection: not a future"); debug!("deduce_future_output_from_projection: not a future");
return None; return None;
} }

View file

@ -769,9 +769,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.filter_map(move |obligation| { .filter_map(move |obligation| {
let bound_predicate = obligation.predicate.kind(); let bound_predicate = obligation.predicate.kind();
match bound_predicate.skip_binder() { match bound_predicate.skip_binder() {
ty::PredicateKind::Projection(data) => { ty::PredicateKind::Projection(data) => Some((
Some((bound_predicate.rebind(data).to_poly_trait_ref(self.tcx), obligation)) bound_predicate.rebind(data).required_poly_trait_ref(self.tcx),
} obligation,
)),
ty::PredicateKind::Trait(data, _) => { ty::PredicateKind::Trait(data, _) => {
Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation)) Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation))
} }

View file

@ -23,6 +23,7 @@ use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_trait_selection::traits::Obligation; use rustc_trait_selection::traits::Obligation;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::iter;
use super::probe::Mode; use super::probe::Mode;
use super::{CandidateSource, MethodError, NoMatchData}; use super::{CandidateSource, MethodError, NoMatchData};
@ -648,21 +649,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::PredicateKind::Projection(pred) => { ty::PredicateKind::Projection(pred) => {
let pred = bound_predicate.rebind(pred); let pred = bound_predicate.rebind(pred);
// `<Foo as Iterator>::Item = String`. // `<Foo as Iterator>::Item = String`.
let trait_ref = let projection_ty = pred.skip_binder().projection_ty;
pred.skip_binder().projection_ty.trait_ref(self.tcx);
let assoc = self let substs_with_infer_self = tcx.mk_substs(
.tcx iter::once(tcx.mk_ty_var(ty::TyVid { index: 0 }).into())
.associated_item(pred.skip_binder().projection_ty.item_def_id); .chain(projection_ty.substs.iter().skip(1)),
let ty = pred.skip_binder().ty;
let obligation = format!("{}::{} = {}", trait_ref, assoc.ident, ty);
let quiet = format!(
"<_ as {}>::{} = {}",
trait_ref.print_only_trait_path(),
assoc.ident,
ty
); );
bound_span_label(trait_ref.self_ty(), &obligation, &quiet);
Some((obligation, trait_ref.self_ty())) let quiet_projection_ty = ty::ProjectionTy {
substs: substs_with_infer_self,
item_def_id: projection_ty.item_def_id,
};
let ty = pred.skip_binder().ty;
let obligation = format!("{} = {}", projection_ty, ty);
let quiet = format!("{} = {}", quiet_projection_ty, ty);
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
Some((obligation, projection_ty.self_ty()))
} }
ty::PredicateKind::Trait(poly_trait_ref, _) => { ty::PredicateKind::Trait(poly_trait_ref, _) => {
let p = poly_trait_ref.trait_ref; let p = poly_trait_ref.trait_ref;

View file

@ -198,7 +198,7 @@ pub fn setup_constraining_predicates<'tcx>(
// `<<T as Bar>::Baz as Iterator>::Output = <U as Iterator>::Output` // `<<T as Bar>::Baz as Iterator>::Output = <U as Iterator>::Output`
// Then the projection only applies if `T` is known, but it still // Then the projection only applies if `T` is known, but it still
// does not determine `U`. // does not determine `U`.
let inputs = parameters_for(&projection.projection_ty.trait_ref(tcx), true); let inputs = parameters_for(&projection.projection_ty, true);
let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(&p)); let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(&p));
if !relies_only_on_inputs { if !relies_only_on_inputs {
continue; continue;

View file

@ -64,6 +64,7 @@ pub trait Deref {
/// The resulting type after dereferencing. /// The resulting type after dereferencing.
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "deref_target"] #[rustc_diagnostic_item = "deref_target"]
#[cfg_attr(not(bootstrap), lang = "deref_target")]
type Target: ?Sized; type Target: ?Sized;
/// Dereferences the value. /// Dereferences the value.

View file

@ -13,4 +13,6 @@ impl X for () {
type Y<T> where Self: Sized = u32; type Y<T> where Self: Sized = u32;
} }
fn f<T: X<Y<()> = i32>>() {}
fn main() { } fn main() { }

View file

@ -0,0 +1,17 @@
// Test that correct syntax is used in suggestion to constrain associated type
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
trait X {
type Y<T>;
}
fn f<T: X>(a: T::Y<i32>) {
//~^ HELP consider constraining the associated type `<T as X>::Y<i32>` to `Vec<i32>`
//~| SUGGESTION Y<i32> = Vec<i32>>
let b: Vec<i32> = a;
//~^ ERROR mismatched types
}
fn main() {}

View file

@ -0,0 +1,27 @@
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/constraint-assoc-type-suggestion.rs:3:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
error[E0308]: mismatched types
--> $DIR/constraint-assoc-type-suggestion.rs:13:23
|
LL | let b: Vec<i32> = a;
| -------- ^ expected struct `Vec`, found associated type
| |
| expected due to this
|
= note: expected struct `Vec<i32>`
found associated type `<T as X>::Y<i32>`
help: consider constraining the associated type `<T as X>::Y<i32>` to `Vec<i32>`
|
LL | fn f<T: X<Y<i32> = Vec<i32>>>(a: T::Y<i32>) {
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0308`.

View file

@ -0,0 +1,35 @@
// run-pass
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
pub trait X {
type Y<'a>;
fn m(&self) -> Self::Y<'_>;
}
impl X for () {
type Y<'a> = &'a ();
fn m(&self) -> Self::Y<'_> {
self
}
}
fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &() {
x.m()
}
fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &() {
x.m()
}
fn h(x: &()) -> &() {
x.m()
}
fn main() {
f(&());
g(&());
h(&());
}

View file

@ -1,11 +1,11 @@
#![feature(generic_associated_types)] #![feature(generic_associated_types)]
//~^ WARNING the feature //~^ WARNING the feature
pub trait SubTrait {} pub trait SubTrait {}
pub trait SuperTrait { pub trait SuperTrait {
type SubType<'a>: SubTrait; type SubType<'a>: SubTrait;
//~^ ERROR missing generics for associated //~^ ERROR missing generics for associated
fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>; fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>;
} }
@ -36,6 +36,4 @@ impl SuperTrait for SuperStruct {
fn main() { fn main() {
let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0)); let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
//~^ ERROR the trait
//~| ERROR the trait
} }

View file

@ -23,41 +23,6 @@ help: use angle brackets to add missing lifetime argument
LL | type SubType<'a><'a>: SubTrait; LL | type SubType<'a><'a>: SubTrait;
| ^^^^ | ^^^^
error[E0038]: the trait `SuperTrait` cannot be made into an object error: aborting due to previous error; 1 warning emitted
--> $DIR/issue-76535.rs:38:14
|
LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
|
= help: consider moving `get_sub` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-76535.rs:10:37
|
LL | pub trait SuperTrait {
| ---------- this trait cannot be made into an object...
...
LL | fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>;
| ^^^^^^^^^^^^^^^^^ ...because method `get_sub` references the `Self` type in its return type
error[E0038]: the trait `SuperTrait` cannot be made into an object For more information about this error, try `rustc --explain E0107`.
--> $DIR/issue-76535.rs:38:57
|
LL | let sub: Box<dyn SuperTrait<SubType = SubStruct>> = Box::new(SuperStruct::new(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
|
= help: consider moving `get_sub` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-76535.rs:10:37
|
LL | pub trait SuperTrait {
| ---------- this trait cannot be made into an object...
...
LL | fn get_sub<'a>(&'a mut self) -> Self::SubType<'a>;
| ^^^^^^^^^^^^^^^^^ ...because method `get_sub` references the `Self` type in its return type
= note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn SuperTrait<SubType = SubStruct<'_>>>>` for `Box<SuperStruct>`
= note: required by cast to type `Box<dyn SuperTrait<SubType = SubStruct<'_>>>`
error: aborting due to 3 previous errors; 1 warning emitted
Some errors have detailed explanations: E0038, E0107.
For more information about an error, try `rustc --explain E0038`.

View file

@ -19,7 +19,7 @@ impl<'a, T> RefCont<'a, T> for Box<T> {
trait MapLike<K, V> { trait MapLike<K, V> {
type VRefCont<'a>: RefCont<'a, V>; type VRefCont<'a>: RefCont<'a, V>;
//~^ ERROR missing generics //~^ ERROR missing generics
fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>; fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
} }
@ -42,6 +42,5 @@ impl<K, V: Default> MapLike<K, V> for Source {
fn main() { fn main() {
let m = Box::new(std::collections::BTreeMap::<u8, u8>::new()) let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>; as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
//~^ ERROR the trait //~^^ ERROR type mismatch resolving
//~^^^ ERROR the trait
} }

View file

@ -14,41 +14,17 @@ help: use angle brackets to add missing lifetime argument
LL | type VRefCont<'a><'a>: RefCont<'a, V>; LL | type VRefCont<'a><'a>: RefCont<'a, V>;
| ^^^^ | ^^^^
error[E0038]: the trait `MapLike` cannot be made into an object error[E0271]: type mismatch resolving `<BTreeMap<u8, u8> as MapLike<u8, u8>>::VRefCont<'static> == (dyn RefCont<'_, u8> + 'static)`
--> $DIR/issue-79422.rs:44:12
|
LL | as Box<dyn MapLike<u8, u8, VRefCont = dyn RefCont<'_, u8>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object
|
= help: consider moving `get` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-79422.rs:23:38
|
LL | trait MapLike<K, V> {
| ------- this trait cannot be made into an object...
...
LL | fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type
error[E0038]: the trait `MapLike` cannot be made into an object
--> $DIR/issue-79422.rs:43:13 --> $DIR/issue-79422.rs:43:13
| |
LL | let m = Box::new(std::collections::BTreeMap::<u8, u8>::new()) LL | let m = Box::new(std::collections::BTreeMap::<u8, u8>::new())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `MapLike` cannot be made into an object | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait object `dyn RefCont`, found reference
| |
= help: consider moving `get` to another trait = note: expected trait object `(dyn RefCont<'_, u8> + 'static)`
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> found reference `&'static u8`
--> $DIR/issue-79422.rs:23:38 = note: required for the cast to the object type `dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>`
|
LL | trait MapLike<K, V> {
| ------- this trait cannot be made into an object...
...
LL | fn get<'a>(&'a self, key: &K) -> Option<Self::VRefCont<'a>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because method `get` references the `Self` type in its return type
= note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>>` for `Box<BTreeMap<u8, u8>>`
= note: required by cast to type `Box<dyn MapLike<u8, u8, VRefCont = (dyn RefCont<'_, u8> + 'static)>>`
error: aborting due to 3 previous errors error: aborting due to 2 previous errors
Some errors have detailed explanations: E0038, E0107. Some errors have detailed explanations: E0107, E0271.
For more information about an error, try `rustc --explain E0038`. For more information about an error, try `rustc --explain E0107`.

View file

@ -0,0 +1,35 @@
// Test that the predicate printed in an unresolved method error prints the
// generics for a generic associated type.
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
//~| NOTE `#[warn(incomplete_features)]` on by default
//~| NOTE see issue #44265
trait X {
type Y<T>;
}
trait M {
fn f(&self) {}
}
impl<T: X<Y<i32> = i32>> M for T {}
struct S;
//~^ NOTE method `f` not found for this
//~| NOTE doesn't satisfy `<S as X>::Y<i32> = i32`
//~| NOTE doesn't satisfy `S: M`
impl X for S {
type Y<T> = bool;
}
fn f(a: S) {
a.f();
//~^ ERROR the method `f` exists for struct `S`, but its trait bounds were not satisfied
//~| NOTE method cannot be called on `S` due to unsatisfied trait bounds
//~| NOTE the following trait bounds were not satisfied:
}
fn main() {}

View file

@ -0,0 +1,29 @@
warning: the feature `generic_associated_types` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/method-unsatified-assoc-type-predicate.rs:4:12
|
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
error[E0599]: the method `f` exists for struct `S`, but its trait bounds were not satisfied
--> $DIR/method-unsatified-assoc-type-predicate.rs:29:7
|
LL | struct S;
| ---------
| |
| method `f` not found for this
| doesn't satisfy `<S as X>::Y<i32> = i32`
| doesn't satisfy `S: M`
...
LL | a.f();
| ^ method cannot be called on `S` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`<S as X>::Y<i32> = i32`
which is required by `S: M`
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0599`.

View file

@ -0,0 +1,36 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
pub trait X {
type Y<'a>;
fn m(&self) -> Self::Y<'_>;
}
impl X for () {
type Y<'a> = &'a ();
fn m(&self) -> Self::Y<'_> {
self
}
}
fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &'static () {
x.m()
//~^ ERROR explicit lifetime required
}
fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &'static () {
x.m()
//~^ ERROR explicit lifetime required
}
fn h(x: &()) -> &'static () {
x.m()
//~^ ERROR explicit lifetime required
}
fn main() {
f(&());
g(&());
h(&());
}

View file

@ -0,0 +1,27 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/projection-type-lifetime-mismatch.rs:18:5
|
LL | fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &'static () {
| ------------------------------- help: add explicit lifetime `'static` to the type of `x`: `&'static impl for<'a> X<Y<'a> = &'a ()>`
LL | x.m()
| ^^^^^ lifetime `'static` required
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/projection-type-lifetime-mismatch.rs:23:5
|
LL | fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &'static () {
| -- help: add explicit lifetime `'static` to the type of `x`: `&'static T`
LL | x.m()
| ^^^^^ lifetime `'static` required
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/projection-type-lifetime-mismatch.rs:28:5
|
LL | fn h(x: &()) -> &'static () {
| --- help: add explicit lifetime `'static` to the type of `x`: `&'static ()`
LL | x.m()
| ^^^^^ lifetime `'static` required
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0621`.

View file

@ -0,0 +1,28 @@
#![allow(incomplete_features)]
#![feature(generic_associated_types)]
pub trait X {
type Y<'a: 'static>;
//~^ WARNING unnecessary lifetime parameter
}
impl X for () {
type Y<'a> = &'a ();
}
struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> {
f: <T as X>::Y<'a>,
//~^ ERROR lifetime bound not satisfied
}
struct C<'a, T: X> {
f: <T as X>::Y<'a>,
//~^ ERROR lifetime bound not satisfied
}
struct D<'a> {
f: <() as X>::Y<'a>,
//~^ ERROR lifetime bound not satisfied
}
fn main() {}

View file

@ -0,0 +1,50 @@
warning: unnecessary lifetime parameter `'a`
--> $DIR/unsatified-item-lifetime-bound.rs:5:12
|
LL | type Y<'a: 'static>;
| ^^^^^^^^^^^
|
= help: you can use the `'static` lifetime directly, in place of `'a`
error[E0478]: lifetime bound not satisfied
--> $DIR/unsatified-item-lifetime-bound.rs:14:8
|
LL | f: <T as X>::Y<'a>,
| ^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 13:10
--> $DIR/unsatified-item-lifetime-bound.rs:13:10
|
LL | struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
error[E0478]: lifetime bound not satisfied
--> $DIR/unsatified-item-lifetime-bound.rs:19:8
|
LL | f: <T as X>::Y<'a>,
| ^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 18:10
--> $DIR/unsatified-item-lifetime-bound.rs:18:10
|
LL | struct C<'a, T: X> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
error[E0478]: lifetime bound not satisfied
--> $DIR/unsatified-item-lifetime-bound.rs:24:8
|
LL | f: <() as X>::Y<'a>,
| ^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 23:10
--> $DIR/unsatified-item-lifetime-bound.rs:23:10
|
LL | struct D<'a> {
| ^^
= note: but lifetime parameter must outlive the static lifetime
error: aborting due to 3 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0478`.