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