1use std::mem;
12use std::ops::ControlFlow;
13
14use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
15use rustc_data_structures::unord::ExtendUnord;
16use rustc_errors::{E0720, ErrorGuaranteed};
17use rustc_hir::def_id::LocalDefId;
18use rustc_hir::intravisit::{self, InferKind, Visitor};
19use rustc_hir::{self as hir, AmbigArg, HirId, find_attr};
20use rustc_infer::traits::solve::Goal;
21use rustc_middle::traits::ObligationCause;
22use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
23use rustc_middle::ty::{
24 self, DefiningScopeKind, DefinitionSiteHiddenType, Flags, Ty, TyCtxt, TypeFoldable, TypeFolder,
25 TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
26 Unnormalized, fold_regions,
27};
28use rustc_span::Span;
29use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
30use rustc_trait_selection::opaque_types::opaque_type_has_defining_use_args;
31use rustc_trait_selection::solve;
32use tracing::{debug, instrument};
33
34use crate::FnCtxt;
35
36impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
40 pub(crate) fn resolve_type_vars_in_body(
41 &self,
42 body: &'tcx hir::Body<'tcx>,
43 ) -> &'tcx ty::TypeckResults<'tcx> {
44 let item_def_id = self.tcx.hir_body_owner_def_id(body.id());
45
46 let rustc_dump_user_args =
49 self.has_rustc_attrs && {
{
'done:
{
for i in
::rustc_attr_ir::HasAttrs::get_attrs(item_def_id, &self.tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcDumpUserArgs) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(self.tcx, item_def_id, RustcDumpUserArgs);
50
51 let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_args);
52 for param in body.params {
53 wbcx.visit_node_id(param.pat.span, param.hir_id);
54 }
55 match self.tcx.hir_body_owner_kind(item_def_id) {
56 hir::BodyOwnerKind::Const { .. }
58 | hir::BodyOwnerKind::Static(_)
59 | hir::BodyOwnerKind::GlobalAsm => {
60 let item_hir_id = self.tcx.local_def_id_to_hir_id(item_def_id);
61 wbcx.visit_node_id(body.value.span, item_hir_id);
62 }
63 hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => {}
65 }
66 wbcx.visit_body(body);
67 wbcx.visit_min_capture_map();
68 wbcx.eval_closure_size();
69 wbcx.visit_fake_reads_map();
70 wbcx.visit_closures();
71 wbcx.visit_liberated_fn_sigs();
72 wbcx.visit_fru_field_types();
73 wbcx.visit_opaque_types();
74 wbcx.visit_coercion_casts();
75 wbcx.visit_user_provided_tys();
76 wbcx.visit_user_provided_sigs();
77 wbcx.visit_coroutine_interior();
78 wbcx.visit_transmutes();
79 wbcx.visit_offloads();
80 wbcx.visit_offset_of_container_types();
81 wbcx.visit_potentially_region_dependent_goals();
82
83 let used_trait_imports =
84 mem::take(&mut self.typeck_results.borrow_mut().used_trait_imports);
85 {
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/writeback.rs:85",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(85u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("used_trait_imports({0:?}) = {1:?}",
item_def_id, used_trait_imports) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
86 wbcx.typeck_results.used_trait_imports = used_trait_imports;
87
88 {
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/writeback.rs:88",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(88u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("writeback: typeck results for {0:?} are {1:#?}",
item_def_id, wbcx.typeck_results) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results);
89
90 self.tcx.arena.alloc(wbcx.typeck_results)
91 }
92}
93
94struct WritebackCx<'cx, 'tcx> {
100 fcx: &'cx FnCtxt<'cx, 'tcx>,
101
102 typeck_results: ty::TypeckResults<'tcx>,
103
104 body: &'tcx hir::Body<'tcx>,
105
106 rustc_dump_user_args: bool,
107}
108
109impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
110 fn new(
111 fcx: &'cx FnCtxt<'cx, 'tcx>,
112 body: &'tcx hir::Body<'tcx>,
113 rustc_dump_user_args: bool,
114 ) -> WritebackCx<'cx, 'tcx> {
115 let owner = body.id().hir_id.owner;
116
117 let mut wbcx = WritebackCx {
118 fcx,
119 typeck_results: ty::TypeckResults::new(owner),
120 body,
121 rustc_dump_user_args,
122 };
123
124 if let Some(e) = fcx.tainted_by_errors() {
128 wbcx.typeck_results.tainted_by_errors = Some(e);
129 }
130
131 wbcx
132 }
133
134 fn tcx(&self) -> TyCtxt<'tcx> {
135 self.fcx.tcx
136 }
137
138 fn write_ty_to_typeck_results(&mut self, hir_id: HirId, ty: Ty<'tcx>) {
139 {
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/writeback.rs:139",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(139u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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_to_typeck_results({0:?}, {1:?})",
hir_id, ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
140 if !(!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions()) {
{
::core::panicking::panic_fmt(format_args!("{0} can\'t be put into typeck results",
ty));
}
};assert!(
141 !ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
142 "{ty} can't be put into typeck results"
143 );
144 self.typeck_results.node_types_mut().insert(hir_id, ty);
145 }
146
147 fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr<'_>) {
152 match e.kind {
153 hir::ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, inner) => {
154 let inner_ty = self.typeck_results.node_type(inner.hir_id);
155
156 if inner_ty.is_scalar() {
157 self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
158 self.typeck_results.node_args_mut().remove(e.hir_id);
159 }
160 }
161 hir::ExprKind::Binary(ref op, lhs, rhs) => {
162 let lhs_ty = self.typeck_results.node_type(lhs.hir_id);
163 let rhs_ty = self.typeck_results.node_type(rhs.hir_id);
164
165 if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
166 self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
167 self.typeck_results.node_args_mut().remove(e.hir_id);
168
169 if !op.node.is_by_value() {
170 let mut adjustments = self.typeck_results.adjustments_mut();
171 if let Some(a) = adjustments.get_mut(lhs.hir_id) {
172 a.pop();
173 }
174 if let Some(a) = adjustments.get_mut(rhs.hir_id) {
175 a.pop();
176 }
177 }
178 }
179 }
180 hir::ExprKind::AssignOp(_, lhs, rhs) => {
181 let lhs_ty = self.typeck_results.node_type(lhs.hir_id);
182 let rhs_ty = self.typeck_results.node_type(rhs.hir_id);
183
184 if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
185 self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
186 self.typeck_results.node_args_mut().remove(e.hir_id);
187
188 if let Some(a) = self.typeck_results.adjustments_mut().get_mut(lhs.hir_id) {
189 a.pop();
190 }
191 }
192 }
193 _ => {}
194 }
195 }
196
197 fn is_builtin_index(
202 &mut self,
203 e: &hir::Expr<'_>,
204 base_ty: Ty<'tcx>,
205 index_ty: Ty<'tcx>,
206 ) -> bool {
207 if let Some(elem_ty) = base_ty.builtin_index()
208 && let Some(exp_ty) = self.typeck_results.expr_ty_opt(e)
209 {
210 elem_ty == exp_ty && index_ty == self.fcx.tcx.types.usize
211 } else {
212 false
213 }
214 }
215
216 fn fix_index_builtin_expr(&mut self, e: &hir::Expr<'_>) {
221 if let hir::ExprKind::Index(base, index, _) = e.kind {
222 let base_ty = self.typeck_results.expr_ty_adjusted(base);
224 if let ty::Ref(_, base_ty_inner, _) = *base_ty.kind() {
225 let index_ty = self.typeck_results.expr_ty_adjusted(index);
226 if self.is_builtin_index(e, base_ty_inner, index_ty) {
227 self.typeck_results.type_dependent_defs_mut().remove(e.hir_id);
229 self.typeck_results.node_args_mut().remove(e.hir_id);
230
231 if let Some(a) = self.typeck_results.adjustments_mut().get_mut(base.hir_id)
232 && let Some(Adjustment {
238 kind: Adjust::Pointer(PointerCoercion::Unsize),
239 ..
240 }) = a.pop()
241 {
242 a.pop();
244 }
245 }
246 }
247 }
248 }
249}
250
251impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
260 fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
261 match e.kind {
262 hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
263 let body = self.fcx.tcx.hir_body(body);
264 for param in body.params {
265 self.visit_node_id(e.span, param.hir_id);
266 }
267
268 self.visit_body(body);
269 }
270 hir::ExprKind::Struct(_, fields, _) => {
271 for field in fields {
272 self.visit_field_id(field.hir_id);
273 }
274 }
275 hir::ExprKind::Field(..) | hir::ExprKind::OffsetOf(..) => {
276 self.visit_field_id(e.hir_id);
277 }
278 _ => {}
279 }
280
281 self.visit_node_id(e.span, e.hir_id);
282 intravisit::walk_expr(self, e);
283
284 self.fix_scalar_builtin_expr(e);
285 self.fix_index_builtin_expr(e);
286 }
287
288 fn visit_inline_const(&mut self, anon_const: &hir::ConstBlock) {
289 let span = self.tcx().def_span(anon_const.def_id);
290 self.visit_node_id(span, anon_const.hir_id);
291
292 let body = self.tcx().hir_body(anon_const.body);
293 self.visit_body(body);
294 }
295
296 fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
297 match &p.kind {
298 hir::GenericParamKind::Lifetime { .. } => {
299 }
301 hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => {
302 self.tcx()
303 .dcx()
304 .span_delayed_bug(p.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unexpected generic param: {0:?}",
p))
})format!("unexpected generic param: {p:?}"));
305 }
306 }
307 }
308
309 fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
310 self.visit_node_id(b.span, b.hir_id);
311 intravisit::walk_block(self, b);
312 }
313
314 fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
315 match p.kind {
316 hir::PatKind::Binding(..) => {
317 let typeck_results = self.fcx.typeck_results.borrow();
318 let bm = typeck_results.extract_binding_mode(self.tcx().sess, p.hir_id, p.span);
319 self.typeck_results.pat_binding_modes_mut().insert(p.hir_id, bm);
320 }
321 hir::PatKind::Struct(_, fields, _) => {
322 for field in fields {
323 self.visit_field_id(field.hir_id);
324 }
325 }
326 _ => {}
327 };
328
329 self.visit_rust_2024_migration_desugared_pats(p.hir_id);
330 self.visit_skipped_ref_pats(p.hir_id);
331 self.visit_pat_adjustments(p.span, p.hir_id);
332
333 self.visit_node_id(p.span, p.hir_id);
334 intravisit::walk_pat(self, p);
335 }
336
337 fn visit_pat_expr(&mut self, expr: &'tcx hir::PatExpr<'tcx>) {
338 self.visit_node_id(expr.span, expr.hir_id);
339 intravisit::walk_pat_expr(self, expr);
340 }
341
342 fn visit_local(&mut self, l: &'tcx hir::LetStmt<'tcx>) {
343 intravisit::walk_local(self, l);
344 let var_ty = self.fcx.local_ty(l.span, l.hir_id);
345 let var_ty = self.resolve(var_ty, &l.span);
346 self.write_ty_to_typeck_results(l.hir_id, var_ty);
347 }
348
349 fn visit_ty(&mut self, hir_ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
350 intravisit::walk_ty(self, hir_ty);
351 if let Some(ty) = self.fcx.node_ty_opt(hir_ty.hir_id) {
354 let ty = self.resolve(ty, &hir_ty.span);
355 self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
356 }
357 }
358
359 fn visit_infer(
360 &mut self,
361 inf_id: HirId,
362 inf_span: Span,
363 _kind: InferKind<'cx>,
364 ) -> Self::Result {
365 self.visit_id(inf_id);
366
367 if let Some(ty) = self.fcx.node_ty_opt(inf_id) {
371 let ty = self.resolve(ty, &inf_span);
372 self.write_ty_to_typeck_results(inf_id, ty);
373 }
374 }
375}
376
377impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
378 fn eval_closure_size(&mut self) {
379 self.tcx().with_stable_hashing_context(|mut hcx| {
380 let fcx_typeck_results = self.fcx.typeck_results.borrow();
381
382 self.typeck_results.closure_size_eval = fcx_typeck_results
383 .closure_size_eval
384 .to_sorted(&mut hcx, false)
385 .into_iter()
386 .map(|(&closure_def_id, data)| {
387 let closure_hir_id = self.tcx().local_def_id_to_hir_id(closure_def_id);
388 let data = self.resolve(*data, &closure_hir_id);
389 (closure_def_id, data)
390 })
391 .collect();
392 })
393 }
394
395 fn visit_min_capture_map(&mut self) {
396 self.tcx().with_stable_hashing_context(|mut hcx| {
397 let fcx_typeck_results = self.fcx.typeck_results.borrow();
398
399 self.typeck_results.closure_min_captures = fcx_typeck_results
400 .closure_min_captures
401 .to_sorted(&mut hcx, false)
402 .into_iter()
403 .map(|(&closure_def_id, root_min_captures)| {
404 let root_var_map_wb = root_min_captures
405 .iter()
406 .map(|(var_hir_id, min_list)| {
407 let min_list_wb = min_list
408 .iter()
409 .map(|captured_place| {
410 let locatable =
411 captured_place.info.path_expr_id.unwrap_or_else(|| {
412 self.tcx().local_def_id_to_hir_id(closure_def_id)
413 });
414 self.resolve(captured_place.clone(), &locatable)
415 })
416 .collect();
417 (*var_hir_id, min_list_wb)
418 })
419 .collect();
420 (closure_def_id, root_var_map_wb)
421 })
422 .collect();
423 })
424 }
425
426 fn visit_fake_reads_map(&mut self) {
427 self.tcx().with_stable_hashing_context(move |mut hcx| {
428 let fcx_typeck_results = self.fcx.typeck_results.borrow();
429
430 self.typeck_results.closure_fake_reads = fcx_typeck_results
431 .closure_fake_reads
432 .to_sorted(&mut hcx, true)
433 .into_iter()
434 .map(|(&closure_def_id, fake_reads)| {
435 let resolved_fake_reads = fake_reads
436 .iter()
437 .map(|(place, cause, hir_id)| {
438 let locatable = self.tcx().local_def_id_to_hir_id(closure_def_id);
439 let resolved_fake_read = self.resolve(place.clone(), &locatable);
440 (resolved_fake_read, *cause, *hir_id)
441 })
442 .collect();
443
444 (closure_def_id, resolved_fake_reads)
445 })
446 .collect();
447 });
448 }
449
450 fn visit_closures(&mut self) {
451 let fcx_typeck_results = self.fcx.typeck_results.borrow();
452 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
453 let common_hir_owner = fcx_typeck_results.hir_owner;
454
455 let fcx_closure_kind_origins =
456 fcx_typeck_results.closure_kind_origins().items_in_stable_order();
457
458 for (local_id, origin) in fcx_closure_kind_origins {
459 let hir_id = HirId { owner: common_hir_owner, local_id };
460 let place_span = origin.0;
461 let place = self.resolve(origin.1.clone(), &place_span);
462 self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place));
463 }
464 }
465
466 fn visit_coercion_casts(&mut self) {
467 let fcx_typeck_results = self.fcx.typeck_results.borrow();
468
469 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
470
471 let fcx_coercion_casts = fcx_typeck_results.coercion_casts().to_sorted_stable_ord();
472 for &local_id in fcx_coercion_casts {
473 self.typeck_results.set_coercion_cast(local_id);
474 }
475 }
476
477 fn visit_user_provided_tys(&mut self) {
478 let fcx_typeck_results = self.fcx.typeck_results.borrow();
479 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
480 let common_hir_owner = fcx_typeck_results.hir_owner;
481
482 if self.rustc_dump_user_args {
483 let sorted_user_provided_types =
484 fcx_typeck_results.user_provided_types().items_in_stable_order();
485
486 let mut errors_buffer = Vec::new();
487 for (local_id, c_ty) in sorted_user_provided_types {
488 let hir_id = HirId { owner: common_hir_owner, local_id };
489
490 if let ty::UserTypeKind::TypeOf(_, user_args) = c_ty.value.kind {
491 let span = self.tcx().hir_span(hir_id);
493 let err =
496 self.tcx().dcx().struct_span_err(span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("user args: {0:?}", user_args))
})format!("user args: {user_args:?}"));
497 errors_buffer.push(err);
498 }
499 }
500
501 if !errors_buffer.is_empty() {
502 errors_buffer.sort_by_key(|diag| diag.span.primary_span());
503 for err in errors_buffer {
504 err.emit();
505 }
506 }
507 }
508
509 self.typeck_results.user_provided_types_mut().extend(
510 fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
511 let hir_id = HirId { owner: common_hir_owner, local_id };
512 (hir_id, *c_ty)
513 }),
514 );
515 }
516
517 fn visit_user_provided_sigs(&mut self) {
518 let fcx_typeck_results = self.fcx.typeck_results.borrow();
519 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
520
521 self.typeck_results.user_provided_sigs.extend_unord(
522 fcx_typeck_results.user_provided_sigs.items().map(|(def_id, c_sig)| (*def_id, *c_sig)),
523 );
524 }
525
526 fn visit_coroutine_interior(&mut self) {
527 let fcx_typeck_results = self.fcx.typeck_results.borrow();
528 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
529 for (predicate, cause) in &fcx_typeck_results.coroutine_stalled_predicates {
530 let (predicate, cause) =
531 self.resolve_coroutine_predicate((*predicate, cause.clone()), &cause.span);
532 self.typeck_results.coroutine_stalled_predicates.insert((predicate, cause));
533 }
534 }
535
536 fn visit_transmutes(&mut self) {
537 let tcx = self.tcx();
538 let fcx_typeck_results = self.fcx.typeck_results.borrow();
539 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
540 for &(from, to, hir_id) in self.fcx.deferred_transmute_checks.borrow().iter() {
541 let span = tcx.hir_span(hir_id);
542 let from = self.resolve(from, &span);
543 let to = self.resolve(to, &span);
544 self.typeck_results.transmutes_to_check.push((from, to, hir_id));
545 }
546 }
547
548 fn visit_offloads(&mut self) {
549 let tcx = self.tcx();
550 let fcx_typeck_results = self.fcx.typeck_results.borrow();
551 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
552 for &(kernel_ty, args_ty, ret_ty, hir_id) in
553 self.fcx.deferred_offload_checks.borrow().iter()
554 {
555 let span = tcx.hir_span(hir_id);
556 let kernel_ty = self.resolve(kernel_ty, &span);
557 let args_ty = self.resolve(args_ty, &span);
558 let ret_ty = self.resolve(ret_ty, &span);
559 self.typeck_results.offloads_to_check.push((kernel_ty, args_ty, ret_ty, hir_id));
560 }
561 }
562
563 fn visit_opaque_types_next(&mut self) {
564 let mut fcx_typeck_results = self.fcx.typeck_results.borrow_mut();
565 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
566 {
match (&self.typeck_results.hidden_types.len(), &0) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(self.typeck_results.hidden_types.len(), 0);
567 self.typeck_results.hidden_types = mem::take(&mut fcx_typeck_results.hidden_types);
568 }
569
570 #[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("visit_opaque_types",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(570u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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;
}
{
if self.fcx.next_trait_solver() {
return self.visit_opaque_types_next();
}
let tcx = self.tcx();
let opaque_types = self.fcx.infcx.clone_opaque_types();
let num_entries =
self.fcx.inner.borrow_mut().opaque_types().num_entries();
let prev =
self.fcx.checked_opaque_types_storage_entries.replace(Some(num_entries));
if true {
{
match (&prev, &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};
for (opaque_type_key, hidden_type) in opaque_types {
let hidden_type =
self.resolve(hidden_type, &hidden_type.span);
let opaque_type_key =
self.resolve(opaque_type_key, &hidden_type.span);
if let &ty::Alias(_, ty::AliasTy {
kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.kind() &&
def_id == opaque_type_key.def_id.to_def_id() &&
args == opaque_type_key.args {
continue;
}
if let Err(err) =
opaque_type_has_defining_use_args(self.fcx, opaque_type_key,
hidden_type.span, DefiningScopeKind::HirTypeck) {
self.typeck_results.hidden_types.insert(opaque_type_key.def_id,
ty::DefinitionSiteHiddenType::new_error(tcx,
err.report(self.fcx)));
}
let hidden_type =
hidden_type.remap_generic_params_to_declaration_params(opaque_type_key,
tcx, DefiningScopeKind::HirTypeck);
if let Some(prev) =
self.typeck_results.hidden_types.insert(opaque_type_key.def_id,
hidden_type) {
let entry =
self.typeck_results.hidden_types.get_mut(&opaque_type_key.def_id).unwrap();
if prev.ty != hidden_type.ty {
let guar =
if let Some(guar) = self.typeck_results.tainted_by_errors {
guar
} else {
let (Ok(guar) | Err(guar)) =
prev.build_mismatch_error(&hidden_type,
tcx).map(|d| d.emit());
guar
};
*entry = DefinitionSiteHiddenType::new_error(tcx, guar);
}
entry.span = prev.span.substitute_dummy(hidden_type.span);
}
}
let recursive_opaques: Vec<_> =
self.typeck_results.hidden_types.iter().filter(|&(&def_id,
hidden_ty)|
{
hidden_ty.ty.instantiate_identity().skip_norm_wip().visit_with(&mut HasRecursiveOpaque {
def_id,
seen: Default::default(),
opaques: &self.typeck_results.hidden_types,
tcx,
}).is_break()
}).map(|(def_id, hidden_ty)|
(*def_id, hidden_ty.span)).collect();
for (def_id, span) in recursive_opaques {
let guar =
self.fcx.dcx().struct_span_err(span,
"cannot resolve opaque type").with_code(E0720).emit();
self.typeck_results.hidden_types.insert(def_id,
DefinitionSiteHiddenType::new_error(tcx, guar));
}
}
}
}#[instrument(skip(self), level = "debug")]
571 fn visit_opaque_types(&mut self) {
572 if self.fcx.next_trait_solver() {
573 return self.visit_opaque_types_next();
574 }
575
576 let tcx = self.tcx();
577 let opaque_types = self.fcx.infcx.clone_opaque_types();
580 let num_entries = self.fcx.inner.borrow_mut().opaque_types().num_entries();
581 let prev = self.fcx.checked_opaque_types_storage_entries.replace(Some(num_entries));
582 debug_assert_eq!(prev, None);
583 for (opaque_type_key, hidden_type) in opaque_types {
584 let hidden_type = self.resolve(hidden_type, &hidden_type.span);
585 let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span);
586 if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
587 hidden_type.ty.kind()
588 && def_id == opaque_type_key.def_id.to_def_id()
589 && args == opaque_type_key.args
590 {
591 continue;
592 }
593
594 if let Err(err) = opaque_type_has_defining_use_args(
595 self.fcx,
596 opaque_type_key,
597 hidden_type.span,
598 DefiningScopeKind::HirTypeck,
599 ) {
600 self.typeck_results.hidden_types.insert(
601 opaque_type_key.def_id,
602 ty::DefinitionSiteHiddenType::new_error(tcx, err.report(self.fcx)),
603 );
604 }
605
606 let hidden_type = hidden_type.remap_generic_params_to_declaration_params(
607 opaque_type_key,
608 tcx,
609 DefiningScopeKind::HirTypeck,
610 );
611
612 if let Some(prev) =
613 self.typeck_results.hidden_types.insert(opaque_type_key.def_id, hidden_type)
614 {
615 let entry =
616 self.typeck_results.hidden_types.get_mut(&opaque_type_key.def_id).unwrap();
617 if prev.ty != hidden_type.ty {
618 let guar = if let Some(guar) = self.typeck_results.tainted_by_errors {
619 guar
620 } else {
621 let (Ok(guar) | Err(guar)) =
622 prev.build_mismatch_error(&hidden_type, tcx).map(|d| d.emit());
623 guar
624 };
625 *entry = DefinitionSiteHiddenType::new_error(tcx, guar);
626 }
627
628 entry.span = prev.span.substitute_dummy(hidden_type.span);
631 }
632 }
633
634 let recursive_opaques: Vec<_> = self
635 .typeck_results
636 .hidden_types
637 .iter()
638 .filter(|&(&def_id, hidden_ty)| {
639 hidden_ty
640 .ty
641 .instantiate_identity()
642 .skip_norm_wip()
643 .visit_with(&mut HasRecursiveOpaque {
644 def_id,
645 seen: Default::default(),
646 opaques: &self.typeck_results.hidden_types,
647 tcx,
648 })
649 .is_break()
650 })
651 .map(|(def_id, hidden_ty)| (*def_id, hidden_ty.span))
652 .collect();
653 for (def_id, span) in recursive_opaques {
654 let guar = self
655 .fcx
656 .dcx()
657 .struct_span_err(span, "cannot resolve opaque type")
658 .with_code(E0720)
659 .emit();
660 self.typeck_results
661 .hidden_types
662 .insert(def_id, DefinitionSiteHiddenType::new_error(tcx, guar));
663 }
664 }
665
666 fn visit_field_id(&mut self, hir_id: HirId) {
667 if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id)
668 {
669 self.typeck_results.field_indices_mut().insert(hir_id, index);
670 }
671 }
672
673 #[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("visit_node_id",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(673u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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()
}], ::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))])
})
} 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;
}
{
if let Some(def) =
self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id)
{
self.typeck_results.type_dependent_defs_mut().insert(hir_id,
def);
}
if let Some(def) =
self.fcx.typeck_results.borrow_mut().splatted_defs_mut().remove(hir_id)
{
self.typeck_results.splatted_defs_mut().insert(hir_id, def);
}
self.visit_adjustments(span, hir_id);
let n_ty = self.fcx.node_ty(hir_id);
let n_ty = self.resolve(n_ty, &span);
self.write_ty_to_typeck_results(hir_id, n_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/writeback.rs:694",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(694u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("n_ty")
}> =
::tracing::__macro_support::FieldName::new("n_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(&n_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if let Some(args) =
self.fcx.typeck_results.borrow().node_args_opt(hir_id) {
let args = self.resolve(args, &span);
{
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/writeback.rs:699",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(699u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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_to_tcx({0:?}, {1:?})",
hir_id, args) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if !(!args.has_infer() && !args.has_placeholders()) {
::core::panicking::panic("assertion failed: !args.has_infer() && !args.has_placeholders()")
};
self.typeck_results.node_args_mut().insert(hir_id, args);
}
}
}
}#[instrument(skip(self, span), level = "debug")]
674 fn visit_node_id(&mut self, span: Span, hir_id: HirId) {
675 if let Some(def) =
677 self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id)
678 {
679 self.typeck_results.type_dependent_defs_mut().insert(hir_id, def);
680 }
681
682 if let Some(def) = self.fcx.typeck_results.borrow_mut().splatted_defs_mut().remove(hir_id) {
684 self.typeck_results.splatted_defs_mut().insert(hir_id, def);
685 }
686
687 self.visit_adjustments(span, hir_id);
689
690 let n_ty = self.fcx.node_ty(hir_id);
692 let n_ty = self.resolve(n_ty, &span);
693 self.write_ty_to_typeck_results(hir_id, n_ty);
694 debug!(?n_ty);
695
696 if let Some(args) = self.fcx.typeck_results.borrow().node_args_opt(hir_id) {
698 let args = self.resolve(args, &span);
699 debug!("write_args_to_tcx({:?}, {:?})", hir_id, args);
700 assert!(!args.has_infer() && !args.has_placeholders());
701 self.typeck_results.node_args_mut().insert(hir_id, args);
702 }
703 }
704
705 #[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("visit_adjustments",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(705u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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()
}], ::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))])
})
} 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 adjustment =
self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id);
match adjustment {
None => {
{
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/writeback.rs:710",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(710u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("no adjustments for node")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
Some(adjustment) => {
let resolved_adjustment = self.resolve(adjustment, &span);
{
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/writeback.rs:715",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(715u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("resolved_adjustment")
}> =
::tracing::__macro_support::FieldName::new("resolved_adjustment");
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(&resolved_adjustment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.typeck_results.adjustments_mut().insert(hir_id,
resolved_adjustment);
}
}
}
}
}#[instrument(skip(self, span), level = "debug")]
706 fn visit_adjustments(&mut self, span: Span, hir_id: HirId) {
707 let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id);
708 match adjustment {
709 None => {
710 debug!("no adjustments for node");
711 }
712
713 Some(adjustment) => {
714 let resolved_adjustment = self.resolve(adjustment, &span);
715 debug!(?resolved_adjustment);
716 self.typeck_results.adjustments_mut().insert(hir_id, resolved_adjustment);
717 }
718 }
719 }
720
721 #[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("visit_rust_2024_migration_desugared_pats",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(721u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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()
}], ::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))])
})
} 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;
}
{
if let Some(is_hard_error) =
self.fcx.typeck_results.borrow_mut().rust_2024_migration_desugared_pats_mut().remove(hir_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/writeback.rs:730",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(730u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("node is a pat whose match ergonomics are desugared by the Rust 2024 migration lint")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.typeck_results.rust_2024_migration_desugared_pats_mut().insert(hir_id,
is_hard_error);
}
}
}
}#[instrument(skip(self), level = "debug")]
722 fn visit_rust_2024_migration_desugared_pats(&mut self, hir_id: hir::HirId) {
723 if let Some(is_hard_error) = self
724 .fcx
725 .typeck_results
726 .borrow_mut()
727 .rust_2024_migration_desugared_pats_mut()
728 .remove(hir_id)
729 {
730 debug!(
731 "node is a pat whose match ergonomics are desugared by the Rust 2024 migration lint"
732 );
733 self.typeck_results
734 .rust_2024_migration_desugared_pats_mut()
735 .insert(hir_id, is_hard_error);
736 }
737 }
738
739 #[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("visit_pat_adjustments",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(739u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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()
}], ::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))])
})
} 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 adjustment =
self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id);
match adjustment {
None => {
{
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/writeback.rs:744",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(744u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("no pat_adjustments for node")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
}
Some(adjustment) => {
let resolved_adjustment = self.resolve(adjustment, &span);
{
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/writeback.rs:749",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(749u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("resolved_adjustment")
}> =
::tracing::__macro_support::FieldName::new("resolved_adjustment");
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(&resolved_adjustment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.typeck_results.pat_adjustments_mut().insert(hir_id,
resolved_adjustment);
}
}
}
}
}#[instrument(skip(self, span), level = "debug")]
740 fn visit_pat_adjustments(&mut self, span: Span, hir_id: HirId) {
741 let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id);
742 match adjustment {
743 None => {
744 debug!("no pat_adjustments for node");
745 }
746
747 Some(adjustment) => {
748 let resolved_adjustment = self.resolve(adjustment, &span);
749 debug!(?resolved_adjustment);
750 self.typeck_results.pat_adjustments_mut().insert(hir_id, resolved_adjustment);
751 }
752 }
753 }
754
755 #[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("visit_skipped_ref_pats",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(755u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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()
}], ::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))])
})
} 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;
}
{
if self.fcx.typeck_results.borrow_mut().skipped_ref_pats_mut().remove(hir_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/writeback.rs:758",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(758u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::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!("node is a skipped ref pat")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.typeck_results.skipped_ref_pats_mut().insert(hir_id);
}
}
}
}#[instrument(skip(self), level = "debug")]
756 fn visit_skipped_ref_pats(&mut self, hir_id: hir::HirId) {
757 if self.fcx.typeck_results.borrow_mut().skipped_ref_pats_mut().remove(hir_id) {
758 debug!("node is a skipped ref pat");
759 self.typeck_results.skipped_ref_pats_mut().insert(hir_id);
760 }
761 }
762
763 fn visit_liberated_fn_sigs(&mut self) {
764 let fcx_typeck_results = self.fcx.typeck_results.borrow();
765 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
766 let common_hir_owner = fcx_typeck_results.hir_owner;
767
768 let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order();
769
770 for (local_id, &fn_sig) in fcx_liberated_fn_sigs {
771 let hir_id = HirId { owner: common_hir_owner, local_id };
772 let fn_sig = self.resolve(fn_sig, &hir_id);
773 self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig);
774 }
775 }
776
777 fn visit_fru_field_types(&mut self) {
778 let fcx_typeck_results = self.fcx.typeck_results.borrow();
779 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
780 let common_hir_owner = fcx_typeck_results.hir_owner;
781
782 let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order();
783
784 for (local_id, ftys) in fcx_fru_field_types {
785 let hir_id = HirId { owner: common_hir_owner, local_id };
786 let ftys = self.resolve(ftys.clone(), &hir_id);
787 self.typeck_results.fru_field_types_mut().insert(hir_id, ftys);
788 }
789 }
790
791 fn visit_offset_of_container_types(&mut self) {
792 let fcx_typeck_results = self.fcx.typeck_results.borrow();
793 {
match (&fcx_typeck_results.hir_owner, &self.typeck_results.hir_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
794 let common_hir_owner = fcx_typeck_results.hir_owner;
795
796 for (local_id, indices) in fcx_typeck_results.offset_of_data().items_in_stable_order() {
797 let hir_id = HirId { owner: common_hir_owner, local_id };
798 let indices = indices
799 .iter()
800 .map(|&(ty, variant, field)| (self.resolve(ty, &hir_id), variant, field))
801 .collect();
802 self.typeck_results.offset_of_data_mut().insert(hir_id, indices);
803 }
804 }
805
806 fn visit_potentially_region_dependent_goals(&mut self) {
807 let obligations = self.fcx.take_hir_typeck_potentially_region_dependent_goals();
808 if self.fcx.tainted_by_errors().is_none() {
809 for obligation in obligations {
810 let (predicate, mut cause) =
811 self.fcx.resolve_vars_if_possible((obligation.predicate, obligation.cause));
812 if predicate.has_non_region_infer() {
813 self.fcx.dcx().span_delayed_bug(
814 cause.span,
815 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unexpected inference variable after writeback: {0:?}",
predicate))
})format!("unexpected inference variable after writeback: {predicate:?}"),
816 );
817 } else {
818 let predicate = self.tcx().erase_and_anonymize_regions(predicate);
819 if cause.has_infer() || cause.has_placeholders() {
820 cause = self.fcx.misc(cause.span);
823 }
824 self.typeck_results
825 .potentially_region_dependent_goals
826 .insert((predicate, cause));
827 }
828 }
829 }
830 }
831
832 fn resolve<T>(&mut self, value: T, span: &dyn Locatable) -> T
833 where
834 T: TypeFoldable<TyCtxt<'tcx>>,
835 {
836 let value = self.fcx.resolve_vars_if_possible(value);
837
838 let mut goals = ::alloc::vec::Vec::new()vec![];
839 let value =
840 value.fold_with(&mut Resolver::new(self.fcx, span, self.body, true, &mut goals));
841
842 let mut unexpected_goals = ::alloc::vec::Vec::new()vec![];
846 self.typeck_results.coroutine_stalled_predicates.extend(
847 goals
848 .into_iter()
849 .map(|pred| {
850 self.fcx.resolve_vars_if_possible(pred).fold_with(&mut Resolver::new(
851 self.fcx,
852 span,
853 self.body,
854 false,
855 &mut unexpected_goals,
856 ))
857 })
858 .map(|goal| (goal.predicate, self.fcx.misc(span.to_span(self.fcx.tcx)))),
860 );
861 {
match (&unexpected_goals, &::alloc::vec::Vec::new()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(unexpected_goals, vec![]);
862
863 if !!value.has_infer() {
::core::panicking::panic("assertion failed: !value.has_infer()")
};assert!(!value.has_infer());
864
865 if let Err(guar) = value.error_reported() {
869 self.typeck_results.tainted_by_errors = Some(guar);
870 }
871
872 value
873 }
874
875 fn resolve_coroutine_predicate<T>(&mut self, value: T, span: &dyn Locatable) -> T
876 where
877 T: TypeFoldable<TyCtxt<'tcx>>,
878 {
879 let value = self.fcx.resolve_vars_if_possible(value);
880
881 let mut goals = ::alloc::vec::Vec::new()vec![];
882 let value =
883 value.fold_with(&mut Resolver::new(self.fcx, span, self.body, false, &mut goals));
884 {
match (&goals, &::alloc::vec::Vec::new()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(goals, vec![]);
885
886 if !!value.has_infer() {
::core::panicking::panic("assertion failed: !value.has_infer()")
};assert!(!value.has_infer());
887
888 if let Err(guar) = value.error_reported() {
892 self.typeck_results.tainted_by_errors = Some(guar);
893 }
894
895 value
896 }
897}
898
899pub(crate) trait Locatable {
900 fn to_span(&self, tcx: TyCtxt<'_>) -> Span;
901}
902
903impl Locatable for Span {
904 fn to_span(&self, _: TyCtxt<'_>) -> Span {
905 *self
906 }
907}
908
909impl Locatable for HirId {
910 fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
911 tcx.hir_span(*self)
912 }
913}
914
915struct Resolver<'cx, 'tcx> {
916 fcx: &'cx FnCtxt<'cx, 'tcx>,
917 span: &'cx dyn Locatable,
918 body: &'tcx hir::Body<'tcx>,
919 should_normalize: bool,
922 nested_goals: &'cx mut Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
923}
924
925impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
926 fn new(
927 fcx: &'cx FnCtxt<'cx, 'tcx>,
928 span: &'cx dyn Locatable,
929 body: &'tcx hir::Body<'tcx>,
930 should_normalize: bool,
931 nested_goals: &'cx mut Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
932 ) -> Resolver<'cx, 'tcx> {
933 Resolver { fcx, span, body, nested_goals, should_normalize }
934 }
935
936 fn report_error(&self, p: impl Into<ty::Term<'tcx>>) -> ErrorGuaranteed {
937 if let Some(guar) = self.fcx.tainted_by_errors() {
938 guar
939 } else {
940 self.fcx
941 .err_ctxt()
942 .emit_inference_failure_err(
943 self.fcx.tcx.hir_body_owner_def_id(self.body.id()),
944 self.span.to_span(self.fcx.tcx),
945 p.into(),
946 TypeAnnotationNeeded::E0282,
947 false,
948 )
949 .emit()
950 }
951 }
952
953 #[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("handle_term",
"rustc_hir_typeck::writeback", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/writeback.rs"),
::tracing_core::__macro_support::Option::Some(953u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::writeback"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("value")
}> =
::tracing::__macro_support::FieldName::new("value");
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(&value)
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: T = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.fcx.tcx;
let mut value =
if self.should_normalize && self.fcx.next_trait_solver() {
let body_def_id = tcx.hir_body_owner_def_id(self.body.id());
let cause =
ObligationCause::misc(self.span.to_span(tcx), body_def_id);
let at = self.fcx.at(&cause, self.fcx.param_env);
let universes =
::alloc::vec::from_elem(None,
outer_exclusive_binder(&value).as_usize());
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(at,
Unnormalized::new_wip(value), universes) {
Ok((value, goals)) => {
self.nested_goals.extend(goals);
value
}
Err(errors) => {
let guar =
self.fcx.err_ctxt().report_fulfillment_errors(errors);
new_err(tcx, guar)
}
}
} else { value };
if value.has_non_region_infer() {
let guar = self.report_error(value);
value = new_err(tcx, guar);
}
value = fold_regions(tcx, value, |_, _| tcx.lifetimes.re_erased);
if tcx.features().generic_const_exprs() {
value =
value.fold_with(&mut EagerlyNormalizeConsts::new(self.fcx));
}
value
}
}
}#[instrument(level = "debug", skip(self, outer_exclusive_binder, new_err))]
954 fn handle_term<T>(
955 &mut self,
956 value: T,
957 outer_exclusive_binder: impl FnOnce(&T) -> ty::DebruijnIndex,
958 new_err: impl Fn(TyCtxt<'tcx>, ErrorGuaranteed) -> T,
959 ) -> T
960 where
961 T: Into<ty::Term<'tcx>> + TypeSuperFoldable<TyCtxt<'tcx>> + Copy,
962 {
963 let tcx = self.fcx.tcx;
964 let mut value = if self.should_normalize && self.fcx.next_trait_solver() {
967 let body_def_id = tcx.hir_body_owner_def_id(self.body.id());
968 let cause = ObligationCause::misc(self.span.to_span(tcx), body_def_id);
969 let at = self.fcx.at(&cause, self.fcx.param_env);
970 let universes = vec![None; outer_exclusive_binder(&value).as_usize()];
971 match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
972 at,
973 Unnormalized::new_wip(value),
974 universes,
975 ) {
976 Ok((value, goals)) => {
977 self.nested_goals.extend(goals);
978 value
979 }
980 Err(errors) => {
981 let guar = self.fcx.err_ctxt().report_fulfillment_errors(errors);
982 new_err(tcx, guar)
983 }
984 }
985 } else {
986 value
987 };
988
989 if value.has_non_region_infer() {
991 let guar = self.report_error(value);
992 value = new_err(tcx, guar);
993 }
994
995 value = fold_regions(tcx, value, |_, _| tcx.lifetimes.re_erased);
1005
1006 if tcx.features().generic_const_exprs() {
1008 value = value.fold_with(&mut EagerlyNormalizeConsts::new(self.fcx));
1009 }
1010
1011 value
1012 }
1013}
1014
1015impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
1016 fn cx(&self) -> TyCtxt<'tcx> {
1017 self.fcx.tcx
1018 }
1019
1020 fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
1021 match r.kind() {
1022 ty::ReBound(..) => r,
1023 _ => self.fcx.tcx.lifetimes.re_erased,
1024 }
1025 }
1026
1027 fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1028 self.handle_term(ty, Ty::outer_exclusive_binder, Ty::new_error)
1029 }
1030
1031 fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
1032 self.handle_term(ct, ty::Const::outer_exclusive_binder, ty::Const::new_error)
1033 }
1034
1035 fn fold_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
1036 if !!self.should_normalize {
{
::core::panicking::panic_fmt(format_args!("normalizing predicates in writeback is not generally sound"));
}
};assert!(
1037 !self.should_normalize,
1038 "normalizing predicates in writeback is not generally sound"
1039 );
1040 predicate.super_fold_with(self)
1041 }
1042}
1043
1044struct EagerlyNormalizeConsts<'tcx> {
1045 tcx: TyCtxt<'tcx>,
1046 typing_env: ty::TypingEnv<'tcx>,
1047}
1048impl<'tcx> EagerlyNormalizeConsts<'tcx> {
1049 fn new(fcx: &FnCtxt<'_, 'tcx>) -> Self {
1050 EagerlyNormalizeConsts { tcx: fcx.tcx, typing_env: fcx.typing_env(fcx.param_env) }
1053 }
1054}
1055
1056impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> {
1057 fn cx(&self) -> TyCtxt<'tcx> {
1058 self.tcx
1059 }
1060
1061 fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
1062 self.tcx
1063 .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(ct))
1064 .unwrap_or(ct)
1065 }
1066}
1067
1068struct HasRecursiveOpaque<'a, 'tcx> {
1069 def_id: LocalDefId,
1070 seen: FxHashSet<LocalDefId>,
1071 opaques: &'a FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'tcx>>,
1072 tcx: TyCtxt<'tcx>,
1073}
1074
1075impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> {
1076 type Result = ControlFlow<()>;
1077
1078 fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1079 if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind()
1080 && let Some(def_id) = def_id.as_local()
1081 {
1082 if self.def_id == def_id {
1083 return ControlFlow::Break(());
1084 }
1085
1086 if self.seen.insert(def_id)
1087 && let Some(hidden_ty) = self.opaques.get(&def_id)
1088 {
1089 hidden_ty.ty.instantiate(self.tcx, args).skip_norm_wip().visit_with(self)?;
1090 }
1091 }
1092
1093 t.super_visit_with(self)
1094 }
1095}