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::{
24 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
25};
26use rustc_middle::ty::{
27 self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity,
28 SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs,
29 UserSelfTy,
30};
31use rustc_middle::{bug, span_bug};
32use rustc_session::lint;
33use rustc_span::Span;
34use rustc_span::def_id::LocalDefId;
35use rustc_span::hygiene::DesugaringKind;
36use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
37use rustc_trait_selection::traits::{
38 self, NormalizeExt, ObligationCauseCode, StructurallyNormalizeExt,
39};
40use tracing::{debug, instrument};
41
42use crate::callee::{self, DeferredCallResolution};
43use crate::errors::{self, CtorIsPrivate};
44use crate::method::{self, MethodCallee};
45use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
46
47impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48 pub(crate) fn transform_args_for_inherent_type_const(
54 &self,
55 def_id: DefId,
56 args: GenericArgsRef<'tcx>,
57 ) -> GenericArgsRef<'tcx> {
58 let tcx = self.tcx;
59 if !tcx.is_type_const(def_id) {
60 return args;
61 }
62 let Some(assoc_item) = tcx.opt_associated_item(def_id) else {
63 return args;
64 };
65 if !#[allow(non_exhaustive_omitted_patterns)] match assoc_item.container {
ty::AssocContainer::InherentImpl => true,
_ => false,
}matches!(assoc_item.container, ty::AssocContainer::InherentImpl) {
66 return args;
67 }
68
69 let impl_def_id = assoc_item.container_id(tcx);
70 let generics = tcx.generics_of(def_id);
71 let impl_args = &args[..generics.parent_count];
72 let self_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args);
73 let own_args = &args[generics.parent_count..];
75 tcx.mk_args_from_iter(
76 std::iter::once(ty::GenericArg::from(self_ty)).chain(own_args.iter().copied()),
77 )
78 }
79
80 pub(crate) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
83 let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() else {
84 return;
85 };
86
87 match span.desugaring_kind() {
88 Some(DesugaringKind::Async) => return,
91
92 Some(DesugaringKind::Await) => return,
96
97 _ => {}
98 }
99
100 self.diverges.set(Diverges::WarnedAlways);
102
103 {
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:103",
"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(103u32),
::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);
104
105 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unreachable {0}", kind))
})format!("unreachable {kind}");
106 self.tcx().node_span_lint(lint::builtin::UNREACHABLE_CODE, id, span, |lint| {
107 lint.primary_message(msg.clone());
108 lint.span_label(span, msg).span_label(
109 orig_span,
110 custom_note.unwrap_or("any code following this expression is unreachable"),
111 );
112 })
113 }
114
115 x;#[instrument(skip(self), level = "debug", ret)]
122 pub(crate) fn resolve_vars_with_obligations<T: TypeFoldable<TyCtxt<'tcx>>>(
123 &self,
124 mut t: T,
125 ) -> T {
126 if !t.has_non_region_infer() {
128 debug!("no inference var, nothing needs doing");
129 return t;
130 }
131
132 t = self.resolve_vars_if_possible(t);
134 if !t.has_non_region_infer() {
135 debug!(?t);
136 return t;
137 }
138
139 self.select_obligations_where_possible(|_| {});
144 self.resolve_vars_if_possible(t)
145 }
146
147 pub(crate) fn record_deferred_call_resolution(
148 &self,
149 closure_def_id: LocalDefId,
150 r: DeferredCallResolution<'tcx>,
151 ) {
152 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
153 deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
154 }
155
156 pub(crate) fn remove_deferred_call_resolutions(
157 &self,
158 closure_def_id: LocalDefId,
159 ) -> Vec<DeferredCallResolution<'tcx>> {
160 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
161 deferred_call_resolutions.remove(&closure_def_id).unwrap_or_default()
162 }
163
164 fn tag(&self) -> String {
165 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:p}", self))
})format!("{self:p}")
166 }
167
168 pub(crate) fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
169 self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
170 ::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))
171 })
172 }
173
174 #[inline]
175 pub(crate) fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
176 {
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:176",
"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(176u32),
::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());
177 let mut typeck = self.typeck_results.borrow_mut();
178 let mut node_ty = typeck.node_types_mut();
179
180 if let Some(prev) = node_ty.insert(id, ty) {
181 if prev.references_error() {
182 node_ty.insert(id, prev);
183 } else if !ty.references_error() {
184 self.dcx().span_delayed_bug(
189 self.tcx.hir_span(id),
190 ::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),
191 );
192 }
193 }
194
195 if let Err(e) = ty.error_reported() {
196 self.set_tainted_by_errors(e);
197 }
198 }
199
200 pub(crate) fn write_field_index(&self, hir_id: HirId, index: FieldIdx) {
201 self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
202 }
203
204 #[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(204u32),
::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))]
205 pub(crate) fn write_resolution(
206 &self,
207 hir_id: HirId,
208 r: Result<(DefKind, DefId), ErrorGuaranteed>,
209 ) {
210 self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
211 }
212
213 #[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(213u32),
::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))]
214 pub(crate) fn write_method_call_and_enforce_effects(
215 &self,
216 hir_id: HirId,
217 span: Span,
218 method: MethodCallee<'tcx>,
219 ) {
220 self.enforce_context_effects(Some(hir_id), span, method.def_id, method.args);
221 self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
222 self.write_args(hir_id, method.args);
223 }
224
225 fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
226 if !args.is_empty() {
227 {
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(&["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());
228
229 self.typeck_results.borrow_mut().node_args_mut().insert(node_id, args);
230 }
231 }
232
233 #[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(240u32),
::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:248",
"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(248u32),
::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:261",
"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(261u32),
::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")]
241 pub(crate) fn write_user_type_annotation_from_args(
242 &self,
243 hir_id: HirId,
244 def_id: DefId,
245 args: GenericArgsRef<'tcx>,
246 user_self_ty: Option<UserSelfTy<'tcx>>,
247 ) {
248 debug!("fcx {}", self.tag());
249
250 if self.tcx.def_kind(def_id) == DefKind::ConstParam {
254 return;
255 }
256
257 if Self::can_contain_user_lifetime_bounds((args, user_self_ty)) {
258 let canonicalized = self.canonicalize_user_type_annotation(ty::UserType::new(
259 ty::UserTypeKind::TypeOf(def_id, UserArgs { args, user_self_ty }),
260 ));
261 debug!(?canonicalized);
262 self.write_user_type_annotation(hir_id, canonicalized);
263 }
264 }
265
266 #[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(266u32),
::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:272",
"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(272u32),
::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:281",
"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(281u32),
::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")]
267 pub(crate) fn write_user_type_annotation(
268 &self,
269 hir_id: HirId,
270 canonical_user_type_annotation: CanonicalUserType<'tcx>,
271 ) {
272 debug!("fcx {}", self.tag());
273
274 if !canonical_user_type_annotation.is_identity() {
276 self.typeck_results
277 .borrow_mut()
278 .user_provided_types_mut()
279 .insert(hir_id, canonical_user_type_annotation);
280 } else {
281 debug!("skipping identity args");
282 }
283 }
284
285 #[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(285u32),
::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:287",
"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(287u32),
::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:300",
"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(300u32),
::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(DerefAdjustKind::Overloaded(overloaded_deref))
=> {
self.enforce_context_effects(None, expr.span,
overloaded_deref.method_call(self.tcx),
self.tcx.mk_args(&[expr_ty.into()]));
}
Adjust::Deref(DerefAdjustKind::Builtin) => {}
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:344",
"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(344u32),
::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")]
286 pub(crate) fn apply_adjustments(&self, expr: &hir::Expr<'_>, adj: Vec<Adjustment<'tcx>>) {
287 debug!("expr = {:#?}", expr);
288
289 if adj.is_empty() {
290 return;
291 }
292
293 let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
294
295 for a in &adj {
296 match a.kind {
297 Adjust::NeverToAny => {
298 if a.target.is_ty_var() {
299 self.diverging_type_vars.borrow_mut().insert(a.target);
300 debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
301 }
302 }
303 Adjust::Deref(DerefAdjustKind::Overloaded(overloaded_deref)) => {
304 self.enforce_context_effects(
305 None,
306 expr.span,
307 overloaded_deref.method_call(self.tcx),
308 self.tcx.mk_args(&[expr_ty.into()]),
309 );
310 }
311 Adjust::Deref(DerefAdjustKind::Builtin) => {
312 }
314 Adjust::Pointer(_pointer_coercion) => {
315 }
317 Adjust::ReborrowPin(_mutability) => {
318 }
321 Adjust::Borrow(_) => {
322 }
324 }
325
326 expr_ty = a.target;
327 }
328
329 let autoborrow_mut = adj.iter().any(|adj| {
330 matches!(
331 adj,
332 &Adjustment {
333 kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
334 ..
335 }
336 )
337 });
338
339 match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) {
340 Entry::Vacant(entry) => {
341 entry.insert(adj);
342 }
343 Entry::Occupied(mut entry) => {
344 debug!(" - composing on top of {:?}", entry.get());
345 match (&mut entry.get_mut()[..], &adj[..]) {
346 (
347 [Adjustment { kind: Adjust::NeverToAny, target }],
348 &[.., Adjustment { target: new_target, .. }],
349 ) => {
350 *target = new_target;
358 }
359
360 (
361 &mut [
362 Adjustment { kind: Adjust::Deref(_), .. },
363 Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), .. },
364 ],
365 &[
366 Adjustment { kind: Adjust::Deref(_), .. },
367 .., ],
369 ) => {
370 *entry.get_mut() = adj;
372 }
373
374 _ => {
375 self.dcx().span_delayed_bug(
378 expr.span,
379 format!(
380 "while adjusting {:?}, can't compose {:?} and {:?}",
381 expr,
382 entry.get(),
383 adj
384 ),
385 );
386
387 *entry.get_mut() = adj;
388 }
389 }
390 }
391 }
392
393 if autoborrow_mut {
397 self.convert_place_derefs_to_mutable(expr);
398 }
399 }
400
401 pub(crate) fn instantiate_bounds(
403 &self,
404 span: Span,
405 def_id: DefId,
406 args: GenericArgsRef<'tcx>,
407 ) -> ty::InstantiatedPredicates<'tcx> {
408 let bounds = self.tcx.predicates_of(def_id);
409 let result = bounds.instantiate(self.tcx, args);
410 let result = self.normalize(span, result);
411 {
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:411",
"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(411u32),
::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);
412 result
413 }
414
415 pub(crate) fn normalize<T>(&self, span: Span, value: T) -> T
416 where
417 T: TypeFoldable<TyCtxt<'tcx>>,
418 {
419 self.register_infer_ok_obligations(
420 self.at(&self.misc(span), self.param_env).normalize(value),
421 )
422 }
423
424 pub(crate) fn require_type_meets(
425 &self,
426 ty: Ty<'tcx>,
427 span: Span,
428 code: traits::ObligationCauseCode<'tcx>,
429 def_id: DefId,
430 ) {
431 self.register_bound(ty, def_id, self.cause(span, code));
432 }
433
434 pub(crate) fn require_type_is_sized(
435 &self,
436 ty: Ty<'tcx>,
437 span: Span,
438 code: traits::ObligationCauseCode<'tcx>,
439 ) {
440 if !ty.references_error() {
441 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
442 self.require_type_meets(ty, span, code, lang_item);
443 }
444 }
445
446 pub(crate) fn require_type_is_sized_deferred(
447 &self,
448 ty: Ty<'tcx>,
449 span: Span,
450 code: traits::ObligationCauseCode<'tcx>,
451 ) {
452 if !ty.references_error() {
453 self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
454 }
455 }
456
457 pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
458 if !ty.references_error() {
459 let tail = self.tcx.struct_tail_raw(
460 ty,
461 &self.misc(span),
462 |ty| {
463 if self.next_trait_solver() {
464 self.try_structurally_resolve_type(span, ty)
465 } else {
466 self.normalize(span, ty)
467 }
468 },
469 || {},
470 );
471 if tail.has_trivial_sizedness(self.tcx, SizedTraitKind::Sized)
473 || #[allow(non_exhaustive_omitted_patterns)] match tail.kind() {
ty::Slice(..) => true,
_ => false,
}matches!(tail.kind(), ty::Slice(..))
474 {
475 } else {
477 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
479 self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
480 }
481 }
482 }
483
484 pub(crate) fn register_bound(
485 &self,
486 ty: Ty<'tcx>,
487 def_id: DefId,
488 cause: traits::ObligationCause<'tcx>,
489 ) {
490 if !ty.references_error() {
491 self.fulfillment_cx.borrow_mut().register_bound(
492 self,
493 self.param_env,
494 ty,
495 def_id,
496 cause,
497 );
498 }
499 }
500
501 pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
502 let ty = self.lowerer().lower_ty(hir_ty);
503 self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
504 LoweredTy::from_raw(self, hir_ty.span, ty)
505 }
506
507 pub(crate) fn collect_impl_trait_clauses_from_hir_ty(
511 &self,
512 hir_ty: &'tcx hir::Ty<'tcx>,
513 ) -> ty::Clauses<'tcx> {
514 struct CollectClauses<'a, 'tcx> {
515 clauses: Vec<ty::Clause<'tcx>>,
516 fcx: &'a FnCtxt<'a, 'tcx>,
517 }
518
519 impl<'tcx> intravisit::Visitor<'tcx> for CollectClauses<'_, 'tcx> {
520 fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
521 if let Some(clauses) = self.fcx.trait_ascriptions.borrow().get(&ty.hir_id.local_id)
522 {
523 self.clauses.extend(clauses.iter().cloned());
524 }
525 intravisit::walk_ty(self, ty)
526 }
527 }
528
529 let mut clauses = CollectClauses { clauses: ::alloc::vec::Vec::new()vec![], fcx: self };
530 clauses.visit_ty_unambig(hir_ty);
531 self.tcx.mk_clauses(&clauses.clauses)
532 }
533
534 #[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(534u32),
::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:537",
"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(537u32),
::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:541",
"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(541u32),
::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)]
535 pub(crate) fn lower_ty_saving_user_provided_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> Ty<'tcx> {
536 let ty = self.lower_ty(hir_ty);
537 debug!(?ty);
538
539 if Self::can_contain_user_lifetime_bounds(ty.raw) {
540 let c_ty = self.canonicalize_response(ty::UserType::new(ty::UserTypeKind::Ty(ty.raw)));
541 debug!(?c_ty);
542 self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_ty.hir_id, c_ty);
543 }
544
545 ty.normalized
546 }
547
548 pub(super) fn user_args_for_adt(ty: LoweredTy<'tcx>) -> UserArgs<'tcx> {
549 match (ty.raw.kind(), ty.normalized.kind()) {
550 (ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
551 (_, ty::Adt(adt, args)) => UserArgs {
552 args,
553 user_self_ty: Some(UserSelfTy { impl_def_id: adt.did(), self_ty: ty.raw }),
554 },
555 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("non-adt type {0:?}", ty))bug!("non-adt type {:?}", ty),
556 }
557 }
558
559 pub(crate) fn lower_const_arg(
560 &self,
561 const_arg: &'tcx hir::ConstArg<'tcx>,
562 ty: Ty<'tcx>,
563 ) -> ty::Const<'tcx> {
564 let ct = self.lowerer().lower_const_arg(const_arg, ty);
565 self.register_wf_obligation(
566 ct.into(),
567 self.tcx.hir_span(const_arg.hir_id),
568 ObligationCauseCode::WellFormed(None),
569 );
570 ct
571 }
572
573 fn can_contain_user_lifetime_bounds<T>(t: T) -> bool
581 where
582 T: TypeVisitable<TyCtxt<'tcx>>,
583 {
584 t.has_free_regions() || t.has_aliases() || t.has_infer_types() || t.has_param()
586 }
587
588 pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> {
589 match self.typeck_results.borrow().node_types().get(id) {
590 Some(&t) => t,
591 None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
592 None => {
593 ::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());
594 }
595 }
596 }
597
598 pub(crate) fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
599 match self.typeck_results.borrow().node_types().get(id) {
600 Some(&t) => Some(t),
601 None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
602 None => None,
603 }
604 }
605
606 pub(crate) fn register_wf_obligation(
608 &self,
609 term: ty::Term<'tcx>,
610 span: Span,
611 code: traits::ObligationCauseCode<'tcx>,
612 ) {
613 let cause = self.cause(span, code);
615 self.register_predicate(traits::Obligation::new(
616 self.tcx,
617 cause,
618 self.param_env,
619 ty::ClauseKind::WellFormed(term),
620 ));
621 }
622
623 pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, span: Span) {
625 for term in args.iter().filter_map(ty::GenericArg::as_term) {
626 self.register_wf_obligation(term, span, ObligationCauseCode::WellFormed(None));
627 }
628 }
629
630 pub(crate) fn field_ty(
634 &self,
635 span: Span,
636 field: &'tcx ty::FieldDef,
637 args: GenericArgsRef<'tcx>,
638 ) -> Ty<'tcx> {
639 self.normalize(span, field.ty(self.tcx, args))
640 }
641
642 #[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(643u32),
::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))]
644 pub(crate) fn drain_stalled_coroutine_obligations(&self) {
645 self.select_obligations_where_possible(|_| {});
650
651 let ty::TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
652 else {
653 bug!();
654 };
655
656 if defining_opaque_types_and_generators
657 .iter()
658 .any(|def_id| self.tcx.is_coroutine(def_id.to_def_id()))
659 {
660 self.typeck_results.borrow_mut().coroutine_stalled_predicates.extend(
661 self.fulfillment_cx
662 .borrow_mut()
663 .drain_stalled_obligations_for_coroutines(&self.infcx)
664 .into_iter()
665 .map(|o| (o.predicate, o.cause)),
666 );
667 }
668 }
669
670 #[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(670u32),
::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")]
671 pub(crate) fn report_ambiguity_errors(&self) {
672 let mut errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
673
674 if !errors.is_empty() {
675 self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
676 self.err_ctxt().report_fulfillment_errors(errors);
677 }
678 }
679
680 pub(crate) fn select_obligations_where_possible(
682 &self,
683 mutate_fulfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
684 ) {
685 let mut result = self.fulfillment_cx.borrow_mut().try_evaluate_obligations(self);
686 if !result.is_empty() {
687 mutate_fulfillment_errors(&mut result);
688 self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
689 self.err_ctxt().report_fulfillment_errors(result);
690 }
691 }
692
693 pub(crate) fn make_overloaded_place_return_type(&self, method: MethodCallee<'tcx>) -> Ty<'tcx> {
698 let ret_ty = method.sig.output();
700
701 ret_ty.builtin_deref(true).unwrap()
703 }
704
705 pub(crate) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
706 let sized_did = self.tcx.lang_items().sized_trait();
707 self.obligations_for_self_ty(self_ty).into_iter().any(|obligation| {
708 match obligation.predicate.kind().skip_binder() {
709 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
710 Some(data.def_id()) == sized_did
711 }
712 _ => false,
713 }
714 })
715 }
716
717 pub(crate) fn err_args(&self, len: usize, guar: ErrorGuaranteed) -> Vec<Ty<'tcx>> {
718 let ty_error = Ty::new_error(self.tcx, guar);
719 ::alloc::vec::from_elem(ty_error, len)vec![ty_error; len]
720 }
721
722 x;#[instrument(level = "trace", skip(self), ret)]
725 pub(crate) fn resolve_ty_and_res_fully_qualified_call(
726 &self,
727 qpath: &'tcx QPath<'tcx>,
728 hir_id: HirId,
729 span: Span,
730 ) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
731 let (ty, qself, item_segment) = match *qpath {
732 QPath::Resolved(ref opt_qself, path) => {
733 return (
734 path.res,
735 opt_qself.as_ref().map(|qself| self.lower_ty(qself)),
736 path.segments,
737 );
738 }
739 QPath::TypeRelative(ref qself, ref segment) => {
740 let ty = self.lowerer().lower_ty(qself);
750 (LoweredTy::from_raw(self, span, ty), qself, segment)
751 }
752 };
753
754 self.register_wf_obligation(
755 ty.raw.into(),
756 qself.span,
757 ObligationCauseCode::WellFormed(None),
758 );
759 self.select_obligations_where_possible(|_| {});
760
761 if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
762 {
763 let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
766 return (def, Some(ty), slice::from_ref(&**item_segment));
767 }
768 let item_name = item_segment.ident;
769 let result = self
770 .resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
771 .or_else(|error| {
772 let guar = self
773 .dcx()
774 .span_delayed_bug(span, "method resolution should've emitted an error");
775 let result = match error {
776 method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
777 _ => Err(guar),
778 };
779
780 let trait_missing_method =
781 matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
782 self.report_method_error(
783 hir_id,
784 ty.normalized,
785 error,
786 Expectation::NoExpectation,
787 trait_missing_method && span.edition().at_least_rust_2021(), );
789
790 result
791 });
792
793 self.write_resolution(hir_id, result);
795 (
796 result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
797 Some(ty),
798 slice::from_ref(&**item_segment),
799 )
800 }
801
802 pub(crate) fn get_fn_decl(
804 &self,
805 blk_id: HirId,
806 ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
807 self.tcx.hir_get_fn_id_for_return_block(blk_id).and_then(|item_id| {
810 match self.tcx.hir_node(item_id) {
811 Node::Item(&hir::Item {
812 kind: hir::ItemKind::Fn { sig, .. }, owner_id, ..
813 }) => Some((owner_id.def_id, sig.decl)),
814 Node::TraitItem(&hir::TraitItem {
815 kind: hir::TraitItemKind::Fn(ref sig, ..),
816 owner_id,
817 ..
818 }) => Some((owner_id.def_id, sig.decl)),
819 Node::ImplItem(&hir::ImplItem {
820 kind: hir::ImplItemKind::Fn(ref sig, ..),
821 owner_id,
822 ..
823 }) => Some((owner_id.def_id, sig.decl)),
824 Node::Expr(&hir::Expr {
825 hir_id,
826 kind: hir::ExprKind::Closure(&hir::Closure { def_id, kind, fn_decl, .. }),
827 ..
828 }) => {
829 match kind {
830 hir::ClosureKind::CoroutineClosure(_) => {
831 return None;
833 }
834 hir::ClosureKind::Closure => Some((def_id, fn_decl)),
835 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
836 _,
837 hir::CoroutineSource::Fn,
838 )) => {
839 let (sig, owner_id) = match self.tcx.parent_hir_node(hir_id) {
840 Node::Item(&hir::Item {
841 kind: hir::ItemKind::Fn { ref sig, .. },
842 owner_id,
843 ..
844 }) => (sig, owner_id),
845 Node::TraitItem(&hir::TraitItem {
846 kind: hir::TraitItemKind::Fn(ref sig, ..),
847 owner_id,
848 ..
849 }) => (sig, owner_id),
850 Node::ImplItem(&hir::ImplItem {
851 kind: hir::ImplItemKind::Fn(ref sig, ..),
852 owner_id,
853 ..
854 }) => (sig, owner_id),
855 _ => return None,
856 };
857 Some((owner_id.def_id, sig.decl))
858 }
859 _ => None,
860 }
861 }
862 _ => None,
863 }
864 })
865 }
866
867 pub(crate) fn note_internal_mutation_in_method(
868 &self,
869 err: &mut Diag<'_>,
870 expr: &hir::Expr<'_>,
871 expected: Option<Ty<'tcx>>,
872 found: Ty<'tcx>,
873 ) {
874 if found != self.tcx.types.unit {
875 return;
876 }
877
878 let ExprKind::MethodCall(path_segment, rcvr, ..) = expr.kind else {
879 return;
880 };
881
882 let rcvr_has_the_expected_type = self
883 .typeck_results
884 .borrow()
885 .expr_ty_adjusted_opt(rcvr)
886 .zip(expected)
887 .is_some_and(|(ty, expected_ty)| expected_ty.peel_refs() == ty.peel_refs());
888
889 let prev_call_mutates_and_returns_unit = || {
890 self.typeck_results
891 .borrow()
892 .type_dependent_def_id(expr.hir_id)
893 .map(|def_id| self.tcx.fn_sig(def_id).skip_binder().skip_binder())
894 .and_then(|sig| sig.inputs_and_output.split_last())
895 .is_some_and(|(output, inputs)| {
896 output.is_unit()
897 && inputs
898 .get(0)
899 .and_then(|self_ty| self_ty.ref_mutability())
900 .is_some_and(rustc_ast::Mutability::is_mut)
901 })
902 };
903
904 if !(rcvr_has_the_expected_type || prev_call_mutates_and_returns_unit()) {
905 return;
906 }
907
908 let mut sp = MultiSpan::from_span(path_segment.ident.span);
909 sp.push_span_label(
910 path_segment.ident.span,
911 ::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!(
912 "this call modifies {} in-place",
913 match rcvr.kind {
914 ExprKind::Path(QPath::Resolved(
915 None,
916 hir::Path { segments: [segment], .. },
917 )) => format!("`{}`", segment.ident),
918 _ => "its receiver".to_string(),
919 }
920 ),
921 );
922
923 let modifies_rcvr_note =
924 ::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);
925 if rcvr_has_the_expected_type {
926 sp.push_span_label(
927 rcvr.span,
928 "you probably want to use this value after calling the method...",
929 );
930 err.span_note(sp, modifies_rcvr_note);
931 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));
932 } else if let ExprKind::MethodCall(..) = rcvr.kind {
933 err.span_note(
934 sp,
935 modifies_rcvr_note + ", it is not meant to be used in method chains.",
936 );
937 } else {
938 err.span_note(sp, modifies_rcvr_note);
939 }
940 }
941
942 #[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(944u32),
::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:995",
"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(995u32),
::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,
})
});
let args_for_user_type =
if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
self.transform_args_for_inherent_type_const(def_id,
args_raw)
} else { args_raw };
self.write_user_type_annotation_from_args(hir_id, def_id,
args_for_user_type, 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:1363",
"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(1363u32),
::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 { ; }
};
let args =
if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
self.transform_args_for_inherent_type_const(def_id, args)
} else { args };
self.write_args(hir_id, args);
(ty_instantiated, res)
}
}
}#[instrument(skip(self, span), level = "debug")]
945 pub(crate) fn instantiate_value_path(
946 &self,
947 segments: &'tcx [hir::PathSegment<'tcx>],
948 self_ty: Option<LoweredTy<'tcx>>,
949 res: Res,
950 span: Span,
951 path_span: Span,
952 hir_id: HirId,
953 ) -> (Ty<'tcx>, Res) {
954 let tcx = self.tcx;
955
956 let generic_segments = match res {
957 Res::Local(_) | Res::SelfCtor(_) => vec![],
958 Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments(
959 segments,
960 self_ty.map(|ty| ty.raw),
961 kind,
962 def_id,
963 span,
964 ),
965 Res::Err => {
966 return (
967 Ty::new_error(
968 tcx,
969 tcx.dcx().span_delayed_bug(span, "could not resolve path {:?}"),
970 ),
971 res,
972 );
973 }
974 _ => bug!("instantiate_value_path on {:?}", res),
975 };
976
977 let mut user_self_ty = None;
978 let mut is_alias_variant_ctor = false;
979 let mut err_extend = GenericsArgsErrExtend::None;
980 match res {
981 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) if let Some(self_ty) = self_ty => {
982 let adt_def = self_ty.normalized.ty_adt_def().unwrap();
983 user_self_ty =
984 Some(UserSelfTy { impl_def_id: adt_def.did(), self_ty: self_ty.raw });
985 is_alias_variant_ctor = true;
986 err_extend = GenericsArgsErrExtend::DefVariant(segments);
987 }
988 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
989 err_extend = GenericsArgsErrExtend::DefVariant(segments);
990 }
991 Res::Def(DefKind::AssocFn | DefKind::AssocConst { .. }, def_id) => {
992 let assoc_item = tcx.associated_item(def_id);
993 let container = assoc_item.container;
994 let container_id = assoc_item.container_id(tcx);
995 debug!(?def_id, ?container, ?container_id);
996 match container {
997 ty::AssocContainer::Trait => {
998 if let Err(e) = callee::check_legal_trait_for_method_call(
999 tcx,
1000 path_span,
1001 None,
1002 span,
1003 container_id,
1004 self.body_id.to_def_id(),
1005 ) {
1006 self.set_tainted_by_errors(e);
1007 }
1008 }
1009 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => {
1010 if segments.len() == 1 {
1011 user_self_ty = self_ty.map(|self_ty| UserSelfTy {
1018 impl_def_id: container_id,
1019 self_ty: self_ty.raw,
1020 });
1021 }
1022 }
1023 }
1024 }
1025 _ => {}
1026 }
1027
1028 let indices: FxHashSet<_> =
1034 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
1035 let generics_err = self.lowerer().prohibit_generic_args(
1036 segments.iter().enumerate().filter_map(|(index, seg)| {
1037 if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None }
1038 }),
1039 err_extend,
1040 );
1041
1042 if let Err(e) = self.lowerer().check_param_res_if_mcg_for_instantiate_value_path(res, span)
1043 {
1044 return (Ty::new_error(self.tcx, e), res);
1045 }
1046
1047 if let Res::Local(hid) = res {
1048 let ty = self.local_ty(span, hid);
1049 let ty = self.normalize(span, ty);
1050 return (ty, res);
1051 }
1052
1053 if let Err(_) = generics_err {
1054 user_self_ty = None;
1056 }
1057
1058 let mut infer_args_for_err = None;
1066
1067 let mut explicit_late_bound = ExplicitLateBound::No;
1068 for &GenericPathSegment(def_id, index) in &generic_segments {
1069 let seg = &segments[index];
1070 let generics = tcx.generics_of(def_id);
1071
1072 let arg_count =
1077 check_generic_arg_count_for_call(self, def_id, generics, seg, IsMethodCall::No);
1078
1079 if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
1080 explicit_late_bound = ExplicitLateBound::Yes;
1081 }
1082
1083 if let Err(GenericArgCountMismatch { reported, .. }) = arg_count.correct {
1084 infer_args_for_err
1085 .get_or_insert_with(|| (reported, FxHashSet::default()))
1086 .1
1087 .insert(index);
1088 self.set_tainted_by_errors(reported); }
1090 }
1091
1092 let has_self = generic_segments
1093 .last()
1094 .is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self);
1095
1096 let (res, implicit_args) = if let Res::Def(DefKind::ConstParam, def) = res {
1097 (res, Some(ty::GenericArgs::identity_for_item(tcx, tcx.parent(def))))
1107 } else if let Res::SelfCtor(impl_def_id) = res {
1108 let ty = LoweredTy::from_raw(
1109 self,
1110 span,
1111 tcx.at(span).type_of(impl_def_id).instantiate_identity(),
1112 );
1113
1114 if std::iter::successors(Some(self.body_id.to_def_id()), |&def_id| {
1122 self.tcx.generics_of(def_id).parent
1123 })
1124 .all(|def_id| def_id != impl_def_id)
1125 {
1126 let sugg = ty.normalized.ty_adt_def().map(|def| errors::ReplaceWithName {
1127 span: path_span,
1128 name: self.tcx.item_name(def.did()).to_ident_string(),
1129 });
1130 let item = match self
1131 .tcx
1132 .hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
1133 {
1134 hir::Node::Item(item) => Some(errors::InnerItem {
1135 span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
1136 }),
1137 _ => None,
1138 };
1139 if ty.raw.has_param() {
1140 let guar = self.dcx().emit_err(errors::SelfCtorFromOuterItem {
1141 span: path_span,
1142 impl_span: tcx.def_span(impl_def_id),
1143 sugg,
1144 item,
1145 });
1146 return (Ty::new_error(self.tcx, guar), res);
1147 } else {
1148 self.tcx.emit_node_span_lint(
1149 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
1150 hir_id,
1151 path_span,
1152 errors::SelfCtorFromOuterItemLint {
1153 impl_span: tcx.def_span(impl_def_id),
1154 sugg,
1155 item,
1156 },
1157 );
1158 }
1159 }
1160
1161 match ty.normalized.ty_adt_def() {
1162 Some(adt_def) if adt_def.has_ctor() => {
1163 let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();
1164 let vis = tcx.visibility(ctor_def_id);
1166 if !vis.is_accessible_from(tcx.parent_module(hir_id).to_def_id(), tcx) {
1167 self.dcx()
1168 .emit_err(CtorIsPrivate { span, def: tcx.def_path_str(adt_def.did()) });
1169 }
1170 let new_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
1171 let user_args = Self::user_args_for_adt(ty);
1172 user_self_ty = user_args.user_self_ty;
1173 (new_res, Some(user_args.args))
1174 }
1175 _ => {
1176 let mut err = self.dcx().struct_span_err(
1177 span,
1178 "the `Self` constructor can only be used with tuple or unit structs",
1179 );
1180 if let Some(adt_def) = ty.normalized.ty_adt_def() {
1181 match adt_def.adt_kind() {
1182 AdtKind::Enum => {
1183 err.help("did you mean to use one of the enum's variants?");
1184 }
1185 AdtKind::Struct | AdtKind::Union => {
1186 err.span_suggestion(
1187 span,
1188 "use curly brackets",
1189 "Self { /* fields */ }",
1190 Applicability::HasPlaceholders,
1191 );
1192 }
1193 }
1194 }
1195 let reported = err.emit();
1196 return (Ty::new_error(tcx, reported), res);
1197 }
1198 }
1199 } else {
1200 (res, None)
1201 };
1202 let def_id = res.def_id();
1203
1204 let (correct, infer_args_for_err) = match infer_args_for_err {
1205 Some((reported, args)) => {
1206 (Err(GenericArgCountMismatch { reported, invalid_args: vec![] }), args)
1207 }
1208 None => (Ok(()), Default::default()),
1209 };
1210
1211 let arg_count = GenericArgCountResult { explicit_late_bound, correct };
1212
1213 struct CtorGenericArgsCtxt<'a, 'tcx> {
1214 fcx: &'a FnCtxt<'a, 'tcx>,
1215 span: Span,
1216 generic_segments: &'a [GenericPathSegment],
1217 infer_args_for_err: &'a FxHashSet<usize>,
1218 segments: &'tcx [hir::PathSegment<'tcx>],
1219 }
1220 impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> {
1221 fn args_for_def_id(
1222 &mut self,
1223 def_id: DefId,
1224 ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
1225 if let Some(&GenericPathSegment(_, index)) =
1226 self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id)
1227 {
1228 if !self.infer_args_for_err.contains(&index) {
1231 if let Some(data) = self.segments[index].args {
1233 return (Some(data), self.segments[index].infer_args);
1234 }
1235 }
1236 return (None, self.segments[index].infer_args);
1237 }
1238
1239 (None, true)
1240 }
1241
1242 fn provided_kind(
1243 &mut self,
1244 preceding_args: &[ty::GenericArg<'tcx>],
1245 param: &ty::GenericParamDef,
1246 arg: &GenericArg<'tcx>,
1247 ) -> ty::GenericArg<'tcx> {
1248 match (¶m.kind, arg) {
1249 (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => self
1250 .fcx
1251 .lowerer()
1252 .lower_lifetime(lt, RegionInferReason::Param(param))
1253 .into(),
1254 (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
1255 self.fcx.lower_ty(ty.as_unambig_ty()).raw.into()
1257 }
1258 (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
1259 self.fcx.lower_ty(&inf.to_ty()).raw.into()
1260 }
1261 (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
1262 .fcx
1263 .lower_const_arg(
1265 ct.as_unambig_ct(),
1266 self.fcx
1267 .tcx
1268 .type_of(param.def_id)
1269 .instantiate(self.fcx.tcx, preceding_args),
1270 )
1271 .into(),
1272 (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
1273 self.fcx.ct_infer(Some(param), inf.span).into()
1274 }
1275 _ => unreachable!(),
1276 }
1277 }
1278
1279 fn inferred_kind(
1280 &mut self,
1281 preceding_args: &[ty::GenericArg<'tcx>],
1282 param: &ty::GenericParamDef,
1283 infer_args: bool,
1284 ) -> ty::GenericArg<'tcx> {
1285 let tcx = self.fcx.tcx();
1286 if !infer_args && let Some(default) = param.default_value(tcx) {
1287 return default.instantiate(tcx, preceding_args);
1290 }
1291 self.fcx.var_for_def(self.span, param)
1296 }
1297 }
1298
1299 let args_raw = implicit_args.unwrap_or_else(|| {
1300 lower_generic_args(
1301 self,
1302 def_id,
1303 &[],
1304 has_self,
1305 self_ty.map(|s| s.raw),
1306 &arg_count,
1307 &mut CtorGenericArgsCtxt {
1308 fcx: self,
1309 span,
1310 generic_segments: &generic_segments,
1311 infer_args_for_err: &infer_args_for_err,
1312 segments,
1313 },
1314 )
1315 });
1316
1317 let args_for_user_type = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
1318 self.transform_args_for_inherent_type_const(def_id, args_raw)
1319 } else {
1320 args_raw
1321 };
1322
1323 self.write_user_type_annotation_from_args(hir_id, def_id, args_for_user_type, user_self_ty);
1325
1326 let args = self.normalize(span, args_raw);
1328
1329 self.add_required_obligations_for_hir(span, def_id, args, hir_id);
1330
1331 let ty = tcx.type_of(def_id);
1334 assert!(!args.has_escaping_bound_vars());
1335 assert!(!ty.skip_binder().has_escaping_bound_vars());
1336 let ty_instantiated = self.normalize(span, ty.instantiate(tcx, args));
1337
1338 if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
1339 let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args));
1345 let self_ty = self.normalize(span, self_ty);
1346 match self.at(&self.misc(span), self.param_env).eq(
1347 DefineOpaqueTypes::Yes,
1348 impl_ty,
1349 self_ty,
1350 ) {
1351 Ok(ok) => self.register_infer_ok_obligations(ok),
1352 Err(_) => {
1353 self.dcx().span_bug(
1354 span,
1355 format!(
1356 "instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
1357 ),
1358 );
1359 }
1360 }
1361 }
1362
1363 debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_instantiated);
1364
1365 let args = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
1366 self.transform_args_for_inherent_type_const(def_id, args)
1367 } else {
1368 args
1369 };
1370
1371 self.write_args(hir_id, args);
1372
1373 (ty_instantiated, res)
1374 }
1375
1376 pub(crate) fn add_required_obligations_for_hir(
1378 &self,
1379 span: Span,
1380 def_id: DefId,
1381 args: GenericArgsRef<'tcx>,
1382 hir_id: HirId,
1383 ) {
1384 self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
1385 ObligationCauseCode::WhereClauseInExpr(def_id, span, hir_id, idx)
1386 })
1387 }
1388
1389 #[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(1389u32),
::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))]
1390 pub(crate) fn add_required_obligations_with_code(
1391 &self,
1392 span: Span,
1393 def_id: DefId,
1394 args: GenericArgsRef<'tcx>,
1395 code: impl Fn(usize, Span) -> ObligationCauseCode<'tcx>,
1396 ) {
1397 let param_env = self.param_env;
1398
1399 let bounds = self.instantiate_bounds(span, def_id, args);
1400
1401 for obligation in traits::predicates_for_generics(
1402 |idx, predicate_span| self.cause(span, code(idx, predicate_span)),
1403 param_env,
1404 bounds,
1405 ) {
1406 self.register_predicate(obligation);
1407 }
1408 }
1409
1410 x;#[instrument(level = "debug", skip(self, sp), ret)]
1416 pub(crate) fn try_structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1417 if self.next_trait_solver()
1418 && let ty::Alias(..) = ty.kind()
1419 {
1420 let result = self
1424 .at(&self.misc(sp), self.param_env)
1425 .structurally_normalize_ty(ty, &mut **self.fulfillment_cx.borrow_mut());
1426 match result {
1427 Ok(normalized_ty) => normalized_ty,
1428 Err(errors) => {
1429 let guar = self.err_ctxt().report_fulfillment_errors(errors);
1430 return Ty::new_error(self.tcx, guar);
1431 }
1432 }
1433 } else {
1434 self.resolve_vars_with_obligations(ty)
1435 }
1436 }
1437
1438 x;#[instrument(level = "debug", skip(self, sp), ret)]
1439 pub(crate) fn try_structurally_resolve_const(
1440 &self,
1441 sp: Span,
1442 ct: ty::Const<'tcx>,
1443 ) -> ty::Const<'tcx> {
1444 let ct = self.resolve_vars_with_obligations(ct);
1445
1446 if self.next_trait_solver()
1447 && let ty::ConstKind::Unevaluated(..) = ct.kind()
1448 {
1449 let result = self
1453 .at(&self.misc(sp), self.param_env)
1454 .structurally_normalize_const(ct, &mut **self.fulfillment_cx.borrow_mut());
1455 match result {
1456 Ok(normalized_ct) => normalized_ct,
1457 Err(errors) => {
1458 let guar = self.err_ctxt().report_fulfillment_errors(errors);
1459 return ty::Const::new_error(self.tcx, guar);
1460 }
1461 }
1462 } else if self.tcx.features().generic_const_exprs() {
1463 rustc_trait_selection::traits::evaluate_const(&self.infcx, ct, self.param_env)
1464 } else {
1465 ct
1466 }
1467 }
1468
1469 pub(crate) fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1478 let ty = self.try_structurally_resolve_type(sp, ty);
1479
1480 if !ty.is_ty_var() { ty } else { self.type_must_be_known_at_this_point(sp, ty) }
1481 }
1482
1483 #[cold]
1484 pub(crate) fn type_must_be_known_at_this_point(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1485 let guar = self.tainted_by_errors().unwrap_or_else(|| {
1486 self.err_ctxt()
1487 .emit_inference_failure_err(
1488 self.body_id,
1489 sp,
1490 ty.into(),
1491 TypeAnnotationNeeded::E0282,
1492 true,
1493 )
1494 .emit()
1495 });
1496 let err = Ty::new_error(self.tcx, guar);
1497 self.demand_suptype(sp, err, ty);
1498 err
1499 }
1500
1501 pub(crate) fn structurally_resolve_const(
1502 &self,
1503 sp: Span,
1504 ct: ty::Const<'tcx>,
1505 ) -> ty::Const<'tcx> {
1506 let ct = self.try_structurally_resolve_const(sp, ct);
1507
1508 if !ct.is_ct_infer() {
1509 ct
1510 } else {
1511 let e = self.tainted_by_errors().unwrap_or_else(|| {
1512 self.err_ctxt()
1513 .emit_inference_failure_err(
1514 self.body_id,
1515 sp,
1516 ct.into(),
1517 TypeAnnotationNeeded::E0282,
1518 true,
1519 )
1520 .emit()
1521 });
1522 ty::Const::new_error(self.tcx, e)
1524 }
1525 }
1526
1527 pub(crate) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
1528 &self,
1529 id: HirId,
1530 ctxt: BreakableCtxt<'tcx>,
1531 f: F,
1532 ) -> (BreakableCtxt<'tcx>, R) {
1533 let index;
1534 {
1535 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1536 index = enclosing_breakables.stack.len();
1537 enclosing_breakables.by_id.insert(id, index);
1538 enclosing_breakables.stack.push(ctxt);
1539 }
1540 let result = f();
1541 let ctxt = {
1542 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1543 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);
1544 enclosing_breakables.by_id.swap_remove(&id).expect("missing breakable context");
1546 enclosing_breakables.stack.pop().expect("missing breakable context")
1547 };
1548 (ctxt, result)
1549 }
1550
1551 pub(crate) fn probe_instantiate_query_response(
1554 &self,
1555 span: Span,
1556 original_values: &OriginalQueryValues<'tcx>,
1557 query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
1558 ) -> InferResult<'tcx, Ty<'tcx>> {
1559 self.instantiate_query_response_and_region_obligations(
1560 &self.misc(span),
1561 self.param_env,
1562 original_values,
1563 query_result,
1564 )
1565 }
1566
1567 pub(crate) fn expr_in_place(&self, mut expr_id: HirId) -> bool {
1569 let mut contained_in_place = false;
1570
1571 while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {
1572 match &parent_expr.kind {
1573 hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {
1574 if lhs.hir_id == expr_id {
1575 contained_in_place = true;
1576 break;
1577 }
1578 }
1579 _ => (),
1580 }
1581 expr_id = parent_expr.hir_id;
1582 }
1583
1584 contained_in_place
1585 }
1586}