Auto merge of #105657 - oli-obk:mk_projection_ty, r=lcnr
Guard ProjectionTy creation against passing the wrong number of substs r? `@lcnr`
This commit is contained in:
commit
a8847df167
71 changed files with 262 additions and 282 deletions
|
@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
.map_bound(|p| p.predicates),
|
.map_bound(|p| p.predicates),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs))
|
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs))
|
||||||
}
|
}
|
||||||
ty::Closure(_, substs) => match substs.as_closure().kind() {
|
ty::Closure(_, substs) => match substs.as_closure().kind() {
|
||||||
|
|
|
@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
|
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
|
||||||
|
|
||||||
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
|
||||||
output_ty = self.infcx.tcx.type_of(def_id)
|
output_ty = self.infcx.tcx.type_of(def_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let kind = match parent_ty.ty.kind() {
|
let kind = match parent_ty.ty.kind() {
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
|
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
|
||||||
}
|
}
|
||||||
kind => kind,
|
kind => kind,
|
||||||
|
|
|
@ -58,7 +58,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||||
// Types with identity (print the module path).
|
// Types with identity (print the module path).
|
||||||
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
|
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
|
||||||
| ty::FnDef(def_id, substs)
|
| ty::FnDef(def_id, substs)
|
||||||
| ty::Alias(_, ty::AliasTy { def_id, substs })
|
| ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||||
| ty::Closure(def_id, substs)
|
| ty::Closure(def_id, substs)
|
||||||
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
|
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
|
||||||
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
|
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
|
||||||
|
|
|
@ -680,7 +680,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
|
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
|
||||||
|
|
||||||
let poly_trait_ref =
|
let poly_trait_ref =
|
||||||
ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars);
|
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
|
||||||
|
|
||||||
debug!(?poly_trait_ref, ?assoc_bindings);
|
debug!(?poly_trait_ref, ?assoc_bindings);
|
||||||
bounds.trait_bounds.push((poly_trait_ref, span, constness));
|
bounds.trait_bounds.push((poly_trait_ref, span, constness));
|
||||||
|
@ -813,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
if let Some(b) = trait_segment.args().bindings.first() {
|
if let Some(b) = trait_segment.args().bindings.first() {
|
||||||
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
|
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
|
||||||
}
|
}
|
||||||
ty::TraitRef::new(trait_def_id, substs)
|
self.tcx().mk_trait_ref(trait_def_id, substs)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self, span))]
|
#[instrument(level = "debug", skip(self, span))]
|
||||||
|
@ -1146,7 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
|
|
||||||
debug!(?substs_trait_ref_and_assoc_item);
|
debug!(?substs_trait_ref_and_assoc_item);
|
||||||
|
|
||||||
ty::AliasTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item }
|
self.tcx().mk_alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item)
|
||||||
});
|
});
|
||||||
|
|
||||||
if !speculative {
|
if !speculative {
|
||||||
|
|
|
@ -570,7 +570,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
||||||
assoc_item,
|
assoc_item,
|
||||||
assoc_item,
|
assoc_item,
|
||||||
default.span,
|
default.span,
|
||||||
ty::TraitRef { def_id: it.owner_id.to_def_id(), substs: trait_substs },
|
tcx.mk_trait_ref(it.owner_id.to_def_id(), trait_substs),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E
|
||||||
impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector {
|
impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector {
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match *t.kind() {
|
match *t.kind() {
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||||
self.0.push(def);
|
self.0.push(def);
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
}
|
}
|
||||||
|
|
|
@ -1746,10 +1746,7 @@ pub fn check_type_bounds<'tcx>(
|
||||||
_ => predicates.push(
|
_ => predicates.push(
|
||||||
ty::Binder::bind_with_vars(
|
ty::Binder::bind_with_vars(
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy {
|
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_substs),
|
||||||
def_id: trait_ty.def_id,
|
|
||||||
substs: rebased_substs,
|
|
||||||
},
|
|
||||||
term: impl_ty_value.into(),
|
term: impl_ty_value.into(),
|
||||||
},
|
},
|
||||||
bound_vars,
|
bound_vars,
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||||
#[instrument(level = "trace", skip(self), ret)]
|
#[instrument(level = "trace", skip(self), ret)]
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
match t.kind() {
|
match t.kind() {
|
||||||
ty::Alias(_, ty::AliasTy { def_id, substs })
|
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||||
if matches!(
|
if matches!(
|
||||||
self.tcx.def_kind(*def_id),
|
self.tcx.def_kind(*def_id),
|
||||||
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
||||||
|
@ -160,7 +160,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||||
// instead of requiring an additional `+ 'a`.
|
// instead of requiring an additional `+ 'a`.
|
||||||
match pred.kind().skip_binder() {
|
match pred.kind().skip_binder() {
|
||||||
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
|
||||||
trait_ref: ty::TraitRef { def_id: _, substs },
|
trait_ref: ty::TraitRef { def_id: _, substs, .. },
|
||||||
constness: _,
|
constness: _,
|
||||||
polarity: _,
|
polarity: _,
|
||||||
})) => {
|
})) => {
|
||||||
|
@ -169,7 +169,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy { substs, def_id: _ },
|
projection_ty: ty::AliasTy { substs, .. },
|
||||||
term,
|
term,
|
||||||
})) => {
|
})) => {
|
||||||
for subst in &substs[1..] {
|
for subst in &substs[1..] {
|
||||||
|
|
|
@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
let substs = sig.output().walk().find_map(|arg| {
|
let substs = sig.output().walk().find_map(|arg| {
|
||||||
if let ty::GenericArgKind::Type(ty) = arg.unpack()
|
if let ty::GenericArgKind::Type(ty) = arg.unpack()
|
||||||
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind()
|
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *ty.kind()
|
||||||
&& def_id == rpit_def_id
|
&& def_id == rpit_def_id
|
||||||
{
|
{
|
||||||
Some(substs)
|
Some(substs)
|
||||||
|
@ -542,15 +542,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
|
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
|
||||||
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
|
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
|
||||||
ty::PredicateKind::Clause(ty::Clause::Trait(
|
ty::PredicateKind::Clause(ty::Clause::Trait(
|
||||||
trait_pred.with_self_type(self.tcx, ty),
|
trait_pred.with_self_ty(self.tcx, ty),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
|
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
|
||||||
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
|
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
|
||||||
proj_pred.projection_ty.substs = self.tcx.mk_substs_trait(
|
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
|
||||||
ty,
|
|
||||||
proj_pred.projection_ty.substs.iter().skip(1),
|
|
||||||
);
|
|
||||||
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
|
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
expected_ty: Ty<'tcx>,
|
expected_ty: Ty<'tcx>,
|
||||||
) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
|
) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
|
||||||
match *expected_ty.kind() {
|
match *expected_ty.kind() {
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
||||||
.deduce_signature_from_predicates(
|
.deduce_signature_from_predicates(
|
||||||
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
|
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
|
||||||
),
|
),
|
||||||
|
@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
get_future_output(obligation.predicate, obligation.cause.span)
|
get_future_output(obligation.predicate, obligation.cause.span)
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
|
||||||
.tcx
|
.tcx
|
||||||
.bound_explicit_item_bounds(def_id)
|
.bound_explicit_item_bounds(def_id)
|
||||||
.subst_iter_copied(self.tcx, substs)
|
.subst_iter_copied(self.tcx, substs)
|
||||||
|
|
|
@ -1805,7 +1805,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
{
|
{
|
||||||
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty);
|
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty);
|
||||||
// Get the `impl Trait`'s `DefId`.
|
// Get the `impl Trait`'s `DefId`.
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind()
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind()
|
||||||
// Get the `impl Trait`'s `Item` so that we can get its trait bounds and
|
// Get the `impl Trait`'s `Item` so that we can get its trait bounds and
|
||||||
// get the `Trait`'s `DefId`.
|
// get the `Trait`'s `DefId`.
|
||||||
&& let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) =
|
&& let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) =
|
||||||
|
|
|
@ -2391,7 +2391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ty::Param(param_ty) => {
|
ty::Param(param_ty) => {
|
||||||
self.point_at_param_definition(&mut err, param_ty);
|
self.point_at_param_definition(&mut err, param_ty);
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) => {
|
ty::Alias(ty::Opaque, _) => {
|
||||||
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
|
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -716,7 +716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if formal_ret.has_infer_types() {
|
if formal_ret.has_infer_types() {
|
||||||
for ty in ret_ty.walk() {
|
for ty in ret_ty.walk() {
|
||||||
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
|
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
|
||||||
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *ty.kind()
|
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *ty.kind()
|
||||||
&& let Some(def_id) = def_id.as_local()
|
&& let Some(def_id) = def_id.as_local()
|
||||||
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
|
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -2124,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, substs: _ })
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, .. })
|
||||||
| ty::Closure(new_def_id, _)
|
| ty::Closure(new_def_id, _)
|
||||||
| ty::FnDef(new_def_id, _) => {
|
| ty::FnDef(new_def_id, _) => {
|
||||||
def_id = new_def_id;
|
def_id = new_def_id;
|
||||||
|
@ -2132,19 +2132,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
_ => {
|
_ => {
|
||||||
// Look for a user-provided impl of a `Fn` trait, and point to it.
|
// Look for a user-provided impl of a `Fn` trait, and point to it.
|
||||||
let new_def_id = self.probe(|_| {
|
let new_def_id = self.probe(|_| {
|
||||||
let trait_ref = ty::TraitRef::new(
|
let trait_ref = self.tcx.mk_trait_ref(
|
||||||
call_kind.to_def_id(self.tcx),
|
call_kind.to_def_id(self.tcx),
|
||||||
self.tcx.mk_substs(
|
[
|
||||||
[
|
callee_ty,
|
||||||
ty::GenericArg::from(callee_ty),
|
self.next_ty_var(TypeVariableOrigin {
|
||||||
self.next_ty_var(TypeVariableOrigin {
|
kind: TypeVariableOriginKind::MiscVariable,
|
||||||
kind: TypeVariableOriginKind::MiscVariable,
|
span: rustc_span::DUMMY_SP,
|
||||||
span: rustc_span::DUMMY_SP,
|
}),
|
||||||
})
|
],
|
||||||
.into(),
|
|
||||||
]
|
|
||||||
.into_iter(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let obligation = traits::Obligation::new(
|
let obligation = traits::Obligation::new(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use rustc_hir_analysis::astconv::AstConv;
|
||||||
use rustc_infer::infer;
|
use rustc_infer::infer;
|
||||||
use rustc_infer::traits::{self, StatementAsExpression};
|
use rustc_infer::traits::{self, StatementAsExpression};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty};
|
use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, Ty};
|
||||||
use rustc_session::errors::ExprParenthesesNeeded;
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let fn_sig = substs.as_closure().sig();
|
let fn_sig = substs.as_closure().sig();
|
||||||
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
|
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||||
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
||||||
|
@ -1277,17 +1277,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Check that we're in fact trying to clone into the expected type
|
// Check that we're in fact trying to clone into the expected type
|
||||||
&& self.can_coerce(*pointee_ty, expected_ty)
|
&& self.can_coerce(*pointee_ty, expected_ty)
|
||||||
// And the expected type doesn't implement `Clone`
|
// And the expected type doesn't implement `Clone`
|
||||||
&& !self.predicate_must_hold_considering_regions(&traits::Obligation {
|
&& !self.predicate_must_hold_considering_regions(&traits::Obligation::new(
|
||||||
cause: traits::ObligationCause::dummy(),
|
self.tcx,
|
||||||
param_env: self.param_env,
|
traits::ObligationCause::dummy(),
|
||||||
recursion_depth: 0,
|
self.param_env,
|
||||||
predicate: ty::Binder::dummy(ty::TraitRef {
|
ty::Binder::dummy(self.tcx.mk_trait_ref(
|
||||||
def_id: clone_trait_did,
|
clone_trait_did,
|
||||||
substs: self.tcx.mk_substs([expected_ty.into()].iter()),
|
[expected_ty],
|
||||||
})
|
)),
|
||||||
.without_const()
|
))
|
||||||
.to_predicate(self.tcx),
|
|
||||||
})
|
|
||||||
{
|
{
|
||||||
diag.span_note(
|
diag.span_note(
|
||||||
callee_expr.span,
|
callee_expr.span,
|
||||||
|
|
|
@ -563,7 +563,7 @@ fn check_must_not_suspend_ty<'tcx>(
|
||||||
}
|
}
|
||||||
ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data),
|
ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data),
|
||||||
// FIXME: support adding the attribute to TAITs
|
// FIXME: support adding the attribute to TAITs
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||||
let mut has_emitted = false;
|
let mut has_emitted = false;
|
||||||
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
|
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
|
||||||
// We only look at the `DefId`, so it is safe to skip the binder here.
|
// We only look at the `DefId`, so it is safe to skip the binder here.
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.var_for_def(span, param)
|
self.var_for_def(span, param)
|
||||||
});
|
});
|
||||||
|
|
||||||
let trait_ref = ty::TraitRef::new(trait_def_id, substs);
|
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
|
||||||
|
|
||||||
// Construct an obligation
|
// Construct an obligation
|
||||||
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
||||||
|
@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.var_for_def(span, param)
|
self.var_for_def(span, param)
|
||||||
});
|
});
|
||||||
|
|
||||||
let trait_ref = ty::TraitRef::new(trait_def_id, substs);
|
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs);
|
||||||
|
|
||||||
// Construct an obligation
|
// Construct an obligation
|
||||||
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
let poly_trait_ref = ty::Binder::dummy(trait_ref);
|
||||||
|
|
|
@ -920,7 +920,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||||
) {
|
) {
|
||||||
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
|
debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id);
|
||||||
let trait_substs = self.fresh_item_substs(trait_def_id);
|
let trait_substs = self.fresh_item_substs(trait_def_id);
|
||||||
let trait_ref = ty::TraitRef::new(trait_def_id, trait_substs);
|
let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs);
|
||||||
|
|
||||||
if self.tcx.is_trait_alias(trait_def_id) {
|
if self.tcx.is_trait_alias(trait_def_id) {
|
||||||
// For trait aliases, assume all supertraits are relevant.
|
// For trait aliases, assume all supertraits are relevant.
|
||||||
|
|
|
@ -557,10 +557,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
.chain(projection_ty.substs.iter().skip(1)),
|
.chain(projection_ty.substs.iter().skip(1)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let quiet_projection_ty = ty::AliasTy {
|
let quiet_projection_ty =
|
||||||
substs: substs_with_infer_self,
|
tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self);
|
||||||
def_id: projection_ty.def_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
let term = pred.skip_binder().term;
|
let term = pred.skip_binder().term;
|
||||||
|
|
||||||
|
|
|
@ -546,7 +546,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
||||||
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
|
||||||
type BreakTy = ();
|
type BreakTy = ();
|
||||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *t.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *t.kind() {
|
||||||
if def_id == self.def_id.to_def_id() {
|
if def_id == self.def_id.to_def_id() {
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
||||||
// relatable.
|
// relatable.
|
||||||
Ok(t)
|
Ok(t)
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
let s = self.relate(substs, substs)?;
|
let s = self.relate(substs, substs)?;
|
||||||
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
|
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,13 +101,13 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
|
||||||
) if a_def_id == b_def_id => {
|
) if a_def_id == b_def_id => {
|
||||||
self.fields.infcx.super_combine_tys(self, a, b)?;
|
self.fields.infcx.super_combine_tys(self, a, b)?;
|
||||||
}
|
}
|
||||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
||||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
||||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||||
{
|
{
|
||||||
self.fields.obligations.extend(
|
self.fields.obligations.extend(
|
||||||
|
|
|
@ -339,7 +339,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
||||||
impl<'tcx> InferCtxt<'tcx> {
|
impl<'tcx> InferCtxt<'tcx> {
|
||||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||||
let (def_id, substs) = match *ty.kind() {
|
let (def_id, substs) = match *ty.kind() {
|
||||||
ty::Alias(_, ty::AliasTy { def_id, substs })
|
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||||
if matches!(
|
if matches!(
|
||||||
self.tcx.def_kind(def_id),
|
self.tcx.def_kind(def_id),
|
||||||
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
|
||||||
|
@ -2767,9 +2767,7 @@ impl TyCategory {
|
||||||
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
|
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
|
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => Some((Self::Opaque, def_id)),
|
||||||
Some((Self::Opaque, def_id))
|
|
||||||
}
|
|
||||||
ty::Generator(def_id, ..) => {
|
ty::Generator(def_id, ..) => {
|
||||||
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
|
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,13 +226,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef {
|
let expected_trait_ref = self
|
||||||
def_id: trait_def_id,
|
|
||||||
substs: expected_substs,
|
|
||||||
});
|
|
||||||
let actual_trait_ref = self
|
|
||||||
.cx
|
.cx
|
||||||
.resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs });
|
.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, expected_substs));
|
||||||
|
let actual_trait_ref =
|
||||||
|
self.cx.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, actual_substs));
|
||||||
|
|
||||||
// Search the expected and actual trait references to see (a)
|
// Search the expected and actual trait references to see (a)
|
||||||
// whether the sub/sup placeholders appear in them (sometimes
|
// whether the sub/sup placeholders appear in them (sometimes
|
||||||
|
|
|
@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
StatementAsExpression::CorrectType
|
StatementAsExpression::CorrectType
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: _ }),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, .. }),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: _ }),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, .. }),
|
||||||
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
|
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
|
||||||
(
|
(
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds, .. }),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds, .. }),
|
||||||
) => {
|
) => {
|
||||||
debug!(
|
debug!(
|
||||||
"both opaque, likely future {:?} {:?} {:?} {:?}",
|
"both opaque, likely future {:?} {:?} {:?} {:?}",
|
||||||
|
|
|
@ -106,11 +106,11 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
|
||||||
) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b),
|
) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b),
|
||||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
||||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
||||||
if this.define_opaque_types() && def_id.is_local() =>
|
if this.define_opaque_types() && def_id.is_local() =>
|
||||||
{
|
{
|
||||||
this.add_obligations(
|
this.add_obligations(
|
||||||
|
|
|
@ -611,8 +611,8 @@ where
|
||||||
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
|
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
|
||||||
|
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
|
||||||
) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| {
|
) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| {
|
||||||
self.tcx().sess.delay_span_bug(
|
self.tcx().sess.delay_span_bug(
|
||||||
self.delegate.span(),
|
self.delegate.span(),
|
||||||
|
@ -620,8 +620,8 @@ where
|
||||||
);
|
);
|
||||||
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
|
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
|
||||||
}),
|
}),
|
||||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
||||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
||||||
if def_id.is_local() =>
|
if def_id.is_local() =>
|
||||||
{
|
{
|
||||||
self.relate_opaques(a, b)
|
self.relate_opaques(a, b)
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
ct_op: |ct| ct,
|
ct_op: |ct| ct,
|
||||||
ty_op: |ty| match *ty.kind() {
|
ty_op: |ty| match *ty.kind() {
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })
|
||||||
if replace_opaque_type(def_id) =>
|
if replace_opaque_type(def_id) =>
|
||||||
{
|
{
|
||||||
let def_span = self.tcx.def_span(def_id);
|
let def_span = self.tcx.def_span(def_id);
|
||||||
|
@ -106,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
||||||
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
|
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) if def_id.is_local() => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) if def_id.is_local() => {
|
||||||
let def_id = def_id.expect_local();
|
let def_id = def_id.expect_local();
|
||||||
let origin = match self.defining_use_anchor {
|
let origin = match self.defining_use_anchor {
|
||||||
DefiningAnchor::Bind(_) => {
|
DefiningAnchor::Bind(_) => {
|
||||||
|
@ -149,9 +149,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
|
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
|
||||||
DefiningAnchor::Error => return None,
|
DefiningAnchor::Error => return None,
|
||||||
};
|
};
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }) =
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
|
||||||
*b.kind()
|
|
||||||
{
|
|
||||||
// We could accept this, but there are various ways to handle this situation, and we don't
|
// We could accept this, but there are various ways to handle this situation, and we don't
|
||||||
// want to make a decision on it right now. Likely this case is so super rare anyway, that
|
// want to make a decision on it right now. Likely this case is so super rare anyway, that
|
||||||
// no one encounters it in practice.
|
// no one encounters it in practice.
|
||||||
|
@ -480,7 +478,7 @@ where
|
||||||
substs.as_generator().resume_ty().visit_with(self);
|
substs.as_generator().resume_ty().visit_with(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs, .. }) => {
|
||||||
// Skip lifetime paramters that are not captures.
|
// Skip lifetime paramters that are not captures.
|
||||||
let variances = self.tcx.variances_of(*def_id);
|
let variances = self.tcx.variances_of(*def_id);
|
||||||
|
|
||||||
|
@ -583,17 +581,16 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
// Replace all other mentions of the same opaque type with the hidden type,
|
// Replace all other mentions of the same opaque type with the hidden type,
|
||||||
// as the bounds must hold on the hidden type after all.
|
// as the bounds must hold on the hidden type after all.
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2 })
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2, .. })
|
||||||
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
||||||
{
|
{
|
||||||
hidden_ty
|
hidden_ty
|
||||||
}
|
}
|
||||||
// FIXME(RPITIT): This can go away when we move to associated types
|
// FIXME(RPITIT): This can go away when we move to associated types
|
||||||
ty::Alias(ty::Projection, ty::AliasTy { def_id: def_id2, substs: substs2 })
|
ty::Alias(
|
||||||
if def_id.to_def_id() == def_id2 && substs == substs2 =>
|
ty::Projection,
|
||||||
{
|
ty::AliasTy { def_id: def_id2, substs: substs2, .. },
|
||||||
hidden_ty
|
) if def_id.to_def_id() == def_id2 && substs == substs2 => hidden_ty,
|
||||||
}
|
|
||||||
_ => ty,
|
_ => ty,
|
||||||
},
|
},
|
||||||
lt_op: |lt| lt,
|
lt_op: |lt| lt,
|
||||||
|
|
|
@ -130,7 +130,7 @@ fn compute_components<'tcx>(
|
||||||
// outlives any other lifetime, which is unsound.
|
// outlives any other lifetime, which is unsound.
|
||||||
// See https://github.com/rust-lang/rust/issues/84305 for
|
// See https://github.com/rust-lang/rust/issues/84305 for
|
||||||
// more details.
|
// more details.
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
out.push(Component::Opaque(def_id, substs));
|
out.push(Component::Opaque(def_id, substs));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ where
|
||||||
substs,
|
substs,
|
||||||
true,
|
true,
|
||||||
|ty| match *ty.kind() {
|
|ty| match *ty.kind() {
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => (def_id, substs),
|
||||||
_ => bug!("expected only projection types from env, not {:?}", ty),
|
_ => bug!("expected only projection types from env, not {:?}", ty),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
|
||||||
) if a_def_id == b_def_id => {
|
) if a_def_id == b_def_id => {
|
||||||
self.fields.infcx.super_combine_tys(self, a, b)?;
|
self.fields.infcx.super_combine_tys(self, a, b)?;
|
||||||
Ok(a)
|
Ok(a)
|
||||||
}
|
}
|
||||||
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
|
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
|
||||||
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
|
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
|
||||||
if self.fields.define_opaque_types && def_id.is_local() =>
|
if self.fields.define_opaque_types && def_id.is_local() =>
|
||||||
{
|
{
|
||||||
self.fields.obligations.extend(
|
self.fields.obligations.extend(
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ impl<'tcx> LateContext<'tcx> {
|
||||||
tcx.associated_items(trait_id)
|
tcx.associated_items(trait_id)
|
||||||
.find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
|
.find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
|
||||||
.and_then(|assoc| {
|
.and_then(|assoc| {
|
||||||
let proj = tcx.mk_projection(assoc.def_id, tcx.mk_substs_trait(self_ty, []));
|
let proj = tcx.mk_projection(assoc.def_id, [self_ty]);
|
||||||
tcx.try_normalize_erasing_regions(self.param_env, proj).ok()
|
tcx.try_normalize_erasing_regions(self.param_env, proj).ok()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
||||||
// then we can emit a suggestion to add the bound.
|
// then we can emit a suggestion to add the bound.
|
||||||
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
|
||||||
(
|
(
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }),
|
||||||
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
|
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
|
||||||
) => Some(AddBound {
|
) => Some(AddBound {
|
||||||
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||||
|
|
||||||
if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
|
if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
|
||||||
&& let ty = cx.typeck_results().expr_ty(&await_expr)
|
&& let ty = cx.typeck_results().expr_ty(&await_expr)
|
||||||
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind()
|
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind()
|
||||||
&& cx.tcx.ty_is_opaque_future(ty)
|
&& cx.tcx.ty_is_opaque_future(ty)
|
||||||
// FIXME: This also includes non-async fns that return `impl Future`.
|
// FIXME: This also includes non-async fns that return `impl Future`.
|
||||||
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
|
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
|
||||||
|
@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
||||||
.map(|inner| MustUsePath::Boxed(Box::new(inner)))
|
.map(|inner| MustUsePath::Boxed(Box::new(inner)))
|
||||||
}
|
}
|
||||||
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
|
||||||
elaborate_predicates_with_span(
|
elaborate_predicates_with_span(
|
||||||
cx.tcx,
|
cx.tcx,
|
||||||
cx.tcx.explicit_item_bounds(def).iter().cloned(),
|
cx.tcx.explicit_item_bounds(def).iter().cloned(),
|
||||||
|
|
|
@ -1847,7 +1847,7 @@ impl<'tcx> Operand<'tcx> {
|
||||||
pub fn function_handle(
|
pub fn function_handle(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
substs: SubstsRef<'tcx>,
|
substs: impl IntoIterator<Item = GenericArg<'tcx>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let ty = tcx.mk_fn_def(def_id, substs);
|
let ty = tcx.mk_fn_def(def_id, substs);
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
|
||||||
.find(|m| m.kind == ty::AssocKind::Fn)
|
.find(|m| m.kind == ty::AssocKind::Fn)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.def_id;
|
.def_id;
|
||||||
tcx.mk_fn_def(method_def_id, tcx.mk_substs_trait(source, []))
|
tcx.mk_fn_def(method_def_id, [source])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::thir::Thir;
|
||||||
use crate::traits;
|
use crate::traits;
|
||||||
use crate::ty::query::{self, TyCtxtAt};
|
use crate::ty::query::{self, TyCtxtAt};
|
||||||
use crate::ty::{
|
use crate::ty::{
|
||||||
self, AdtDef, AdtDefData, AdtKind, AliasTy, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
|
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
|
||||||
ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid,
|
ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid,
|
||||||
GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
|
GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy,
|
||||||
PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions,
|
PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions,
|
||||||
|
@ -2321,7 +2321,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
/// Given a `ty`, return whether it's an `impl Future<...>`.
|
/// Given a `ty`, return whether it's an `impl Future<...>`.
|
||||||
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
|
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
|
||||||
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false };
|
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
|
||||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||||
|
|
||||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
||||||
|
@ -2565,15 +2565,35 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
pub fn mk_fn_def(
|
||||||
debug_assert_eq!(
|
self,
|
||||||
self.generics_of(def_id).count(),
|
def_id: DefId,
|
||||||
substs.len(),
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
"wrong number of generic parameters for {def_id:?}: {substs:?}",
|
) -> Ty<'tcx> {
|
||||||
);
|
let substs = self.check_substs(def_id, substs);
|
||||||
self.mk_ty(FnDef(def_id, substs))
|
self.mk_ty(FnDef(def_id, substs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn check_substs(
|
||||||
|
self,
|
||||||
|
_def_id: DefId,
|
||||||
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
|
) -> SubstsRef<'tcx> {
|
||||||
|
let substs = substs.into_iter().map(Into::into);
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
{
|
||||||
|
let n = self.generics_of(_def_id).count();
|
||||||
|
assert_eq!(
|
||||||
|
(n, Some(n)),
|
||||||
|
substs.size_hint(),
|
||||||
|
"wrong number of generic parameters for {_def_id:?}: {:?}",
|
||||||
|
substs.collect::<Vec<_>>(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self.mk_substs(substs)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
|
||||||
self.mk_ty(FnPtr(fty))
|
self.mk_ty(FnPtr(fty))
|
||||||
|
@ -2590,13 +2610,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
pub fn mk_projection(
|
||||||
debug_assert_eq!(
|
self,
|
||||||
self.generics_of(item_def_id).count(),
|
item_def_id: DefId,
|
||||||
substs.len(),
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
"wrong number of generic parameters for {item_def_id:?}: {substs:?}",
|
) -> Ty<'tcx> {
|
||||||
);
|
self.mk_ty(Alias(ty::Projection, self.mk_alias_ty(item_def_id, substs)))
|
||||||
self.mk_ty(Alias(ty::Projection, AliasTy { def_id: item_def_id, substs }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2666,7 +2685,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||||
self.mk_ty(Alias(ty::Opaque, ty::AliasTy { def_id, substs }))
|
self.mk_ty(Alias(ty::Opaque, self.mk_alias_ty(def_id, substs)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||||
|
@ -2855,16 +2874,17 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
) -> ty::TraitRef<'tcx> {
|
) -> ty::TraitRef<'tcx> {
|
||||||
let substs = substs.into_iter().map(Into::into);
|
let substs = self.check_substs(trait_def_id, substs);
|
||||||
let n = self.generics_of(trait_def_id).count();
|
ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
|
||||||
debug_assert_eq!(
|
}
|
||||||
(n, Some(n)),
|
|
||||||
substs.size_hint(),
|
pub fn mk_alias_ty(
|
||||||
"wrong number of generic parameters for {trait_def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?",
|
self,
|
||||||
substs.collect::<Vec<_>>(),
|
def_id: DefId,
|
||||||
);
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
let substs = self.mk_substs(substs);
|
) -> ty::AliasTy<'tcx> {
|
||||||
ty::TraitRef::new(trait_def_id, substs)
|
let substs = self.check_substs(def_id, substs);
|
||||||
|
ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_bound_variable_kinds<
|
pub fn mk_bound_variable_kinds<
|
||||||
|
|
|
@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
||||||
return ControlFlow::Break(());
|
return ControlFlow::Break(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Alias(Opaque, AliasTy { def_id, substs: _ }) => {
|
Alias(Opaque, AliasTy { def_id, .. }) => {
|
||||||
let parent = self.tcx.parent(*def_id);
|
let parent = self.tcx.parent(*def_id);
|
||||||
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||||
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind()
|
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = self.tcx.type_of(parent).kind()
|
||||||
&& parent_opaque_def_id == def_id
|
&& parent_opaque_def_id == def_id
|
||||||
{
|
{
|
||||||
// Okay
|
// Okay
|
||||||
|
|
|
@ -779,8 +779,7 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let assoc = self.associated_item(proj_ty.def_id);
|
let assoc = self.associated_item(proj_ty.def_id);
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind()
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() {
|
||||||
{
|
|
||||||
let opaque_local_def_id = def_id.as_local();
|
let opaque_local_def_id = def_id.as_local();
|
||||||
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
|
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
|
||||||
match &self.hir().expect_item(opaque_local_def_id).kind {
|
match &self.hir().expect_item(opaque_local_def_id).kind {
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl FlagComputation {
|
||||||
self.add_projection_ty(data);
|
self.add_projection_ty(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => {
|
&ty::Alias(ty::Opaque, ty::AliasTy { substs, .. }) => {
|
||||||
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
|
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
|
||||||
self.add_substs(substs);
|
self.add_substs(substs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,8 +781,8 @@ impl<'tcx> TraitPredicate<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||||
Self { trait_ref: self.trait_ref.with_self_type(tcx, self_ty), ..self }
|
Self { trait_ref: self.trait_ref.with_self_ty(tcx, self_ty), ..self }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn def_id(self) -> DefId {
|
pub fn def_id(self) -> DefId {
|
||||||
|
@ -1050,6 +1050,18 @@ impl<'tcx> PolyProjectionPredicate<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> ProjectionPredicate<'tcx> {
|
||||||
|
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||||
|
Self {
|
||||||
|
projection_ty: tcx.mk_alias_ty(
|
||||||
|
self.projection_ty.def_id,
|
||||||
|
[self_ty.into()].into_iter().chain(self.projection_ty.substs.iter().skip(1)),
|
||||||
|
),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ToPolyTraitRef<'tcx> {
|
pub trait ToPolyTraitRef<'tcx> {
|
||||||
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
|
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,10 +169,8 @@ pub trait Printer<'tcx>: Sized {
|
||||||
self.path_append(
|
self.path_append(
|
||||||
|cx: Self| {
|
|cx: Self| {
|
||||||
if trait_qualify_parent {
|
if trait_qualify_parent {
|
||||||
let trait_ref = ty::TraitRef::new(
|
let trait_ref =
|
||||||
parent_def_id,
|
cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied());
|
||||||
cx.tcx().intern_substs(parent_substs),
|
|
||||||
);
|
|
||||||
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
|
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
|
||||||
} else {
|
} else {
|
||||||
cx.print_def_path(parent_def_id, parent_substs)
|
cx.print_def_path(parent_def_id, parent_substs)
|
||||||
|
|
|
@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
|
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
// FIXME(eddyb) print this with `print_def_path`.
|
// FIXME(eddyb) print this with `print_def_path`.
|
||||||
// We use verbose printing in 'NO_QUERIES' mode, to
|
// We use verbose printing in 'NO_QUERIES' mode, to
|
||||||
// avoid needing to call `predicates_of`. This should
|
// avoid needing to call `predicates_of`. This should
|
||||||
|
@ -743,7 +743,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
let parent = self.tcx().parent(def_id);
|
let parent = self.tcx().parent(def_id);
|
||||||
match self.tcx().def_kind(parent) {
|
match self.tcx().def_kind(parent) {
|
||||||
DefKind::TyAlias | DefKind::AssocTy => {
|
DefKind::TyAlias | DefKind::AssocTy => {
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, substs: _ }) =
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
|
||||||
*self.tcx().type_of(parent).kind()
|
*self.tcx().type_of(parent).kind()
|
||||||
{
|
{
|
||||||
if d == def_id {
|
if d == def_id {
|
||||||
|
|
|
@ -280,7 +280,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
|
||||||
Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id)))
|
Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id)))
|
||||||
} else {
|
} else {
|
||||||
let substs = relation.relate(a.substs, b.substs)?;
|
let substs = relation.relate(a.substs, b.substs)?;
|
||||||
Ok(ty::AliasTy { def_id: a.def_id, substs: &substs })
|
Ok(relation.tcx().mk_alias_ty(a.def_id, substs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
|
||||||
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
|
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
|
||||||
} else {
|
} else {
|
||||||
let substs = relate_substs(relation, a.substs, b.substs)?;
|
let substs = relate_substs(relation, a.substs, b.substs)?;
|
||||||
Ok(ty::TraitRef { def_id: a.def_id, substs })
|
Ok(relation.tcx().mk_trait_ref(a.def_id, substs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,8 +557,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
|
||||||
) if a_def_id == b_def_id => {
|
) if a_def_id == b_def_id => {
|
||||||
if relation.intercrate() {
|
if relation.intercrate() {
|
||||||
// During coherence, opaque types should be treated as equal to each other, even if their generic params
|
// During coherence, opaque types should be treated as equal to each other, even if their generic params
|
||||||
|
|
|
@ -816,14 +816,13 @@ impl<'tcx> List<ty::PolyExistentialPredicate<'tcx>> {
|
||||||
pub struct TraitRef<'tcx> {
|
pub struct TraitRef<'tcx> {
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
pub substs: SubstsRef<'tcx>,
|
pub substs: SubstsRef<'tcx>,
|
||||||
|
/// This field exists to prevent the creation of `TraitRef` without
|
||||||
|
/// calling [TyCtxt::mk_trait_ref].
|
||||||
|
pub(super) _use_mk_trait_ref_instead: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TraitRef<'tcx> {
|
impl<'tcx> TraitRef<'tcx> {
|
||||||
pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> {
|
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||||
TraitRef { def_id, substs }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
|
||||||
tcx.mk_trait_ref(
|
tcx.mk_trait_ref(
|
||||||
self.def_id,
|
self.def_id,
|
||||||
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
|
[self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
|
||||||
|
@ -833,10 +832,7 @@ impl<'tcx> TraitRef<'tcx> {
|
||||||
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
|
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
|
||||||
/// are the parameters defined on trait.
|
/// are the parameters defined on trait.
|
||||||
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
|
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> {
|
||||||
ty::Binder::dummy(TraitRef {
|
ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id)))
|
||||||
def_id,
|
|
||||||
substs: InternalSubsts::identity_for_item(tcx, def_id),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -850,7 +846,7 @@ impl<'tcx> TraitRef<'tcx> {
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
) -> ty::TraitRef<'tcx> {
|
) -> ty::TraitRef<'tcx> {
|
||||||
let defs = tcx.generics_of(trait_id);
|
let defs = tcx.generics_of(trait_id);
|
||||||
ty::TraitRef { def_id: trait_id, substs: tcx.intern_substs(&substs[..defs.params.len()]) }
|
tcx.mk_trait_ref(trait_id, tcx.intern_substs(&substs[..defs.params.len()]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1166,6 +1162,10 @@ pub struct AliasTy<'tcx> {
|
||||||
/// `TraitRef` containing this associated type, which is in `tcx.associated_item(def_id).container`,
|
/// `TraitRef` containing this associated type, which is in `tcx.associated_item(def_id).container`,
|
||||||
/// aka. `tcx.parent(def_id)`.
|
/// aka. `tcx.parent(def_id)`.
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
|
|
||||||
|
/// This field exists to prevent the creation of `ProjectionTy` without using
|
||||||
|
/// [TyCtxt::mk_alias_ty].
|
||||||
|
pub(super) _use_mk_alias_ty_instead: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> AliasTy<'tcx> {
|
impl<'tcx> AliasTy<'tcx> {
|
||||||
|
@ -1190,10 +1190,7 @@ impl<'tcx> AliasTy<'tcx> {
|
||||||
let trait_def_id = self.trait_def_id(tcx);
|
let trait_def_id = self.trait_def_id(tcx);
|
||||||
let trait_generics = tcx.generics_of(trait_def_id);
|
let trait_generics = tcx.generics_of(trait_def_id);
|
||||||
(
|
(
|
||||||
ty::TraitRef {
|
tcx.mk_trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
|
||||||
def_id: trait_def_id,
|
|
||||||
substs: self.substs.truncate_to(tcx, trait_generics),
|
|
||||||
},
|
|
||||||
&self.substs[trait_generics.count()..],
|
&self.substs[trait_generics.count()..],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1207,7 +1204,7 @@ impl<'tcx> AliasTy<'tcx> {
|
||||||
/// as well.
|
/// as well.
|
||||||
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
|
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
|
||||||
let def_id = self.trait_def_id(tcx);
|
let def_id = self.trait_def_id(tcx);
|
||||||
ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) }
|
tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn self_ty(&self) -> Ty<'tcx> {
|
pub fn self_ty(&self) -> Ty<'tcx> {
|
||||||
|
@ -1449,10 +1446,8 @@ impl<'tcx> ExistentialProjection<'tcx> {
|
||||||
debug_assert!(!self_ty.has_escaping_bound_vars());
|
debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy {
|
projection_ty: tcx
|
||||||
def_id: self.def_id,
|
.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)),
|
||||||
substs: tcx.mk_substs_trait(self_ty, self.substs),
|
|
||||||
},
|
|
||||||
term: self.term,
|
term: self.term,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -825,7 +825,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *t.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *t.kind() {
|
||||||
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
|
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
|
||||||
} else if t.has_opaque_types() {
|
} else if t.has_opaque_types() {
|
||||||
t.super_fold_with(self)
|
t.super_fold_with(self)
|
||||||
|
|
|
@ -142,7 +142,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
let exchange_malloc = Operand::function_handle(
|
let exchange_malloc = Operand::function_handle(
|
||||||
tcx,
|
tcx,
|
||||||
tcx.require_lang_item(LangItem::ExchangeMalloc, Some(expr_span)),
|
tcx.require_lang_item(LangItem::ExchangeMalloc, Some(expr_span)),
|
||||||
ty::List::empty(),
|
[],
|
||||||
expr_span,
|
expr_span,
|
||||||
);
|
);
|
||||||
let storage = this.temp(tcx.mk_mut_ptr(tcx.types.u8), expr_span);
|
let storage = this.temp(tcx.mk_mut_ptr(tcx.types.u8), expr_span);
|
||||||
|
|
|
@ -838,8 +838,6 @@ fn trait_method<'tcx>(
|
||||||
method_name: Symbol,
|
method_name: Symbol,
|
||||||
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||||
) -> ConstantKind<'tcx> {
|
) -> ConstantKind<'tcx> {
|
||||||
let substs = tcx.mk_substs(substs.into_iter().map(Into::into));
|
|
||||||
|
|
||||||
// The unhygienic comparison here is acceptable because this is only
|
// The unhygienic comparison here is acceptable because this is only
|
||||||
// used on known traits.
|
// used on known traits.
|
||||||
let item = tcx
|
let item = tcx
|
||||||
|
|
|
@ -614,7 +614,6 @@ where
|
||||||
let drop_trait = tcx.require_lang_item(LangItem::Drop, None);
|
let drop_trait = tcx.require_lang_item(LangItem::Drop, None);
|
||||||
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
|
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
|
||||||
let ty = self.place_ty(self.place);
|
let ty = self.place_ty(self.place);
|
||||||
let substs = tcx.mk_substs_trait(ty, []);
|
|
||||||
|
|
||||||
let ref_ty =
|
let ref_ty =
|
||||||
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut });
|
tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut });
|
||||||
|
@ -632,7 +631,12 @@ where
|
||||||
)],
|
)],
|
||||||
terminator: Some(Terminator {
|
terminator: Some(Terminator {
|
||||||
kind: TerminatorKind::Call {
|
kind: TerminatorKind::Call {
|
||||||
func: Operand::function_handle(tcx, drop_fn, substs, self.source_info.span),
|
func: Operand::function_handle(
|
||||||
|
tcx,
|
||||||
|
drop_fn,
|
||||||
|
[ty.into()],
|
||||||
|
self.source_info.span,
|
||||||
|
),
|
||||||
args: vec![Operand::Move(Place::from(ref_place))],
|
args: vec![Operand::Move(Place::from(ref_place))],
|
||||||
destination: unit_temp,
|
destination: unit_temp,
|
||||||
target: Some(succ),
|
target: Some(succ),
|
||||||
|
|
|
@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let kind = match parent_ty.ty.kind() {
|
let kind = match parent_ty.ty.kind() {
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
|
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
|
||||||
}
|
}
|
||||||
kind => kind,
|
kind => kind,
|
||||||
|
|
|
@ -336,8 +336,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
||||||
// we must subst the self_ty because it's
|
// we must subst the self_ty because it's
|
||||||
// otherwise going to be TySelf and we can't index
|
// otherwise going to be TySelf and we can't index
|
||||||
// or access fields of a Place of type TySelf.
|
// or access fields of a Place of type TySelf.
|
||||||
let substs = tcx.mk_substs_trait(self_ty, []);
|
let sig = tcx.bound_fn_sig(def_id).subst(tcx, &[self_ty.into()]);
|
||||||
let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs);
|
|
||||||
let sig = tcx.erase_late_bound_regions(sig);
|
let sig = tcx.erase_late_bound_regions(sig);
|
||||||
let span = tcx.def_span(def_id);
|
let span = tcx.def_span(def_id);
|
||||||
|
|
||||||
|
@ -417,10 +416,8 @@ impl<'tcx> CloneShimBuilder<'tcx> {
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
let substs = tcx.mk_substs_trait(ty, []);
|
|
||||||
|
|
||||||
// `func == Clone::clone(&ty) -> ty`
|
// `func == Clone::clone(&ty) -> ty`
|
||||||
let func_ty = tcx.mk_fn_def(self.def_id, substs);
|
let func_ty = tcx.mk_fn_def(self.def_id, [ty]);
|
||||||
let func = Operand::Constant(Box::new(Constant {
|
let func = Operand::Constant(Box::new(Constant {
|
||||||
span: self.span,
|
span: self.span,
|
||||||
user_ty: None,
|
user_ty: None,
|
||||||
|
@ -575,9 +572,8 @@ fn build_call_shim<'tcx>(
|
||||||
|
|
||||||
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
|
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
|
||||||
let arg_tup = tcx.mk_tup(untuple_args.iter());
|
let arg_tup = tcx.mk_tup(untuple_args.iter());
|
||||||
let sig_substs = tcx.mk_substs_trait(ty, [ty::subst::GenericArg::from(arg_tup)]);
|
|
||||||
|
|
||||||
(Some(sig_substs), Some(untuple_args))
|
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
(None, None)
|
||||||
};
|
};
|
||||||
|
@ -588,7 +584,7 @@ fn build_call_shim<'tcx>(
|
||||||
|
|
||||||
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
||||||
let mut sig =
|
let mut sig =
|
||||||
if let Some(sig_substs) = sig_substs { sig.subst(tcx, sig_substs) } else { sig.0 };
|
if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 };
|
||||||
|
|
||||||
if let CallKind::Indirect(fnty) = call_kind {
|
if let CallKind::Indirect(fnty) = call_kind {
|
||||||
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This
|
// `sig` determines our local decls, and thus the callee type in the `Call` terminator. This
|
||||||
|
|
|
@ -110,26 +110,25 @@ where
|
||||||
V: DefIdVisitor<'tcx> + ?Sized,
|
V: DefIdVisitor<'tcx> + ?Sized,
|
||||||
{
|
{
|
||||||
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<V::BreakTy> {
|
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||||
let TraitRef { def_id, substs } = trait_ref;
|
let TraitRef { def_id, substs, .. } = trait_ref;
|
||||||
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref.print_only_trait_path())?;
|
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref.print_only_trait_path())?;
|
||||||
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::AliasTy<'tcx>) -> ControlFlow<V::BreakTy> {
|
fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||||
let tcx = self.def_id_visitor.tcx();
|
let tcx = self.def_id_visitor.tcx();
|
||||||
let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id)
|
let (trait_ref, assoc_substs) =
|
||||||
!= DefKind::ImplTraitPlaceholder
|
if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder {
|
||||||
{
|
projection.trait_ref_and_own_substs(tcx)
|
||||||
projection.trait_ref_and_own_substs(tcx)
|
} else {
|
||||||
} else {
|
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
|
||||||
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
|
let def_id = tcx.impl_trait_in_trait_parent(projection.def_id);
|
||||||
let def_id = tcx.impl_trait_in_trait_parent(projection.def_id);
|
let trait_generics = tcx.generics_of(def_id);
|
||||||
let trait_generics = tcx.generics_of(def_id);
|
(
|
||||||
(
|
tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)),
|
||||||
ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) },
|
&projection.substs[trait_generics.count()..],
|
||||||
&projection.substs[trait_generics.count()..],
|
)
|
||||||
)
|
};
|
||||||
};
|
|
||||||
self.visit_trait(trait_ref)?;
|
self.visit_trait(trait_ref)?;
|
||||||
if self.def_id_visitor.shallow() {
|
if self.def_id_visitor.shallow() {
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
|
@ -235,7 +234,7 @@ where
|
||||||
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?;
|
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||||
// Skip repeated `Opaque`s to avoid infinite recursion.
|
// Skip repeated `Opaque`s to avoid infinite recursion.
|
||||||
if self.visited_opaque_tys.insert(def_id) {
|
if self.visited_opaque_tys.insert(def_id) {
|
||||||
// The intent is to treat `impl Trait1 + Trait2` identically to
|
// The intent is to treat `impl Trait1 + Trait2` identically to
|
||||||
|
|
|
@ -216,7 +216,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
// Print all nominal types as paths (unlike `pretty_print_type`).
|
// Print all nominal types as paths (unlike `pretty_print_type`).
|
||||||
ty::FnDef(def_id, substs)
|
ty::FnDef(def_id, substs)
|
||||||
| ty::Alias(_, ty::AliasTy { def_id, substs })
|
| ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||||
| ty::Closure(def_id, substs)
|
| ty::Closure(def_id, substs)
|
||||||
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
|
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
|
||||||
|
|
||||||
|
|
|
@ -439,7 +439,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||||
// Mangle all nominal types as paths.
|
// Mangle all nominal types as paths.
|
||||||
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
|
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
|
||||||
| ty::FnDef(def_id, substs)
|
| ty::FnDef(def_id, substs)
|
||||||
| ty::Alias(_, ty::AliasTy { def_id, substs })
|
| ty::Alias(_, ty::AliasTy { def_id, substs, .. })
|
||||||
| ty::Closure(def_id, substs)
|
| ty::Closure(def_id, substs)
|
||||||
| ty::Generator(def_id, substs, _) => {
|
| ty::Generator(def_id, substs, _) => {
|
||||||
self = self.print_def_path(def_id, substs)?;
|
self = self.print_def_path(def_id, substs)?;
|
||||||
|
|
|
@ -1036,7 +1036,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
&& self.fallback_has_occurred
|
&& self.fallback_has_occurred
|
||||||
{
|
{
|
||||||
let predicate = trait_predicate.map_bound(|trait_pred| {
|
let predicate = trait_predicate.map_bound(|trait_pred| {
|
||||||
trait_pred.with_self_type(self.tcx, self.tcx.mk_unit())
|
trait_pred.with_self_ty(self.tcx, self.tcx.mk_unit())
|
||||||
});
|
});
|
||||||
let unit_obligation = obligation.with(tcx, predicate);
|
let unit_obligation = obligation.with(tcx, predicate);
|
||||||
if self.predicate_may_hold(&unit_obligation) {
|
if self.predicate_may_hold(&unit_obligation) {
|
||||||
|
@ -2085,8 +2085,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
|
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
|
||||||
) -> PredicateObligation<'tcx> {
|
) -> PredicateObligation<'tcx> {
|
||||||
let trait_pred = trait_ref_and_ty
|
let trait_pred =
|
||||||
.map_bound(|(tr, new_self_ty)| tr.with_self_type(self.tcx, new_self_ty));
|
trait_ref_and_ty.map_bound(|(tr, new_self_ty)| tr.with_self_ty(self.tcx, new_self_ty));
|
||||||
|
|
||||||
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred)
|
Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred)
|
||||||
}
|
}
|
||||||
|
|
|
@ -878,7 +878,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
fn_sig.inputs().map_bound(|inputs| &inputs[1..]),
|
fn_sig.inputs().map_bound(|inputs| &inputs[1..]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
|
||||||
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
|
||||||
|
@ -2662,7 +2662,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
Some(ident) => err.span_note(ident.span, &msg),
|
Some(ident) => err.span_note(ident.span, &msg),
|
||||||
None => err.note(&msg),
|
None => err.note(&msg),
|
||||||
},
|
},
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||||
// Avoid printing the future from `core::future::identity_future`, it's not helpful
|
// Avoid printing the future from `core::future::identity_future`, it's not helpful
|
||||||
if tcx.parent(*def_id) == identity_future {
|
if tcx.parent(*def_id) == identity_future {
|
||||||
break 'print;
|
break 'print;
|
||||||
|
@ -2975,7 +2975,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
self.tcx.mk_projection(
|
self.tcx.mk_projection(
|
||||||
item_def_id,
|
item_def_id,
|
||||||
// Future::Output has no substs
|
// Future::Output has no substs
|
||||||
self.tcx.mk_substs_trait(trait_pred.self_ty(), []),
|
[trait_pred.self_ty()],
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let InferOk { value: projection_ty, .. } =
|
let InferOk { value: projection_ty, .. } =
|
||||||
|
@ -3265,9 +3265,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
// in. For example, this would be what `Iterator::Item` is here.
|
// in. For example, this would be what `Iterator::Item` is here.
|
||||||
let ty_var = self.infcx.next_ty_var(origin);
|
let ty_var = self.infcx.next_ty_var(origin);
|
||||||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||||
let trait_ref = ty::Binder::dummy(ty::PredicateKind::Clause(
|
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||||
ty::Clause::Projection(ty::ProjectionPredicate {
|
ty::Clause::Projection(ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy { substs, def_id: proj.def_id },
|
projection_ty: tcx.mk_alias_ty(proj.def_id, substs),
|
||||||
term: ty_var.into(),
|
term: ty_var.into(),
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
@ -3277,7 +3277,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
span,
|
span,
|
||||||
expr.hir_id,
|
expr.hir_id,
|
||||||
param_env,
|
param_env,
|
||||||
trait_ref,
|
projection,
|
||||||
));
|
));
|
||||||
if ocx.select_where_possible().is_empty() {
|
if ocx.select_where_possible().is_empty() {
|
||||||
// `ty_var` now holds the type that `Item` is for `ExprTy`.
|
// `ty_var` now holds the type that `Item` is for `ExprTy`.
|
||||||
|
|
|
@ -425,13 +425,8 @@ pub fn fully_solve_bound<'tcx>(
|
||||||
bound: DefId,
|
bound: DefId,
|
||||||
) -> Vec<FulfillmentError<'tcx>> {
|
) -> Vec<FulfillmentError<'tcx>> {
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
let trait_ref = ty::TraitRef { def_id: bound, substs: tcx.mk_substs_trait(ty, []) };
|
let trait_ref = tcx.mk_trait_ref(bound, [ty]);
|
||||||
let obligation = Obligation {
|
let obligation = Obligation::new(tcx, cause, param_env, ty::Binder::dummy(trait_ref));
|
||||||
cause,
|
|
||||||
recursion_depth: 0,
|
|
||||||
param_env,
|
|
||||||
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx),
|
|
||||||
};
|
|
||||||
|
|
||||||
fully_solve_obligation(infcx, obligation)
|
fully_solve_obligation(infcx, obligation)
|
||||||
}
|
}
|
||||||
|
|
|
@ -694,18 +694,12 @@ fn receiver_is_dispatchable<'tcx>(
|
||||||
|
|
||||||
// U: Trait<Arg1, ..., ArgN>
|
// U: Trait<Arg1, ..., ArgN>
|
||||||
let trait_predicate = {
|
let trait_predicate = {
|
||||||
let substs =
|
let trait_def_id = method.trait_container(tcx).unwrap();
|
||||||
InternalSubsts::for_item(tcx, method.trait_container(tcx).unwrap(), |param, _| {
|
let substs = InternalSubsts::for_item(tcx, trait_def_id, |param, _| {
|
||||||
if param.index == 0 {
|
if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) }
|
||||||
unsized_self_ty.into()
|
});
|
||||||
} else {
|
|
||||||
tcx.mk_param_from_def(param)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ty::Binder::dummy(ty::TraitRef { def_id: unsize_did, substs })
|
ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx)
|
||||||
.without_const()
|
|
||||||
.to_predicate(tcx)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let caller_bounds: Vec<Predicate<'tcx>> =
|
let caller_bounds: Vec<Predicate<'tcx>> =
|
||||||
|
|
|
@ -496,7 +496,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
// This is really important. While we *can* handle this, this has
|
// This is really important. While we *can* handle this, this has
|
||||||
// severe performance implications for large opaque types with
|
// severe performance implications for large opaque types with
|
||||||
// late-bound regions. See `issue-88862` benchmark.
|
// late-bound regions. See `issue-88862` benchmark.
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. })
|
||||||
if !substs.has_escaping_bound_vars() =>
|
if !substs.has_escaping_bound_vars() =>
|
||||||
{
|
{
|
||||||
// Only normalize `impl Trait` outside of type inference, usually in codegen.
|
// Only normalize `impl Trait` outside of type inference, usually in codegen.
|
||||||
|
@ -1309,8 +1309,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
|
||||||
let trait_substs =
|
let trait_substs =
|
||||||
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
|
obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id));
|
||||||
// FIXME(named-returns): Binders
|
// FIXME(named-returns): Binders
|
||||||
let trait_predicate =
|
let trait_predicate = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, trait_substs));
|
||||||
ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs });
|
|
||||||
|
|
||||||
let _ = selcx.infcx.commit_if_ok(|_| {
|
let _ = selcx.infcx.commit_if_ok(|_| {
|
||||||
match selcx.select(&obligation.with(tcx, trait_predicate)) {
|
match selcx.select(&obligation.with(tcx, trait_predicate)) {
|
||||||
|
@ -1867,10 +1866,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
|
||||||
};
|
};
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy {
|
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs),
|
||||||
substs: trait_ref.substs,
|
|
||||||
def_id: obligation.predicate.def_id,
|
|
||||||
},
|
|
||||||
term: ty.into(),
|
term: ty.into(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1909,10 +1905,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy {
|
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs),
|
||||||
substs: trait_ref.substs,
|
|
||||||
def_id: obligation.predicate.def_id,
|
|
||||||
},
|
|
||||||
term: return_ty.into(),
|
term: return_ty.into(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1965,10 +1958,8 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||||
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
|
bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate);
|
||||||
};
|
};
|
||||||
|
|
||||||
let predicate = ty::ProjectionPredicate {
|
let predicate =
|
||||||
projection_ty: ty::AliasTy { substs, def_id: item_def_id },
|
ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, substs), term };
|
||||||
term,
|
|
||||||
};
|
|
||||||
|
|
||||||
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||||
.with_addl_obligations(obligations)
|
.with_addl_obligations(obligations)
|
||||||
|
@ -2037,7 +2028,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
||||||
flag,
|
flag,
|
||||||
)
|
)
|
||||||
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
||||||
projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: fn_once_output_def_id },
|
projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.substs),
|
||||||
term: ret_type.into(),
|
term: ret_type.into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
|
||||||
// This is really important. While we *can* handle this, this has
|
// This is really important. While we *can* handle this, this has
|
||||||
// severe performance implications for large opaque types with
|
// severe performance implications for large opaque types with
|
||||||
// late-bound regions. See `issue-88862` benchmark.
|
// late-bound regions. See `issue-88862` benchmark.
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. })
|
||||||
if !substs.has_escaping_bound_vars() =>
|
if !substs.has_escaping_bound_vars() =>
|
||||||
{
|
{
|
||||||
// Only normalize `impl Trait` outside of type inference, usually in codegen.
|
// Only normalize `impl Trait` outside of type inference, usually in codegen.
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub(crate) fn update<'tcx, T>(
|
||||||
.kind()
|
.kind()
|
||||||
.rebind(
|
.rebind(
|
||||||
// (*) binder moved here
|
// (*) binder moved here
|
||||||
ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_type(infcx.tcx, new_self_ty)))
|
ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_ty(infcx.tcx, new_self_ty)))
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// Don't report overflow errors. Otherwise equivalent to may_hold.
|
// Don't report overflow errors. Otherwise equivalent to may_hold.
|
||||||
|
|
|
@ -536,7 +536,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
let ty = traits::normalize_projection_type(
|
let ty = traits::normalize_projection_type(
|
||||||
self,
|
self,
|
||||||
param_env,
|
param_env,
|
||||||
ty::AliasTy { def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs },
|
tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.substs),
|
||||||
cause.clone(),
|
cause.clone(),
|
||||||
0,
|
0,
|
||||||
// We're *intentionally* throwing these away,
|
// We're *intentionally* throwing these away,
|
||||||
|
|
|
@ -155,7 +155,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
|
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
|
||||||
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
|
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
|
||||||
let (def_id, substs) = match *placeholder_self_ty.kind() {
|
let (def_id, substs) = match *placeholder_self_ty.kind() {
|
||||||
ty::Alias(_, ty::AliasTy { def_id, substs }) => (def_id, substs),
|
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs),
|
||||||
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
|
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1595,7 +1595,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
|
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
|
||||||
ty::Alias(_, ty::AliasTy { def_id, substs }) => (def_id, substs),
|
ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs),
|
||||||
_ => {
|
_ => {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
obligation.cause.span,
|
obligation.cause.span,
|
||||||
|
@ -2259,7 +2259,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect())
|
t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
// We can resolve the `impl Trait` to its concrete type,
|
// We can resolve the `impl Trait` to its concrete type,
|
||||||
// which enforces a DAG between the functions requiring
|
// which enforces a DAG between the functions requiring
|
||||||
// the auto trait bounds in question.
|
// the auto trait bounds in question.
|
||||||
|
|
|
@ -648,7 +648,7 @@ impl<'tcx> WfPredicates<'tcx> {
|
||||||
// types appearing in the fn signature
|
// types appearing in the fn signature
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
// All of the requirements on type parameters
|
// All of the requirements on type parameters
|
||||||
// have already been checked for `impl Trait` in
|
// have already been checked for `impl Trait` in
|
||||||
// return position. We do need to check type-alias-impl-trait though.
|
// return position. We do need to check type-alias-impl-trait though.
|
||||||
|
|
|
@ -433,7 +433,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }),
|
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }),
|
||||||
OpaqueType(opaque_ty_id, ..),
|
OpaqueType(opaque_ty_id, ..),
|
||||||
) => def_id == opaque_ty_id.0,
|
) => def_id == opaque_ty_id.0,
|
||||||
(&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0,
|
(&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0,
|
||||||
|
@ -789,7 +789,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *ty.kind() {
|
||||||
if def_id == self.opaque_ty_id.0 && substs == self.identity_substs {
|
if def_id == self.opaque_ty_id.0 && substs == self.identity_substs {
|
||||||
return self.tcx.mk_ty(ty::Bound(
|
return self.tcx.mk_ty(ty::Bound(
|
||||||
self.binder_index,
|
self.binder_index,
|
||||||
|
|
|
@ -347,13 +347,13 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
|
||||||
ty::Tuple(types) => {
|
ty::Tuple(types) => {
|
||||||
chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner))
|
chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner))
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Projection, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
|
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
|
||||||
associated_ty_id: chalk_ir::AssocTypeId(def_id),
|
associated_ty_id: chalk_ir::AssocTypeId(def_id),
|
||||||
substitution: substs.lower_into(interner),
|
substitution: substs.lower_into(interner),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
|
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
|
||||||
opaque_ty_id: chalk_ir::OpaqueTyId(def_id),
|
opaque_ty_id: chalk_ir::OpaqueTyId(def_id),
|
||||||
substitution: substs.lower_into(interner),
|
substitution: substs.lower_into(interner),
|
||||||
|
@ -443,11 +443,11 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
|
||||||
TyKind::Str => ty::Str,
|
TyKind::Str => ty::Str,
|
||||||
TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias(
|
TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias(
|
||||||
ty::Opaque,
|
ty::Opaque,
|
||||||
ty::AliasTy { def_id: opaque_ty.0, substs: substitution.lower_into(interner) },
|
interner.tcx.mk_alias_ty(opaque_ty.0, substitution.lower_into(interner)),
|
||||||
),
|
),
|
||||||
TyKind::AssociatedType(assoc_ty, substitution) => ty::Alias(
|
TyKind::AssociatedType(assoc_ty, substitution) => ty::Alias(
|
||||||
ty::Projection,
|
ty::Projection,
|
||||||
ty::AliasTy { substs: substitution.lower_into(interner), def_id: assoc_ty.0 },
|
interner.tcx.mk_alias_ty(assoc_ty.0, substitution.lower_into(interner)),
|
||||||
),
|
),
|
||||||
TyKind::Foreign(def_id) => ty::Foreign(def_id.0),
|
TyKind::Foreign(def_id) => ty::Foreign(def_id.0),
|
||||||
TyKind::Error => return interner.tcx.ty_error(),
|
TyKind::Error => return interner.tcx.ty_error(),
|
||||||
|
@ -458,17 +458,17 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
|
||||||
TyKind::Alias(alias_ty) => match alias_ty {
|
TyKind::Alias(alias_ty) => match alias_ty {
|
||||||
chalk_ir::AliasTy::Projection(projection) => ty::Alias(
|
chalk_ir::AliasTy::Projection(projection) => ty::Alias(
|
||||||
ty::Projection,
|
ty::Projection,
|
||||||
ty::AliasTy {
|
interner.tcx.mk_alias_ty(
|
||||||
def_id: projection.associated_ty_id.0,
|
projection.associated_ty_id.0,
|
||||||
substs: projection.substitution.lower_into(interner),
|
projection.substitution.lower_into(interner),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
chalk_ir::AliasTy::Opaque(opaque) => ty::Alias(
|
chalk_ir::AliasTy::Opaque(opaque) => ty::Alias(
|
||||||
ty::Opaque,
|
ty::Opaque,
|
||||||
ty::AliasTy {
|
interner.tcx.mk_alias_ty(
|
||||||
def_id: opaque.opaque_ty_id.0,
|
opaque.opaque_ty_id.0,
|
||||||
substs: opaque.substitution.lower_into(interner),
|
opaque.substitution.lower_into(interner),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
TyKind::Function(_quantified_ty) => unimplemented!(),
|
TyKind::Function(_quantified_ty) => unimplemented!(),
|
||||||
|
|
|
@ -1835,7 +1835,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||||
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
||||||
// by looking up the bounds associated with the def_id.
|
// by looking up the bounds associated with the def_id.
|
||||||
let bounds = cx
|
let bounds = cx
|
||||||
|
|
|
@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::traits::Reveal;
|
use rustc_middle::traits::Reveal;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
|
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
|
||||||
TraitRef, Ty, TyCtxt,
|
Ty, TyCtxt,
|
||||||
};
|
};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
|
@ -513,9 +513,9 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||||
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
|
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
|
||||||
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
||||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||||
trait_ref: TraitRef::new(
|
trait_ref: tcx.mk_trait_ref(
|
||||||
eq_trait_id,
|
eq_trait_id,
|
||||||
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
|
[tcx.mk_param_from_def(param)],
|
||||||
),
|
),
|
||||||
constness: BoundConstness::NotConst,
|
constness: BoundConstness::NotConst,
|
||||||
polarity: ImplPolarity::Positive,
|
polarity: ImplPolarity::Positive,
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ret_ty = return_ty(cx, hir_id);
|
let ret_ty = return_ty(cx, hir_id);
|
||||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs }) = *ret_ty.kind() {
|
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
|
||||||
let preds = cx.tcx.explicit_item_bounds(def_id);
|
let preds = cx.tcx.explicit_item_bounds(def_id);
|
||||||
let mut is_future = false;
|
let mut is_future = false;
|
||||||
for &(p, _span) in preds {
|
for &(p, _span) in preds {
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() {
|
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *inner_ty.kind() {
|
||||||
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
|
for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) {
|
||||||
match predicate.kind().skip_binder() {
|
match predicate.kind().skip_binder() {
|
||||||
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through
|
||||||
|
@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||||
is_must_use_ty(cx, *ty)
|
is_must_use_ty(cx, *ty)
|
||||||
},
|
},
|
||||||
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
|
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
|
||||||
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||||
|
@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
|
||||||
Some(ExprFnSig::Closure(decl, subs.as_closure().sig()))
|
Some(ExprFnSig::Closure(decl, subs.as_closure().sig()))
|
||||||
},
|
},
|
||||||
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
|
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
|
||||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)),
|
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)),
|
||||||
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
|
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
|
||||||
ty::Dynamic(bounds, _, _) => {
|
ty::Dynamic(bounds, _, _) => {
|
||||||
let lang_items = cx.tcx.lang_items();
|
let lang_items = cx.tcx.lang_items();
|
||||||
|
@ -1039,10 +1039,10 @@ pub fn make_projection<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(AliasTy {
|
Some(tcx.mk_alias_ty(
|
||||||
|
assoc_item.def_id,
|
||||||
substs,
|
substs,
|
||||||
def_id: assoc_item.def_id,
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
helper(
|
helper(
|
||||||
tcx,
|
tcx,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue