summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_typeck/src/method
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_hir_typeck/src/method
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_hir_typeck/src/method')
-rw-r--r--compiler/rustc_hir_typeck/src/method/confirm.rs60
-rw-r--r--compiler/rustc_hir_typeck/src/method/mod.rs35
-rw-r--r--compiler/rustc_hir_typeck/src/method/probe.rs55
-rw-r--r--compiler/rustc_hir_typeck/src/method/suggest.rs60
4 files changed, 135 insertions, 75 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs
index 98529b666..87edb8031 100644
--- a/compiler/rustc_hir_typeck/src/method/confirm.rs
+++ b/compiler/rustc_hir_typeck/src/method/confirm.rs
@@ -10,7 +10,7 @@ use rustc_hir_analysis::astconv::generics::{
use rustc_hir_analysis::astconv::{AstConv, CreateSubstsForGenericArgsCtxt, IsMethodCall};
use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk};
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
-use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
+use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{self, SubstsRef};
@@ -26,6 +26,7 @@ struct ConfirmContext<'a, 'tcx> {
span: Span,
self_expr: &'tcx hir::Expr<'tcx>,
call_expr: &'tcx hir::Expr<'tcx>,
+ skip_record_for_diagnostics: bool,
}
impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
@@ -59,6 +60,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr);
confirm_cx.confirm(unadjusted_self_ty, pick, segment)
}
+
+ pub fn confirm_method_for_diagnostic(
+ &self,
+ span: Span,
+ self_expr: &'tcx hir::Expr<'tcx>,
+ call_expr: &'tcx hir::Expr<'tcx>,
+ unadjusted_self_ty: Ty<'tcx>,
+ pick: &probe::Pick<'tcx>,
+ segment: &hir::PathSegment<'_>,
+ ) -> ConfirmResult<'tcx> {
+ let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr);
+ confirm_cx.skip_record_for_diagnostics = true;
+ confirm_cx.confirm(unadjusted_self_ty, pick, segment)
+ }
}
impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
@@ -68,7 +83,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
self_expr: &'tcx hir::Expr<'tcx>,
call_expr: &'tcx hir::Expr<'tcx>,
) -> ConfirmContext<'a, 'tcx> {
- ConfirmContext { fcx, span, self_expr, call_expr }
+ ConfirmContext { fcx, span, self_expr, call_expr, skip_record_for_diagnostics: false }
}
fn confirm(
@@ -128,7 +143,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// a custom error in that case.
if illegal_sized_bound.is_none() {
self.add_obligations(
- self.tcx.mk_fn_ptr(method_sig),
+ Ty::new_fn_ptr(self.tcx, method_sig),
all_substs,
method_predicates,
pick.item.def_id,
@@ -156,7 +171,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// time writing the results into the various typeck results.
let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
- return self.tcx.ty_error_with_message(
+ return Ty::new_error_with_message(self.tcx,
rustc_span::DUMMY_SP,
format!("failed autoderef {}", pick.autoderefs),
);
@@ -164,7 +179,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
assert_eq!(n, pick.autoderefs);
let mut adjustments = self.adjust_steps(&autoderef);
- let mut target = self.structurally_resolved_type(autoderef.span(), ty);
+ let mut target = self.structurally_resolve_type(autoderef.span(), ty);
match pick.autoref_or_ptr_adjustment {
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
@@ -172,7 +187,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// Type we're wrapping in a reference, used later for unsizing
let base_ty = target;
- target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl, ty: target });
+ target = Ty::new_ref(self.tcx, region, ty::TypeAndMut { mutbl, ty: target });
// Method call receivers are the primary use case
// for two-phase borrows.
@@ -185,31 +200,35 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
if unsize {
let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
- self.tcx.mk_slice(*elem_ty)
+ Ty::new_slice(self.tcx, *elem_ty)
} else {
bug!(
"AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}",
base_ty
)
};
- target = self
- .tcx
- .mk_ref(region, ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty });
- adjustments
- .push(Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target });
+ target = Ty::new_ref(
+ self.tcx,
+ region,
+ ty::TypeAndMut { mutbl: mutbl.into(), ty: unsized_ty },
+ );
+ adjustments.push(Adjustment {
+ kind: Adjust::Pointer(PointerCoercion::Unsize),
+ target,
+ });
}
}
Some(probe::AutorefOrPtrAdjustment::ToConstPtr) => {
target = match target.kind() {
&ty::RawPtr(ty::TypeAndMut { ty, mutbl }) => {
assert!(mutbl.is_mut());
- self.tcx.mk_ptr(ty::TypeAndMut { mutbl: hir::Mutability::Not, ty })
+ Ty::new_ptr(self.tcx, ty::TypeAndMut { mutbl: hir::Mutability::Not, ty })
}
other => panic!("Cannot adjust receiver type {:?} to const ptr", other),
};
adjustments.push(Adjustment {
- kind: Adjust::Pointer(PointerCast::MutToConstPointer),
+ kind: Adjust::Pointer(PointerCoercion::MutToConstPointer),
target,
});
}
@@ -219,7 +238,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
self.register_predicates(autoderef.into_obligations());
// Write out the final adjustments.
- self.apply_adjustments(self.self_expr, adjustments);
+ if !self.skip_record_for_diagnostics {
+ self.apply_adjustments(self.self_expr, adjustments);
+ }
target
}
@@ -453,7 +474,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
});
debug!("instantiate_method_substs: user_type_annotation={:?}", user_type_annotation);
- self.fcx.write_user_type_annotation(self.call_expr.hir_id, user_type_annotation);
+
+ if !self.skip_record_for_diagnostics {
+ self.fcx.write_user_type_annotation(self.call_expr.hir_id, user_type_annotation);
+ }
}
self.normalize(self.span, substs)
@@ -586,9 +610,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
traits::elaborate(self.tcx, predicates.predicates.iter().copied())
// We don't care about regions here.
.filter_map(|pred| match pred.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
- if trait_pred.def_id() == sized_def_id =>
- {
+ ty::ClauseKind::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => {
let span = predicates
.iter()
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs
index 6f4d674ba..e52cea188 100644
--- a/compiler/rustc_hir_typeck/src/method/mod.rs
+++ b/compiler/rustc_hir_typeck/src/method/mod.rs
@@ -205,9 +205,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(span) = result.illegal_sized_bound {
let mut needs_mut = false;
if let ty::Ref(region, t_type, mutability) = self_ty.kind() {
- let trait_type = self
- .tcx
- .mk_ref(*region, ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() });
+ let trait_type = Ty::new_ref(
+ self.tcx,
+ *region,
+ ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
+ );
// We probe again to see if there might be a borrow mutability discrepancy.
match self.lookup_probe(
segment.ident,
@@ -254,6 +256,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(result.callee)
}
+ pub fn lookup_method_for_diagnostic(
+ &self,
+ self_ty: Ty<'tcx>,
+ segment: &hir::PathSegment<'_>,
+ span: Span,
+ call_expr: &'tcx hir::Expr<'tcx>,
+ self_expr: &'tcx hir::Expr<'tcx>,
+ ) -> Result<MethodCallee<'tcx>, MethodError<'tcx>> {
+ let pick = self.lookup_probe_for_diagnostic(
+ segment.ident,
+ self_ty,
+ call_expr,
+ ProbeScope::TraitsInScope,
+ None,
+ )?;
+
+ Ok(self
+ .confirm_method_for_diagnostic(span, self_expr, call_expr, self_ty, &pick, segment)
+ .callee)
+ }
+
#[instrument(level = "debug", skip(self, call_expr))]
pub fn lookup_probe(
&self,
@@ -443,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
));
// Also add an obligation for the method type being well-formed.
- let method_ty = tcx.mk_fn_ptr(ty::Binder::dummy(fn_sig));
+ let method_ty = Ty::new_fn_ptr(tcx, ty::Binder::dummy(fn_sig));
debug!(
"lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}",
method_ty, obligation
@@ -452,7 +475,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
tcx,
obligation.cause,
self.param_env,
- ty::Binder::dummy(ty::PredicateKind::WellFormed(method_ty.into())),
+ ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
+ method_ty.into(),
+ ))),
));
let callee = MethodCallee { def_id, substs, sig: fn_sig };
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs
index 9f3d35a77..03a3eebbd 100644
--- a/compiler/rustc_hir_typeck/src/method/probe.rs
+++ b/compiler/rustc_hir_typeck/src/method/probe.rs
@@ -9,10 +9,10 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
-use rustc_hir_analysis::astconv::InferCtxtExt as _;
use rustc_hir_analysis::autoderef::{self, Autoderef};
use rustc_infer::infer::canonical::OriginalQueryValues;
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
+use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
use rustc_infer::infer::DefineOpaqueTypes;
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
use rustc_middle::middle::stability;
@@ -449,15 +449,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}
} else {
- // Encountered a real ambiguity, so abort the lookup. If `ty` is not
- // an `Err`, report the right "type annotations needed" error pointing
- // to it.
+ // Ended up encountering a type variable when doing autoderef,
+ // but it may not be a type variable after processing obligations
+ // in our local `FnCtxt`, so don't call `structurally_resolve_type`.
let ty = &bad_ty.ty;
let ty = self
.probe_instantiate_query_response(span, &orig_values, ty)
.unwrap_or_else(|_| span_bug!(span, "instantiating {:?} failed?", ty));
- let ty = self.structurally_resolved_type(span, ty.value);
- assert!(matches!(ty.kind(), ty::Error(_)));
+ let ty = self.resolve_vars_if_possible(ty.value);
+ let guar = match *ty.kind() {
+ ty::Infer(ty::TyVar(_)) => self
+ .err_ctxt()
+ .emit_inference_failure_err(self.body_id, span, ty.into(), E0282, true)
+ .emit(),
+ ty::Error(guar) => guar,
+ _ => bug!("unexpected bad final type in method autoderef"),
+ };
+ self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: Vec::new(),
unsatisfied_predicates: Vec::new(),
@@ -543,7 +551,7 @@ fn method_autoderef_steps<'tcx>(
steps.push(CandidateStep {
self_ty: infcx.make_query_response_ignoring_pending_obligations(
inference_vars,
- infcx.tcx.mk_slice(*elem_ty),
+ Ty::new_slice(infcx.tcx, *elem_ty),
),
autoderefs: dereferences,
// this could be from an unsafe deref if we had
@@ -826,7 +834,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => {
+ ty::ClauseKind::Trait(trait_predicate) => {
match *trait_predicate.trait_ref.self_ty().kind() {
ty::Param(p) if p == param_ty => {
Some(bound_predicate.rebind(trait_predicate.trait_ref))
@@ -834,20 +842,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
_ => None,
}
}
- ty::PredicateKind::Subtype(..)
- | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
- | ty::PredicateKind::Coerce(..)
- | ty::PredicateKind::Clause(ty::Clause::Projection(..))
- | ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
- | ty::PredicateKind::WellFormed(..)
- | ty::PredicateKind::ObjectSafe(..)
- | ty::PredicateKind::ClosureKind(..)
- | ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
- | ty::PredicateKind::ConstEvaluatable(..)
- | ty::PredicateKind::ConstEquate(..)
- | ty::PredicateKind::Ambiguous
- | ty::PredicateKind::AliasRelate(..)
- | ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
+ ty::ClauseKind::RegionOutlives(_)
+ | ty::ClauseKind::TypeOutlives(_)
+ | ty::ClauseKind::Projection(_)
+ | ty::ClauseKind::ConstArgHasType(_, _)
+ | ty::ClauseKind::WellFormed(_)
+ | ty::ClauseKind::ConstEvaluatable(_) => None,
}
});
@@ -954,7 +954,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
trait_def_id: DefId,
) {
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_substs_for_item(self.span, trait_def_id);
let trait_ref = ty::TraitRef::new(self.tcx, trait_def_id, trait_substs);
if self.tcx.is_trait_alias(trait_def_id) {
@@ -1215,7 +1215,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// In general, during probing we erase regions.
let region = tcx.lifetimes.re_erased;
- let autoref_ty = tcx.mk_ref(region, ty::TypeAndMut { ty: self_ty, mutbl });
+ let autoref_ty = Ty::new_ref(tcx, region, ty::TypeAndMut { ty: self_ty, mutbl });
self.pick_method(autoref_ty, unstable_candidates).map(|r| {
r.map(|mut pick| {
pick.autoderefs = step.autoderefs;
@@ -1245,7 +1245,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
};
let const_self_ty = ty::TypeAndMut { ty, mutbl: hir::Mutability::Not };
- let const_ptr_ty = self.tcx.mk_ptr(const_self_ty);
+ let const_ptr_ty = Ty::new_ptr(self.tcx, const_self_ty);
self.pick_method(const_ptr_ty, unstable_candidates).map(|r| {
r.map(|mut pick| {
pick.autoderefs = step.autoderefs;
@@ -1441,8 +1441,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
trait_ref: ty::TraitRef<'tcx>,
) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
let cause = traits::ObligationCause::misc(self.span, self.body_id);
- let predicate = ty::Binder::dummy(trait_ref);
- let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, predicate);
+ let obligation = traits::Obligation::new(self.tcx, cause, self.param_env, trait_ref);
traits::SelectionContext::new(self).select(&obligation)
}
@@ -1899,7 +1898,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
&self,
impl_def_id: DefId,
) -> (ty::EarlyBinder<Ty<'tcx>>, SubstsRef<'tcx>) {
- (self.tcx.type_of(impl_def_id), self.fresh_item_substs(impl_def_id))
+ (self.tcx.type_of(impl_def_id), self.fresh_substs_for_item(self.span, impl_def_id))
}
/// Replaces late-bound-regions bound by `value` with `'static` using
diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs
index e04cc44b5..5f924f309 100644
--- a/compiler/rustc_hir_typeck/src/method/suggest.rs
+++ b/compiler/rustc_hir_typeck/src/method/suggest.rs
@@ -211,7 +211,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() {
if needs_mut {
- let trait_type = self.tcx.mk_ref(
+ let trait_type = Ty::new_ref(
+ self.tcx,
*region,
ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() },
);
@@ -473,6 +474,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut custom_span_label = false;
let static_candidates = &mut no_match_data.static_candidates;
+
+ // `static_candidates` may have same candidates appended by
+ // inherent and extension, which may result in incorrect
+ // diagnostic.
+ static_candidates.dedup();
+
if !static_candidates.is_empty() {
err.note(
"found the following associated functions; to be used as methods, \
@@ -536,7 +543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut unimplemented_traits = FxHashMap::default();
let mut unimplemented_traits_only = true;
for (predicate, _parent_pred, cause) in unsatisfied_predicates {
- if let (ty::PredicateKind::Clause(ty::Clause::Trait(p)), Some(cause)) =
+ if let (ty::PredicateKind::Clause(ty::ClauseKind::Trait(p)), Some(cause)) =
(predicate.kind().skip_binder(), cause.as_ref())
{
if p.trait_ref.self_ty() != rcvr_ty {
@@ -563,7 +570,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// because of some non-Clone item being iterated over.
for (predicate, _parent_pred, _cause) in unsatisfied_predicates {
match predicate.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(p))
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(p))
if unimplemented_traits.contains_key(&p.trait_ref.def_id) => {}
_ => {
unimplemented_traits_only = false;
@@ -575,7 +582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut collect_type_param_suggestions =
|self_ty: Ty<'tcx>, parent_pred: ty::Predicate<'tcx>, obligation: &str| {
// We don't care about regions here, so it's fine to skip the binder here.
- if let (ty::Param(_), ty::PredicateKind::Clause(ty::Clause::Trait(p))) =
+ if let (ty::Param(_), ty::PredicateKind::Clause(ty::ClauseKind::Trait(p))) =
(self_ty.kind(), parent_pred.kind().skip_binder())
{
let hir = self.tcx.hir();
@@ -635,13 +642,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut format_pred = |pred: ty::Predicate<'tcx>| {
let bound_predicate = pred.kind();
match bound_predicate.skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
+ ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
let pred = bound_predicate.rebind(pred);
// `<Foo as Iterator>::Item = String`.
let projection_ty = pred.skip_binder().projection_ty;
let substs_with_infer_self = tcx.mk_substs_from_iter(
- iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into())
+ iter::once(Ty::new_var(tcx, ty::TyVid::from_u32(0)).into())
.chain(projection_ty.substs.iter().skip(1)),
);
@@ -659,7 +666,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
Some((obligation, projection_ty.self_ty()))
}
- ty::PredicateKind::Clause(ty::Clause::Trait(poly_trait_ref)) => {
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(poly_trait_ref)) => {
let p = poly_trait_ref.trait_ref;
let self_ty = p.self_ty();
let path = p.print_only_trait_path();
@@ -690,7 +697,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
// Don't point out the span of `WellFormed` predicates.
- if !matches!(p.kind().skip_binder(), ty::PredicateKind::Clause(_)) {
+ if !matches!(
+ p.kind().skip_binder(),
+ ty::PredicateKind::Clause(
+ ty::ClauseKind::Projection(..) | ty::ClauseKind::Trait(..)
+ )
+ ) {
continue;
};
@@ -731,7 +743,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let sized_pred =
unsatisfied_predicates.iter().any(|(pred, _, _)| {
match pred.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
Some(pred.def_id()) == self.tcx.lang_items().sized_trait()
&& pred.polarity == ty::ImplPolarity::Positive
}
@@ -2003,16 +2015,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
let all_local_types_needing_impls =
errors.iter().all(|e| match e.obligation.predicate.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => match pred.self_ty().kind() {
- ty::Adt(def, _) => def.did().is_local(),
- _ => false,
- },
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
+ match pred.self_ty().kind() {
+ ty::Adt(def, _) => def.did().is_local(),
+ _ => false,
+ }
+ }
_ => false,
});
let mut preds: Vec<_> = errors
.iter()
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => Some(pred),
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => Some(pred),
_ => None,
})
.collect();
@@ -2083,7 +2097,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut derives = Vec::<(String, Span, Symbol)>::new();
let mut traits = Vec::new();
for (pred, _, _) in unsatisfied_predicates {
- let Some(ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))) =
+ let Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))) =
pred.kind().no_bound_vars()
else {
continue
@@ -2395,8 +2409,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// just this list.
for (rcvr_ty, post) in &[
(rcvr_ty, ""),
- (self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "),
- (self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"),
+ (Ty::new_mut_ref(self.tcx, self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "),
+ (Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, rcvr_ty), "&"),
] {
match self.lookup_probe_for_diagnostic(
item_name,
@@ -2431,10 +2445,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
for (rcvr_ty, pre) in &[
- (self.tcx.mk_lang_item(*rcvr_ty, LangItem::OwnedBox), "Box::new"),
- (self.tcx.mk_lang_item(*rcvr_ty, LangItem::Pin), "Pin::new"),
- (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"),
- (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"),
+ (Ty::new_lang_item(self.tcx, *rcvr_ty, LangItem::OwnedBox), "Box::new"),
+ (Ty::new_lang_item(self.tcx, *rcvr_ty, LangItem::Pin), "Pin::new"),
+ (Ty::new_diagnostic_item(self.tcx, *rcvr_ty, sym::Arc), "Arc::new"),
+ (Ty::new_diagnostic_item(self.tcx, *rcvr_ty, sym::Rc), "Rc::new"),
] {
if let Some(new_rcvr_t) = *rcvr_ty
&& let Ok(pick) = self.lookup_probe_for_diagnostic(
@@ -2518,10 +2532,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match p.kind().skip_binder() {
// Hide traits if they are present in predicates as they can be fixed without
// having to implement them.
- ty::PredicateKind::Clause(ty::Clause::Trait(t)) => {
+ ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
t.def_id() == info.def_id
}
- ty::PredicateKind::Clause(ty::Clause::Projection(p)) => {
+ ty::PredicateKind::Clause(ty::ClauseKind::Projection(p)) => {
p.projection_ty.def_id == info.def_id
}
_ => false,