1use std::collections::hash_map::Entry;
2use std::slice;
3
4use rustc_abi::FieldIdx;
5use rustc_data_structures::fx::FxHashSet;
6use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
7use rustc_hir::def::{CtorOf, DefKind, Res};
8use rustc_hir::def_id::DefId;
9use rustc_hir::intravisit::VisitorExt;
10use rustc_hir::lang_items::LangItem;
11use rustc_hir::{self as hir, AmbigArg, ExprKind, GenericArg, HirId, Node, QPath, intravisit};
12use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend;
13use rustc_hir_analysis::hir_ty_lowering::generics::{
14 check_generic_arg_count_for_call, lower_generic_args,
15};
16use rustc_hir_analysis::hir_ty_lowering::{
17 ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer,
18 GenericPathSegment, HirTyLowerer, IsMethodCall, RegionInferReason,
19};
20use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
21use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
22use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
23use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
24use rustc_middle::ty::{
25 self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity,
26 SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs,
27 UserSelfTy,
28};
29use rustc_middle::{bug, span_bug};
30use rustc_session::lint;
31use rustc_span::Span;
32use rustc_span::def_id::LocalDefId;
33use rustc_span::hygiene::DesugaringKind;
34use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
35use rustc_trait_selection::traits::{
36 self, NormalizeExt, ObligationCauseCode, StructurallyNormalizeExt,
37};
38use tracing::{debug, instrument};
39
40use crate::callee::{self, DeferredCallResolution};
41use crate::errors::{self, CtorIsPrivate};
42use crate::method::{self, MethodCallee};
43use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
44
45impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46 pub(crate) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
49 let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() else {
50 return;
51 };
52
53 match span.desugaring_kind() {
54 Some(DesugaringKind::Async) => return,
57
58 Some(DesugaringKind::Await) => return,
62
63 _ => {}
64 }
65
66 self.diverges.set(Diverges::WarnedAlways);
68
69 {
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/fn_ctxt/_impl.rs:69",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(69u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("warn_if_unreachable: id={0:?} span={1:?} kind={2}",
id, span, kind) as &dyn Value))])
});
} else { ; }
};debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
70
71 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unreachable {0}", kind))
})format!("unreachable {kind}");
72 self.tcx().node_span_lint(lint::builtin::UNREACHABLE_CODE, id, span, |lint| {
73 lint.primary_message(msg.clone());
74 lint.span_label(span, msg).span_label(
75 orig_span,
76 custom_note.unwrap_or("any code following this expression is unreachable"),
77 );
78 })
79 }
80
81 x;#[instrument(skip(self), level = "debug", ret)]
88 pub(crate) fn resolve_vars_with_obligations<T: TypeFoldable<TyCtxt<'tcx>>>(
89 &self,
90 mut t: T,
91 ) -> T {
92 if !t.has_non_region_infer() {
94 debug!("no inference var, nothing needs doing");
95 return t;
96 }
97
98 t = self.resolve_vars_if_possible(t);
100 if !t.has_non_region_infer() {
101 debug!(?t);
102 return t;
103 }
104
105 self.select_obligations_where_possible(|_| {});
110 self.resolve_vars_if_possible(t)
111 }
112
113 pub(crate) fn record_deferred_call_resolution(
114 &self,
115 closure_def_id: LocalDefId,
116 r: DeferredCallResolution<'tcx>,
117 ) {
118 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
119 deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
120 }
121
122 pub(crate) fn remove_deferred_call_resolutions(
123 &self,
124 closure_def_id: LocalDefId,
125 ) -> Vec<DeferredCallResolution<'tcx>> {
126 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
127 deferred_call_resolutions.remove(&closure_def_id).unwrap_or_default()
128 }
129
130 fn tag(&self) -> String {
131 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:p}", self))
})format!("{self:p}")
132 }
133
134 pub(crate) fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
135 self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
136 ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("no type for local variable {0}",
self.tcx.hir_id_to_string(nid)))span_bug!(span, "no type for local variable {}", self.tcx.hir_id_to_string(nid))
137 })
138 }
139
140 #[inline]
141 pub(crate) fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
142 {
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/fn_ctxt/_impl.rs:142",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(142u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("write_ty({0:?}, {1:?}) in fcx {2}",
id, self.resolve_vars_if_possible(ty), self.tag()) as
&dyn Value))])
});
} else { ; }
};debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
143 let mut typeck = self.typeck_results.borrow_mut();
144 let mut node_ty = typeck.node_types_mut();
145
146 if let Some(prev) = node_ty.insert(id, ty) {
147 if prev.references_error() {
148 node_ty.insert(id, prev);
149 } else if !ty.references_error() {
150 self.dcx().span_delayed_bug(
155 self.tcx.hir_span(id),
156 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{1}` overridden by `{2}` for {3:?} in {0:?}",
self.body_id, prev, ty, id))
})format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id),
157 );
158 }
159 }
160
161 if let Err(e) = ty.error_reported() {
162 self.set_tainted_by_errors(e);
163 }
164 }
165
166 pub(crate) fn write_field_index(&self, hir_id: HirId, index: FieldIdx) {
167 self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
168 }
169
170 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_resolution",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(170u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["hir_id", "r"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id,
r);
}
}
}#[instrument(level = "debug", skip(self))]
171 pub(crate) fn write_resolution(
172 &self,
173 hir_id: HirId,
174 r: Result<(DefKind, DefId), ErrorGuaranteed>,
175 ) {
176 self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
177 }
178
179 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_method_call_and_enforce_effects",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(179u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["hir_id", "span",
"method"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
self.enforce_context_effects(Some(hir_id), span, method.def_id,
method.args);
self.write_resolution(hir_id,
Ok((DefKind::AssocFn, method.def_id)));
self.write_args(hir_id, method.args);
}
}
}#[instrument(level = "debug", skip(self))]
180 pub(crate) fn write_method_call_and_enforce_effects(
181 &self,
182 hir_id: HirId,
183 span: Span,
184 method: MethodCallee<'tcx>,
185 ) {
186 self.enforce_context_effects(Some(hir_id), span, method.def_id, method.args);
187 self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
188 self.write_args(hir_id, method.args);
189 }
190
191 fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
192 if !args.is_empty() {
193 {
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/fn_ctxt/_impl.rs:193",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(193u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("write_args({0:?}, {1:?}) in fcx {2}",
node_id, args, self.tag()) as &dyn Value))])
});
} else { ; }
};debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
194
195 self.typeck_results.borrow_mut().node_args_mut().insert(node_id, args);
196 }
197 }
198
199 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_user_type_annotation_from_args",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(206u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["hir_id", "def_id",
"args", "user_self_ty"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&user_self_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
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/fn_ctxt/_impl.rs:214",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(214u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("fcx {0}",
self.tag()) as &dyn Value))])
});
} else { ; }
};
if self.tcx.def_kind(def_id) == DefKind::ConstParam { return; }
if Self::can_contain_user_lifetime_bounds((args, user_self_ty)) {
let canonicalized =
self.canonicalize_user_type_annotation(ty::UserType::new(ty::UserTypeKind::TypeOf(def_id,
UserArgs { args, user_self_ty })));
{
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/fn_ctxt/_impl.rs:227",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(227u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["canonicalized"],
::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(&debug(&canonicalized)
as &dyn Value))])
});
} else { ; }
};
self.write_user_type_annotation(hir_id, canonicalized);
}
}
}
}#[instrument(skip(self), level = "debug")]
207 pub(crate) fn write_user_type_annotation_from_args(
208 &self,
209 hir_id: HirId,
210 def_id: DefId,
211 args: GenericArgsRef<'tcx>,
212 user_self_ty: Option<UserSelfTy<'tcx>>,
213 ) {
214 debug!("fcx {}", self.tag());
215
216 if self.tcx.def_kind(def_id) == DefKind::ConstParam {
220 return;
221 }
222
223 if Self::can_contain_user_lifetime_bounds((args, user_self_ty)) {
224 let canonicalized = self.canonicalize_user_type_annotation(ty::UserType::new(
225 ty::UserTypeKind::TypeOf(def_id, UserArgs { args, user_self_ty }),
226 ));
227 debug!(?canonicalized);
228 self.write_user_type_annotation(hir_id, canonicalized);
229 }
230 }
231
232 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("write_user_type_annotation",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(232u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["hir_id",
"canonical_user_type_annotation"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&canonical_user_type_annotation)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
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/fn_ctxt/_impl.rs:238",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(238u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("fcx {0}",
self.tag()) as &dyn Value))])
});
} else { ; }
};
if !canonical_user_type_annotation.is_identity() {
self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_id,
canonical_user_type_annotation);
} else {
{
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/fn_ctxt/_impl.rs:247",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(247u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("skipping identity args")
as &dyn Value))])
});
} else { ; }
};
}
}
}
}#[instrument(skip(self), level = "debug")]
233 pub(crate) fn write_user_type_annotation(
234 &self,
235 hir_id: HirId,
236 canonical_user_type_annotation: CanonicalUserType<'tcx>,
237 ) {
238 debug!("fcx {}", self.tag());
239
240 if !canonical_user_type_annotation.is_identity() {
242 self.typeck_results
243 .borrow_mut()
244 .user_provided_types_mut()
245 .insert(hir_id, canonical_user_type_annotation);
246 } else {
247 debug!("skipping identity args");
248 }
249 }
250
251 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("apply_adjustments",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(251u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["adj"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adj)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
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/fn_ctxt/_impl.rs:253",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(253u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("expr = {0:#?}",
expr) as &dyn Value))])
});
} else { ; }
};
if adj.is_empty() { return; }
let mut expr_ty =
self.typeck_results.borrow().expr_ty_adjusted(expr);
for a in &adj {
match a.kind {
Adjust::NeverToAny => {
if a.target.is_ty_var() {
self.diverging_type_vars.borrow_mut().insert(a.target);
{
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/fn_ctxt/_impl.rs:266",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(266u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!("apply_adjustments: adding `{0:?}` as diverging type var",
a.target) as &dyn Value))])
});
} else { ; }
};
}
}
Adjust::Deref(Some(overloaded_deref)) => {
self.enforce_context_effects(None, expr.span,
overloaded_deref.method_call(self.tcx),
self.tcx.mk_args(&[expr_ty.into()]));
}
Adjust::Deref(None) => {}
Adjust::Pointer(_pointer_coercion) => {}
Adjust::ReborrowPin(_mutability) => {}
Adjust::Borrow(_) => {}
}
expr_ty = a.target;
}
let autoborrow_mut =
adj.iter().any(|adj|
{
#[allow(non_exhaustive_omitted_patterns)]
match adj {
&Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut {
.. })), .. } => true,
_ => false,
}
});
match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id)
{
Entry::Vacant(entry) => { entry.insert(adj); }
Entry::Occupied(mut entry) => {
{
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/fn_ctxt/_impl.rs:310",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(310u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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!(" - composing on top of {0:?}",
entry.get()) as &dyn Value))])
});
} else { ; }
};
match (&mut entry.get_mut()[..], &adj[..]) {
([Adjustment { kind: Adjust::NeverToAny, target }],
&[.., Adjustment { target: new_target, .. }]) => {
*target = new_target;
}
(&mut [Adjustment { kind: Adjust::Deref(_), .. },
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), ..
}], &[Adjustment { kind: Adjust::Deref(_), .. }, ..]) => {
*entry.get_mut() = adj;
}
_ => {
self.dcx().span_delayed_bug(expr.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("while adjusting {0:?}, can\'t compose {1:?} and {2:?}",
expr, entry.get(), adj))
}));
*entry.get_mut() = adj;
}
}
}
}
if autoborrow_mut { self.convert_place_derefs_to_mutable(expr); }
}
}
}#[instrument(skip(self, expr), level = "debug")]
252 pub(crate) fn apply_adjustments(&self, expr: &hir::Expr<'_>, adj: Vec<Adjustment<'tcx>>) {
253 debug!("expr = {:#?}", expr);
254
255 if adj.is_empty() {
256 return;
257 }
258
259 let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
260
261 for a in &adj {
262 match a.kind {
263 Adjust::NeverToAny => {
264 if a.target.is_ty_var() {
265 self.diverging_type_vars.borrow_mut().insert(a.target);
266 debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
267 }
268 }
269 Adjust::Deref(Some(overloaded_deref)) => {
270 self.enforce_context_effects(
271 None,
272 expr.span,
273 overloaded_deref.method_call(self.tcx),
274 self.tcx.mk_args(&[expr_ty.into()]),
275 );
276 }
277 Adjust::Deref(None) => {
278 }
280 Adjust::Pointer(_pointer_coercion) => {
281 }
283 Adjust::ReborrowPin(_mutability) => {
284 }
287 Adjust::Borrow(_) => {
288 }
290 }
291
292 expr_ty = a.target;
293 }
294
295 let autoborrow_mut = adj.iter().any(|adj| {
296 matches!(
297 adj,
298 &Adjustment {
299 kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
300 ..
301 }
302 )
303 });
304
305 match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) {
306 Entry::Vacant(entry) => {
307 entry.insert(adj);
308 }
309 Entry::Occupied(mut entry) => {
310 debug!(" - composing on top of {:?}", entry.get());
311 match (&mut entry.get_mut()[..], &adj[..]) {
312 (
313 [Adjustment { kind: Adjust::NeverToAny, target }],
314 &[.., Adjustment { target: new_target, .. }],
315 ) => {
316 *target = new_target;
324 }
325
326 (
327 &mut [
328 Adjustment { kind: Adjust::Deref(_), .. },
329 Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), .. },
330 ],
331 &[
332 Adjustment { kind: Adjust::Deref(_), .. },
333 .., ],
335 ) => {
336 *entry.get_mut() = adj;
338 }
339
340 _ => {
341 self.dcx().span_delayed_bug(
344 expr.span,
345 format!(
346 "while adjusting {:?}, can't compose {:?} and {:?}",
347 expr,
348 entry.get(),
349 adj
350 ),
351 );
352
353 *entry.get_mut() = adj;
354 }
355 }
356 }
357 }
358
359 if autoborrow_mut {
363 self.convert_place_derefs_to_mutable(expr);
364 }
365 }
366
367 pub(crate) fn instantiate_bounds(
369 &self,
370 span: Span,
371 def_id: DefId,
372 args: GenericArgsRef<'tcx>,
373 ) -> ty::InstantiatedPredicates<'tcx> {
374 let bounds = self.tcx.predicates_of(def_id);
375 let result = bounds.instantiate(self.tcx, args);
376 let result = self.normalize(span, result);
377 {
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/fn_ctxt/_impl.rs:377",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(377u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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_bounds(bounds={0:?}, args={1:?}) = {2:?}",
bounds, args, result) as &dyn Value))])
});
} else { ; }
};debug!("instantiate_bounds(bounds={:?}, args={:?}) = {:?}", bounds, args, result);
378 result
379 }
380
381 pub(crate) fn normalize<T>(&self, span: Span, value: T) -> T
382 where
383 T: TypeFoldable<TyCtxt<'tcx>>,
384 {
385 self.register_infer_ok_obligations(
386 self.at(&self.misc(span), self.param_env).normalize(value),
387 )
388 }
389
390 pub(crate) fn require_type_meets(
391 &self,
392 ty: Ty<'tcx>,
393 span: Span,
394 code: traits::ObligationCauseCode<'tcx>,
395 def_id: DefId,
396 ) {
397 self.register_bound(ty, def_id, self.cause(span, code));
398 }
399
400 pub(crate) fn require_type_is_sized(
401 &self,
402 ty: Ty<'tcx>,
403 span: Span,
404 code: traits::ObligationCauseCode<'tcx>,
405 ) {
406 if !ty.references_error() {
407 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
408 self.require_type_meets(ty, span, code, lang_item);
409 }
410 }
411
412 pub(crate) fn require_type_is_sized_deferred(
413 &self,
414 ty: Ty<'tcx>,
415 span: Span,
416 code: traits::ObligationCauseCode<'tcx>,
417 ) {
418 if !ty.references_error() {
419 self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
420 }
421 }
422
423 pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
424 if !ty.references_error() {
425 let tail = self.tcx.struct_tail_raw(
426 ty,
427 &self.misc(span),
428 |ty| {
429 if self.next_trait_solver() {
430 self.try_structurally_resolve_type(span, ty)
431 } else {
432 self.normalize(span, ty)
433 }
434 },
435 || {},
436 );
437 if tail.has_trivial_sizedness(self.tcx, SizedTraitKind::Sized)
439 || #[allow(non_exhaustive_omitted_patterns)] match tail.kind() {
ty::Slice(..) => true,
_ => false,
}matches!(tail.kind(), ty::Slice(..))
440 {
441 } else {
443 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
445 self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
446 }
447 }
448 }
449
450 pub(crate) fn register_bound(
451 &self,
452 ty: Ty<'tcx>,
453 def_id: DefId,
454 cause: traits::ObligationCause<'tcx>,
455 ) {
456 if !ty.references_error() {
457 self.fulfillment_cx.borrow_mut().register_bound(
458 self,
459 self.param_env,
460 ty,
461 def_id,
462 cause,
463 );
464 }
465 }
466
467 pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
468 let ty = self.lowerer().lower_ty(hir_ty);
469 self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
470 LoweredTy::from_raw(self, hir_ty.span, ty)
471 }
472
473 pub(crate) fn collect_impl_trait_clauses_from_hir_ty(
477 &self,
478 hir_ty: &'tcx hir::Ty<'tcx>,
479 ) -> ty::Clauses<'tcx> {
480 struct CollectClauses<'a, 'tcx> {
481 clauses: Vec<ty::Clause<'tcx>>,
482 fcx: &'a FnCtxt<'a, 'tcx>,
483 }
484
485 impl<'tcx> intravisit::Visitor<'tcx> for CollectClauses<'_, 'tcx> {
486 fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
487 if let Some(clauses) = self.fcx.trait_ascriptions.borrow().get(&ty.hir_id.local_id)
488 {
489 self.clauses.extend(clauses.iter().cloned());
490 }
491 intravisit::walk_ty(self, ty)
492 }
493 }
494
495 let mut clauses = CollectClauses { clauses: ::alloc::vec::Vec::new()vec![], fcx: self };
496 clauses.visit_ty_unambig(hir_ty);
497 self.tcx.mk_clauses(&clauses.clauses)
498 }
499
500 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_ty_saving_user_provided_ty",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(500u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let ty = self.lower_ty(hir_ty);
{
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/fn_ctxt/_impl.rs:503",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(503u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["ty"],
::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(&debug(&ty) as
&dyn Value))])
});
} else { ; }
};
if Self::can_contain_user_lifetime_bounds(ty.raw) {
let c_ty =
self.canonicalize_response(ty::UserType::new(ty::UserTypeKind::Ty(ty.raw)));
{
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/fn_ctxt/_impl.rs:507",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(507u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["c_ty"],
::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(&debug(&c_ty) as
&dyn Value))])
});
} else { ; }
};
self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_ty.hir_id,
c_ty);
}
ty.normalized
}
}
}#[instrument(level = "debug", skip_all)]
501 pub(crate) fn lower_ty_saving_user_provided_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> Ty<'tcx> {
502 let ty = self.lower_ty(hir_ty);
503 debug!(?ty);
504
505 if Self::can_contain_user_lifetime_bounds(ty.raw) {
506 let c_ty = self.canonicalize_response(ty::UserType::new(ty::UserTypeKind::Ty(ty.raw)));
507 debug!(?c_ty);
508 self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_ty.hir_id, c_ty);
509 }
510
511 ty.normalized
512 }
513
514 pub(super) fn user_args_for_adt(ty: LoweredTy<'tcx>) -> UserArgs<'tcx> {
515 match (ty.raw.kind(), ty.normalized.kind()) {
516 (ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
517 (_, ty::Adt(adt, args)) => UserArgs {
518 args,
519 user_self_ty: Some(UserSelfTy { impl_def_id: adt.did(), self_ty: ty.raw }),
520 },
521 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("non-adt type {0:?}", ty))bug!("non-adt type {:?}", ty),
522 }
523 }
524
525 pub(crate) fn lower_const_arg(
526 &self,
527 const_arg: &'tcx hir::ConstArg<'tcx>,
528 ty: Ty<'tcx>,
529 ) -> ty::Const<'tcx> {
530 let ct = self.lowerer().lower_const_arg(const_arg, ty);
531 self.register_wf_obligation(
532 ct.into(),
533 self.tcx.hir_span(const_arg.hir_id),
534 ObligationCauseCode::WellFormed(None),
535 );
536 ct
537 }
538
539 fn can_contain_user_lifetime_bounds<T>(t: T) -> bool
547 where
548 T: TypeVisitable<TyCtxt<'tcx>>,
549 {
550 t.has_free_regions() || t.has_aliases() || t.has_infer_types()
551 }
552
553 pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> {
554 match self.typeck_results.borrow().node_types().get(id) {
555 Some(&t) => t,
556 None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
557 None => {
558 ::rustc_middle::util::bug::bug_fmt(format_args!("no type for node {0} in fcx {1}",
self.tcx.hir_id_to_string(id), self.tag()));bug!("no type for node {} in fcx {}", self.tcx.hir_id_to_string(id), self.tag());
559 }
560 }
561 }
562
563 pub(crate) fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
564 match self.typeck_results.borrow().node_types().get(id) {
565 Some(&t) => Some(t),
566 None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
567 None => None,
568 }
569 }
570
571 pub(crate) fn register_wf_obligation(
573 &self,
574 term: ty::Term<'tcx>,
575 span: Span,
576 code: traits::ObligationCauseCode<'tcx>,
577 ) {
578 let cause = self.cause(span, code);
580 self.register_predicate(traits::Obligation::new(
581 self.tcx,
582 cause,
583 self.param_env,
584 ty::ClauseKind::WellFormed(term),
585 ));
586 }
587
588 pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, span: Span) {
590 for term in args.iter().filter_map(ty::GenericArg::as_term) {
591 self.register_wf_obligation(term, span, ObligationCauseCode::WellFormed(None));
592 }
593 }
594
595 pub(crate) fn field_ty(
599 &self,
600 span: Span,
601 field: &'tcx ty::FieldDef,
602 args: GenericArgsRef<'tcx>,
603 ) -> Ty<'tcx> {
604 self.normalize(span, field.ty(self.tcx, args))
605 }
606
607 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("drain_stalled_coroutine_obligations",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(608u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
self.select_obligations_where_possible(|_| {});
let ty::TypingMode::Analysis {
defining_opaque_types_and_generators } =
self.typing_mode() else {
::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached"));
};
if defining_opaque_types_and_generators.iter().any(|def_id|
self.tcx.is_coroutine(def_id.to_def_id())) {
self.typeck_results.borrow_mut().coroutine_stalled_predicates.extend(self.fulfillment_cx.borrow_mut().drain_stalled_obligations_for_coroutines(&self.infcx).into_iter().map(|o|
(o.predicate, o.cause)));
}
}
}
}#[instrument(level = "debug", skip(self))]
609 pub(crate) fn drain_stalled_coroutine_obligations(&self) {
610 self.select_obligations_where_possible(|_| {});
615
616 let ty::TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
617 else {
618 bug!();
619 };
620
621 if defining_opaque_types_and_generators
622 .iter()
623 .any(|def_id| self.tcx.is_coroutine(def_id.to_def_id()))
624 {
625 self.typeck_results.borrow_mut().coroutine_stalled_predicates.extend(
626 self.fulfillment_cx
627 .borrow_mut()
628 .drain_stalled_obligations_for_coroutines(&self.infcx)
629 .into_iter()
630 .map(|o| (o.predicate, o.cause)),
631 );
632 }
633 }
634
635 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("report_ambiguity_errors",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(635u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut errors =
self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
if !errors.is_empty() {
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
self.err_ctxt().report_fulfillment_errors(errors);
}
}
}
}#[instrument(skip(self), level = "debug")]
636 pub(crate) fn report_ambiguity_errors(&self) {
637 let mut errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
638
639 if !errors.is_empty() {
640 self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
641 self.err_ctxt().report_fulfillment_errors(errors);
642 }
643 }
644
645 pub(crate) fn select_obligations_where_possible(
647 &self,
648 mutate_fulfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
649 ) {
650 let mut result = self.fulfillment_cx.borrow_mut().try_evaluate_obligations(self);
651 if !result.is_empty() {
652 mutate_fulfillment_errors(&mut result);
653 self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
654 self.err_ctxt().report_fulfillment_errors(result);
655 }
656 }
657
658 pub(crate) fn make_overloaded_place_return_type(&self, method: MethodCallee<'tcx>) -> Ty<'tcx> {
663 let ret_ty = method.sig.output();
665
666 ret_ty.builtin_deref(true).unwrap()
668 }
669
670 pub(crate) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
671 let sized_did = self.tcx.lang_items().sized_trait();
672 self.obligations_for_self_ty(self_ty).into_iter().any(|obligation| {
673 match obligation.predicate.kind().skip_binder() {
674 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
675 Some(data.def_id()) == sized_did
676 }
677 _ => false,
678 }
679 })
680 }
681
682 pub(crate) fn err_args(&self, len: usize, guar: ErrorGuaranteed) -> Vec<Ty<'tcx>> {
683 let ty_error = Ty::new_error(self.tcx, guar);
684 ::alloc::vec::from_elem(ty_error, len)vec![ty_error; len]
685 }
686
687 x;#[instrument(level = "trace", skip(self), ret)]
690 pub(crate) fn resolve_ty_and_res_fully_qualified_call(
691 &self,
692 qpath: &'tcx QPath<'tcx>,
693 hir_id: HirId,
694 span: Span,
695 ) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
696 let (ty, qself, item_segment) = match *qpath {
697 QPath::Resolved(ref opt_qself, path) => {
698 return (
699 path.res,
700 opt_qself.as_ref().map(|qself| self.lower_ty(qself)),
701 path.segments,
702 );
703 }
704 QPath::TypeRelative(ref qself, ref segment) => {
705 let ty = self.lowerer().lower_ty(qself);
715 (LoweredTy::from_raw(self, span, ty), qself, segment)
716 }
717 };
718
719 self.register_wf_obligation(
720 ty.raw.into(),
721 qself.span,
722 ObligationCauseCode::WellFormed(None),
723 );
724 self.select_obligations_where_possible(|_| {});
725
726 if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
727 {
728 let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
731 return (def, Some(ty), slice::from_ref(&**item_segment));
732 }
733 let item_name = item_segment.ident;
734 let result = self
735 .resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
736 .or_else(|error| {
737 let guar = self
738 .dcx()
739 .span_delayed_bug(span, "method resolution should've emitted an error");
740 let result = match error {
741 method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
742 _ => Err(guar),
743 };
744
745 let trait_missing_method =
746 matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
747 self.report_method_error(
748 hir_id,
749 ty.normalized,
750 error,
751 Expectation::NoExpectation,
752 trait_missing_method && span.edition().at_least_rust_2021(), );
754
755 result
756 });
757
758 self.write_resolution(hir_id, result);
760 (
761 result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
762 Some(ty),
763 slice::from_ref(&**item_segment),
764 )
765 }
766
767 pub(crate) fn get_fn_decl(
769 &self,
770 blk_id: HirId,
771 ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
772 self.tcx.hir_get_fn_id_for_return_block(blk_id).and_then(|item_id| {
775 match self.tcx.hir_node(item_id) {
776 Node::Item(&hir::Item {
777 kind: hir::ItemKind::Fn { sig, .. }, owner_id, ..
778 }) => Some((owner_id.def_id, sig.decl)),
779 Node::TraitItem(&hir::TraitItem {
780 kind: hir::TraitItemKind::Fn(ref sig, ..),
781 owner_id,
782 ..
783 }) => Some((owner_id.def_id, sig.decl)),
784 Node::ImplItem(&hir::ImplItem {
785 kind: hir::ImplItemKind::Fn(ref sig, ..),
786 owner_id,
787 ..
788 }) => Some((owner_id.def_id, sig.decl)),
789 Node::Expr(&hir::Expr {
790 hir_id,
791 kind: hir::ExprKind::Closure(&hir::Closure { def_id, kind, fn_decl, .. }),
792 ..
793 }) => {
794 match kind {
795 hir::ClosureKind::CoroutineClosure(_) => {
796 return None;
798 }
799 hir::ClosureKind::Closure => Some((def_id, fn_decl)),
800 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
801 _,
802 hir::CoroutineSource::Fn,
803 )) => {
804 let (sig, owner_id) = match self.tcx.parent_hir_node(hir_id) {
805 Node::Item(&hir::Item {
806 kind: hir::ItemKind::Fn { ref sig, .. },
807 owner_id,
808 ..
809 }) => (sig, owner_id),
810 Node::TraitItem(&hir::TraitItem {
811 kind: hir::TraitItemKind::Fn(ref sig, ..),
812 owner_id,
813 ..
814 }) => (sig, owner_id),
815 Node::ImplItem(&hir::ImplItem {
816 kind: hir::ImplItemKind::Fn(ref sig, ..),
817 owner_id,
818 ..
819 }) => (sig, owner_id),
820 _ => return None,
821 };
822 Some((owner_id.def_id, sig.decl))
823 }
824 _ => None,
825 }
826 }
827 _ => None,
828 }
829 })
830 }
831
832 pub(crate) fn note_internal_mutation_in_method(
833 &self,
834 err: &mut Diag<'_>,
835 expr: &hir::Expr<'_>,
836 expected: Option<Ty<'tcx>>,
837 found: Ty<'tcx>,
838 ) {
839 if found != self.tcx.types.unit {
840 return;
841 }
842
843 let ExprKind::MethodCall(path_segment, rcvr, ..) = expr.kind else {
844 return;
845 };
846
847 let rcvr_has_the_expected_type = self
848 .typeck_results
849 .borrow()
850 .expr_ty_adjusted_opt(rcvr)
851 .zip(expected)
852 .is_some_and(|(ty, expected_ty)| expected_ty.peel_refs() == ty.peel_refs());
853
854 let prev_call_mutates_and_returns_unit = || {
855 self.typeck_results
856 .borrow()
857 .type_dependent_def_id(expr.hir_id)
858 .map(|def_id| self.tcx.fn_sig(def_id).skip_binder().skip_binder())
859 .and_then(|sig| sig.inputs_and_output.split_last())
860 .is_some_and(|(output, inputs)| {
861 output.is_unit()
862 && inputs
863 .get(0)
864 .and_then(|self_ty| self_ty.ref_mutability())
865 .is_some_and(rustc_ast::Mutability::is_mut)
866 })
867 };
868
869 if !(rcvr_has_the_expected_type || prev_call_mutates_and_returns_unit()) {
870 return;
871 }
872
873 let mut sp = MultiSpan::from_span(path_segment.ident.span);
874 sp.push_span_label(
875 path_segment.ident.span,
876 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("this call modifies {0} in-place",
match rcvr.kind {
ExprKind::Path(QPath::Resolved(None, hir::Path {
segments: [segment], .. })) =>
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", segment.ident))
}),
_ => "its receiver".to_string(),
}))
})format!(
877 "this call modifies {} in-place",
878 match rcvr.kind {
879 ExprKind::Path(QPath::Resolved(
880 None,
881 hir::Path { segments: [segment], .. },
882 )) => format!("`{}`", segment.ident),
883 _ => "its receiver".to_string(),
884 }
885 ),
886 );
887
888 let modifies_rcvr_note =
889 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("method `{0}` modifies its receiver in-place",
path_segment.ident))
})format!("method `{}` modifies its receiver in-place", path_segment.ident);
890 if rcvr_has_the_expected_type {
891 sp.push_span_label(
892 rcvr.span,
893 "you probably want to use this value after calling the method...",
894 );
895 err.span_note(sp, modifies_rcvr_note);
896 err.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("...instead of the `()` output of method `{0}`",
path_segment.ident))
})format!("...instead of the `()` output of method `{}`", path_segment.ident));
897 } else if let ExprKind::MethodCall(..) = rcvr.kind {
898 err.span_note(
899 sp,
900 modifies_rcvr_note + ", it is not meant to be used in method chains.",
901 );
902 } else {
903 err.span_note(sp, modifies_rcvr_note);
904 }
905 }
906
907 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("instantiate_value_path",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(909u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["segments",
"self_ty", "res", "path_span", "hir_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segments)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path_span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: (Ty<'tcx>, Res) = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let generic_segments =
match res {
Res::Local(_) | Res::SelfCtor(_) =>
::alloc::vec::Vec::new(),
Res::Def(kind, def_id) =>
self.lowerer().probe_generic_path_segments(segments,
self_ty.map(|ty| ty.raw), kind, def_id, span),
Res::Err => {
return (Ty::new_error(tcx,
tcx.dcx().span_delayed_bug(span,
"could not resolve path {:?}")), res);
}
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("instantiate_value_path on {0:?}",
res)),
};
let mut user_self_ty = None;
let mut is_alias_variant_ctor = false;
let mut err_extend = GenericsArgsErrExtend::None;
match res {
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) if
let Some(self_ty) = self_ty => {
let adt_def = self_ty.normalized.ty_adt_def().unwrap();
user_self_ty =
Some(UserSelfTy {
impl_def_id: adt_def.did(),
self_ty: self_ty.raw,
});
is_alias_variant_ctor = true;
err_extend = GenericsArgsErrExtend::DefVariant(segments);
}
Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
err_extend = GenericsArgsErrExtend::DefVariant(segments);
}
Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
let assoc_item = tcx.associated_item(def_id);
let container = assoc_item.container;
let container_id = assoc_item.container_id(tcx);
{
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/fn_ctxt/_impl.rs:960",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(960u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["def_id",
"container", "container_id"],
::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(&debug(&def_id) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&container)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&container_id)
as &dyn Value))])
});
} else { ; }
};
match container {
ty::AssocContainer::Trait => {
if let Err(e) =
callee::check_legal_trait_for_method_call(tcx, path_span,
None, span, container_id, self.body_id.to_def_id()) {
self.set_tainted_by_errors(e);
}
}
ty::AssocContainer::InherentImpl |
ty::AssocContainer::TraitImpl(_) => {
if segments.len() == 1 {
user_self_ty =
self_ty.map(|self_ty|
UserSelfTy {
impl_def_id: container_id,
self_ty: self_ty.raw,
});
}
}
}
}
_ => {}
}
let indices: FxHashSet<_> =
generic_segments.iter().map(|GenericPathSegment(_, index)|
index).collect();
let generics_err =
self.lowerer().prohibit_generic_args(segments.iter().enumerate().filter_map(|(index,
seg)|
{
if !indices.contains(&index) || is_alias_variant_ctor {
Some(seg)
} else { None }
}), err_extend);
if let Err(e) =
self.lowerer().check_param_res_if_mcg_for_instantiate_value_path(res,
span) {
return (Ty::new_error(self.tcx, e), res);
}
if let Res::Local(hid) = res {
let ty = self.local_ty(span, hid);
let ty = self.normalize(span, ty);
return (ty, res);
}
if let Err(_) = generics_err { user_self_ty = None; }
let mut infer_args_for_err = None;
let mut explicit_late_bound = ExplicitLateBound::No;
for &GenericPathSegment(def_id, index) in &generic_segments {
let seg = &segments[index];
let generics = tcx.generics_of(def_id);
let arg_count =
check_generic_arg_count_for_call(self, def_id, generics,
seg, IsMethodCall::No);
if let ExplicitLateBound::Yes = arg_count.explicit_late_bound
{
explicit_late_bound = ExplicitLateBound::Yes;
}
if let Err(GenericArgCountMismatch { reported, .. }) =
arg_count.correct {
infer_args_for_err.get_or_insert_with(||
(reported, FxHashSet::default())).1.insert(index);
self.set_tainted_by_errors(reported);
}
}
let has_self =
generic_segments.last().is_some_and(|GenericPathSegment(def_id,
_)| tcx.generics_of(*def_id).has_self);
let (res, implicit_args) =
if let Res::Def(DefKind::ConstParam, def) = res {
(res,
Some(ty::GenericArgs::identity_for_item(tcx,
tcx.parent(def))))
} else if let Res::SelfCtor(impl_def_id) = res {
let ty =
LoweredTy::from_raw(self, span,
tcx.at(span).type_of(impl_def_id).instantiate_identity());
if std::iter::successors(Some(self.body_id.to_def_id()),
|def_id|
{
self.tcx.generics_of(def_id).parent
}).all(|def_id| def_id != impl_def_id) {
let sugg =
ty.normalized.ty_adt_def().map(|def|
errors::ReplaceWithName {
span: path_span,
name: self.tcx.item_name(def.did()).to_ident_string(),
});
let item =
match self.tcx.hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
{
hir::Node::Item(item) =>
Some(errors::InnerItem {
span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
}),
_ => None,
};
if ty.raw.has_param() {
let guar =
self.dcx().emit_err(errors::SelfCtorFromOuterItem {
span: path_span,
impl_span: tcx.def_span(impl_def_id),
sugg,
item,
});
return (Ty::new_error(self.tcx, guar), res);
} else {
self.tcx.emit_node_span_lint(SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
hir_id, path_span,
errors::SelfCtorFromOuterItemLint {
impl_span: tcx.def_span(impl_def_id),
sugg,
item,
});
}
}
match ty.normalized.ty_adt_def() {
Some(adt_def) if adt_def.has_ctor() => {
let (ctor_kind, ctor_def_id) =
adt_def.non_enum_variant().ctor.unwrap();
let vis = tcx.visibility(ctor_def_id);
if !vis.is_accessible_from(tcx.parent_module(hir_id).to_def_id(),
tcx) {
self.dcx().emit_err(CtorIsPrivate {
span,
def: tcx.def_path_str(adt_def.did()),
});
}
let new_res =
Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind),
ctor_def_id);
let user_args = Self::user_args_for_adt(ty);
user_self_ty = user_args.user_self_ty;
(new_res, Some(user_args.args))
}
_ => {
let mut err =
self.dcx().struct_span_err(span,
"the `Self` constructor can only be used with tuple or unit structs");
if let Some(adt_def) = ty.normalized.ty_adt_def() {
match adt_def.adt_kind() {
AdtKind::Enum => {
err.help("did you mean to use one of the enum's variants?");
}
AdtKind::Struct | AdtKind::Union => {
err.span_suggestion(span, "use curly brackets",
"Self { /* fields */ }", Applicability::HasPlaceholders);
}
}
}
let reported = err.emit();
return (Ty::new_error(tcx, reported), res);
}
}
} else { (res, None) };
let def_id = res.def_id();
let (correct, infer_args_for_err) =
match infer_args_for_err {
Some((reported, args)) => {
(Err(GenericArgCountMismatch {
reported,
invalid_args: ::alloc::vec::Vec::new(),
}), args)
}
None => (Ok(()), Default::default()),
};
let arg_count =
GenericArgCountResult { explicit_late_bound, correct };
struct CtorGenericArgsCtxt<'a, 'tcx> {
fcx: &'a FnCtxt<'a, 'tcx>,
span: Span,
generic_segments: &'a [GenericPathSegment],
infer_args_for_err: &'a FxHashSet<usize>,
segments: &'tcx [hir::PathSegment<'tcx>],
}
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for
CtorGenericArgsCtxt<'a, 'tcx> {
fn args_for_def_id(&mut self, def_id: DefId)
-> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
if let Some(&GenericPathSegment(_, index)) =
self.generic_segments.iter().find(|&GenericPathSegment(did,
_)| *did == def_id) {
if !self.infer_args_for_err.contains(&index) {
if let Some(data) = self.segments[index].args {
return (Some(data), self.segments[index].infer_args);
}
}
return (None, self.segments[index].infer_args);
}
(None, true)
}
fn provided_kind(&mut self,
preceding_args: &[ty::GenericArg<'tcx>],
param: &ty::GenericParamDef, arg: &GenericArg<'tcx>)
-> ty::GenericArg<'tcx> {
match (¶m.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) =>
self.fcx.lowerer().lower_lifetime(lt,
RegionInferReason::Param(param)).into(),
(GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) =>
{
self.fcx.lower_ty(ty.as_unambig_ty()).raw.into()
}
(GenericParamDefKind::Type { .. }, GenericArg::Infer(inf))
=> {
self.fcx.lower_ty(&inf.to_ty()).raw.into()
}
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct))
=>
self.fcx.lower_const_arg(ct.as_unambig_ct(),
self.fcx.tcx.type_of(param.def_id).instantiate(self.fcx.tcx,
preceding_args)).into(),
(&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf))
=> {
self.fcx.ct_infer(Some(param), inf.span).into()
}
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
}
}
fn inferred_kind(&mut self,
preceding_args: &[ty::GenericArg<'tcx>],
param: &ty::GenericParamDef, infer_args: bool)
-> ty::GenericArg<'tcx> {
let tcx = self.fcx.tcx();
if !infer_args &&
let Some(default) = param.default_value(tcx) {
return default.instantiate(tcx, preceding_args);
}
self.fcx.var_for_def(self.span, param)
}
}
let args_raw =
implicit_args.unwrap_or_else(||
{
lower_generic_args(self, def_id, &[], has_self,
self_ty.map(|s| s.raw), &arg_count,
&mut CtorGenericArgsCtxt {
fcx: self,
span,
generic_segments: &generic_segments,
infer_args_for_err: &infer_args_for_err,
segments,
})
});
self.write_user_type_annotation_from_args(hir_id, def_id,
args_raw, user_self_ty);
let args = self.normalize(span, args_raw);
self.add_required_obligations_for_hir(span, def_id, args, hir_id);
let ty = tcx.type_of(def_id);
if !!args.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !args.has_escaping_bound_vars()")
};
if !!ty.skip_binder().has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !ty.skip_binder().has_escaping_bound_vars()")
};
let ty_instantiated =
self.normalize(span, ty.instantiate(tcx, args));
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
let impl_ty =
self.normalize(span,
tcx.type_of(impl_def_id).instantiate(tcx, args));
let self_ty = self.normalize(span, self_ty);
match self.at(&self.misc(span),
self.param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty)
{
Ok(ok) => self.register_infer_ok_obligations(ok),
Err(_) => {
self.dcx().span_bug(span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("instantiate_value_path: (UFCS) {0:?} was a subtype of {1:?} but now is not?",
self_ty, impl_ty))
}));
}
}
}
{
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/fn_ctxt/_impl.rs:1322",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(1322u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::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_value_path: type of {0:?} is {1:?}",
hir_id, ty_instantiated) as &dyn Value))])
});
} else { ; }
};
self.write_args(hir_id, args);
(ty_instantiated, res)
}
}
}#[instrument(skip(self, span), level = "debug")]
910 pub(crate) fn instantiate_value_path(
911 &self,
912 segments: &'tcx [hir::PathSegment<'tcx>],
913 self_ty: Option<LoweredTy<'tcx>>,
914 res: Res,
915 span: Span,
916 path_span: Span,
917 hir_id: HirId,
918 ) -> (Ty<'tcx>, Res) {
919 let tcx = self.tcx;
920
921 let generic_segments = match res {
922 Res::Local(_) | Res::SelfCtor(_) => vec![],
923 Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments(
924 segments,
925 self_ty.map(|ty| ty.raw),
926 kind,
927 def_id,
928 span,
929 ),
930 Res::Err => {
931 return (
932 Ty::new_error(
933 tcx,
934 tcx.dcx().span_delayed_bug(span, "could not resolve path {:?}"),
935 ),
936 res,
937 );
938 }
939 _ => bug!("instantiate_value_path on {:?}", res),
940 };
941
942 let mut user_self_ty = None;
943 let mut is_alias_variant_ctor = false;
944 let mut err_extend = GenericsArgsErrExtend::None;
945 match res {
946 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) if let Some(self_ty) = self_ty => {
947 let adt_def = self_ty.normalized.ty_adt_def().unwrap();
948 user_self_ty =
949 Some(UserSelfTy { impl_def_id: adt_def.did(), self_ty: self_ty.raw });
950 is_alias_variant_ctor = true;
951 err_extend = GenericsArgsErrExtend::DefVariant(segments);
952 }
953 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
954 err_extend = GenericsArgsErrExtend::DefVariant(segments);
955 }
956 Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => {
957 let assoc_item = tcx.associated_item(def_id);
958 let container = assoc_item.container;
959 let container_id = assoc_item.container_id(tcx);
960 debug!(?def_id, ?container, ?container_id);
961 match container {
962 ty::AssocContainer::Trait => {
963 if let Err(e) = callee::check_legal_trait_for_method_call(
964 tcx,
965 path_span,
966 None,
967 span,
968 container_id,
969 self.body_id.to_def_id(),
970 ) {
971 self.set_tainted_by_errors(e);
972 }
973 }
974 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => {
975 if segments.len() == 1 {
976 user_self_ty = self_ty.map(|self_ty| UserSelfTy {
983 impl_def_id: container_id,
984 self_ty: self_ty.raw,
985 });
986 }
987 }
988 }
989 }
990 _ => {}
991 }
992
993 let indices: FxHashSet<_> =
999 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
1000 let generics_err = self.lowerer().prohibit_generic_args(
1001 segments.iter().enumerate().filter_map(|(index, seg)| {
1002 if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None }
1003 }),
1004 err_extend,
1005 );
1006
1007 if let Err(e) = self.lowerer().check_param_res_if_mcg_for_instantiate_value_path(res, span)
1008 {
1009 return (Ty::new_error(self.tcx, e), res);
1010 }
1011
1012 if let Res::Local(hid) = res {
1013 let ty = self.local_ty(span, hid);
1014 let ty = self.normalize(span, ty);
1015 return (ty, res);
1016 }
1017
1018 if let Err(_) = generics_err {
1019 user_self_ty = None;
1021 }
1022
1023 let mut infer_args_for_err = None;
1031
1032 let mut explicit_late_bound = ExplicitLateBound::No;
1033 for &GenericPathSegment(def_id, index) in &generic_segments {
1034 let seg = &segments[index];
1035 let generics = tcx.generics_of(def_id);
1036
1037 let arg_count =
1042 check_generic_arg_count_for_call(self, def_id, generics, seg, IsMethodCall::No);
1043
1044 if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
1045 explicit_late_bound = ExplicitLateBound::Yes;
1046 }
1047
1048 if let Err(GenericArgCountMismatch { reported, .. }) = arg_count.correct {
1049 infer_args_for_err
1050 .get_or_insert_with(|| (reported, FxHashSet::default()))
1051 .1
1052 .insert(index);
1053 self.set_tainted_by_errors(reported); }
1055 }
1056
1057 let has_self = generic_segments
1058 .last()
1059 .is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self);
1060
1061 let (res, implicit_args) = if let Res::Def(DefKind::ConstParam, def) = res {
1062 (res, Some(ty::GenericArgs::identity_for_item(tcx, tcx.parent(def))))
1072 } else if let Res::SelfCtor(impl_def_id) = res {
1073 let ty = LoweredTy::from_raw(
1074 self,
1075 span,
1076 tcx.at(span).type_of(impl_def_id).instantiate_identity(),
1077 );
1078
1079 if std::iter::successors(Some(self.body_id.to_def_id()), |def_id| {
1087 self.tcx.generics_of(def_id).parent
1088 })
1089 .all(|def_id| def_id != impl_def_id)
1090 {
1091 let sugg = ty.normalized.ty_adt_def().map(|def| errors::ReplaceWithName {
1092 span: path_span,
1093 name: self.tcx.item_name(def.did()).to_ident_string(),
1094 });
1095 let item = match self
1096 .tcx
1097 .hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
1098 {
1099 hir::Node::Item(item) => Some(errors::InnerItem {
1100 span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
1101 }),
1102 _ => None,
1103 };
1104 if ty.raw.has_param() {
1105 let guar = self.dcx().emit_err(errors::SelfCtorFromOuterItem {
1106 span: path_span,
1107 impl_span: tcx.def_span(impl_def_id),
1108 sugg,
1109 item,
1110 });
1111 return (Ty::new_error(self.tcx, guar), res);
1112 } else {
1113 self.tcx.emit_node_span_lint(
1114 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
1115 hir_id,
1116 path_span,
1117 errors::SelfCtorFromOuterItemLint {
1118 impl_span: tcx.def_span(impl_def_id),
1119 sugg,
1120 item,
1121 },
1122 );
1123 }
1124 }
1125
1126 match ty.normalized.ty_adt_def() {
1127 Some(adt_def) if adt_def.has_ctor() => {
1128 let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();
1129 let vis = tcx.visibility(ctor_def_id);
1131 if !vis.is_accessible_from(tcx.parent_module(hir_id).to_def_id(), tcx) {
1132 self.dcx()
1133 .emit_err(CtorIsPrivate { span, def: tcx.def_path_str(adt_def.did()) });
1134 }
1135 let new_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
1136 let user_args = Self::user_args_for_adt(ty);
1137 user_self_ty = user_args.user_self_ty;
1138 (new_res, Some(user_args.args))
1139 }
1140 _ => {
1141 let mut err = self.dcx().struct_span_err(
1142 span,
1143 "the `Self` constructor can only be used with tuple or unit structs",
1144 );
1145 if let Some(adt_def) = ty.normalized.ty_adt_def() {
1146 match adt_def.adt_kind() {
1147 AdtKind::Enum => {
1148 err.help("did you mean to use one of the enum's variants?");
1149 }
1150 AdtKind::Struct | AdtKind::Union => {
1151 err.span_suggestion(
1152 span,
1153 "use curly brackets",
1154 "Self { /* fields */ }",
1155 Applicability::HasPlaceholders,
1156 );
1157 }
1158 }
1159 }
1160 let reported = err.emit();
1161 return (Ty::new_error(tcx, reported), res);
1162 }
1163 }
1164 } else {
1165 (res, None)
1166 };
1167 let def_id = res.def_id();
1168
1169 let (correct, infer_args_for_err) = match infer_args_for_err {
1170 Some((reported, args)) => {
1171 (Err(GenericArgCountMismatch { reported, invalid_args: vec![] }), args)
1172 }
1173 None => (Ok(()), Default::default()),
1174 };
1175
1176 let arg_count = GenericArgCountResult { explicit_late_bound, correct };
1177
1178 struct CtorGenericArgsCtxt<'a, 'tcx> {
1179 fcx: &'a FnCtxt<'a, 'tcx>,
1180 span: Span,
1181 generic_segments: &'a [GenericPathSegment],
1182 infer_args_for_err: &'a FxHashSet<usize>,
1183 segments: &'tcx [hir::PathSegment<'tcx>],
1184 }
1185 impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> {
1186 fn args_for_def_id(
1187 &mut self,
1188 def_id: DefId,
1189 ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
1190 if let Some(&GenericPathSegment(_, index)) =
1191 self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id)
1192 {
1193 if !self.infer_args_for_err.contains(&index) {
1196 if let Some(data) = self.segments[index].args {
1198 return (Some(data), self.segments[index].infer_args);
1199 }
1200 }
1201 return (None, self.segments[index].infer_args);
1202 }
1203
1204 (None, true)
1205 }
1206
1207 fn provided_kind(
1208 &mut self,
1209 preceding_args: &[ty::GenericArg<'tcx>],
1210 param: &ty::GenericParamDef,
1211 arg: &GenericArg<'tcx>,
1212 ) -> ty::GenericArg<'tcx> {
1213 match (¶m.kind, arg) {
1214 (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => self
1215 .fcx
1216 .lowerer()
1217 .lower_lifetime(lt, RegionInferReason::Param(param))
1218 .into(),
1219 (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
1220 self.fcx.lower_ty(ty.as_unambig_ty()).raw.into()
1222 }
1223 (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
1224 self.fcx.lower_ty(&inf.to_ty()).raw.into()
1225 }
1226 (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
1227 .fcx
1228 .lower_const_arg(
1230 ct.as_unambig_ct(),
1231 self.fcx
1232 .tcx
1233 .type_of(param.def_id)
1234 .instantiate(self.fcx.tcx, preceding_args),
1235 )
1236 .into(),
1237 (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
1238 self.fcx.ct_infer(Some(param), inf.span).into()
1239 }
1240 _ => unreachable!(),
1241 }
1242 }
1243
1244 fn inferred_kind(
1245 &mut self,
1246 preceding_args: &[ty::GenericArg<'tcx>],
1247 param: &ty::GenericParamDef,
1248 infer_args: bool,
1249 ) -> ty::GenericArg<'tcx> {
1250 let tcx = self.fcx.tcx();
1251 if !infer_args && let Some(default) = param.default_value(tcx) {
1252 return default.instantiate(tcx, preceding_args);
1255 }
1256 self.fcx.var_for_def(self.span, param)
1261 }
1262 }
1263
1264 let args_raw = implicit_args.unwrap_or_else(|| {
1265 lower_generic_args(
1266 self,
1267 def_id,
1268 &[],
1269 has_self,
1270 self_ty.map(|s| s.raw),
1271 &arg_count,
1272 &mut CtorGenericArgsCtxt {
1273 fcx: self,
1274 span,
1275 generic_segments: &generic_segments,
1276 infer_args_for_err: &infer_args_for_err,
1277 segments,
1278 },
1279 )
1280 });
1281
1282 self.write_user_type_annotation_from_args(hir_id, def_id, args_raw, user_self_ty);
1284
1285 let args = self.normalize(span, args_raw);
1287
1288 self.add_required_obligations_for_hir(span, def_id, args, hir_id);
1289
1290 let ty = tcx.type_of(def_id);
1293 assert!(!args.has_escaping_bound_vars());
1294 assert!(!ty.skip_binder().has_escaping_bound_vars());
1295 let ty_instantiated = self.normalize(span, ty.instantiate(tcx, args));
1296
1297 if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
1298 let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args));
1304 let self_ty = self.normalize(span, self_ty);
1305 match self.at(&self.misc(span), self.param_env).eq(
1306 DefineOpaqueTypes::Yes,
1307 impl_ty,
1308 self_ty,
1309 ) {
1310 Ok(ok) => self.register_infer_ok_obligations(ok),
1311 Err(_) => {
1312 self.dcx().span_bug(
1313 span,
1314 format!(
1315 "instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
1316 ),
1317 );
1318 }
1319 }
1320 }
1321
1322 debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_instantiated);
1323 self.write_args(hir_id, args);
1324
1325 (ty_instantiated, res)
1326 }
1327
1328 pub(crate) fn add_required_obligations_for_hir(
1330 &self,
1331 span: Span,
1332 def_id: DefId,
1333 args: GenericArgsRef<'tcx>,
1334 hir_id: HirId,
1335 ) {
1336 self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
1337 ObligationCauseCode::WhereClauseInExpr(def_id, span, hir_id, idx)
1338 })
1339 }
1340
1341 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("add_required_obligations_with_code",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(1341u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&["def_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let param_env = self.param_env;
let bounds = self.instantiate_bounds(span, def_id, args);
for obligation in
traits::predicates_for_generics(|idx, predicate_span|
self.cause(span, code(idx, predicate_span)), param_env,
bounds) {
self.register_predicate(obligation);
}
}
}
}#[instrument(level = "debug", skip(self, code, span, args))]
1342 pub(crate) fn add_required_obligations_with_code(
1343 &self,
1344 span: Span,
1345 def_id: DefId,
1346 args: GenericArgsRef<'tcx>,
1347 code: impl Fn(usize, Span) -> ObligationCauseCode<'tcx>,
1348 ) {
1349 let param_env = self.param_env;
1350
1351 let bounds = self.instantiate_bounds(span, def_id, args);
1352
1353 for obligation in traits::predicates_for_generics(
1354 |idx, predicate_span| self.cause(span, code(idx, predicate_span)),
1355 param_env,
1356 bounds,
1357 ) {
1358 self.register_predicate(obligation);
1359 }
1360 }
1361
1362 x;#[instrument(level = "debug", skip(self, sp), ret)]
1368 pub(crate) fn try_structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1369 if self.next_trait_solver()
1370 && let ty::Alias(..) = ty.kind()
1371 {
1372 let result = self
1376 .at(&self.misc(sp), self.param_env)
1377 .structurally_normalize_ty(ty, &mut **self.fulfillment_cx.borrow_mut());
1378 match result {
1379 Ok(normalized_ty) => normalized_ty,
1380 Err(errors) => {
1381 let guar = self.err_ctxt().report_fulfillment_errors(errors);
1382 return Ty::new_error(self.tcx, guar);
1383 }
1384 }
1385 } else {
1386 self.resolve_vars_with_obligations(ty)
1387 }
1388 }
1389
1390 x;#[instrument(level = "debug", skip(self, sp), ret)]
1391 pub(crate) fn try_structurally_resolve_const(
1392 &self,
1393 sp: Span,
1394 ct: ty::Const<'tcx>,
1395 ) -> ty::Const<'tcx> {
1396 let ct = self.resolve_vars_with_obligations(ct);
1397
1398 if self.next_trait_solver()
1399 && let ty::ConstKind::Unevaluated(..) = ct.kind()
1400 {
1401 let result = self
1405 .at(&self.misc(sp), self.param_env)
1406 .structurally_normalize_const(ct, &mut **self.fulfillment_cx.borrow_mut());
1407 match result {
1408 Ok(normalized_ct) => normalized_ct,
1409 Err(errors) => {
1410 let guar = self.err_ctxt().report_fulfillment_errors(errors);
1411 return ty::Const::new_error(self.tcx, guar);
1412 }
1413 }
1414 } else if self.tcx.features().generic_const_exprs() {
1415 rustc_trait_selection::traits::evaluate_const(&self.infcx, ct, self.param_env)
1416 } else {
1417 ct
1418 }
1419 }
1420
1421 pub(crate) fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1430 let ty = self.try_structurally_resolve_type(sp, ty);
1431
1432 if !ty.is_ty_var() { ty } else { self.type_must_be_known_at_this_point(sp, ty) }
1433 }
1434
1435 #[cold]
1436 pub(crate) fn type_must_be_known_at_this_point(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1437 let guar = self.tainted_by_errors().unwrap_or_else(|| {
1438 self.err_ctxt()
1439 .emit_inference_failure_err(
1440 self.body_id,
1441 sp,
1442 ty.into(),
1443 TypeAnnotationNeeded::E0282,
1444 true,
1445 )
1446 .emit()
1447 });
1448 let err = Ty::new_error(self.tcx, guar);
1449 self.demand_suptype(sp, err, ty);
1450 err
1451 }
1452
1453 pub(crate) fn structurally_resolve_const(
1454 &self,
1455 sp: Span,
1456 ct: ty::Const<'tcx>,
1457 ) -> ty::Const<'tcx> {
1458 let ct = self.try_structurally_resolve_const(sp, ct);
1459
1460 if !ct.is_ct_infer() {
1461 ct
1462 } else {
1463 let e = self.tainted_by_errors().unwrap_or_else(|| {
1464 self.err_ctxt()
1465 .emit_inference_failure_err(
1466 self.body_id,
1467 sp,
1468 ct.into(),
1469 TypeAnnotationNeeded::E0282,
1470 true,
1471 )
1472 .emit()
1473 });
1474 ty::Const::new_error(self.tcx, e)
1476 }
1477 }
1478
1479 pub(crate) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
1480 &self,
1481 id: HirId,
1482 ctxt: BreakableCtxt<'tcx>,
1483 f: F,
1484 ) -> (BreakableCtxt<'tcx>, R) {
1485 let index;
1486 {
1487 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1488 index = enclosing_breakables.stack.len();
1489 enclosing_breakables.by_id.insert(id, index);
1490 enclosing_breakables.stack.push(ctxt);
1491 }
1492 let result = f();
1493 let ctxt = {
1494 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1495 if true {
if !(enclosing_breakables.stack.len() == index + 1) {
::core::panicking::panic("assertion failed: enclosing_breakables.stack.len() == index + 1")
};
};debug_assert!(enclosing_breakables.stack.len() == index + 1);
1496 enclosing_breakables.by_id.swap_remove(&id).expect("missing breakable context");
1498 enclosing_breakables.stack.pop().expect("missing breakable context")
1499 };
1500 (ctxt, result)
1501 }
1502
1503 pub(crate) fn probe_instantiate_query_response(
1506 &self,
1507 span: Span,
1508 original_values: &OriginalQueryValues<'tcx>,
1509 query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
1510 ) -> InferResult<'tcx, Ty<'tcx>> {
1511 self.instantiate_query_response_and_region_obligations(
1512 &self.misc(span),
1513 self.param_env,
1514 original_values,
1515 query_result,
1516 )
1517 }
1518
1519 pub(crate) fn expr_in_place(&self, mut expr_id: HirId) -> bool {
1521 let mut contained_in_place = false;
1522
1523 while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {
1524 match &parent_expr.kind {
1525 hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {
1526 if lhs.hir_id == expr_id {
1527 contained_in_place = true;
1528 break;
1529 }
1530 }
1531 _ => (),
1532 }
1533 expr_id = parent_expr.hir_id;
1534 }
1535
1536 contained_in_place
1537 }
1538}