1use std::fmt::Debug;
2use std::ops::Deref;
3
4use rustc_hir as hir;
5use rustc_hir::GenericArg;
6use rustc_hir::def_id::DefId;
7use rustc_hir_analysis::hir_ty_lowering::generics::{
8 check_generic_arg_count_for_value_path, lower_generic_args,
9};
10use rustc_hir_analysis::hir_ty_lowering::{
11 GenericArgsLowerer, HirTyLowerer, IsMethodCall, RegionInferReason,
12};
13use rustc_infer::infer::{
14 BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin,
15};
16use rustc_lint::builtin::{
17 AMBIGUOUS_GLOB_IMPORTED_TRAITS, RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
18};
19use rustc_middle::traits::ObligationCauseCode;
20use rustc_middle::ty::adjustment::{
21 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
22 PointerCoercion,
23};
24use rustc_middle::ty::{
25 self, AssocContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt,
26 TypeFoldable, TypeVisitableExt, UserArgs,
27};
28use rustc_middle::{bug, span_bug};
29use rustc_span::{DUMMY_SP, Span};
30use rustc_trait_selection::traits;
31use tracing::debug;
32
33use super::{MethodCallee, probe};
34use crate::errors::{SupertraitItemShadowee, SupertraitItemShadower, SupertraitItemShadowing};
35use crate::{FnCtxt, callee};
36
37struct ConfirmContext<'a, 'tcx> {
38 fcx: &'a FnCtxt<'a, 'tcx>,
39 span: Span,
40 self_expr: &'tcx hir::Expr<'tcx>,
41 call_expr: &'tcx hir::Expr<'tcx>,
42 skip_record_for_diagnostics: bool,
43}
44
45impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> {
46 type Target = FnCtxt<'a, 'tcx>;
47 fn deref(&self) -> &Self::Target {
48 self.fcx
49 }
50}
51
52#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ConfirmResult<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "ConfirmResult",
"callee", &self.callee, "illegal_sized_bound",
&&self.illegal_sized_bound)
}
}Debug)]
53pub(crate) struct ConfirmResult<'tcx> {
54 pub callee: MethodCallee<'tcx>,
55 pub illegal_sized_bound: Option<Span>,
56}
57
58impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
59 pub(crate) fn confirm_method(
60 &self,
61 span: Span,
62 self_expr: &'tcx hir::Expr<'tcx>,
63 call_expr: &'tcx hir::Expr<'tcx>,
64 unadjusted_self_ty: Ty<'tcx>,
65 pick: &probe::Pick<'tcx>,
66 segment: &'tcx hir::PathSegment<'tcx>,
67 ) -> ConfirmResult<'tcx> {
68 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:68",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(68u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("confirm(unadjusted_self_ty={0:?}, pick={1:?}, generic_args={2:?})",
unadjusted_self_ty, pick, segment.args) as &dyn Value))])
});
} else { ; }
};debug!(
69 "confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})",
70 unadjusted_self_ty, pick, segment.args,
71 );
72
73 let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr);
74 confirm_cx.confirm(unadjusted_self_ty, pick, segment)
75 }
76
77 pub(crate) fn confirm_method_for_diagnostic(
78 &self,
79 span: Span,
80 self_expr: &'tcx hir::Expr<'tcx>,
81 call_expr: &'tcx hir::Expr<'tcx>,
82 unadjusted_self_ty: Ty<'tcx>,
83 pick: &probe::Pick<'tcx>,
84 segment: &hir::PathSegment<'tcx>,
85 ) -> ConfirmResult<'tcx> {
86 let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr);
87 confirm_cx.skip_record_for_diagnostics = true;
88 confirm_cx.confirm(unadjusted_self_ty, pick, segment)
89 }
90}
91
92impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
93 fn new(
94 fcx: &'a FnCtxt<'a, 'tcx>,
95 span: Span,
96 self_expr: &'tcx hir::Expr<'tcx>,
97 call_expr: &'tcx hir::Expr<'tcx>,
98 ) -> ConfirmContext<'a, 'tcx> {
99 ConfirmContext { fcx, span, self_expr, call_expr, skip_record_for_diagnostics: false }
100 }
101
102 fn confirm(
103 &mut self,
104 unadjusted_self_ty: Ty<'tcx>,
105 pick: &probe::Pick<'tcx>,
106 segment: &hir::PathSegment<'tcx>,
107 ) -> ConfirmResult<'tcx> {
108 let self_ty = self.adjust_self_ty(unadjusted_self_ty, pick);
110
111 let rcvr_args = self.fresh_receiver_args(self_ty, pick);
113 let all_args = self.instantiate_method_args(pick, segment, rcvr_args);
114
115 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:115",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(115u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("rcvr_args={0:?}, all_args={1:?}",
rcvr_args, all_args) as &dyn Value))])
});
} else { ; }
};debug!("rcvr_args={rcvr_args:?}, all_args={all_args:?}");
116
117 let (method_sig, method_predicates) = self.instantiate_method_sig(pick, all_args);
119
120 let filler_args = rcvr_args
129 .extend_to(self.tcx, pick.item.def_id, |def, _| self.tcx.mk_param_from_def(def));
130 let illegal_sized_bound = self.predicates_require_illegal_sized_bound(
131 self.tcx.predicates_of(pick.item.def_id).instantiate(self.tcx, filler_args),
132 );
133
134 let method_sig_rcvr = self.normalize(self.span, method_sig.inputs()[0]);
141 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:141",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(141u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("confirm: self_ty={0:?} method_sig_rcvr={1:?} method_sig={2:?} method_predicates={3:?}",
self_ty, method_sig_rcvr, method_sig, method_predicates) as
&dyn Value))])
});
} else { ; }
};debug!(
142 "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?} method_predicates={:?}",
143 self_ty, method_sig_rcvr, method_sig, method_predicates
144 );
145 self.unify_receivers(self_ty, method_sig_rcvr, pick);
146
147 let method_sig = self.normalize(self.span, method_sig);
148
149 self.check_for_illegal_method_calls(pick);
151
152 self.lint_shadowed_supertrait_items(pick, segment);
154
155 self.lint_ambiguously_glob_imported_traits(pick, segment);
157
158 if illegal_sized_bound.is_none() {
162 self.add_obligations(method_sig, all_args, method_predicates, pick.item.def_id);
163 }
164
165 let callee = MethodCallee { def_id: pick.item.def_id, args: all_args, sig: method_sig };
167 ConfirmResult { callee, illegal_sized_bound }
168 }
169
170 fn adjust_self_ty(
174 &mut self,
175 unadjusted_self_ty: Ty<'tcx>,
176 pick: &probe::Pick<'tcx>,
177 ) -> Ty<'tcx> {
178 let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
181 let Some((mut target, n)) = autoderef.nth(pick.autoderefs) else {
182 return Ty::new_error_with_message(
183 self.tcx,
184 DUMMY_SP,
185 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("failed autoderef {0}",
pick.autoderefs))
})format!("failed autoderef {}", pick.autoderefs),
186 );
187 };
188 match (&n, &pick.autoderefs) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(n, pick.autoderefs);
189
190 let mut adjustments = self.adjust_steps(&autoderef);
191 match pick.autoref_or_ptr_adjustment {
192 Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
193 let region = self.next_region_var(RegionVariableOrigin::Autoref(self.span));
194 let base_ty = target;
196
197 target = Ty::new_ref(self.tcx, region, target, mutbl);
198
199 let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes);
202
203 adjustments
204 .push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), target });
205
206 if unsize {
207 let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() {
208 Ty::new_slice(self.tcx, *elem_ty)
209 } else {
210 ::rustc_middle::util::bug::bug_fmt(format_args!("AutorefOrPtrAdjustment\'s unsize flag should only be set for array ty, found {0}",
base_ty))bug!(
211 "AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}",
212 base_ty
213 )
214 };
215 target = Ty::new_ref(self.tcx, region, unsized_ty, mutbl.into());
216 adjustments.push(Adjustment {
217 kind: Adjust::Pointer(PointerCoercion::Unsize),
218 target,
219 });
220 }
221 }
222 Some(probe::AutorefOrPtrAdjustment::ToConstPtr) => {
223 target = match target.kind() {
224 &ty::RawPtr(ty, mutbl) => {
225 if !mutbl.is_mut() {
::core::panicking::panic("assertion failed: mutbl.is_mut()")
};assert!(mutbl.is_mut());
226 Ty::new_imm_ptr(self.tcx, ty)
227 }
228 other => {
::core::panicking::panic_fmt(format_args!("Cannot adjust receiver type {0:?} to const ptr",
other));
}panic!("Cannot adjust receiver type {other:?} to const ptr"),
229 };
230
231 adjustments.push(Adjustment {
232 kind: Adjust::Pointer(PointerCoercion::MutToConstPointer),
233 target,
234 });
235 }
236
237 Some(probe::AutorefOrPtrAdjustment::ReborrowPin(mutbl)) => {
238 let region = self.next_region_var(RegionVariableOrigin::Autoref(self.span));
239
240 target = match target.kind() {
241 ty::Adt(pin, args) if self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => {
242 let inner_ty = match args[0].expect_ty().kind() {
243 ty::Ref(_, ty, _) => *ty,
244 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("Expected a reference type for argument to Pin"))bug!("Expected a reference type for argument to Pin"),
245 };
246 adjustments.push(Adjustment {
247 kind: Adjust::Deref(DerefAdjustKind::Pin),
248 target: inner_ty,
249 });
250 Ty::new_pinned_ref(self.tcx, region, inner_ty, mutbl)
251 }
252 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("Cannot adjust receiver type for reborrowing pin of {0:?}",
target))bug!("Cannot adjust receiver type for reborrowing pin of {target:?}"),
253 };
254 adjustments
255 .push(Adjustment { kind: Adjust::Borrow(AutoBorrow::Pin(mutbl)), target });
256 }
257 None => {}
258 }
259
260 self.register_predicates(autoderef.into_obligations());
261
262 if !self.skip_record_for_diagnostics {
264 self.apply_adjustments(self.self_expr, adjustments);
265 }
266
267 target
268 }
269
270 fn fresh_receiver_args(
277 &mut self,
278 self_ty: Ty<'tcx>,
279 pick: &probe::Pick<'tcx>,
280 ) -> GenericArgsRef<'tcx> {
281 match pick.kind {
282 probe::InherentImplPick => {
283 let impl_def_id = pick.item.container_id(self.tcx);
284 if !#[allow(non_exhaustive_omitted_patterns)] match pick.item.container {
AssocContainer::InherentImpl => true,
_ => false,
} {
{
::core::panicking::panic_fmt(format_args!("impl {0:?} is not an inherent impl",
impl_def_id));
}
};assert!(
285 matches!(pick.item.container, AssocContainer::InherentImpl),
286 "impl {impl_def_id:?} is not an inherent impl"
287 );
288 self.fresh_args_for_item(self.span, impl_def_id)
289 }
290
291 probe::ObjectPick => {
292 let trait_def_id = pick.item.container_id(self.tcx);
293
294 if !self.tcx.is_dyn_compatible(trait_def_id) {
299 return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
300 }
301
302 if self_ty.references_error() {
309 return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
310 }
311
312 self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
313 let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty);
324 let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id);
325 let upcast_trait_ref =
326 this.instantiate_binder_with_fresh_vars(upcast_poly_trait_ref);
327 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:327",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(327u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("original_poly_trait_ref={0:?} upcast_trait_ref={1:?} target_trait={2:?}",
original_poly_trait_ref, upcast_trait_ref, trait_def_id) as
&dyn Value))])
});
} else { ; }
};debug!(
328 "original_poly_trait_ref={:?} upcast_trait_ref={:?} target_trait={:?}",
329 original_poly_trait_ref, upcast_trait_ref, trait_def_id
330 );
331 upcast_trait_ref.args
332 })
333 }
334
335 probe::TraitPick(_) => {
336 let trait_def_id = pick.item.container_id(self.tcx);
337
338 self.fresh_args_for_item(self.span, trait_def_id)
344 }
345
346 probe::WhereClausePick(poly_trait_ref) => {
347 self.instantiate_binder_with_fresh_vars(poly_trait_ref).args
350 }
351 }
352 }
353
354 fn extract_existential_trait_ref<R, F>(&mut self, self_ty: Ty<'tcx>, mut closure: F) -> R
355 where
356 F: FnMut(&mut ConfirmContext<'a, 'tcx>, Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>) -> R,
357 {
358 let mut autoderef = self.fcx.autoderef(self.span, self_ty);
364
365 if self.tcx.features().arbitrary_self_types()
368 || self.tcx.features().arbitrary_self_types_pointers()
369 {
370 autoderef = autoderef.use_receiver_trait();
371 }
372
373 autoderef
374 .include_raw_pointers()
375 .find_map(|(ty, _)| match ty.kind() {
376 ty::Dynamic(data, ..) => Some(closure(
377 self,
378 ty,
379 data.principal().unwrap_or_else(|| {
380 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("calling trait method on empty object?"))span_bug!(self.span, "calling trait method on empty object?")
381 }),
382 )),
383 _ => None,
384 })
385 .unwrap_or_else(|| {
386 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("self-type `{0}` for ObjectPick never dereferenced to an object",
self_ty))span_bug!(
387 self.span,
388 "self-type `{}` for ObjectPick never dereferenced to an object",
389 self_ty
390 )
391 })
392 }
393
394 fn instantiate_method_args(
395 &mut self,
396 pick: &probe::Pick<'tcx>,
397 seg: &hir::PathSegment<'tcx>,
398 parent_args: GenericArgsRef<'tcx>,
399 ) -> GenericArgsRef<'tcx> {
400 let generics = self.tcx.generics_of(pick.item.def_id);
404
405 let arg_count_correct = check_generic_arg_count_for_value_path(
406 self.fcx,
407 pick.item.def_id,
408 generics,
409 seg,
410 IsMethodCall::Yes,
411 );
412
413 match (&generics.parent_count, &parent_args.len()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(generics.parent_count, parent_args.len());
416
417 struct GenericArgsCtxt<'a, 'tcx> {
418 cfcx: &'a ConfirmContext<'a, 'tcx>,
419 pick: &'a probe::Pick<'tcx>,
420 seg: &'a hir::PathSegment<'tcx>,
421 }
422 impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
423 fn args_for_def_id(
424 &mut self,
425 def_id: DefId,
426 ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
427 if def_id == self.pick.item.def_id {
428 if let Some(data) = self.seg.args {
429 return (Some(data), false);
430 }
431 }
432 (None, false)
433 }
434
435 fn provided_kind(
436 &mut self,
437 preceding_args: &[ty::GenericArg<'tcx>],
438 param: &ty::GenericParamDef,
439 arg: &GenericArg<'tcx>,
440 ) -> ty::GenericArg<'tcx> {
441 match (¶m.kind, arg) {
442 (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => self
443 .cfcx
444 .fcx
445 .lowerer()
446 .lower_lifetime(lt, RegionInferReason::Param(param))
447 .into(),
448 (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
449 self.cfcx.lower_ty(ty.as_unambig_ty()).raw.into()
451 }
452 (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
453 self.cfcx.lower_ty(&inf.to_ty()).raw.into()
454 }
455 (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
456 .cfcx
457 .lower_const_arg(
459 ct.as_unambig_ct(),
460 self.cfcx
461 .tcx
462 .type_of(param.def_id)
463 .instantiate(self.cfcx.tcx, preceding_args),
464 )
465 .into(),
466 (GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
467 self.cfcx.ct_infer(Some(param), inf.span).into()
468 }
469 (kind, arg) => {
470 ::rustc_middle::util::bug::bug_fmt(format_args!("mismatched method arg kind {0:?} in turbofish: {1:?}",
kind, arg))bug!("mismatched method arg kind {kind:?} in turbofish: {arg:?}")
471 }
472 }
473 }
474
475 fn inferred_kind(
476 &mut self,
477 _preceding_args: &[ty::GenericArg<'tcx>],
478 param: &ty::GenericParamDef,
479 _infer_args: bool,
480 ) -> ty::GenericArg<'tcx> {
481 self.cfcx.var_for_def(self.cfcx.span, param)
482 }
483 }
484
485 let args = lower_generic_args(
486 self.fcx,
487 pick.item.def_id,
488 parent_args,
489 false,
490 None,
491 &arg_count_correct,
492 &mut GenericArgsCtxt { cfcx: self, pick, seg },
493 );
494
495 if !args.is_empty() && !generics.is_own_empty() {
510 let user_type_annotation = self.probe(|_| {
511 let user_args = UserArgs {
512 args: GenericArgs::for_item(self.tcx, pick.item.def_id, |param, _| {
513 let i = param.index as usize;
514 if i < generics.parent_count {
515 self.fcx.var_for_def(DUMMY_SP, param)
516 } else {
517 args[i]
518 }
519 }),
520 user_self_ty: None, };
522
523 self.fcx.canonicalize_user_type_annotation(ty::UserType::new(
524 ty::UserTypeKind::TypeOf(pick.item.def_id, user_args),
525 ))
526 });
527
528 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:528",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(528u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("instantiate_method_args: user_type_annotation={0:?}",
user_type_annotation) as &dyn Value))])
});
} else { ; }
};debug!("instantiate_method_args: user_type_annotation={:?}", user_type_annotation);
529
530 if !self.skip_record_for_diagnostics {
531 self.fcx.write_user_type_annotation(self.call_expr.hir_id, user_type_annotation);
532 }
533 }
534
535 self.normalize(self.span, args)
536 }
537
538 fn unify_receivers(
539 &mut self,
540 self_ty: Ty<'tcx>,
541 method_self_ty: Ty<'tcx>,
542 pick: &probe::Pick<'tcx>,
543 ) {
544 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:544",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(544u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("unify_receivers: self_ty={0:?} method_self_ty={1:?} span={2:?} pick={3:?}",
self_ty, method_self_ty, self.span, pick) as &dyn Value))])
});
} else { ; }
};debug!(
545 "unify_receivers: self_ty={:?} method_self_ty={:?} span={:?} pick={:?}",
546 self_ty, method_self_ty, self.span, pick
547 );
548 let cause = self.cause(self.self_expr.span, ObligationCauseCode::Misc);
549 match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
550 Ok(InferOk { obligations, value: () }) => {
551 self.register_predicates(obligations);
552 }
553 Err(terr) => {
554 if self.tcx.features().arbitrary_self_types() {
555 self.err_ctxt()
556 .report_mismatched_types(
557 &cause,
558 self.param_env,
559 method_self_ty,
560 self_ty,
561 terr,
562 )
563 .emit();
564 } else {
565 self.dcx().span_delayed_bug(
568 cause.span,
569 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} was a subtype of {1} but now is not?",
self_ty, method_self_ty))
})format!("{self_ty} was a subtype of {method_self_ty} but now is not?"),
570 );
571 }
572 }
573 }
574 }
575
576 fn instantiate_method_sig(
580 &mut self,
581 pick: &probe::Pick<'tcx>,
582 all_args: GenericArgsRef<'tcx>,
583 ) -> (ty::FnSig<'tcx>, ty::InstantiatedPredicates<'tcx>) {
584 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:584",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(584u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("instantiate_method_sig(pick={0:?}, all_args={1:?})",
pick, all_args) as &dyn Value))])
});
} else { ; }
};debug!("instantiate_method_sig(pick={:?}, all_args={:?})", pick, all_args);
585
586 let def_id = pick.item.def_id;
590 let method_predicates = self.tcx.predicates_of(def_id).instantiate(self.tcx, all_args);
591
592 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:592",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(592u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("method_predicates after instantiation = {0:?}",
method_predicates) as &dyn Value))])
});
} else { ; }
};debug!("method_predicates after instantiation = {:?}", method_predicates);
593
594 let sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, all_args);
595 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:595",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(595u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("type scheme instantiated, sig={0:?}",
sig) as &dyn Value))])
});
} else { ; }
};debug!("type scheme instantiated, sig={:?}", sig);
596
597 let sig = self.instantiate_binder_with_fresh_vars(sig);
598 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:598",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(598u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("late-bound lifetimes from method instantiated, sig={0:?}",
sig) as &dyn Value))])
});
} else { ; }
};debug!("late-bound lifetimes from method instantiated, sig={:?}", sig);
599
600 (sig, method_predicates)
601 }
602
603 fn add_obligations(
604 &mut self,
605 sig: ty::FnSig<'tcx>,
606 all_args: GenericArgsRef<'tcx>,
607 method_predicates: ty::InstantiatedPredicates<'tcx>,
608 def_id: DefId,
609 ) {
610 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/confirm.rs:610",
"rustc_hir_typeck::method::confirm",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/confirm.rs"),
::tracing_core::__macro_support::Option::Some(610u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::confirm"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("add_obligations: sig={0:?} all_args={1:?} method_predicates={2:?} def_id={3:?}",
sig, all_args, method_predicates, def_id) as &dyn Value))])
});
} else { ; }
};debug!(
611 "add_obligations: sig={:?} all_args={:?} method_predicates={:?} def_id={:?}",
612 sig, all_args, method_predicates, def_id
613 );
614
615 for obligation in traits::predicates_for_generics(
619 |idx, span| {
620 let code = ObligationCauseCode::WhereClauseInExpr(
621 def_id,
622 span,
623 self.call_expr.hir_id,
624 idx,
625 );
626 self.cause(self.span, code)
627 },
628 |pred| self.normalize(self.call_expr.span, pred),
629 self.param_env,
630 method_predicates,
631 ) {
632 self.register_predicate(obligation);
633 }
634
635 self.add_wf_bounds(all_args, self.call_expr.span);
638
639 for ty in sig.inputs_and_output {
643 self.register_wf_obligation(
644 ty.into(),
645 self.span,
646 ObligationCauseCode::WellFormed(None),
647 );
648 }
649 }
650
651 fn predicates_require_illegal_sized_bound(
655 &self,
656 predicates: ty::InstantiatedPredicates<'tcx>,
657 ) -> Option<Span> {
658 let sized_def_id = self.tcx.lang_items().sized_trait()?;
659
660 traits::elaborate(self.tcx, predicates.predicates.iter().copied())
661 .filter_map(|pred| match pred.kind().skip_binder() {
663 ty::ClauseKind::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => {
664 let span = predicates
665 .iter()
666 .find_map(|(p, span)| if p == pred { Some(span) } else { None })
667 .unwrap_or(DUMMY_SP);
668 Some((trait_pred, span))
669 }
670 _ => None,
671 })
672 .find_map(|(trait_pred, span)| match trait_pred.self_ty().kind() {
673 ty::Dynamic(..) => Some(span),
674 _ => None,
675 })
676 }
677
678 fn check_for_illegal_method_calls(&self, pick: &probe::Pick<'_>) {
679 if let Some(trait_def_id) = pick.item.trait_container(self.tcx)
681 && let Err(e) = callee::check_legal_trait_for_method_call(
682 self.tcx,
683 self.span,
684 Some(self.self_expr.span),
685 self.call_expr.span,
686 trait_def_id,
687 self.body_id.to_def_id(),
688 )
689 {
690 self.set_tainted_by_errors(e);
691 }
692 }
693
694 fn lint_shadowed_supertrait_items(
695 &self,
696 pick: &probe::Pick<'_>,
697 segment: &hir::PathSegment<'tcx>,
698 ) {
699 if pick.shadowed_candidates.is_empty() {
700 return;
701 }
702
703 let shadower_span = self.tcx.def_span(pick.item.def_id);
704 let subtrait = self.tcx.item_name(pick.item.trait_container(self.tcx).unwrap());
705 let shadower = SupertraitItemShadower { span: shadower_span, subtrait };
706
707 let shadowee = if let [shadowee] = &pick.shadowed_candidates[..] {
708 let shadowee_span = self.tcx.def_span(shadowee.def_id);
709 let supertrait = self.tcx.item_name(shadowee.trait_container(self.tcx).unwrap());
710 SupertraitItemShadowee::Labeled { span: shadowee_span, supertrait }
711 } else {
712 let (traits, spans): (Vec<_>, Vec<_>) = pick
713 .shadowed_candidates
714 .iter()
715 .map(|item| {
716 (
717 self.tcx.item_name(item.trait_container(self.tcx).unwrap()),
718 self.tcx.def_span(item.def_id),
719 )
720 })
721 .unzip();
722 SupertraitItemShadowee::Several { traits: traits.into(), spans: spans.into() }
723 };
724
725 self.tcx.emit_node_span_lint(
726 RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
727 segment.hir_id,
728 segment.ident.span,
729 SupertraitItemShadowing { shadower, shadowee, item: segment.ident.name, subtrait },
730 );
731 }
732
733 fn lint_ambiguously_glob_imported_traits(
734 &self,
735 pick: &probe::Pick<'_>,
736 segment: &hir::PathSegment<'tcx>,
737 ) {
738 if pick.kind != probe::PickKind::TraitPick(true) {
739 return;
740 }
741 let trait_name = self.tcx.item_name(pick.item.container_id(self.tcx));
742 let import_span = self.tcx.hir_span_if_local(pick.import_ids[0].to_def_id()).unwrap();
743
744 self.tcx.emit_node_lint(
745 AMBIGUOUS_GLOB_IMPORTED_TRAITS,
746 segment.hir_id,
747 rustc_errors::DiagDecorator(|diag| {
748 diag.primary_message(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Use of ambiguously glob imported trait `{0}`",
trait_name))
})format!(
749 "Use of ambiguously glob imported trait `{trait_name}`"
750 ))
751 .span(segment.ident.span)
752 .span_label(import_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` imported ambiguously here",
trait_name))
})format!("`{trait_name}` imported ambiguously here"))
753 .help(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Import `{0}` explicitly",
trait_name))
})format!("Import `{trait_name}` explicitly"));
754 }),
755 );
756 }
757
758 fn upcast(
759 &mut self,
760 source_trait_ref: ty::PolyTraitRef<'tcx>,
761 target_trait_def_id: DefId,
762 ) -> ty::PolyTraitRef<'tcx> {
763 let upcast_trait_refs =
764 traits::upcast_choices(self.tcx, source_trait_ref, target_trait_def_id);
765
766 if let &[upcast_trait_ref] = upcast_trait_refs.as_slice() {
768 upcast_trait_ref
769 } else {
770 self.dcx().span_delayed_bug(
771 self.span,
772 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("cannot uniquely upcast `{0:?}` to `{1:?}`: `{2:?}`",
source_trait_ref, target_trait_def_id, upcast_trait_refs))
})format!(
773 "cannot uniquely upcast `{:?}` to `{:?}`: `{:?}`",
774 source_trait_ref, target_trait_def_id, upcast_trait_refs
775 ),
776 );
777
778 ty::Binder::dummy(ty::TraitRef::new_from_args(
779 self.tcx,
780 target_trait_def_id,
781 ty::GenericArgs::extend_with_error(self.tcx, target_trait_def_id, &[]),
782 ))
783 }
784 }
785
786 fn instantiate_binder_with_fresh_vars<T>(&self, value: ty::Binder<'tcx, T>) -> T
787 where
788 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
789 {
790 self.fcx.instantiate_binder_with_fresh_vars(
791 self.span,
792 BoundRegionConversionTime::FnCall,
793 value,
794 )
795 }
796}