1use std::collections::hash_map::Entry;
2use std::slice;
3
4use rustc_abi::FieldIdx;
5use rustc_data_structures::fx::FxHashSet;
6use rustc_data_structures::thin_vec::ThinVec;
7use rustc_errors::{
8 Applicability, Diag, DiagCtxtHandle, Diagnostic, ErrorGuaranteed, Level, MultiSpan,
9};
10use rustc_hir::attrs::lang_items::LangItem;
11use rustc_hir::def::{CtorOf, DefKind, Res};
12use rustc_hir::def_id::DefId;
13use rustc_hir::intravisit::VisitorExt;
14use rustc_hir::{self as hir, AmbigArg, ExprKind, GenericArg, HirId, Node, QPath, intravisit};
15use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend;
16use rustc_hir_analysis::hir_ty_lowering::generics::{
17 check_generic_arg_count_for_value_path, lower_generic_args,
18};
19use rustc_hir_analysis::hir_ty_lowering::{
20 ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer,
21 GenericPathSegment, HirTyLowerer, IsMethodCall, RegionInferReason,
22};
23use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
24use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
25use rustc_infer::traits::TraitErrors;
26use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
27use rustc_middle::ty::adjustment::{
28 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
29};
30use rustc_middle::ty::{
31 self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity,
32 SizedTraitKind, SplattedDef, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt,
33 Unnormalized, UserArgs, UserSelfTy,
34};
35use rustc_middle::{bug, span_bug};
36use rustc_session::lint;
37use rustc_span::Span;
38use rustc_span::def_id::LocalDefId;
39use rustc_span::hygiene::DesugaringKind;
40use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
41use rustc_trait_selection::traits::{
42 self, NormalizeExt, ObligationCauseCode, StructurallyNormalizeExt, TraitEngine,
43};
44use tracing::{debug, instrument};
45
46use crate::callee::{self, DeferredCallResolution, SplatLoweringInfo};
47use crate::diagnostics::{self, CtorIsPrivate};
48use crate::method::{self, MethodCallee};
49use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
50
51impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
52 pub(crate) fn transform_args_for_inherent_type_const(
58 &self,
59 def_id: DefId,
60 args: GenericArgsRef<'tcx>,
61 ) -> GenericArgsRef<'tcx> {
62 let tcx = self.tcx;
63 if !tcx.is_type_const(def_id) {
64 return args;
65 }
66 let Some(assoc_item) = tcx.opt_associated_item(def_id) else {
67 return args;
68 };
69 if !#[allow(non_exhaustive_omitted_patterns)] match assoc_item.container {
ty::AssocContainer::InherentImpl => true,
_ => false,
}matches!(assoc_item.container, ty::AssocContainer::InherentImpl) {
70 return args;
71 }
72
73 let impl_def_id = assoc_item.container_id(tcx);
74 let generics = tcx.generics_of(def_id);
75 let impl_args = &args[..generics.parent_count];
76 let self_ty = tcx.type_of(impl_def_id).instantiate(tcx, impl_args).skip_norm_wip();
77 let own_args = &args[generics.parent_count..];
79 tcx.mk_args_from_iter(
80 std::iter::once(ty::GenericArg::from(self_ty)).chain(own_args.iter().copied()),
81 )
82 }
83
84 pub(crate) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
87 struct UnreachableItem<'a, 'b> {
88 kind: &'a str,
89 span: Span,
90 orig_span: Span,
91 custom_note: Option<&'b str>,
92 }
93
94 impl<'a, 'b, 'c> Diagnostic<'a, ()> for UnreachableItem<'b, 'c> {
95 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
96 let Self { kind, span, orig_span, custom_note } = self;
97 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unreachable {0}", kind))
})format!("unreachable {kind}");
98 Diag::new(dcx, level, msg.clone()).with_span_label(span, msg).with_span_label(
99 orig_span,
100 custom_note.map(|c| c.to_owned()).unwrap_or_else(|| {
101 "any code following this expression is unreachable".to_owned()
102 }),
103 )
104 }
105 }
106
107 let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() else {
108 return;
109 };
110
111 match span.desugaring_kind() {
112 Some(DesugaringKind::Async) => return,
115
116 Some(DesugaringKind::Await) => return,
120
121 _ => {}
122 }
123
124 if self.tcx.is_automatically_derived(self.tcx.parent(id.owner.def_id.into())) {
127 return;
128 }
129
130 self.diverges.set(Diverges::WarnedAlways);
132
133 {
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:133",
"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(133u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("warn_if_unreachable: id={0:?} span={1:?} kind={2}",
id, span, kind) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
134
135 self.tcx().emit_node_span_lint(
136 lint::builtin::UNREACHABLE_CODE,
137 id,
138 span,
139 UnreachableItem { kind, span, orig_span, custom_note },
140 );
141 }
142
143 x;#[instrument(skip(self), level = "debug", ret)]
148 pub(crate) fn resolve_vars_with_obligations<T: TypeFoldable<TyCtxt<'tcx>>>(
149 &self,
150 mut t: T,
151 ) -> T {
152 if !t.has_non_region_infer() {
154 debug!("no inference var, nothing needs doing");
155 return t;
156 }
157
158 t = self.resolve_vars_if_possible(t);
160 if !t.has_non_region_infer() {
161 debug!(?t);
162 return t;
163 }
164
165 self.select_obligations_where_possible(|_| {});
170 self.resolve_vars_if_possible(t)
171 }
172
173 pub(crate) fn record_deferred_call_resolution(
174 &self,
175 closure_def_id: LocalDefId,
176 r: DeferredCallResolution<'tcx>,
177 ) {
178 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
179 deferred_call_resolutions.entry(closure_def_id).or_default().push(r);
180 }
181
182 pub(crate) fn remove_deferred_call_resolutions(
183 &self,
184 closure_def_id: LocalDefId,
185 ) -> Vec<DeferredCallResolution<'tcx>> {
186 let mut deferred_call_resolutions = self.deferred_call_resolutions.borrow_mut();
187 deferred_call_resolutions.remove(&closure_def_id).unwrap_or_default()
188 }
189
190 fn tag(&self) -> String {
191 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:p}", self))
})format!("{self:p}")
192 }
193
194 pub(crate) fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
195 self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
196 ::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))
197 })
198 }
199
200 #[inline]
201 pub(crate) fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
202 {
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:202",
"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(202u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::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 ::tracing::field::Value))])
});
} else { ; }
};debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
203 let mut typeck = self.typeck_results.borrow_mut();
204 let mut node_ty = typeck.node_types_mut();
205
206 if let Some(prev) = node_ty.insert(id, ty) {
207 if prev.references_error() {
208 node_ty.insert(id, prev);
209 } else if !ty.references_error() {
210 self.dcx().span_delayed_bug(
215 self.tcx.hir_span(id),
216 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{1}` overridden by `{2}` for {3:?} in {0:?}",
self.body_def_id, prev, ty, id))
})format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_def_id),
217 );
218 }
219 }
220
221 if let Err(e) = ty.error_reported() {
222 self.set_tainted_by_errors(e);
223 }
224 }
225
226 pub(crate) fn write_field_index(&self, hir_id: HirId, index: FieldIdx) {
227 self.typeck_results.borrow_mut().field_indices_mut().insert(hir_id, index);
228 }
229
230 #[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(230u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
as &dyn ::tracing::field::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))]
231 pub(crate) fn write_resolution(
232 &self,
233 hir_id: HirId,
234 r: Result<(DefKind, DefId), ErrorGuaranteed>,
235 ) {
236 self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
237 }
238
239 #[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_splatted_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(239u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
as &dyn ::tracing::field::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().splatted_defs_mut().insert(hir_id,
r);
}
}
}#[instrument(level = "debug", skip(self))]
240 pub(crate) fn write_splatted_resolution(
241 &self,
242 hir_id: HirId,
243 r: Result<SplattedDef<'tcx>, ErrorGuaranteed>,
244 ) {
245 self.typeck_results.borrow_mut().splatted_defs_mut().insert(hir_id, r);
246 }
247
248 #[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(248u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("method")
}> =
::tracing::__macro_support::FieldName::new("method");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
as &dyn ::tracing::field::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))]
249 pub(crate) fn write_method_call_and_enforce_effects(
250 &self,
251 hir_id: HirId,
252 span: Span,
253 method: MethodCallee<'tcx>,
254 ) {
255 self.enforce_context_effects(Some(hir_id), span, method.def_id, method.args);
256 self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
257 self.write_args(hir_id, method.args);
258 }
259
260 #[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_splatted_call",
"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(260u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_id")
}> =
::tracing::__macro_support::FieldName::new("fn_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("callee_generic_args")
}> =
::tracing::__macro_support::FieldName::new("callee_generic_args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("first_tupled_arg_index")
}> =
::tracing::__macro_support::FieldName::new("first_tupled_arg_index");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tupled_args_count")
}> =
::tracing::__macro_support::FieldName::new("tupled_args_count");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&callee_generic_args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&first_tupled_arg_index
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&tupled_args_count
as &dyn ::tracing::field::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;
}
{
match fn_id {
SplatLoweringInfo::FnDef(def_id) => {
self.write_splatted_resolution(hir_id,
Ok(SplattedDef::FnDef {
def_id,
arg_index: first_tupled_arg_index,
arg_count: tupled_args_count,
}));
if let Some(callee_generic_args) = callee_generic_args {
self.write_args(hir_id, callee_generic_args);
}
}
SplatLoweringInfo::FnPtr(fn_ty) => {
self.write_splatted_resolution(hir_id,
Ok(SplattedDef::FnPtr {
fn_ptr_type: fn_ty,
arg_index: first_tupled_arg_index,
arg_count: tupled_args_count,
}));
if let Some(callee_generic_args) = callee_generic_args {
self.write_args(hir_id, callee_generic_args);
}
}
SplatLoweringInfo::Error(guar) => {
self.write_splatted_resolution(hir_id, Err(guar));
if let Some(callee_generic_args) = callee_generic_args {
self.write_args(hir_id, callee_generic_args);
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
261 pub(crate) fn write_splatted_call(
262 &self,
263 hir_id: HirId,
264 span: Span,
265 fn_id: SplatLoweringInfo<'tcx>,
266 callee_generic_args: Option<GenericArgsRef<'tcx>>,
267 first_tupled_arg_index: u16,
268 tupled_args_count: u16,
269 ) {
270 match fn_id {
274 SplatLoweringInfo::FnDef(def_id) => {
276 self.write_splatted_resolution(
277 hir_id,
278 Ok(SplattedDef::FnDef {
279 def_id,
280 arg_index: first_tupled_arg_index,
281 arg_count: tupled_args_count,
282 }),
283 );
284 if let Some(callee_generic_args) = callee_generic_args {
285 self.write_args(hir_id, callee_generic_args);
286 }
287 }
288 SplatLoweringInfo::FnPtr(fn_ty) => {
290 self.write_splatted_resolution(
293 hir_id,
294 Ok(SplattedDef::FnPtr {
295 fn_ptr_type: fn_ty,
296 arg_index: first_tupled_arg_index,
297 arg_count: tupled_args_count,
298 }),
299 );
300 if let Some(callee_generic_args) = callee_generic_args {
302 self.write_args(hir_id, callee_generic_args);
303 }
304 }
305 SplatLoweringInfo::Error(guar) => {
306 self.write_splatted_resolution(hir_id, Err(guar));
307 if let Some(callee_generic_args) = callee_generic_args {
308 self.write_args(hir_id, callee_generic_args);
309 }
310 }
311 }
312 }
313
314 fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
315 if !args.is_empty() {
316 {
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:316",
"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(316u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("write_args({0:?}, {1:?}) in fcx {2}",
node_id, args, self.tag()) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
317
318 self.typeck_results.borrow_mut().node_args_mut().insert(node_id, args);
319 }
320 }
321
322 #[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(329u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("user_self_ty")
}> =
::tracing::__macro_support::FieldName::new("user_self_ty");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&user_self_ty)
as &dyn ::tracing::field::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:337",
"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(337u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("fcx {0}",
self.tag()) as &dyn ::tracing::field::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:350",
"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(350u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("canonicalized")
}> =
::tracing::__macro_support::FieldName::new("canonicalized");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&canonicalized)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.write_user_type_annotation(hir_id, canonicalized);
}
}
}
}#[instrument(skip(self), level = "debug")]
330 pub(crate) fn write_user_type_annotation_from_args(
331 &self,
332 hir_id: HirId,
333 def_id: DefId,
334 args: GenericArgsRef<'tcx>,
335 user_self_ty: Option<UserSelfTy<'tcx>>,
336 ) {
337 debug!("fcx {}", self.tag());
338
339 if self.tcx.def_kind(def_id) == DefKind::ConstParam {
343 return;
344 }
345
346 if Self::can_contain_user_lifetime_bounds((args, user_self_ty)) {
347 let canonicalized = self.canonicalize_user_type_annotation(ty::UserType::new(
348 ty::UserTypeKind::TypeOf(def_id, UserArgs { args, user_self_ty }),
349 ));
350 debug!(?canonicalized);
351 self.write_user_type_annotation(hir_id, canonicalized);
352 }
353 }
354
355 #[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(355u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("canonical_user_type_annotation")
}> =
::tracing::__macro_support::FieldName::new("canonical_user_type_annotation");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&canonical_user_type_annotation)
as &dyn ::tracing::field::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:361",
"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(361u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("fcx {0}",
self.tag()) as &dyn ::tracing::field::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:370",
"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(370u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("skipping identity args")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
}
}
}#[instrument(skip(self), level = "debug")]
356 pub(crate) fn write_user_type_annotation(
357 &self,
358 hir_id: HirId,
359 canonical_user_type_annotation: CanonicalUserType<'tcx>,
360 ) {
361 debug!("fcx {}", self.tag());
362
363 if !canonical_user_type_annotation.is_identity() {
365 self.typeck_results
366 .borrow_mut()
367 .user_provided_types_mut()
368 .insert(hir_id, canonical_user_type_annotation);
369 } else {
370 debug!("skipping identity args");
371 }
372 }
373
374 #[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(374u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("adj")
}> =
::tracing::__macro_support::FieldName::new("adj");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adj)
as &dyn ::tracing::field::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:376",
"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(376u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("expr = {0:#?}",
expr) as &dyn ::tracing::field::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 let ty::Infer(ty::TyVar(a_id)) = a.target.kind() {
self.diverging_type_vars.borrow_mut().push(*a_id);
{
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:389",
"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(389u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("apply_adjustments: adding `{0:?}` as diverging type var",
a.target) as &dyn ::tracing::field::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::Deref(DerefAdjustKind::Pin) => {}
Adjust::Pointer(_pointer_coercion) => {}
Adjust::GenericReborrow(_) => {}
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:435",
"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(435u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!(" - composing on top of {0:?}",
entry.get()) as &dyn ::tracing::field::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")]
375 pub(crate) fn apply_adjustments(&self, expr: &hir::Expr<'_>, adj: Vec<Adjustment<'tcx>>) {
376 debug!("expr = {:#?}", expr);
377
378 if adj.is_empty() {
379 return;
380 }
381
382 let mut expr_ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
383
384 for a in &adj {
385 match a.kind {
386 Adjust::NeverToAny => {
387 if let ty::Infer(ty::TyVar(a_id)) = a.target.kind() {
388 self.diverging_type_vars.borrow_mut().push(*a_id);
389 debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
390 }
391 }
392 Adjust::Deref(DerefAdjustKind::Overloaded(overloaded_deref)) => {
393 self.enforce_context_effects(
394 None,
395 expr.span,
396 overloaded_deref.method_call(self.tcx),
397 self.tcx.mk_args(&[expr_ty.into()]),
398 );
399 }
400 Adjust::Deref(DerefAdjustKind::Builtin) => {
401 }
403 Adjust::Deref(DerefAdjustKind::Pin) => {
404 }
406 Adjust::Pointer(_pointer_coercion) => {
407 }
409 Adjust::GenericReborrow(_) => {
410 }
412 Adjust::Borrow(_) => {
413 }
415 }
416
417 expr_ty = a.target;
418 }
419
420 let autoborrow_mut = adj.iter().any(|adj| {
421 matches!(
422 adj,
423 &Adjustment {
424 kind: Adjust::Borrow(AutoBorrow::Ref(AutoBorrowMutability::Mut { .. })),
425 ..
426 }
427 )
428 });
429
430 match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) {
431 Entry::Vacant(entry) => {
432 entry.insert(adj);
433 }
434 Entry::Occupied(mut entry) => {
435 debug!(" - composing on top of {:?}", entry.get());
436 match (&mut entry.get_mut()[..], &adj[..]) {
437 (
438 [Adjustment { kind: Adjust::NeverToAny, target }],
439 &[.., Adjustment { target: new_target, .. }],
440 ) => {
441 *target = new_target;
449 }
450
451 (
452 &mut [
453 Adjustment { kind: Adjust::Deref(_), .. },
454 Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), .. },
455 ],
456 &[
457 Adjustment { kind: Adjust::Deref(_), .. },
458 .., ],
460 ) => {
461 *entry.get_mut() = adj;
463 }
464
465 _ => {
466 self.dcx().span_delayed_bug(
469 expr.span,
470 format!(
471 "while adjusting {:?}, can't compose {:?} and {:?}",
472 expr,
473 entry.get(),
474 adj
475 ),
476 );
477
478 *entry.get_mut() = adj;
479 }
480 }
481 }
482 }
483
484 if autoborrow_mut {
488 self.convert_place_derefs_to_mutable(expr);
489 }
490 }
491
492 pub(crate) fn normalize<T>(&self, span: Span, value: Unnormalized<'tcx, T>) -> T
493 where
494 T: TypeFoldable<TyCtxt<'tcx>>,
495 {
496 self.register_infer_ok_obligations(
497 self.at(&self.misc(span), self.param_env).normalize(value),
498 )
499 }
500
501 pub(crate) fn require_type_meets(
502 &self,
503 ty: Ty<'tcx>,
504 span: Span,
505 code: traits::ObligationCauseCode<'tcx>,
506 def_id: DefId,
507 ) {
508 self.register_bound(ty, def_id, self.cause(span, code));
509 }
510
511 pub(crate) fn require_type_is_sized(
512 &self,
513 ty: Ty<'tcx>,
514 span: Span,
515 code: traits::ObligationCauseCode<'tcx>,
516 ) {
517 if !ty.references_error() {
518 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
519 self.require_type_meets(ty, span, code, lang_item);
520 }
521 }
522
523 pub(crate) fn require_type_is_sized_deferred(
524 &self,
525 ty: Ty<'tcx>,
526 span: Span,
527 code: traits::ObligationCauseCode<'tcx>,
528 ) {
529 if !ty.references_error() {
530 self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
531 }
532 }
533
534 pub(crate) fn require_type_has_static_alignment(&self, ty: Ty<'tcx>, span: Span) {
535 if !ty.references_error() {
536 let tail = self.tcx.struct_tail_raw(
537 ty,
538 &self.misc(span),
539 |ty| self.normalize(span, ty),
540 || {},
541 );
542 if tail.has_trivial_sizedness(self.tcx, SizedTraitKind::Sized)
544 || #[allow(non_exhaustive_omitted_patterns)] match tail.kind() {
ty::Slice(..) => true,
_ => false,
}matches!(tail.kind(), ty::Slice(..))
545 {
546 } else {
548 let lang_item = self.tcx.require_lang_item(LangItem::Sized, span);
550 self.require_type_meets(ty, span, ObligationCauseCode::Misc, lang_item);
551 }
552 }
553 }
554
555 pub(crate) fn register_bound(
556 &self,
557 ty: Ty<'tcx>,
558 def_id: DefId,
559 cause: traits::ObligationCause<'tcx>,
560 ) {
561 if !ty.references_error() {
562 self.fulfillment_cx.borrow_mut().register_bound(
563 self,
564 self.param_env,
565 ty,
566 def_id,
567 cause,
568 );
569 }
570 }
571
572 pub(crate) fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> LoweredTy<'tcx> {
573 let ty = self.lowerer().lower_ty(hir_ty);
574 self.register_wf_obligation(ty.into(), hir_ty.span, ObligationCauseCode::WellFormed(None));
575 LoweredTy::from_raw(self, hir_ty.span, ty)
576 }
577
578 pub(crate) fn collect_impl_trait_clauses_from_hir_ty(
582 &self,
583 hir_ty: &'tcx hir::Ty<'tcx>,
584 ) -> ty::Clauses<'tcx> {
585 struct CollectClauses<'a, 'tcx> {
586 clauses: Vec<ty::Clause<'tcx>>,
587 fcx: &'a FnCtxt<'a, 'tcx>,
588 }
589
590 impl<'tcx> intravisit::Visitor<'tcx> for CollectClauses<'_, 'tcx> {
591 fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
592 if let Some(clauses) = self.fcx.trait_ascriptions.borrow().get(&ty.hir_id.local_id)
593 {
594 self.clauses.extend(clauses.iter().cloned());
595 }
596 intravisit::walk_ty(self, ty)
597 }
598 }
599
600 let mut collect_clauses = CollectClauses { clauses: ::alloc::vec::Vec::new()vec![], fcx: self };
601 collect_clauses.visit_ty_unambig(hir_ty);
602 self.tcx.mk_clauses(&collect_clauses.clauses)
603 }
604
605 #[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(605u32),
::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_all(&[]) })
} 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:608",
"rustc_hir_typeck::fn_ctxt::_impl", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs"),
::tracing_core::__macro_support::Option::Some(608u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::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:612",
"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(612u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("c_ty")
}> =
::tracing::__macro_support::FieldName::new("c_ty");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&c_ty)
as &dyn ::tracing::field::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)]
606 pub(crate) fn lower_ty_saving_user_provided_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> Ty<'tcx> {
607 let ty = self.lower_ty(hir_ty);
608 debug!(?ty);
609
610 if Self::can_contain_user_lifetime_bounds(ty.raw) {
611 let c_ty = self.canonicalize_response(ty::UserType::new(ty::UserTypeKind::Ty(ty.raw)));
612 debug!(?c_ty);
613 self.typeck_results.borrow_mut().user_provided_types_mut().insert(hir_ty.hir_id, c_ty);
614 }
615
616 ty.normalized
617 }
618
619 pub(super) fn user_args_for_adt(ty: LoweredTy<'tcx>) -> UserArgs<'tcx> {
620 match (ty.raw.kind(), ty.normalized.kind()) {
621 (ty::Adt(_, args), _) => UserArgs { args, user_self_ty: None },
622 (_, ty::Adt(adt, args)) => UserArgs {
623 args,
624 user_self_ty: Some(UserSelfTy { impl_def_id: adt.did(), self_ty: ty.raw }),
625 },
626 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("non-adt type {0:?}", ty))bug!("non-adt type {:?}", ty),
627 }
628 }
629
630 pub(crate) fn lower_const_arg(
631 &self,
632 const_arg: &'tcx hir::ConstArg<'tcx>,
633 ty: Ty<'tcx>,
634 ) -> ty::Const<'tcx> {
635 let ct = self.lowerer().lower_const_arg(const_arg, ty);
636 self.register_wf_obligation(
637 ct.into(),
638 self.tcx.hir_span(const_arg.hir_id),
639 ObligationCauseCode::WellFormed(None),
640 );
641 ct
642 }
643
644 fn can_contain_user_lifetime_bounds<T>(t: T) -> bool
652 where
653 T: TypeVisitable<TyCtxt<'tcx>>,
654 {
655 t.has_free_regions() || t.has_aliases() || t.has_infer_types() || t.has_param()
657 }
658
659 pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> {
660 match self.typeck_results.borrow().node_types().get(id) {
661 Some(&t) => t,
662 None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
663 None => {
664 ::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());
665 }
666 }
667 }
668
669 pub(crate) fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
670 match self.typeck_results.borrow().node_types().get(id) {
671 Some(&t) => Some(t),
672 None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
673 None => None,
674 }
675 }
676
677 pub(crate) fn register_wf_obligation(
679 &self,
680 term: ty::Term<'tcx>,
681 span: Span,
682 code: traits::ObligationCauseCode<'tcx>,
683 ) {
684 let cause = self.cause(span, code);
686 self.register_predicate(traits::Obligation::new(
687 self.tcx,
688 cause,
689 self.param_env,
690 ty::ClauseKind::WellFormed(term),
691 ));
692 }
693
694 pub(crate) fn add_wf_bounds(&self, args: GenericArgsRef<'tcx>, span: Span) {
696 for term in args.iter().filter_map(ty::GenericArg::as_term) {
697 self.register_wf_obligation(term, span, ObligationCauseCode::WellFormed(None));
698 }
699 }
700
701 pub(crate) fn field_ty(
705 &self,
706 span: Span,
707 field: &'tcx ty::FieldDef,
708 args: GenericArgsRef<'tcx>,
709 ) -> Ty<'tcx> {
710 self.normalize(span, field.ty(self.tcx, args))
711 }
712
713 #[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(714u32),
::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_all(&[]) })
} 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 defining_opaque_types_and_generators =
match self.typing_mode() {
ty::TypingMode::Typeck {
defining_opaque_types_and_generators } => {
defining_opaque_types_and_generators
}
ty::TypingMode::Coherence | ty::TypingMode::Reflection |
ty::TypingMode::PostTypeckUntilBorrowck { .. } |
ty::TypingMode::PostBorrowck { .. } |
ty::TypingMode::PostAnalysis | ty::TypingMode::Codegen => {
::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))]
715 pub(crate) fn drain_stalled_coroutine_obligations(&self) {
716 self.select_obligations_where_possible(|_| {});
721
722 let defining_opaque_types_and_generators = match self.typing_mode() {
723 ty::TypingMode::Typeck { defining_opaque_types_and_generators } => {
724 defining_opaque_types_and_generators
725 }
726 ty::TypingMode::Coherence
727 | ty::TypingMode::Reflection
728 | ty::TypingMode::PostTypeckUntilBorrowck { .. }
729 | ty::TypingMode::PostBorrowck { .. }
730 | ty::TypingMode::PostAnalysis
731 | ty::TypingMode::Codegen => {
732 bug!()
733 }
734 };
735
736 if defining_opaque_types_and_generators
737 .iter()
738 .any(|def_id| self.tcx.is_coroutine(def_id.to_def_id()))
739 {
740 self.typeck_results.borrow_mut().coroutine_stalled_predicates.extend(
741 self.fulfillment_cx
742 .borrow_mut()
743 .drain_stalled_obligations_for_coroutines(&self.infcx)
744 .into_iter()
745 .map(|o| (o.predicate, o.cause)),
746 );
747 }
748 }
749
750 #[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(750u32),
::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_all(&[]) })
} 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 errors =
self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
if let TraitErrors::HasErrors(mut errors) = errors {
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
self.err_ctxt().report_fulfillment_errors(errors);
}
}
}
}#[instrument(skip(self), level = "debug")]
751 pub(crate) fn report_ambiguity_errors(&self) {
752 let errors = self.fulfillment_cx.borrow_mut().collect_remaining_errors(self);
753
754 if let TraitErrors::HasErrors(mut errors) = errors {
755 self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
756 self.err_ctxt().report_fulfillment_errors(errors);
757 }
758 }
759
760 pub(crate) fn select_obligations_where_possible(
762 &self,
763 mutate_fulfillment_errors: impl Fn(&mut ThinVec<traits::FulfillmentError<'tcx>>),
764 ) {
765 let result = self.fulfillment_cx.borrow_mut().try_evaluate_obligations(self);
766 if let TraitErrors::HasErrors(mut result) = result {
767 mutate_fulfillment_errors(&mut result);
768 self.adjust_fulfillment_errors_for_expr_obligation(&mut result);
769 self.err_ctxt().report_fulfillment_errors(result);
770 }
771 }
772
773 pub(crate) fn make_overloaded_place_return_type(&self, method: MethodCallee<'tcx>) -> Ty<'tcx> {
778 let ret_ty = method.sig.output();
780
781 ret_ty.builtin_deref(true).unwrap()
783 }
784
785 pub(crate) fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
786 let sized_did = self.tcx.lang_items().sized_trait();
787
788 self.obligations_for_self_ty(self_ty, super::UseSubtyping::Yes).into_iter().any(
792 |obligation| match obligation.predicate.kind().skip_binder() {
793 ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
794 Some(data.def_id()) == sized_did
795 }
796 _ => false,
797 },
798 )
799 }
800
801 pub(crate) fn err_args(&self, len: usize, guar: ErrorGuaranteed) -> Vec<Ty<'tcx>> {
802 let ty_error = Ty::new_error(self.tcx, guar);
803 ::alloc::vec::from_elem(ty_error, len)vec![ty_error; len]
804 }
805
806 x;#[instrument(level = "trace", skip(self), ret)]
809 pub(crate) fn resolve_ty_and_res_fully_qualified_call(
810 &self,
811 qpath: &'tcx QPath<'tcx>,
812 hir_id: HirId,
813 span: Span,
814 ) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
815 let (ty, qself, item_segment) = match *qpath {
816 QPath::Resolved(ref opt_qself, path) => {
817 return (
818 path.res,
819 opt_qself.as_ref().map(|qself| self.lower_ty(qself)),
820 path.segments,
821 );
822 }
823 QPath::TypeRelative(ref qself, ref segment) => {
824 let ty = self.lowerer().lower_ty(qself);
834 (LoweredTy::from_raw(self, span, ty), qself, segment)
835 }
836 };
837
838 self.register_wf_obligation(
839 ty.raw.into(),
840 qself.span,
841 ObligationCauseCode::WellFormed(None),
842 );
843 self.select_obligations_where_possible(|_| {});
844
845 if let Some(&cached_result) = self.typeck_results.borrow().type_dependent_defs().get(hir_id)
846 {
847 let def = cached_result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id));
850 return (def, Some(ty), slice::from_ref(&**item_segment));
851 }
852 let item_name = item_segment.ident;
853 let result = self
854 .resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
855 .or_else(|error| {
856 let guar = self
857 .dcx()
858 .span_delayed_bug(span, "method resolution should've emitted an error");
859 let result = match error {
860 method::MethodError::PrivateMatch(kind, def_id, _) => Ok((kind, def_id)),
861 _ => Err(guar),
862 };
863
864 let trait_missing_method =
865 matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
866 self.report_method_error(
867 hir_id,
868 ty.normalized,
869 error,
870 Expectation::NoExpectation,
871 trait_missing_method && span.edition().at_least_rust_2021(), );
873
874 result
875 });
876
877 self.write_resolution(hir_id, result);
879 (
880 result.map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
881 Some(ty),
882 slice::from_ref(&**item_segment),
883 )
884 }
885
886 pub(crate) fn get_fn_decl(
888 &self,
889 blk_id: HirId,
890 ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>)> {
891 self.tcx.hir_get_fn_id_for_return_block(blk_id).and_then(|item_id| {
894 match self.tcx.hir_node(item_id) {
895 Node::Item(&hir::Item {
896 kind: hir::ItemKind::Fn { sig, .. }, owner_id, ..
897 }) => Some((owner_id.def_id, sig.decl)),
898 Node::TraitItem(&hir::TraitItem {
899 kind: hir::TraitItemKind::Fn(ref sig, ..),
900 owner_id,
901 ..
902 }) => Some((owner_id.def_id, sig.decl)),
903 Node::ImplItem(&hir::ImplItem {
904 kind: hir::ImplItemKind::Fn(ref sig, ..),
905 owner_id,
906 ..
907 }) => Some((owner_id.def_id, sig.decl)),
908 Node::Expr(&hir::Expr {
909 hir_id,
910 kind: hir::ExprKind::Closure(&hir::Closure { def_id, kind, fn_decl, .. }),
911 ..
912 }) => {
913 match kind {
914 hir::ClosureKind::CoroutineClosure(_) => {
915 return None;
917 }
918 hir::ClosureKind::Closure => Some((def_id, fn_decl)),
919 hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
920 _,
921 hir::CoroutineSource::Fn,
922 )) => {
923 let (sig, owner_id) = match self.tcx.parent_hir_node(hir_id) {
924 Node::Item(&hir::Item {
925 kind: hir::ItemKind::Fn { ref sig, .. },
926 owner_id,
927 ..
928 }) => (sig, owner_id),
929 Node::TraitItem(&hir::TraitItem {
930 kind: hir::TraitItemKind::Fn(ref sig, ..),
931 owner_id,
932 ..
933 }) => (sig, owner_id),
934 Node::ImplItem(&hir::ImplItem {
935 kind: hir::ImplItemKind::Fn(ref sig, ..),
936 owner_id,
937 ..
938 }) => (sig, owner_id),
939 _ => return None,
940 };
941 Some((owner_id.def_id, sig.decl))
942 }
943 _ => None,
944 }
945 }
946 _ => None,
947 }
948 })
949 }
950
951 pub(crate) fn note_internal_mutation_in_method(
952 &self,
953 err: &mut Diag<'_>,
954 expr: &hir::Expr<'_>,
955 expected: Option<Ty<'tcx>>,
956 found: Ty<'tcx>,
957 ) {
958 if found != self.tcx.types.unit {
959 return;
960 }
961
962 let ExprKind::MethodCall(path_segment, rcvr, ..) = expr.kind else {
963 return;
964 };
965
966 let rcvr_has_the_expected_type = self
967 .typeck_results
968 .borrow()
969 .expr_ty_adjusted_opt(rcvr)
970 .zip(expected)
971 .is_some_and(|(ty, expected_ty)| expected_ty.peel_refs() == ty.peel_refs());
972
973 let prev_call_mutates_and_returns_unit = || {
974 self.typeck_results
975 .borrow()
976 .type_dependent_def_id(expr.hir_id)
977 .map(|def_id| self.tcx.fn_sig(def_id).skip_binder().skip_binder())
978 .and_then(|sig| sig.inputs_and_output.split_last())
979 .is_some_and(|(output, inputs)| {
980 output.is_unit()
981 && inputs
982 .get(0)
983 .and_then(|self_ty| self_ty.ref_mutability())
984 .is_some_and(rustc_ast::Mutability::is_mut)
985 })
986 };
987
988 if !(rcvr_has_the_expected_type || prev_call_mutates_and_returns_unit()) {
989 return;
990 }
991
992 let mut sp = MultiSpan::from_span(path_segment.ident.span);
993 sp.push_span_label(
994 path_segment.ident.span,
995 ::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!(
996 "this call modifies {} in-place",
997 match rcvr.kind {
998 ExprKind::Path(QPath::Resolved(
999 None,
1000 hir::Path { segments: [segment], .. },
1001 )) => format!("`{}`", segment.ident),
1002 _ => "its receiver".to_string(),
1003 }
1004 ),
1005 );
1006
1007 let modifies_rcvr_note =
1008 ::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);
1009 if rcvr_has_the_expected_type {
1010 sp.push_span_label(
1011 rcvr.span,
1012 "you probably want to use this value after calling the method...",
1013 );
1014 err.span_note(sp, modifies_rcvr_note);
1015 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));
1016 } else if let ExprKind::MethodCall(..) = rcvr.kind {
1017 err.span_note(
1018 sp,
1019 modifies_rcvr_note + ", it is not meant to be used in method chains.",
1020 );
1021 } else {
1022 err.span_note(sp, modifies_rcvr_note);
1023 }
1024 }
1025
1026 #[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(1028u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segments")
}> =
::tracing::__macro_support::FieldName::new("segments");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path_span")
}> =
::tracing::__macro_support::FieldName::new("path_span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_id");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segments)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path_span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_id)
as &dyn ::tracing::field::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:1079",
"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(1079u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("container")
}> =
::tracing::__macro_support::FieldName::new("container");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("container_id")
}> =
::tracing::__macro_support::FieldName::new("container_id");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&container)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&container_id)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match container {
ty::AssocContainer::Trait => {
let arg_span =
if let hir::Node::Expr(call_expr) =
self.tcx.parent_hir_node(hir_id) &&
let hir::ExprKind::Call(_, args) = call_expr.kind &&
let Some(first_arg) = args.first() {
let mut arg = first_arg;
while let hir::ExprKind::AddrOf(_, _, inner) = arg.kind {
arg = inner;
}
Some(arg.span)
} else { None };
if let Err(e) =
callee::check_legal_trait_for_method_call(tcx, path_span,
arg_span, span, container_id, self.body_def_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, Unnormalized::new_wip(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_value_path(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().skip_norm_wip());
if std::iter::successors(Some(self.body_def_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|
diagnostics::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(diagnostics::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(diagnostics::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,
diagnostics::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).skip_norm_wip()).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).skip_norm_wip();
}
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, Unnormalized::new_wip(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, Unnormalized::new_wip(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:1467",
"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(1467u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("instantiate_value_path: type of {0:?} is {1:?}",
hir_id, ty_instantiated) as &dyn ::tracing::field::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")]
1029 pub(crate) fn instantiate_value_path(
1030 &self,
1031 segments: &'tcx [hir::PathSegment<'tcx>],
1032 self_ty: Option<LoweredTy<'tcx>>,
1033 res: Res,
1034 span: Span,
1035 path_span: Span,
1036 hir_id: HirId,
1037 ) -> (Ty<'tcx>, Res) {
1038 let tcx = self.tcx;
1039
1040 let generic_segments = match res {
1041 Res::Local(_) | Res::SelfCtor(_) => vec![],
1042 Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments(
1043 segments,
1044 self_ty.map(|ty| ty.raw),
1045 kind,
1046 def_id,
1047 span,
1048 ),
1049 Res::Err => {
1050 return (
1051 Ty::new_error(
1052 tcx,
1053 tcx.dcx().span_delayed_bug(span, "could not resolve path {:?}"),
1054 ),
1055 res,
1056 );
1057 }
1058 _ => bug!("instantiate_value_path on {:?}", res),
1059 };
1060
1061 let mut user_self_ty = None;
1062 let mut is_alias_variant_ctor = false;
1063 let mut err_extend = GenericsArgsErrExtend::None;
1064 match res {
1065 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) if let Some(self_ty) = self_ty => {
1066 let adt_def = self_ty.normalized.ty_adt_def().unwrap();
1067 user_self_ty =
1068 Some(UserSelfTy { impl_def_id: adt_def.did(), self_ty: self_ty.raw });
1069 is_alias_variant_ctor = true;
1070 err_extend = GenericsArgsErrExtend::DefVariant(segments);
1071 }
1072 Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => {
1073 err_extend = GenericsArgsErrExtend::DefVariant(segments);
1074 }
1075 Res::Def(DefKind::AssocFn | DefKind::AssocConst { .. }, def_id) => {
1076 let assoc_item = tcx.associated_item(def_id);
1077 let container = assoc_item.container;
1078 let container_id = assoc_item.container_id(tcx);
1079 debug!(?def_id, ?container, ?container_id);
1080 match container {
1081 ty::AssocContainer::Trait => {
1082 let arg_span = if let hir::Node::Expr(call_expr) =
1083 self.tcx.parent_hir_node(hir_id)
1084 && let hir::ExprKind::Call(_, args) = call_expr.kind
1085 && let Some(first_arg) = args.first()
1086 {
1087 let mut arg = first_arg;
1088 while let hir::ExprKind::AddrOf(_, _, inner) = arg.kind {
1089 arg = inner;
1090 }
1091 Some(arg.span)
1092 } else {
1093 None
1094 };
1095
1096 if let Err(e) = callee::check_legal_trait_for_method_call(
1097 tcx,
1098 path_span,
1099 arg_span,
1100 span,
1101 container_id,
1102 self.body_def_id.to_def_id(),
1103 ) {
1104 self.set_tainted_by_errors(e);
1105 }
1106 }
1107 ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => {
1108 if segments.len() == 1 {
1109 user_self_ty = self_ty.map(|self_ty| UserSelfTy {
1116 impl_def_id: container_id,
1117 self_ty: self_ty.raw,
1118 });
1119 }
1120 }
1121 }
1122 }
1123 _ => {}
1124 }
1125
1126 let indices: FxHashSet<_> =
1132 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
1133 let generics_err = self.lowerer().prohibit_generic_args(
1134 segments.iter().enumerate().filter_map(|(index, seg)| {
1135 if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None }
1136 }),
1137 err_extend,
1138 );
1139
1140 if let Err(e) = self.lowerer().check_param_res_if_mcg_for_instantiate_value_path(res, span)
1141 {
1142 return (Ty::new_error(self.tcx, e), res);
1143 }
1144
1145 if let Res::Local(hid) = res {
1146 let ty = self.local_ty(span, hid);
1147 let ty = self.normalize(span, Unnormalized::new_wip(ty));
1148 return (ty, res);
1149 }
1150
1151 if let Err(_) = generics_err {
1152 user_self_ty = None;
1154 }
1155
1156 let mut infer_args_for_err = None;
1164
1165 let mut explicit_late_bound = ExplicitLateBound::No;
1166 for &GenericPathSegment(def_id, index) in &generic_segments {
1167 let seg = &segments[index];
1168 let generics = tcx.generics_of(def_id);
1169
1170 let arg_count = check_generic_arg_count_for_value_path(
1175 self,
1176 def_id,
1177 generics,
1178 seg,
1179 IsMethodCall::No,
1180 );
1181
1182 if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
1183 explicit_late_bound = ExplicitLateBound::Yes;
1184 }
1185
1186 if let Err(GenericArgCountMismatch { reported, .. }) = arg_count.correct {
1187 infer_args_for_err
1188 .get_or_insert_with(|| (reported, FxHashSet::default()))
1189 .1
1190 .insert(index);
1191 self.set_tainted_by_errors(reported); }
1193 }
1194
1195 let has_self = generic_segments
1196 .last()
1197 .is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self);
1198
1199 let (res, implicit_args) = if let Res::Def(DefKind::ConstParam, def) = res {
1200 (res, Some(ty::GenericArgs::identity_for_item(tcx, tcx.parent(def))))
1210 } else if let Res::SelfCtor(impl_def_id) = res {
1211 let ty = LoweredTy::from_raw(
1212 self,
1213 span,
1214 tcx.at(span).type_of(impl_def_id).instantiate_identity().skip_norm_wip(),
1215 );
1216
1217 if std::iter::successors(Some(self.body_def_id.to_def_id()), |&def_id| {
1225 self.tcx.generics_of(def_id).parent
1226 })
1227 .all(|def_id| def_id != impl_def_id)
1228 {
1229 let sugg = ty.normalized.ty_adt_def().map(|def| diagnostics::ReplaceWithName {
1230 span: path_span,
1231 name: self.tcx.item_name(def.did()).to_ident_string(),
1232 });
1233 let item = match self
1234 .tcx
1235 .hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
1236 {
1237 hir::Node::Item(item) => Some(diagnostics::InnerItem {
1238 span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
1239 }),
1240 _ => None,
1241 };
1242 if ty.raw.has_param() {
1243 let guar = self.dcx().emit_err(diagnostics::SelfCtorFromOuterItem {
1244 span: path_span,
1245 impl_span: tcx.def_span(impl_def_id),
1246 sugg,
1247 item,
1248 });
1249 return (Ty::new_error(self.tcx, guar), res);
1250 } else {
1251 self.tcx.emit_node_span_lint(
1252 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
1253 hir_id,
1254 path_span,
1255 diagnostics::SelfCtorFromOuterItemLint {
1256 impl_span: tcx.def_span(impl_def_id),
1257 sugg,
1258 item,
1259 },
1260 );
1261 }
1262 }
1263
1264 match ty.normalized.ty_adt_def() {
1265 Some(adt_def) if adt_def.has_ctor() => {
1266 let (ctor_kind, ctor_def_id) = adt_def.non_enum_variant().ctor.unwrap();
1267 let vis = tcx.visibility(ctor_def_id);
1269 if !vis.is_accessible_from(tcx.parent_module(hir_id).to_def_id(), tcx) {
1270 self.dcx()
1271 .emit_err(CtorIsPrivate { span, def: tcx.def_path_str(adt_def.did()) });
1272 }
1273 let new_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
1274 let user_args = Self::user_args_for_adt(ty);
1275 user_self_ty = user_args.user_self_ty;
1276 (new_res, Some(user_args.args))
1277 }
1278 _ => {
1279 let mut err = self.dcx().struct_span_err(
1280 span,
1281 "the `Self` constructor can only be used with tuple or unit structs",
1282 );
1283 if let Some(adt_def) = ty.normalized.ty_adt_def() {
1284 match adt_def.adt_kind() {
1285 AdtKind::Enum => {
1286 err.help("did you mean to use one of the enum's variants?");
1287 }
1288 AdtKind::Struct | AdtKind::Union => {
1289 err.span_suggestion(
1290 span,
1291 "use curly brackets",
1292 "Self { /* fields */ }",
1293 Applicability::HasPlaceholders,
1294 );
1295 }
1296 }
1297 }
1298 let reported = err.emit();
1299 return (Ty::new_error(tcx, reported), res);
1300 }
1301 }
1302 } else {
1303 (res, None)
1304 };
1305 let def_id = res.def_id();
1306
1307 let (correct, infer_args_for_err) = match infer_args_for_err {
1308 Some((reported, args)) => {
1309 (Err(GenericArgCountMismatch { reported, invalid_args: vec![] }), args)
1310 }
1311 None => (Ok(()), Default::default()),
1312 };
1313
1314 let arg_count = GenericArgCountResult { explicit_late_bound, correct };
1315
1316 struct CtorGenericArgsCtxt<'a, 'tcx> {
1317 fcx: &'a FnCtxt<'a, 'tcx>,
1318 span: Span,
1319 generic_segments: &'a [GenericPathSegment],
1320 infer_args_for_err: &'a FxHashSet<usize>,
1321 segments: &'tcx [hir::PathSegment<'tcx>],
1322 }
1323 impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> {
1324 fn args_for_def_id(
1325 &mut self,
1326 def_id: DefId,
1327 ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) {
1328 if let Some(&GenericPathSegment(_, index)) =
1329 self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id)
1330 {
1331 if !self.infer_args_for_err.contains(&index) {
1334 if let Some(data) = self.segments[index].args {
1336 return (Some(data), self.segments[index].infer_args);
1337 }
1338 }
1339 return (None, self.segments[index].infer_args);
1340 }
1341
1342 (None, true)
1343 }
1344
1345 fn provided_kind(
1346 &mut self,
1347 preceding_args: &[ty::GenericArg<'tcx>],
1348 param: &ty::GenericParamDef,
1349 arg: &GenericArg<'tcx>,
1350 ) -> ty::GenericArg<'tcx> {
1351 match (¶m.kind, arg) {
1352 (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => self
1353 .fcx
1354 .lowerer()
1355 .lower_lifetime(lt, RegionInferReason::Param(param))
1356 .into(),
1357 (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => {
1358 self.fcx.lower_ty(ty.as_unambig_ty()).raw.into()
1360 }
1361 (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => {
1362 self.fcx.lower_ty(&inf.to_ty()).raw.into()
1363 }
1364 (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
1365 .fcx
1366 .lower_const_arg(
1368 ct.as_unambig_ct(),
1369 self.fcx
1370 .tcx
1371 .type_of(param.def_id)
1372 .instantiate(self.fcx.tcx, preceding_args)
1373 .skip_norm_wip(),
1374 )
1375 .into(),
1376 (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
1377 self.fcx.ct_infer(Some(param), inf.span).into()
1378 }
1379 _ => unreachable!(),
1380 }
1381 }
1382
1383 fn inferred_kind(
1384 &mut self,
1385 preceding_args: &[ty::GenericArg<'tcx>],
1386 param: &ty::GenericParamDef,
1387 infer_args: bool,
1388 ) -> ty::GenericArg<'tcx> {
1389 let tcx = self.fcx.tcx();
1390 if !infer_args && let Some(default) = param.default_value(tcx) {
1391 return default.instantiate(tcx, preceding_args).skip_norm_wip();
1394 }
1395 self.fcx.var_for_def(self.span, param)
1400 }
1401 }
1402
1403 let args_raw = implicit_args.unwrap_or_else(|| {
1404 lower_generic_args(
1405 self,
1406 def_id,
1407 &[],
1408 has_self,
1409 self_ty.map(|s| s.raw),
1410 &arg_count,
1411 &mut CtorGenericArgsCtxt {
1412 fcx: self,
1413 span,
1414 generic_segments: &generic_segments,
1415 infer_args_for_err: &infer_args_for_err,
1416 segments,
1417 },
1418 )
1419 });
1420
1421 let args_for_user_type = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
1422 self.transform_args_for_inherent_type_const(def_id, args_raw)
1423 } else {
1424 args_raw
1425 };
1426
1427 self.write_user_type_annotation_from_args(hir_id, def_id, args_for_user_type, user_self_ty);
1429
1430 let args = self.normalize(span, Unnormalized::new_wip(args_raw));
1432
1433 self.add_required_obligations_for_hir(span, def_id, args, hir_id);
1434
1435 let ty = tcx.type_of(def_id);
1438 assert!(!args.has_escaping_bound_vars());
1439 assert!(!ty.skip_binder().has_escaping_bound_vars());
1440 let ty_instantiated = self.normalize(span, ty.instantiate(tcx, args));
1441
1442 if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
1443 let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args));
1449 let self_ty = self.normalize(span, Unnormalized::new_wip(self_ty));
1450 match self.at(&self.misc(span), self.param_env).eq(
1451 DefineOpaqueTypes::Yes,
1452 impl_ty,
1453 self_ty,
1454 ) {
1455 Ok(ok) => self.register_infer_ok_obligations(ok),
1456 Err(_) => {
1457 self.dcx().span_bug(
1458 span,
1459 format!(
1460 "instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
1461 ),
1462 );
1463 }
1464 }
1465 }
1466
1467 debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_instantiated);
1468
1469 let args = if let Res::Def(DefKind::AssocConst { .. }, def_id) = res {
1470 self.transform_args_for_inherent_type_const(def_id, args)
1471 } else {
1472 args
1473 };
1474
1475 self.write_args(hir_id, args);
1476
1477 (ty_instantiated, res)
1478 }
1479
1480 pub(crate) fn add_required_obligations_for_hir(
1482 &self,
1483 span: Span,
1484 def_id: DefId,
1485 args: GenericArgsRef<'tcx>,
1486 hir_id: HirId,
1487 ) {
1488 self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
1489 ObligationCauseCode::WhereClauseInExpr(def_id, span, hir_id, idx)
1490 })
1491 }
1492
1493 #[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(1493u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::_impl"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::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.tcx.clauses_of(def_id).instantiate(self.tcx, args);
for obligation in
traits::predicates_for_generics(|idx, clause_span|
self.cause(span, code(idx, clause_span)),
|clause| self.normalize(span, clause), param_env, bounds) {
self.register_predicate(obligation);
}
}
}
}#[instrument(level = "debug", skip(self, code, span, args))]
1494 pub(crate) fn add_required_obligations_with_code(
1495 &self,
1496 span: Span,
1497 def_id: DefId,
1498 args: GenericArgsRef<'tcx>,
1499 code: impl Fn(usize, Span) -> ObligationCauseCode<'tcx>,
1500 ) {
1501 let param_env = self.param_env;
1502
1503 let bounds = self.tcx.clauses_of(def_id).instantiate(self.tcx, args);
1504
1505 for obligation in traits::predicates_for_generics(
1506 |idx, clause_span| self.cause(span, code(idx, clause_span)),
1507 |clause| self.normalize(span, clause),
1508 param_env,
1509 bounds,
1510 ) {
1511 self.register_predicate(obligation);
1512 }
1513 }
1514
1515 x;#[instrument(level = "debug", skip(self, sp), ret)]
1516 pub(crate) fn try_structurally_resolve_const(
1517 &self,
1518 sp: Span,
1519 ct: ty::Const<'tcx>,
1520 ) -> ty::Const<'tcx> {
1521 let ct = self.resolve_vars_with_obligations(ct);
1522
1523 if self.next_trait_solver()
1524 && let ty::ConstKind::Alias(..) = ct.kind()
1525 {
1526 let result = self.at(&self.misc(sp), self.param_env).structurally_normalize_const(
1530 Unnormalized::new_wip(ct),
1531 &mut *self.fulfillment_cx.borrow_mut(),
1532 );
1533 match result {
1534 Ok(normalized_ct) => normalized_ct,
1535 Err(errors) => {
1536 let guar = self.err_ctxt().report_fulfillment_errors(errors);
1537 return ty::Const::new_error(self.tcx, guar);
1538 }
1539 }
1540 } else if self.tcx.features().generic_const_exprs() {
1541 rustc_trait_selection::traits::evaluate_const(&self.infcx, ct, self.param_env)
1542 } else {
1543 ct
1544 }
1545 }
1546
1547 pub(crate) fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1556 let ty = self.resolve_vars_with_obligations(ty);
1557
1558 if !ty.is_ty_var() { ty } else { self.type_must_be_known_at_this_point(sp, ty) }
1559 }
1560
1561 #[cold]
1562 pub(crate) fn type_must_be_known_at_this_point(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1563 let guar = self.tainted_by_errors().unwrap_or_else(|| {
1564 self.err_ctxt()
1565 .emit_inference_failure_err(
1566 self.body_def_id,
1567 sp,
1568 ty.into(),
1569 TypeAnnotationNeeded::E0282,
1570 true,
1571 )
1572 .emit()
1573 });
1574 let err = Ty::new_error(self.tcx, guar);
1575 self.demand_suptype(sp, err, ty);
1576 err
1577 }
1578
1579 pub(crate) fn structurally_resolve_const(
1580 &self,
1581 sp: Span,
1582 ct: ty::Const<'tcx>,
1583 ) -> ty::Const<'tcx> {
1584 let ct = self.try_structurally_resolve_const(sp, ct);
1585
1586 if !ct.is_ct_infer() {
1587 ct
1588 } else {
1589 let e = self.tainted_by_errors().unwrap_or_else(|| {
1590 self.err_ctxt()
1591 .emit_inference_failure_err(
1592 self.body_def_id,
1593 sp,
1594 ct.into(),
1595 TypeAnnotationNeeded::E0282,
1596 true,
1597 )
1598 .emit()
1599 });
1600 ty::Const::new_error(self.tcx, e)
1602 }
1603 }
1604
1605 pub(crate) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
1606 &self,
1607 id: HirId,
1608 ctxt: BreakableCtxt<'tcx>,
1609 f: F,
1610 ) -> (BreakableCtxt<'tcx>, R) {
1611 let index;
1612 {
1613 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1614 index = enclosing_breakables.stack.len();
1615 enclosing_breakables.by_id.insert(id, index);
1616 enclosing_breakables.stack.push(ctxt);
1617 }
1618 let result = f();
1619 let ctxt = {
1620 let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
1621 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);
1622 enclosing_breakables.by_id.swap_remove(&id).expect("missing breakable context");
1624 enclosing_breakables.stack.pop().expect("missing breakable context")
1625 };
1626 (ctxt, result)
1627 }
1628
1629 pub(crate) fn probe_instantiate_query_response(
1632 &self,
1633 span: Span,
1634 original_values: &OriginalQueryValues<'tcx>,
1635 query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
1636 ) -> InferResult<'tcx, Ty<'tcx>> {
1637 self.instantiate_query_response_and_region_obligations(
1638 &self.misc(span),
1639 self.param_env,
1640 original_values,
1641 query_result,
1642 )
1643 }
1644
1645 pub(crate) fn expr_in_place(&self, mut expr_id: HirId) -> bool {
1647 let mut contained_in_place = false;
1648
1649 while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {
1650 match &parent_expr.kind {
1651 hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => {
1652 if lhs.hir_id == expr_id {
1653 contained_in_place = true;
1654 break;
1655 }
1656 }
1657 _ => (),
1658 }
1659 expr_id = parent_expr.hir_id;
1660 }
1661
1662 contained_in_place
1663 }
1664}