Auto merge of #106696 - kylematsuda:early-binder, r=lcnr
Switch to `EarlyBinder` for `const_param_default` and `impl_trait_ref` queries Part of the work to close #105779 and implement https://github.com/rust-lang/types-team/issues/78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This PR adds `EarlyBinder` to the return type of `const_param_default` and `impl_trait_ref`, and removes their `bound_X` variants. r? `@lcnr`
This commit is contained in:
commit
b8f9cb345a
55 changed files with 145 additions and 112 deletions
|
@ -511,9 +511,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
return tcx.const_error(ty).into();
|
return tcx.const_error(ty).into();
|
||||||
}
|
}
|
||||||
if !infer_args && has_default {
|
if !infer_args && has_default {
|
||||||
tcx.bound_const_param_default(param.def_id)
|
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
|
||||||
.subst(tcx, substs.unwrap())
|
|
||||||
.into()
|
|
||||||
} else {
|
} else {
|
||||||
if infer_args {
|
if infer_args {
|
||||||
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
||||||
|
@ -2068,7 +2066,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.one_bound_for_assoc_type(
|
self.one_bound_for_assoc_type(
|
||||||
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref)),
|
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
|
||||||
|| "Self".to_string(),
|
|| "Self".to_string(),
|
||||||
assoc_ident,
|
assoc_ident,
|
||||||
span,
|
span,
|
||||||
|
@ -2157,7 +2155,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
.is_accessible_from(self.item_def_id(), tcx)
|
.is_accessible_from(self.item_def_id(), tcx)
|
||||||
&& tcx.all_impls(*trait_def_id)
|
&& tcx.all_impls(*trait_def_id)
|
||||||
.any(|impl_def_id| {
|
.any(|impl_def_id| {
|
||||||
let trait_ref = tcx.bound_impl_trait_ref(impl_def_id);
|
let trait_ref = tcx.impl_trait_ref(impl_def_id);
|
||||||
trait_ref.map_or(false, |trait_ref| {
|
trait_ref.map_or(false, |trait_ref| {
|
||||||
let impl_ = trait_ref.subst(
|
let impl_ = trait_ref.subst(
|
||||||
tcx,
|
tcx,
|
||||||
|
@ -2310,7 +2308,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative
|
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative
|
||||||
})
|
})
|
||||||
.filter_map(|impl_def_id| tcx.impl_trait_ref(impl_def_id))
|
.filter_map(|impl_def_id| tcx.impl_trait_ref(impl_def_id))
|
||||||
.map(|impl_| impl_.self_ty())
|
.map(|impl_| impl_.subst_identity().self_ty())
|
||||||
// We don't care about blanket impls.
|
// We don't care about blanket impls.
|
||||||
.filter(|self_ty| !self_ty.has_non_region_param())
|
.filter(|self_ty| !self_ty.has_non_region_param())
|
||||||
.map(|self_ty| tcx.erase_regions(self_ty).to_string())
|
.map(|self_ty| tcx.erase_regions(self_ty).to_string())
|
||||||
|
|
|
@ -540,7 +540,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||||
tcx,
|
tcx,
|
||||||
it.span,
|
it.span,
|
||||||
it.owner_id.def_id,
|
it.owner_id.def_id,
|
||||||
impl_trait_ref,
|
impl_trait_ref.subst_identity(),
|
||||||
&impl_.items,
|
&impl_.items,
|
||||||
);
|
);
|
||||||
check_on_unimplemented(tcx, it);
|
check_on_unimplemented(tcx, it);
|
||||||
|
|
|
@ -616,7 +616,8 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
||||||
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
|
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
|
||||||
let impl_m = tcx.opt_associated_item(def_id).unwrap();
|
let impl_m = tcx.opt_associated_item(def_id).unwrap();
|
||||||
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
|
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
|
||||||
let impl_trait_ref = tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap();
|
let impl_trait_ref =
|
||||||
|
tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity();
|
||||||
let param_env = tcx.param_env(def_id);
|
let param_env = tcx.param_env(def_id);
|
||||||
|
|
||||||
// First, check a few of the same things as `compare_impl_method`,
|
// First, check a few of the same things as `compare_impl_method`,
|
||||||
|
@ -1684,7 +1685,8 @@ pub(super) fn compare_impl_const_raw(
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let impl_const_item = tcx.associated_item(impl_const_item_def);
|
let impl_const_item = tcx.associated_item(impl_const_item_def);
|
||||||
let trait_const_item = tcx.associated_item(trait_const_item_def);
|
let trait_const_item = tcx.associated_item(trait_const_item_def);
|
||||||
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
|
let impl_trait_ref =
|
||||||
|
tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap().subst_identity();
|
||||||
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
|
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
|
||||||
|
|
||||||
let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());
|
let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());
|
||||||
|
|
|
@ -182,7 +182,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||||
hir::ItemKind::Impl(ref impl_) => {
|
hir::ItemKind::Impl(ref impl_) => {
|
||||||
let is_auto = tcx
|
let is_auto = tcx
|
||||||
.impl_trait_ref(def_id)
|
.impl_trait_ref(def_id)
|
||||||
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
|
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
|
||||||
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
|
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
|
||||||
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
|
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
|
||||||
let mut err =
|
let mut err =
|
||||||
|
@ -1253,7 +1253,7 @@ fn check_impl<'tcx>(
|
||||||
// `#[rustc_reservation_impl]` impls are not real impls and
|
// `#[rustc_reservation_impl]` impls are not real impls and
|
||||||
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
||||||
// won't hold).
|
// won't hold).
|
||||||
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().subst_identity();
|
||||||
let trait_ref = wfcx.normalize(
|
let trait_ref = wfcx.normalize(
|
||||||
ast_trait_ref.path.span,
|
ast_trait_ref.path.span,
|
||||||
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
||||||
|
@ -1350,7 +1350,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
||||||
// is incorrect when dealing with unused substs, for example
|
// is incorrect when dealing with unused substs, for example
|
||||||
// for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>`
|
// for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>`
|
||||||
// we should eagerly error.
|
// we should eagerly error.
|
||||||
let default_ct = tcx.const_param_default(param.def_id);
|
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
|
||||||
if !default_ct.needs_subst() {
|
if !default_ct.needs_subst() {
|
||||||
wfcx.register_wf_obligation(
|
wfcx.register_wf_obligation(
|
||||||
tcx.def_span(param.def_id),
|
tcx.def_span(param.def_id),
|
||||||
|
@ -1396,7 +1396,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
||||||
GenericParamDefKind::Const { .. } => {
|
GenericParamDefKind::Const { .. } => {
|
||||||
// If the param has a default, ...
|
// If the param has a default, ...
|
||||||
if is_our_default(param) {
|
if is_our_default(param) {
|
||||||
let default_ct = tcx.const_param_default(param.def_id);
|
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
|
||||||
// ... and it's not a dependent default, ...
|
// ... and it's not a dependent default, ...
|
||||||
if !default_ct.needs_subst() {
|
if !default_ct.needs_subst() {
|
||||||
// ... then substitute it with the default.
|
// ... then substitute it with the default.
|
||||||
|
|
|
@ -192,7 +192,7 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
|
||||||
let source = tcx.type_of(impl_did);
|
let source = tcx.type_of(impl_did);
|
||||||
assert!(!source.has_escaping_bound_vars());
|
assert!(!source.has_escaping_bound_vars());
|
||||||
let target = {
|
let target = {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
|
||||||
assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
|
assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait);
|
||||||
|
|
||||||
trait_ref.substs.type_at(1)
|
trait_ref.substs.type_at(1)
|
||||||
|
@ -354,7 +354,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
|
||||||
});
|
});
|
||||||
|
|
||||||
let source = tcx.type_of(impl_did);
|
let source = tcx.type_of(impl_did);
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_did).unwrap().subst_identity();
|
||||||
assert_eq!(trait_ref.def_id, coerce_unsized_trait);
|
assert_eq!(trait_ref.def_id, coerce_unsized_trait);
|
||||||
let target = trait_ref.substs.type_at(1);
|
let target = trait_ref.substs.type_at(1);
|
||||||
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target);
|
debug!("visit_implementation_of_coerce_unsized: {:?} -> {:?} (bound)", source, target);
|
||||||
|
|
|
@ -128,7 +128,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||||
|
|
||||||
let impls = tcx.hir().trait_impls(def_id);
|
let impls = tcx.hir().trait_impls(def_id);
|
||||||
for &impl_def_id in impls {
|
for &impl_def_id in impls {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
|
||||||
|
|
||||||
check_impl(tcx, impl_def_id, trait_ref);
|
check_impl(tcx, impl_def_id, trait_ref);
|
||||||
check_object_overlap(tcx, impl_def_id, trait_ref);
|
check_object_overlap(tcx, impl_def_id, trait_ref);
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
impl_def_id: LocalDefId,
|
impl_def_id: LocalDefId,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
|
||||||
trait_ref.error_reported()?;
|
trait_ref.error_reported()?;
|
||||||
|
|
||||||
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);
|
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
|
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
|
||||||
|
|
||||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
||||||
|
let trait_ref = trait_ref.subst_identity();
|
||||||
let trait_def = tcx.trait_def(trait_ref.def_id);
|
let trait_def = tcx.trait_def(trait_ref.def_id);
|
||||||
let unsafe_attr =
|
let unsafe_attr =
|
||||||
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
|
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
|
||||||
|
|
|
@ -1339,18 +1339,22 @@ fn suggest_impl_trait<'tcx>(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
|
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
|
||||||
let icx = ItemCtxt::new(tcx, def_id);
|
let icx = ItemCtxt::new(tcx, def_id);
|
||||||
let item = tcx.hir().expect_item(def_id.expect_local());
|
let item = tcx.hir().expect_item(def_id.expect_local());
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Impl(ref impl_) => impl_.of_trait.as_ref().map(|ast_trait_ref| {
|
hir::ItemKind::Impl(ref impl_) => impl_
|
||||||
let selfty = tcx.type_of(def_id);
|
.of_trait
|
||||||
icx.astconv().instantiate_mono_trait_ref(
|
.as_ref()
|
||||||
ast_trait_ref,
|
.map(|ast_trait_ref| {
|
||||||
selfty,
|
let selfty = tcx.type_of(def_id);
|
||||||
check_impl_constness(tcx, impl_.constness, ast_trait_ref),
|
icx.astconv().instantiate_mono_trait_ref(
|
||||||
)
|
ast_trait_ref,
|
||||||
}),
|
selfty,
|
||||||
|
check_impl_constness(tcx, impl_.constness, ast_trait_ref),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(ty::EarlyBinder),
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
Node::Item(item) => match item.kind {
|
Node::Item(item) => match item.kind {
|
||||||
ItemKind::Impl(ref impl_) => {
|
ItemKind::Impl(ref impl_) => {
|
||||||
if impl_.defaultness.is_default() {
|
if impl_.defaultness.is_default() {
|
||||||
is_default_impl_trait = tcx.impl_trait_ref(def_id).map(ty::Binder::dummy);
|
is_default_impl_trait =
|
||||||
|
tcx.impl_trait_ref(def_id).map(|t| ty::Binder::dummy(t.subst_identity()));
|
||||||
}
|
}
|
||||||
&impl_.generics
|
&impl_.generics
|
||||||
}
|
}
|
||||||
|
@ -251,7 +252,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
// for details.
|
// for details.
|
||||||
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
|
if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
|
||||||
let self_ty = tcx.type_of(def_id);
|
let self_ty = tcx.type_of(def_id);
|
||||||
let trait_ref = tcx.impl_trait_ref(def_id);
|
let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity);
|
||||||
cgp::setup_constraining_predicates(
|
cgp::setup_constraining_predicates(
|
||||||
tcx,
|
tcx,
|
||||||
&mut predicates,
|
&mut predicates,
|
||||||
|
|
|
@ -85,7 +85,7 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
}
|
}
|
||||||
let impl_generics = tcx.generics_of(impl_def_id);
|
let impl_generics = tcx.generics_of(impl_def_id);
|
||||||
let impl_predicates = tcx.predicates_of(impl_def_id);
|
let impl_predicates = tcx.predicates_of(impl_def_id);
|
||||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
|
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity);
|
||||||
|
|
||||||
let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref);
|
let mut input_parameters = cgp::parameters_for_impl(impl_self_ty, impl_trait_ref);
|
||||||
cgp::identify_constrained_generic_params(
|
cgp::identify_constrained_generic_params(
|
||||||
|
|
|
@ -90,7 +90,7 @@ pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
|
||||||
|
|
||||||
fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option<Node> {
|
fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option<Node> {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl1_def_id)?;
|
let trait_ref = tcx.impl_trait_ref(impl1_def_id)?;
|
||||||
let trait_def = tcx.trait_def(trait_ref.def_id);
|
let trait_def = tcx.trait_def(trait_ref.skip_binder().def_id);
|
||||||
|
|
||||||
let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?;
|
let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?;
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ fn unconstrained_parent_impl_substs<'tcx>(
|
||||||
let impl_generic_predicates = tcx.predicates_of(impl_def_id);
|
let impl_generic_predicates = tcx.predicates_of(impl_def_id);
|
||||||
let mut unconstrained_parameters = FxHashSet::default();
|
let mut unconstrained_parameters = FxHashSet::default();
|
||||||
let mut constrained_params = FxHashSet::default();
|
let mut constrained_params = FxHashSet::default();
|
||||||
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
|
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::subst_identity);
|
||||||
|
|
||||||
// Unfortunately the functions in `constrained_generic_parameters` don't do
|
// Unfortunately the functions in `constrained_generic_parameters` don't do
|
||||||
// what we want here. We want only a list of constrained parameters while
|
// what we want here. We want only a list of constrained parameters while
|
||||||
|
@ -370,7 +370,7 @@ fn check_predicates<'tcx>(
|
||||||
});
|
});
|
||||||
|
|
||||||
// Include the well-formed predicates of the type parameters of the impl.
|
// Include the well-formed predicates of the type parameters of the impl.
|
||||||
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().substs {
|
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity().substs {
|
||||||
let infcx = &tcx.infer_ctxt().build();
|
let infcx = &tcx.infer_ctxt().build();
|
||||||
let obligations = wf::obligations(
|
let obligations = wf::obligations(
|
||||||
infcx,
|
infcx,
|
||||||
|
|
|
@ -1224,9 +1224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Const { has_default } => {
|
GenericParamDefKind::Const { has_default } => {
|
||||||
if !infer_args && has_default {
|
if !infer_args && has_default {
|
||||||
tcx.bound_const_param_default(param.def_id)
|
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
|
||||||
.subst(tcx, substs.unwrap())
|
|
||||||
.into()
|
|
||||||
} else {
|
} else {
|
||||||
self.fcx.var_for_def(self.span, param)
|
self.fcx.var_for_def(self.span, param)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1072,7 +1072,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// the impl, if local to crate (item may be defaulted), else nothing.
|
// the impl, if local to crate (item may be defaulted), else nothing.
|
||||||
let Some(item) = self.associated_value(impl_did, item_name).or_else(|| {
|
let Some(item) = self.associated_value(impl_did, item_name).or_else(|| {
|
||||||
let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
|
let impl_trait_ref = self.tcx.impl_trait_ref(impl_did)?;
|
||||||
self.associated_value(impl_trait_ref.def_id, item_name)
|
self.associated_value(impl_trait_ref.skip_binder().def_id, item_name)
|
||||||
}) else {
|
}) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
@ -1090,7 +1090,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let insertion = match self.tcx.impl_trait_ref(impl_did) {
|
let insertion = match self.tcx.impl_trait_ref(impl_did) {
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
Some(trait_ref) => {
|
Some(trait_ref) => {
|
||||||
format!(" of the trait `{}`", self.tcx.def_path_str(trait_ref.def_id))
|
format!(
|
||||||
|
" of the trait `{}`",
|
||||||
|
self.tcx.def_path_str(trait_ref.skip_binder().def_id)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1121,7 +1124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
if let Some(sugg_span) = sugg_span
|
if let Some(sugg_span) = sugg_span
|
||||||
&& let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
|
&& let Some(trait_ref) = self.tcx.impl_trait_ref(impl_did) {
|
||||||
let path = self.tcx.def_path_str(trait_ref.def_id);
|
let path = self.tcx.def_path_str(trait_ref.skip_binder().def_id);
|
||||||
|
|
||||||
let ty = match item.kind {
|
let ty = match item.kind {
|
||||||
ty::AssocKind::Const | ty::AssocKind::Type => rcvr_ty,
|
ty::AssocKind::Const | ty::AssocKind::Type => rcvr_ty,
|
||||||
|
@ -2616,7 +2619,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.tcx.impl_polarity(*imp_did) == ty::ImplPolarity::Negative
|
self.tcx.impl_polarity(*imp_did) == ty::ImplPolarity::Negative
|
||||||
})
|
})
|
||||||
.any(|imp_did| {
|
.any(|imp_did| {
|
||||||
let imp = self.tcx.impl_trait_ref(imp_did).unwrap();
|
let imp = self.tcx.impl_trait_ref(imp_did).unwrap().subst_identity();
|
||||||
let imp_simp =
|
let imp_simp =
|
||||||
simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder);
|
simplify_type(self.tcx, imp.self_ty(), TreatParams::AsPlaceholder);
|
||||||
imp_simp.map_or(false, |s| s == simp_rcvr_ty)
|
imp_simp.map_or(false, |s| s == simp_rcvr_ty)
|
||||||
|
|
|
@ -320,6 +320,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
.impl_trait_ref(impl_def_id)
|
.impl_trait_ref(impl_def_id)
|
||||||
else { return; };
|
else { return; };
|
||||||
let trait_substs = trait_ref
|
let trait_substs = trait_ref
|
||||||
|
.subst_identity()
|
||||||
// Replace the explicit self type with `Self` for better suggestion rendering
|
// Replace the explicit self type with `Self` for better suggestion rendering
|
||||||
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
|
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
|
||||||
.substs;
|
.substs;
|
||||||
|
|
|
@ -1555,7 +1555,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
self.tables.impl_defaultness.set(def_id.index, *defaultness);
|
self.tables.impl_defaultness.set(def_id.index, *defaultness);
|
||||||
self.tables.constness.set(def_id.index, *constness);
|
self.tables.constness.set(def_id.index, *constness);
|
||||||
|
|
||||||
let trait_ref = self.tcx.impl_trait_ref(def_id);
|
let trait_ref = self.tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::skip_binder);
|
||||||
if let Some(trait_ref) = trait_ref {
|
if let Some(trait_ref) = trait_ref {
|
||||||
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
||||||
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
|
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
|
||||||
|
@ -1899,6 +1899,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
for id in tcx.hir().items() {
|
for id in tcx.hir().items() {
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
|
||||||
if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) {
|
if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) {
|
||||||
|
let trait_ref = trait_ref.subst_identity();
|
||||||
|
|
||||||
let simplified_self_ty = fast_reject::simplify_type(
|
let simplified_self_ty = fast_reject::simplify_type(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
trait_ref.self_ty(),
|
trait_ref.self_ty(),
|
||||||
|
|
|
@ -359,8 +359,8 @@ define_tables! {
|
||||||
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
|
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
|
||||||
fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>,
|
fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>,
|
||||||
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
|
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
|
||||||
impl_trait_ref: Table<DefIndex, LazyValue<ty::TraitRef<'static>>>,
|
impl_trait_ref: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::TraitRef<'static>>>>,
|
||||||
const_param_default: Table<DefIndex, LazyValue<rustc_middle::ty::Const<'static>>>,
|
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
|
||||||
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
|
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
|
||||||
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
|
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
|
||||||
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
|
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
|
||||||
|
|
|
@ -102,6 +102,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> {
|
pub fn impl_subject(self, def_id: DefId) -> ImplSubject<'tcx> {
|
||||||
self.impl_trait_ref(def_id)
|
self.impl_trait_ref(def_id)
|
||||||
|
.map(|t| t.subst_identity())
|
||||||
.map(ImplSubject::Trait)
|
.map(ImplSubject::Trait)
|
||||||
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id)))
|
.unwrap_or_else(|| ImplSubject::Inherent(self.type_of(def_id)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ rustc_queries! {
|
||||||
|
|
||||||
/// Given the def_id of a const-generic parameter, computes the associated default const
|
/// Given the def_id of a const-generic parameter, computes the associated default const
|
||||||
/// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
|
/// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
|
||||||
query const_param_default(param: DefId) -> ty::Const<'tcx> {
|
query const_param_default(param: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
|
||||||
desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
|
desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
|
||||||
cache_on_disk_if { param.is_local() }
|
cache_on_disk_if { param.is_local() }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
|
@ -737,7 +737,7 @@ rustc_queries! {
|
||||||
|
|
||||||
/// Given an `impl_id`, return the trait it implements.
|
/// Given an `impl_id`, return the trait it implements.
|
||||||
/// Return `None` if this is an inherent impl.
|
/// Return `None` if this is an inherent impl.
|
||||||
query impl_trait_ref(impl_id: DefId) -> Option<ty::TraitRef<'tcx>> {
|
query impl_trait_ref(impl_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
|
||||||
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
|
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
|
||||||
cache_on_disk_if { impl_id.is_local() }
|
cache_on_disk_if { impl_id.is_local() }
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
|
|
|
@ -239,7 +239,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> {
|
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Const<'_>> {
|
||||||
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
|
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
|
||||||
hir::Node::GenericParam(hir::GenericParam {
|
hir::Node::GenericParam(hir::GenericParam {
|
||||||
kind: hir::GenericParamKind::Const { default: Some(ac), .. },
|
kind: hir::GenericParamKind::Const { default: Some(ac), .. },
|
||||||
|
@ -250,5 +250,5 @@ pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> {
|
||||||
"`const_param_default` expected a generic parameter with a constant"
|
"`const_param_default` expected a generic parameter with a constant"
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
Const::from_anon_const(tcx, default_def_id)
|
ty::EarlyBinder(Const::from_anon_const(tcx, default_def_id))
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl GenericParamDef {
|
||||||
Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into()))
|
Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into()))
|
||||||
}
|
}
|
||||||
GenericParamDefKind::Const { has_default } if has_default => {
|
GenericParamDefKind::Const { has_default } if has_default => {
|
||||||
Some(tcx.bound_const_param_default(self.def_id).map_bound(|c| c.into()))
|
Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2187,8 +2187,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
) -> Option<ImplOverlapKind> {
|
) -> Option<ImplOverlapKind> {
|
||||||
// If either trait impl references an error, they're allowed to overlap,
|
// If either trait impl references an error, they're allowed to overlap,
|
||||||
// as one of them essentially doesn't exist.
|
// as one of them essentially doesn't exist.
|
||||||
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.references_error())
|
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.subst_identity().references_error())
|
||||||
|| self.impl_trait_ref(def_id2).map_or(false, |tr| tr.references_error())
|
|| self
|
||||||
|
.impl_trait_ref(def_id2)
|
||||||
|
.map_or(false, |tr| tr.subst_identity().references_error())
|
||||||
{
|
{
|
||||||
return Some(ImplOverlapKind::Permitted { marker: false });
|
return Some(ImplOverlapKind::Permitted { marker: false });
|
||||||
}
|
}
|
||||||
|
@ -2218,7 +2220,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let is_marker_overlap = {
|
let is_marker_overlap = {
|
||||||
let is_marker_impl = |def_id: DefId| -> bool {
|
let is_marker_impl = |def_id: DefId| -> bool {
|
||||||
let trait_ref = self.impl_trait_ref(def_id);
|
let trait_ref = self.impl_trait_ref(def_id);
|
||||||
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)
|
trait_ref.map_or(false, |tr| self.trait_def(tr.skip_binder().def_id).is_marker)
|
||||||
};
|
};
|
||||||
is_marker_impl(def_id1) && is_marker_impl(def_id2)
|
is_marker_impl(def_id1) && is_marker_impl(def_id2)
|
||||||
};
|
};
|
||||||
|
@ -2364,7 +2366,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
|
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
|
||||||
/// If it implements no trait, returns `None`.
|
/// If it implements no trait, returns `None`.
|
||||||
pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {
|
pub fn trait_id_of_impl(self, def_id: DefId) -> Option<DefId> {
|
||||||
self.impl_trait_ref(def_id).map(|tr| tr.def_id)
|
self.impl_trait_ref(def_id).map(|tr| tr.skip_binder().def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the given `DefId` describes an item belonging to a trait,
|
/// If the given `DefId` describes an item belonging to a trait,
|
||||||
|
|
|
@ -32,6 +32,10 @@ impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> {
|
||||||
type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
|
type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::EarlyBinder<T> {
|
||||||
|
type Value<'tcx> = ty::EarlyBinder<T::Value<'tcx>>;
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! trivially_parameterized_over_tcx {
|
macro_rules! trivially_parameterized_over_tcx {
|
||||||
($($ty:ty),+ $(,)?) => {
|
($($ty:ty),+ $(,)?) => {
|
||||||
|
|
|
@ -116,7 +116,7 @@ pub trait Printer<'tcx>: Sized {
|
||||||
DefPathData::Impl => {
|
DefPathData::Impl => {
|
||||||
let generics = self.tcx().generics_of(def_id);
|
let generics = self.tcx().generics_of(def_id);
|
||||||
let self_ty = self.tcx().bound_type_of(def_id);
|
let self_ty = self.tcx().bound_type_of(def_id);
|
||||||
let impl_trait_ref = self.tcx().bound_impl_trait_ref(def_id);
|
let impl_trait_ref = self.tcx().impl_trait_ref(def_id);
|
||||||
let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() {
|
let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() {
|
||||||
(
|
(
|
||||||
self_ty.subst(self.tcx(), substs),
|
self_ty.subst(self.tcx(), substs),
|
||||||
|
|
|
@ -713,6 +713,10 @@ impl<'tcx, T: TypeFoldable<'tcx>> ty::EarlyBinder<T> {
|
||||||
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
|
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
|
||||||
self.0.fold_with(&mut folder)
|
self.0.fold_with(&mut folder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn subst_identity(self) -> T {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -652,13 +652,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
ty::EarlyBinder(self.fn_sig(def_id))
|
ty::EarlyBinder(self.fn_sig(def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bound_impl_trait_ref(
|
|
||||||
self,
|
|
||||||
def_id: DefId,
|
|
||||||
) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
|
|
||||||
self.impl_trait_ref(def_id).map(|i| ty::EarlyBinder(i))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bound_explicit_item_bounds(
|
pub fn bound_explicit_item_bounds(
|
||||||
self,
|
self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
|
@ -673,10 +666,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
ty::EarlyBinder(self.item_bounds(def_id))
|
ty::EarlyBinder(self.item_bounds(def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
|
|
||||||
ty::EarlyBinder(self.const_param_default(def_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bound_predicates_of(
|
pub fn bound_predicates_of(
|
||||||
self,
|
self,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
|
|
|
@ -94,6 +94,18 @@ impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for Representability {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::EarlyBinder<Ty<'_>> {
|
||||||
|
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo<DepKind>]) -> Self {
|
||||||
|
ty::EarlyBinder(Ty::from_cycle_error(tcx, cycle))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::EarlyBinder<ty::Binder<'_, ty::FnSig<'_>>> {
|
||||||
|
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo<DepKind>]) -> Self {
|
||||||
|
ty::EarlyBinder(ty::Binder::from_cycle_error(tcx, cycle))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// item_and_field_ids should form a cycle where each field contains the
|
// item_and_field_ids should form a cycle where each field contains the
|
||||||
// type in the next element in the list
|
// type in the next element in the list
|
||||||
pub fn recursive_type_error(
|
pub fn recursive_type_error(
|
||||||
|
|
|
@ -1352,6 +1352,8 @@ fn create_mono_items_for_default_impls<'tcx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
||||||
|
let trait_ref = trait_ref.subst_identity();
|
||||||
|
|
||||||
let param_env = ty::ParamEnv::reveal_all();
|
let param_env = ty::ParamEnv::reveal_all();
|
||||||
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
|
||||||
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);
|
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);
|
||||||
|
|
|
@ -266,7 +266,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||||
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of)
|
if let Some(trait_of) = self.tcx.trait_id_of_impl(impl_of)
|
||||||
&& self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads)
|
&& self.tcx.has_attr(trait_of, sym::rustc_trivial_field_reads)
|
||||||
{
|
{
|
||||||
let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap();
|
let trait_ref = self.tcx.impl_trait_ref(impl_of).unwrap().subst_identity();
|
||||||
if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind()
|
if let ty::Adt(adt_def, _) = trait_ref.self_ty().kind()
|
||||||
&& let Some(adt_def_id) = adt_def.did().as_local()
|
&& let Some(adt_def_id) = adt_def.did().as_local()
|
||||||
{
|
{
|
||||||
|
|
|
@ -338,7 +338,7 @@ trait VisibilityLike: Sized {
|
||||||
let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX };
|
let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX };
|
||||||
find.visit(tcx.type_of(def_id));
|
find.visit(tcx.type_of(def_id));
|
||||||
if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
|
if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
|
||||||
find.visit_trait(trait_ref);
|
find.visit_trait(trait_ref.subst_identity());
|
||||||
}
|
}
|
||||||
find.min
|
find.min
|
||||||
}
|
}
|
||||||
|
@ -838,7 +838,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
|
||||||
GenericParamDefKind::Const { has_default } => {
|
GenericParamDefKind::Const { has_default } => {
|
||||||
self.visit(self.ev.tcx.type_of(param.def_id));
|
self.visit(self.ev.tcx.type_of(param.def_id));
|
||||||
if has_default {
|
if has_default {
|
||||||
self.visit(self.ev.tcx.const_param_default(param.def_id));
|
self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -858,7 +858,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
|
||||||
|
|
||||||
fn trait_ref(&mut self) -> &mut Self {
|
fn trait_ref(&mut self) -> &mut Self {
|
||||||
if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) {
|
if let Some(trait_ref) = self.ev.tcx.impl_trait_ref(self.item_def_id) {
|
||||||
self.visit_trait(trait_ref);
|
self.visit_trait(trait_ref.subst_identity());
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
||||||
) {
|
) {
|
||||||
let tcx = acx.cx.tcx;
|
let tcx = acx.cx.tcx;
|
||||||
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
|
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
|
||||||
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap();
|
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
||||||
if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
||||||
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
||||||
) {
|
) {
|
||||||
let tcx = acx.cx.tcx;
|
let tcx = acx.cx.tcx;
|
||||||
|
|
||||||
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap();
|
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||||
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
|
||||||
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
|
||||||
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub fn overlapping_impls(
|
||||||
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
|
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
|
||||||
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
|
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
|
||||||
let may_overlap = match (impl1_ref, impl2_ref) {
|
let may_overlap = match (impl1_ref, impl2_ref) {
|
||||||
(Some(a), Some(b)) => iter::zip(a.substs, b.substs)
|
(Some(a), Some(b)) => iter::zip(a.skip_binder().substs, b.skip_binder().substs)
|
||||||
.all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)),
|
.all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)),
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
let self_ty1 = tcx.type_of(impl1_def_id);
|
let self_ty1 = tcx.type_of(impl1_def_id);
|
||||||
|
@ -126,7 +126,7 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
|
||||||
let header = ty::ImplHeader {
|
let header = ty::ImplHeader {
|
||||||
impl_def_id,
|
impl_def_id,
|
||||||
self_ty: tcx.bound_type_of(impl_def_id).subst(tcx, impl_substs),
|
self_ty: tcx.bound_type_of(impl_def_id).subst(tcx, impl_substs),
|
||||||
trait_ref: tcx.bound_impl_trait_ref(impl_def_id).map(|i| i.subst(tcx, impl_substs)),
|
trait_ref: tcx.impl_trait_ref(impl_def_id).map(|i| i.subst(tcx, impl_substs)),
|
||||||
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
|
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe
|
||||||
|
|
||||||
// We only except this routine to be invoked on implementations
|
// We only except this routine to be invoked on implementations
|
||||||
// of a trait, not inherent implementations.
|
// of a trait, not inherent implementations.
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
|
||||||
debug!("orphan_check: trait_ref={:?}", trait_ref);
|
debug!("orphan_check: trait_ref={:?}", trait_ref);
|
||||||
|
|
||||||
// If the *trait* is local to the crate, ok.
|
// If the *trait* is local to the crate, ok.
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub fn recompute_applicable_impls<'tcx>(
|
||||||
ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref);
|
ocx.normalize(&ObligationCause::dummy(), param_env, placeholder_obligation.trait_ref);
|
||||||
|
|
||||||
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
|
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
|
||||||
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs);
|
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs);
|
||||||
let impl_trait_ref = ocx.normalize(&ObligationCause::dummy(), param_env, impl_trait_ref);
|
let impl_trait_ref = ocx.normalize(&ObligationCause::dummy(), param_env, impl_trait_ref);
|
||||||
|
|
||||||
if let Err(_) =
|
if let Err(_) =
|
||||||
|
|
|
@ -1964,7 +1964,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let imp = self.tcx.impl_trait_ref(def_id).unwrap();
|
let imp = self.tcx.impl_trait_ref(def_id).unwrap().skip_binder();
|
||||||
|
|
||||||
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false)
|
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false)
|
||||||
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })
|
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })
|
||||||
|
@ -2062,6 +2062,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
|| self.tcx.is_builtin_derive(def_id)
|
|| self.tcx.is_builtin_derive(def_id)
|
||||||
})
|
})
|
||||||
.filter_map(|def_id| self.tcx.impl_trait_ref(def_id))
|
.filter_map(|def_id| self.tcx.impl_trait_ref(def_id))
|
||||||
|
.map(ty::EarlyBinder::subst_identity)
|
||||||
.filter(|trait_ref| {
|
.filter(|trait_ref| {
|
||||||
let self_ty = trait_ref.self_ty();
|
let self_ty = trait_ref.self_ty();
|
||||||
// Avoid mentioning type parameters.
|
// Avoid mentioning type parameters.
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| {
|
self.tcx.for_each_relevant_impl(trait_ref.def_id, trait_self_ty, |def_id| {
|
||||||
let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
|
let impl_substs = self.fresh_substs_for_item(obligation.cause.span, def_id);
|
||||||
let impl_trait_ref = tcx.bound_impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs);
|
let impl_trait_ref = tcx.impl_trait_ref(def_id).unwrap().subst(tcx, impl_substs);
|
||||||
|
|
||||||
let impl_self_ty = impl_trait_ref.self_ty();
|
let impl_self_ty = impl_trait_ref.self_ty();
|
||||||
|
|
||||||
|
|
|
@ -521,8 +521,10 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI
|
||||||
|
|
||||||
let generics = tcx.generics_of(trait_item_def_id);
|
let generics = tcx.generics_of(trait_item_def_id);
|
||||||
let predicates = tcx.predicates_of(trait_item_def_id);
|
let predicates = tcx.predicates_of(trait_item_def_id);
|
||||||
let impl_trait_ref =
|
let impl_trait_ref = tcx
|
||||||
tcx.impl_trait_ref(impl_def_id).expect("expected impl to correspond to trait");
|
.impl_trait_ref(impl_def_id)
|
||||||
|
.expect("expected impl to correspond to trait")
|
||||||
|
.subst_identity();
|
||||||
let param_env = tcx.param_env(impl_def_id);
|
let param_env = tcx.param_env(impl_def_id);
|
||||||
|
|
||||||
let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id };
|
let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id };
|
||||||
|
|
|
@ -357,7 +357,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
// Before we create the substitutions and everything, first
|
// Before we create the substitutions and everything, first
|
||||||
// consider a "quick reject". This avoids creating more types
|
// consider a "quick reject". This avoids creating more types
|
||||||
// and so forth that we need to.
|
// and so forth that we need to.
|
||||||
let impl_trait_ref = self.tcx().bound_impl_trait_ref(impl_def_id).unwrap();
|
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
|
||||||
if self.fast_reject_trait_refs(obligation, &impl_trait_ref.0) {
|
if self.fast_reject_trait_refs(obligation, &impl_trait_ref.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2335,7 +2335,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
impl_def_id: DefId,
|
impl_def_id: DefId,
|
||||||
obligation: &TraitObligation<'tcx>,
|
obligation: &TraitObligation<'tcx>,
|
||||||
) -> Normalized<'tcx, SubstsRef<'tcx>> {
|
) -> Normalized<'tcx, SubstsRef<'tcx>> {
|
||||||
let impl_trait_ref = self.tcx().bound_impl_trait_ref(impl_def_id).unwrap();
|
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();
|
||||||
match self.match_impl(impl_def_id, impl_trait_ref, obligation) {
|
match self.match_impl(impl_def_id, impl_trait_ref, obligation) {
|
||||||
Ok(substs) => substs,
|
Ok(substs) => substs,
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub fn translate_substs<'tcx>(
|
||||||
param_env, source_impl, source_substs, target_node
|
param_env, source_impl, source_substs, target_node
|
||||||
);
|
);
|
||||||
let source_trait_ref =
|
let source_trait_ref =
|
||||||
infcx.tcx.bound_impl_trait_ref(source_impl).unwrap().subst(infcx.tcx, &source_substs);
|
infcx.tcx.impl_trait_ref(source_impl).unwrap().subst(infcx.tcx, &source_substs);
|
||||||
|
|
||||||
// translate the Self and Param parts of the substitution, since those
|
// translate the Self and Param parts of the substitution, since those
|
||||||
// vary across impls
|
// vary across impls
|
||||||
|
@ -148,7 +148,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
|
||||||
|
|
||||||
// create a parameter environment corresponding to a (placeholder) instantiation of impl1
|
// create a parameter environment corresponding to a (placeholder) instantiation of impl1
|
||||||
let penv = tcx.param_env(impl1_def_id);
|
let penv = tcx.param_env(impl1_def_id);
|
||||||
let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap();
|
let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity();
|
||||||
|
|
||||||
// Create an infcx, taking the predicates of impl1 as assumptions:
|
// Create an infcx, taking the predicates of impl1 as assumptions:
|
||||||
let infcx = tcx.infer_ctxt().build();
|
let infcx = tcx.infer_ctxt().build();
|
||||||
|
@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>(
|
||||||
pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
|
pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id)?;
|
let trait_ref = tcx.impl_trait_ref(impl_def_id)?.subst_identity();
|
||||||
let mut w = "impl".to_owned();
|
let mut w = "impl".to_owned();
|
||||||
|
|
||||||
let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);
|
let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);
|
||||||
|
|
|
@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> {
|
||||||
impl<'tcx> ChildrenExt<'tcx> for Children {
|
impl<'tcx> ChildrenExt<'tcx> for Children {
|
||||||
/// Insert an impl into this set of children without comparing to any existing impls.
|
/// Insert an impl into this set of children without comparing to any existing impls.
|
||||||
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
|
||||||
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
|
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
|
||||||
{
|
{
|
||||||
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
|
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
|
||||||
|
@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
|
||||||
/// an impl with a parent. The impl must be present in the list of
|
/// an impl with a parent. The impl must be present in the list of
|
||||||
/// children already.
|
/// children already.
|
||||||
fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
|
||||||
let vec: &mut Vec<DefId>;
|
let vec: &mut Vec<DefId>;
|
||||||
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
|
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
|
||||||
{
|
{
|
||||||
|
@ -181,7 +181,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
|
||||||
if le && !ge {
|
if le && !ge {
|
||||||
debug!(
|
debug!(
|
||||||
"descending as child of TraitRef {:?}",
|
"descending as child of TraitRef {:?}",
|
||||||
tcx.impl_trait_ref(possible_sibling).unwrap()
|
tcx.impl_trait_ref(possible_sibling).unwrap().subst_identity()
|
||||||
);
|
);
|
||||||
|
|
||||||
// The impl specializes `possible_sibling`.
|
// The impl specializes `possible_sibling`.
|
||||||
|
@ -189,7 +189,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
|
||||||
} else if ge && !le {
|
} else if ge && !le {
|
||||||
debug!(
|
debug!(
|
||||||
"placing as parent of TraitRef {:?}",
|
"placing as parent of TraitRef {:?}",
|
||||||
tcx.impl_trait_ref(possible_sibling).unwrap()
|
tcx.impl_trait_ref(possible_sibling).unwrap().subst_identity()
|
||||||
);
|
);
|
||||||
|
|
||||||
replace_children.push(possible_sibling);
|
replace_children.push(possible_sibling);
|
||||||
|
@ -275,7 +275,8 @@ impl<'tcx> GraphExt<'tcx> for Graph {
|
||||||
) -> Result<Option<FutureCompatOverlapError<'tcx>>, OverlapError<'tcx>> {
|
) -> Result<Option<FutureCompatOverlapError<'tcx>>, OverlapError<'tcx>> {
|
||||||
assert!(impl_def_id.is_local());
|
assert!(impl_def_id.is_local());
|
||||||
|
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
// FIXME: use `EarlyBinder` in `self.children`
|
||||||
|
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
|
||||||
let trait_def_id = trait_ref.def_id;
|
let trait_def_id = trait_ref.def_id;
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -388,7 +389,7 @@ pub(crate) fn assoc_def(
|
||||||
impl_def_id: DefId,
|
impl_def_id: DefId,
|
||||||
assoc_def_id: DefId,
|
assoc_def_id: DefId,
|
||||||
) -> Result<LeafDef, ErrorGuaranteed> {
|
) -> Result<LeafDef, ErrorGuaranteed> {
|
||||||
let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id;
|
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
|
||||||
let trait_def = tcx.trait_def(trait_def_id);
|
let trait_def = tcx.trait_def(trait_def_id);
|
||||||
|
|
||||||
// This function may be called while we are still building the
|
// This function may be called while we are still building the
|
||||||
|
|
|
@ -309,7 +309,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
|
let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
|
||||||
let binders = binders_for(self.interner, bound_vars);
|
let binders = binders_for(self.interner, bound_vars);
|
||||||
|
|
||||||
let trait_ref = self.interner.tcx.bound_impl_trait_ref(def_id).expect("not an impl");
|
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
|
||||||
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
|
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
|
||||||
|
|
||||||
let where_clauses = self.where_clauses_for(def_id, bound_vars);
|
let where_clauses = self.where_clauses_for(def_id, bound_vars);
|
||||||
|
@ -351,7 +351,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
let all_impls = self.interner.tcx.all_impls(def_id);
|
let all_impls = self.interner.tcx.all_impls(def_id);
|
||||||
let matched_impls = all_impls.filter(|impl_def_id| {
|
let matched_impls = all_impls.filter(|impl_def_id| {
|
||||||
use chalk_ir::could_match::CouldMatch;
|
use chalk_ir::could_match::CouldMatch;
|
||||||
let trait_ref = self.interner.tcx.bound_impl_trait_ref(*impl_def_id).unwrap();
|
let trait_ref = self.interner.tcx.impl_trait_ref(*impl_def_id).unwrap();
|
||||||
let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id);
|
let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id);
|
||||||
|
|
||||||
let self_ty = trait_ref.map_bound(|t| t.self_ty());
|
let self_ty = trait_ref.map_bound(|t| t.self_ty());
|
||||||
|
@ -380,7 +380,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||||
let trait_def_id = auto_trait_id.0;
|
let trait_def_id = auto_trait_id.0;
|
||||||
let all_impls = self.interner.tcx.all_impls(trait_def_id);
|
let all_impls = self.interner.tcx.all_impls(trait_def_id);
|
||||||
for impl_def_id in all_impls {
|
for impl_def_id in all_impls {
|
||||||
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
|
||||||
let self_ty = trait_ref.self_ty();
|
let self_ty = trait_ref.self_ty();
|
||||||
let provides = match (self_ty.kind(), chalk_ty) {
|
let provides = match (self_ty.kind(), chalk_ty) {
|
||||||
(&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did() == id.0.did(),
|
(&ty::Adt(impl_adt_def, ..), Adt(id, ..)) => impl_adt_def.did() == id.0.did(),
|
||||||
|
|
|
@ -21,14 +21,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
|
||||||
assumed_wf_types.extend(liberated_sig.inputs_and_output);
|
assumed_wf_types.extend(liberated_sig.inputs_and_output);
|
||||||
tcx.intern_type_list(&assumed_wf_types)
|
tcx.intern_type_list(&assumed_wf_types)
|
||||||
}
|
}
|
||||||
DefKind::Impl => match tcx.impl_trait_ref(def_id) {
|
DefKind::Impl => {
|
||||||
Some(trait_ref) => {
|
match tcx.impl_trait_ref(def_id) {
|
||||||
let types: Vec<_> = trait_ref.substs.types().collect();
|
Some(trait_ref) => {
|
||||||
tcx.intern_type_list(&types)
|
let types: Vec<_> = trait_ref.skip_binder().substs.types().collect();
|
||||||
|
tcx.intern_type_list(&types)
|
||||||
|
}
|
||||||
|
// Only the impl self type
|
||||||
|
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
|
||||||
}
|
}
|
||||||
// Only the impl self type
|
}
|
||||||
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
|
|
||||||
},
|
|
||||||
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
|
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
|
||||||
DefKind::Mod
|
DefKind::Mod
|
||||||
| DefKind::Struct
|
| DefKind::Struct
|
||||||
|
|
|
@ -289,7 +289,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica
|
||||||
// In a trait impl, we assume that the header trait ref and all its
|
// In a trait impl, we assume that the header trait ref and all its
|
||||||
// constituents are well-formed.
|
// constituents are well-formed.
|
||||||
NodeKind::TraitImpl => {
|
NodeKind::TraitImpl => {
|
||||||
let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl");
|
let trait_ref = tcx.impl_trait_ref(def_id).expect("not an impl").subst_identity();
|
||||||
|
|
||||||
// FIXME(chalk): this has problems because of late-bound regions
|
// FIXME(chalk): this has problems because of late-bound regions
|
||||||
//inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk()));
|
//inputs.extend(trait_ref.substs.iter().flat_map(|arg| arg.walk()));
|
||||||
|
@ -360,7 +360,8 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Ty<'_>> {
|
||||||
|
|
||||||
let trait_ref = tcx
|
let trait_ref = tcx
|
||||||
.impl_trait_ref(def_id)
|
.impl_trait_ref(def_id)
|
||||||
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
|
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id))
|
||||||
|
.skip_binder();
|
||||||
|
|
||||||
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);
|
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
|
||||||
trait_def_id,
|
trait_def_id,
|
||||||
impl_def_id
|
impl_def_id
|
||||||
);
|
);
|
||||||
let trait_ref = cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
|
let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||||
if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) {
|
if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,7 @@ pub(crate) fn build_impl(
|
||||||
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl");
|
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_impl");
|
||||||
|
|
||||||
let tcx = cx.tcx;
|
let tcx = cx.tcx;
|
||||||
let associated_trait = tcx.impl_trait_ref(did);
|
let associated_trait = tcx.impl_trait_ref(did).map(ty::EarlyBinder::skip_binder);
|
||||||
|
|
||||||
// Only inline impl if the implemented trait is
|
// Only inline impl if the implemented trait is
|
||||||
// reachable in rustdoc generated documentation
|
// reachable in rustdoc generated documentation
|
||||||
|
|
|
@ -506,7 +506,9 @@ fn clean_generic_param_def<'tcx>(
|
||||||
Some(def.def_id),
|
Some(def.def_id),
|
||||||
)),
|
)),
|
||||||
default: match has_default {
|
default: match has_default {
|
||||||
true => Some(Box::new(cx.tcx.const_param_default(def.def_id).to_string())),
|
true => Some(Box::new(
|
||||||
|
cx.tcx.const_param_default(def.def_id).subst_identity().to_string(),
|
||||||
|
)),
|
||||||
false => None,
|
false => None,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -786,7 +786,7 @@ fn trait_impls_for<'a>(
|
||||||
tcx.find_map_relevant_impl(trait_, ty, |impl_| {
|
tcx.find_map_relevant_impl(trait_, ty, |impl_| {
|
||||||
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
|
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
|
||||||
// Check if these are the same type.
|
// Check if these are the same type.
|
||||||
let impl_type = trait_ref.self_ty();
|
let impl_type = trait_ref.skip_binder().self_ty();
|
||||||
trace!(
|
trace!(
|
||||||
"comparing type {} with kind {:?} against type {:?}",
|
"comparing type {} with kind {:?} against type {:?}",
|
||||||
impl_type,
|
impl_type,
|
||||||
|
|
|
@ -251,7 +251,7 @@ fn check_hash_peq<'tcx>(
|
||||||
|
|
||||||
// Only care about `impl PartialEq<Foo> for Foo`
|
// Only care about `impl PartialEq<Foo> for Foo`
|
||||||
// For `impl PartialEq<B> for A, input_types is [A, B]
|
// For `impl PartialEq<B> for A, input_types is [A, B]
|
||||||
if trait_ref.substs.type_at(1) == ty {
|
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
DERIVED_HASH_WITH_MANUAL_EQ,
|
DERIVED_HASH_WITH_MANUAL_EQ,
|
||||||
|
@ -299,7 +299,7 @@ fn check_ord_partial_ord<'tcx>(
|
||||||
|
|
||||||
// Only care about `impl PartialOrd<Foo> for Foo`
|
// Only care about `impl PartialOrd<Foo> for Foo`
|
||||||
// For `impl PartialOrd<B> for A, input_types is [A, B]
|
// For `impl PartialOrd<B> for A, input_types is [A, B]
|
||||||
if trait_ref.substs.type_at(1) == ty {
|
if trait_ref.subst_identity().substs.type_at(1) == ty {
|
||||||
let mess = if partial_ord_is_automatically_derived {
|
let mess = if partial_ord_is_automatically_derived {
|
||||||
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
|
"you are implementing `Ord` explicitly but have derived `PartialOrd`"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||||
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
||||||
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
|
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.skip_binder().def_id);
|
||||||
then {
|
then {
|
||||||
lint_impl_body(cx, item.span, impl_.items);
|
lint_impl_body(cx, item.span, impl_.items);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||||
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
|
&& let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
|
||||||
// `impl Into<target_ty> for self_ty`
|
// `impl Into<target_ty> for self_ty`
|
||||||
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
||||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity)
|
||||||
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
||||||
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
|
||||||
let container_id = assoc_item.container_id(cx.tcx);
|
let container_id = assoc_item.container_id(cx.tcx);
|
||||||
let trait_def_id = match assoc_item.container {
|
let trait_def_id = match assoc_item.container {
|
||||||
TraitContainer => Some(container_id),
|
TraitContainer => Some(container_id),
|
||||||
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
|
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.skip_binder().def_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(trait_def_id) = trait_def_id {
|
if let Some(trait_def_id) = trait_def_id {
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
|
||||||
if send_trait == trait_id;
|
if send_trait == trait_id;
|
||||||
if hir_impl.polarity == ImplPolarity::Positive;
|
if hir_impl.polarity == ImplPolarity::Positive;
|
||||||
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
|
||||||
if let self_ty = ty_trait_ref.self_ty();
|
if let self_ty = ty_trait_ref.subst_identity().self_ty();
|
||||||
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
|
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
|
||||||
then {
|
then {
|
||||||
let mut non_send_fields = Vec::new();
|
let mut non_send_fields = Vec::new();
|
||||||
|
|
|
@ -244,7 +244,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||||
})) => {
|
})) => {
|
||||||
#[allow(trivial_casts)]
|
#[allow(trivial_casts)]
|
||||||
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
|
if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
|
||||||
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
&& let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity())
|
||||||
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
|
&& let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
|
||||||
{
|
{
|
||||||
(
|
(
|
||||||
|
|
|
@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
|
||||||
then {
|
then {
|
||||||
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
|
// `self_ty` is the semantic self type of `impl <trait> for <type>`. This cannot be
|
||||||
// `Self`.
|
// `Self`.
|
||||||
let self_ty = impl_trait_ref.self_ty();
|
let self_ty = impl_trait_ref.subst_identity().self_ty();
|
||||||
|
|
||||||
// `trait_method_sig` is the signature of the function, how it is declared in the
|
// `trait_method_sig` is the signature of the function, how it is declared in the
|
||||||
// trait, not in the impl of the trait.
|
// trait, not in the impl of the trait.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue