1use std::collections::hash_map::Entry;
2use std::hash::Hash;
3use std::iter;
4
5use rustc_abi::{FieldIdx, VariantIdx};
6use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
7use rustc_data_structures::unord::{ExtendUnord, UnordItems, UnordSet};
8use rustc_errors::ErrorGuaranteed;
9use rustc_hir::def::{DefKind, Res};
10use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
11use rustc_hir::hir_id::OwnerId;
12use rustc_hir::{
13 self as hir, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability,
14};
15use rustc_index::IndexVec;
16use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
17use rustc_session::Session;
18use rustc_span::Span;
19
20use super::RvalueScopes;
21use crate::hir::place::Place as HirPlace;
22use crate::infer::canonical::Canonical;
23use crate::mir::FakeReadCause;
24use crate::traits::ObligationCause;
25use crate::ty::{
26 self, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData, GenericArgKind, GenericArgs,
27 GenericArgsRef, Ty, UserArgs, tls,
28};
29
30#[derive(TyEncodable, TyDecodable, Debug, HashStable)]
31pub struct TypeckResults<'tcx> {
32 pub hir_owner: OwnerId,
34
35 type_dependent_defs: ItemLocalMap<Result<(DefKind, DefId), ErrorGuaranteed>>,
38
39 field_indices: ItemLocalMap<FieldIdx>,
44
45 node_types: ItemLocalMap<Ty<'tcx>>,
49
50 node_args: ItemLocalMap<GenericArgsRef<'tcx>>,
55
56 user_provided_types: ItemLocalMap<CanonicalUserType<'tcx>>,
66
67 pub user_provided_sigs: LocalDefIdMap<CanonicalPolyFnSig<'tcx>>,
70
71 adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,
72
73 pat_binding_modes: ItemLocalMap<BindingMode>,
75
76 rust_2024_migration_desugared_pats: ItemLocalMap<Rust2024IncompatiblePatInfo>,
79
80 pat_adjustments: ItemLocalMap<Vec<ty::adjustment::PatAdjustment<'tcx>>>,
103
104 skipped_ref_pats: ItemLocalSet,
107
108 closure_kind_origins: ItemLocalMap<(Span, HirPlace<'tcx>)>,
111
112 liberated_fn_sigs: ItemLocalMap<ty::FnSig<'tcx>>,
147
148 fru_field_types: ItemLocalMap<Vec<Ty<'tcx>>>,
153
154 coercion_casts: ItemLocalSet,
157
158 pub used_trait_imports: UnordSet<LocalDefId>,
161
162 pub tainted_by_errors: Option<ErrorGuaranteed>,
165
166 pub concrete_opaque_types: FxIndexMap<LocalDefId, ty::OpaqueHiddenType<'tcx>>,
171
172 pub closure_min_captures: ty::MinCaptureInformationMap<'tcx>,
175
176 pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, HirId)>>,
199
200 pub rvalue_scopes: RvalueScopes,
204
205 pub coroutine_stalled_predicates: FxIndexSet<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>,
208
209 pub closure_size_eval: LocalDefIdMap<ClosureSizeProfileData<'tcx>>,
212
213 offset_of_data: ItemLocalMap<(Ty<'tcx>, Vec<(VariantIdx, FieldIdx)>)>,
215}
216
217impl<'tcx> TypeckResults<'tcx> {
218 pub fn new(hir_owner: OwnerId) -> TypeckResults<'tcx> {
219 TypeckResults {
220 hir_owner,
221 type_dependent_defs: Default::default(),
222 field_indices: Default::default(),
223 user_provided_types: Default::default(),
224 user_provided_sigs: Default::default(),
225 node_types: Default::default(),
226 node_args: Default::default(),
227 adjustments: Default::default(),
228 pat_binding_modes: Default::default(),
229 pat_adjustments: Default::default(),
230 rust_2024_migration_desugared_pats: Default::default(),
231 skipped_ref_pats: Default::default(),
232 closure_kind_origins: Default::default(),
233 liberated_fn_sigs: Default::default(),
234 fru_field_types: Default::default(),
235 coercion_casts: Default::default(),
236 used_trait_imports: Default::default(),
237 tainted_by_errors: None,
238 concrete_opaque_types: Default::default(),
239 closure_min_captures: Default::default(),
240 closure_fake_reads: Default::default(),
241 rvalue_scopes: Default::default(),
242 coroutine_stalled_predicates: Default::default(),
243 closure_size_eval: Default::default(),
244 offset_of_data: Default::default(),
245 }
246 }
247
248 pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: HirId) -> Res {
250 match *qpath {
251 hir::QPath::Resolved(_, path) => path.res,
252 hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
253 .type_dependent_def(id)
254 .map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
255 }
256 }
257
258 pub fn type_dependent_defs(
259 &self,
260 ) -> LocalTableInContext<'_, Result<(DefKind, DefId), ErrorGuaranteed>> {
261 LocalTableInContext { hir_owner: self.hir_owner, data: &self.type_dependent_defs }
262 }
263
264 pub fn type_dependent_def(&self, id: HirId) -> Option<(DefKind, DefId)> {
265 validate_hir_id_for_typeck_results(self.hir_owner, id);
266 self.type_dependent_defs.get(&id.local_id).cloned().and_then(|r| r.ok())
267 }
268
269 pub fn type_dependent_def_id(&self, id: HirId) -> Option<DefId> {
270 self.type_dependent_def(id).map(|(_, def_id)| def_id)
271 }
272
273 pub fn type_dependent_defs_mut(
274 &mut self,
275 ) -> LocalTableInContextMut<'_, Result<(DefKind, DefId), ErrorGuaranteed>> {
276 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.type_dependent_defs }
277 }
278
279 pub fn field_indices(&self) -> LocalTableInContext<'_, FieldIdx> {
280 LocalTableInContext { hir_owner: self.hir_owner, data: &self.field_indices }
281 }
282
283 pub fn field_indices_mut(&mut self) -> LocalTableInContextMut<'_, FieldIdx> {
284 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices }
285 }
286
287 pub fn field_index(&self, id: HirId) -> FieldIdx {
288 self.field_indices().get(id).cloned().expect("no index for a field")
289 }
290
291 pub fn opt_field_index(&self, id: HirId) -> Option<FieldIdx> {
292 self.field_indices().get(id).cloned()
293 }
294
295 pub fn user_provided_types(&self) -> LocalTableInContext<'_, CanonicalUserType<'tcx>> {
296 LocalTableInContext { hir_owner: self.hir_owner, data: &self.user_provided_types }
297 }
298
299 pub fn user_provided_types_mut(
300 &mut self,
301 ) -> LocalTableInContextMut<'_, CanonicalUserType<'tcx>> {
302 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.user_provided_types }
303 }
304
305 pub fn node_types(&self) -> LocalTableInContext<'_, Ty<'tcx>> {
306 LocalTableInContext { hir_owner: self.hir_owner, data: &self.node_types }
307 }
308
309 pub fn node_types_mut(&mut self) -> LocalTableInContextMut<'_, Ty<'tcx>> {
310 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types }
311 }
312
313 pub fn node_type(&self, id: HirId) -> Ty<'tcx> {
314 self.node_type_opt(id).unwrap_or_else(|| {
315 bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir_id_to_string(id)))
316 })
317 }
318
319 pub fn node_type_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
320 validate_hir_id_for_typeck_results(self.hir_owner, id);
321 self.node_types.get(&id.local_id).cloned()
322 }
323
324 pub fn node_args_mut(&mut self) -> LocalTableInContextMut<'_, GenericArgsRef<'tcx>> {
325 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args }
326 }
327
328 pub fn node_args(&self, id: HirId) -> GenericArgsRef<'tcx> {
329 validate_hir_id_for_typeck_results(self.hir_owner, id);
330 self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty())
331 }
332
333 pub fn node_args_opt(&self, id: HirId) -> Option<GenericArgsRef<'tcx>> {
334 validate_hir_id_for_typeck_results(self.hir_owner, id);
335 self.node_args.get(&id.local_id).cloned()
336 }
337
338 pub fn pat_ty(&self, pat: &hir::Pat<'_>) -> Ty<'tcx> {
343 self.node_type(pat.hir_id)
344 }
345
346 pub fn expr_ty(&self, expr: &hir::Expr<'_>) -> Ty<'tcx> {
357 self.node_type(expr.hir_id)
358 }
359
360 pub fn expr_ty_opt(&self, expr: &hir::Expr<'_>) -> Option<Ty<'tcx>> {
361 self.node_type_opt(expr.hir_id)
362 }
363
364 pub fn adjustments(&self) -> LocalTableInContext<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {
365 LocalTableInContext { hir_owner: self.hir_owner, data: &self.adjustments }
366 }
367
368 pub fn adjustments_mut(
369 &mut self,
370 ) -> LocalTableInContextMut<'_, Vec<ty::adjustment::Adjustment<'tcx>>> {
371 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.adjustments }
372 }
373
374 pub fn expr_adjustments(&self, expr: &hir::Expr<'_>) -> &[ty::adjustment::Adjustment<'tcx>] {
375 validate_hir_id_for_typeck_results(self.hir_owner, expr.hir_id);
376 self.adjustments.get(&expr.hir_id.local_id).map_or(&[], |a| &a[..])
377 }
378
379 pub fn expr_ty_adjusted(&self, expr: &hir::Expr<'_>) -> Ty<'tcx> {
382 self.expr_adjustments(expr).last().map_or_else(|| self.expr_ty(expr), |adj| adj.target)
383 }
384
385 pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr<'_>) -> Option<Ty<'tcx>> {
386 self.expr_adjustments(expr).last().map(|adj| adj.target).or_else(|| self.expr_ty_opt(expr))
387 }
388
389 pub fn is_method_call(&self, expr: &hir::Expr<'_>) -> bool {
390 if let hir::ExprKind::Path(_) = expr.kind {
393 return false;
394 }
395
396 matches!(self.type_dependent_defs().get(expr.hir_id), Some(Ok((DefKind::AssocFn, _))))
397 }
398
399 pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> BindingMode {
402 self.pat_binding_modes().get(id).copied().unwrap_or_else(|| {
403 s.dcx().span_bug(sp, "missing binding mode");
404 })
405 }
406
407 pub fn pat_binding_modes(&self) -> LocalTableInContext<'_, BindingMode> {
408 LocalTableInContext { hir_owner: self.hir_owner, data: &self.pat_binding_modes }
409 }
410
411 pub fn pat_binding_modes_mut(&mut self) -> LocalTableInContextMut<'_, BindingMode> {
412 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_binding_modes }
413 }
414
415 pub fn pat_adjustments(
416 &self,
417 ) -> LocalTableInContext<'_, Vec<ty::adjustment::PatAdjustment<'tcx>>> {
418 LocalTableInContext { hir_owner: self.hir_owner, data: &self.pat_adjustments }
419 }
420
421 pub fn pat_adjustments_mut(
422 &mut self,
423 ) -> LocalTableInContextMut<'_, Vec<ty::adjustment::PatAdjustment<'tcx>>> {
424 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_adjustments }
425 }
426
427 pub fn rust_2024_migration_desugared_pats(
428 &self,
429 ) -> LocalTableInContext<'_, Rust2024IncompatiblePatInfo> {
430 LocalTableInContext {
431 hir_owner: self.hir_owner,
432 data: &self.rust_2024_migration_desugared_pats,
433 }
434 }
435
436 pub fn rust_2024_migration_desugared_pats_mut(
437 &mut self,
438 ) -> LocalTableInContextMut<'_, Rust2024IncompatiblePatInfo> {
439 LocalTableInContextMut {
440 hir_owner: self.hir_owner,
441 data: &mut self.rust_2024_migration_desugared_pats,
442 }
443 }
444
445 pub fn skipped_ref_pats(&self) -> LocalSetInContext<'_> {
446 LocalSetInContext { hir_owner: self.hir_owner, data: &self.skipped_ref_pats }
447 }
448
449 pub fn skipped_ref_pats_mut(&mut self) -> LocalSetInContextMut<'_> {
450 LocalSetInContextMut { hir_owner: self.hir_owner, data: &mut self.skipped_ref_pats }
451 }
452
453 pub fn pat_has_ref_mut_binding(&self, pat: &hir::Pat<'_>) -> bool {
462 let mut has_ref_mut = false;
463 pat.walk(|pat| {
464 if let hir::PatKind::Binding(_, id, _, _) = pat.kind
465 && let Some(BindingMode(ByRef::Yes(Mutability::Mut), _)) =
466 self.pat_binding_modes().get(id)
467 {
468 has_ref_mut = true;
469 false
471 } else {
472 true
473 }
474 });
475 has_ref_mut
476 }
477
478 pub fn closure_min_captures_flattened(
481 &self,
482 closure_def_id: LocalDefId,
483 ) -> impl Iterator<Item = &ty::CapturedPlace<'tcx>> {
484 self.closure_min_captures
485 .get(&closure_def_id)
486 .map(|closure_min_captures| closure_min_captures.values().flat_map(|v| v.iter()))
487 .into_iter()
488 .flatten()
489 }
490
491 pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, HirPlace<'tcx>)> {
492 LocalTableInContext { hir_owner: self.hir_owner, data: &self.closure_kind_origins }
493 }
494
495 pub fn closure_kind_origins_mut(
496 &mut self,
497 ) -> LocalTableInContextMut<'_, (Span, HirPlace<'tcx>)> {
498 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.closure_kind_origins }
499 }
500
501 pub fn liberated_fn_sigs(&self) -> LocalTableInContext<'_, ty::FnSig<'tcx>> {
502 LocalTableInContext { hir_owner: self.hir_owner, data: &self.liberated_fn_sigs }
503 }
504
505 pub fn liberated_fn_sigs_mut(&mut self) -> LocalTableInContextMut<'_, ty::FnSig<'tcx>> {
506 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.liberated_fn_sigs }
507 }
508
509 pub fn fru_field_types(&self) -> LocalTableInContext<'_, Vec<Ty<'tcx>>> {
510 LocalTableInContext { hir_owner: self.hir_owner, data: &self.fru_field_types }
511 }
512
513 pub fn fru_field_types_mut(&mut self) -> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
514 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types }
515 }
516
517 pub fn is_coercion_cast(&self, hir_id: HirId) -> bool {
518 validate_hir_id_for_typeck_results(self.hir_owner, hir_id);
519 self.coercion_casts.contains(&hir_id.local_id)
520 }
521
522 pub fn set_coercion_cast(&mut self, id: ItemLocalId) {
523 self.coercion_casts.insert(id);
524 }
525
526 pub fn coercion_casts(&self) -> &ItemLocalSet {
527 &self.coercion_casts
528 }
529
530 pub fn offset_of_data(
531 &self,
532 ) -> LocalTableInContext<'_, (Ty<'tcx>, Vec<(VariantIdx, FieldIdx)>)> {
533 LocalTableInContext { hir_owner: self.hir_owner, data: &self.offset_of_data }
534 }
535
536 pub fn offset_of_data_mut(
537 &mut self,
538 ) -> LocalTableInContextMut<'_, (Ty<'tcx>, Vec<(VariantIdx, FieldIdx)>)> {
539 LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.offset_of_data }
540 }
541}
542
543#[inline]
551fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
552 if hir_id.owner != hir_owner {
553 invalid_hir_id_for_typeck_results(hir_owner, hir_id);
554 }
555}
556
557#[cold]
558#[inline(never)]
559fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
560 ty::tls::with(|tcx| {
561 bug!(
562 "node {} cannot be placed in TypeckResults with hir_owner {:?}",
563 tcx.hir_id_to_string(hir_id),
564 hir_owner
565 )
566 });
567}
568
569pub struct LocalTableInContext<'a, V> {
570 hir_owner: OwnerId,
571 data: &'a ItemLocalMap<V>,
572}
573
574impl<'a, V> LocalTableInContext<'a, V> {
575 pub fn contains_key(&self, id: HirId) -> bool {
576 validate_hir_id_for_typeck_results(self.hir_owner, id);
577 self.data.contains_key(&id.local_id)
578 }
579
580 pub fn get(&self, id: HirId) -> Option<&'a V> {
581 validate_hir_id_for_typeck_results(self.hir_owner, id);
582 self.data.get(&id.local_id)
583 }
584
585 pub fn items(
586 &self,
587 ) -> UnordItems<(hir::ItemLocalId, &'a V), impl Iterator<Item = (hir::ItemLocalId, &'a V)>>
588 {
589 self.data.items().map(|(id, value)| (*id, value))
590 }
591
592 pub fn items_in_stable_order(&self) -> Vec<(ItemLocalId, &'a V)> {
593 self.data.items().map(|(&k, v)| (k, v)).into_sorted_stable_ord_by_key(|(k, _)| k)
594 }
595}
596
597impl<'a, V> ::std::ops::Index<HirId> for LocalTableInContext<'a, V> {
598 type Output = V;
599
600 fn index(&self, key: HirId) -> &V {
601 self.get(key).unwrap_or_else(|| {
602 bug!("LocalTableInContext({:?}): key {:?} not found", self.hir_owner, key)
603 })
604 }
605}
606
607pub struct LocalTableInContextMut<'a, V> {
608 hir_owner: OwnerId,
609 data: &'a mut ItemLocalMap<V>,
610}
611
612impl<'a, V> LocalTableInContextMut<'a, V> {
613 pub fn get_mut(&mut self, id: HirId) -> Option<&mut V> {
614 validate_hir_id_for_typeck_results(self.hir_owner, id);
615 self.data.get_mut(&id.local_id)
616 }
617
618 pub fn get(&mut self, id: HirId) -> Option<&V> {
619 validate_hir_id_for_typeck_results(self.hir_owner, id);
620 self.data.get(&id.local_id)
621 }
622
623 pub fn entry(&mut self, id: HirId) -> Entry<'_, hir::ItemLocalId, V> {
624 validate_hir_id_for_typeck_results(self.hir_owner, id);
625 self.data.entry(id.local_id)
626 }
627
628 pub fn insert(&mut self, id: HirId, val: V) -> Option<V> {
629 validate_hir_id_for_typeck_results(self.hir_owner, id);
630 self.data.insert(id.local_id, val)
631 }
632
633 pub fn remove(&mut self, id: HirId) -> Option<V> {
634 validate_hir_id_for_typeck_results(self.hir_owner, id);
635 self.data.remove(&id.local_id)
636 }
637
638 pub fn extend(&mut self, items: UnordItems<(HirId, V), impl Iterator<Item = (HirId, V)>>) {
639 self.data.extend_unord(items.map(|(id, value)| {
640 validate_hir_id_for_typeck_results(self.hir_owner, id);
641 (id.local_id, value)
642 }))
643 }
644}
645
646#[derive(Clone, Copy, Debug)]
647pub struct LocalSetInContext<'a> {
648 hir_owner: OwnerId,
649 data: &'a ItemLocalSet,
650}
651
652impl<'a> LocalSetInContext<'a> {
653 pub fn is_empty(&self) -> bool {
654 self.data.is_empty()
655 }
656
657 pub fn contains(&self, id: hir::HirId) -> bool {
658 validate_hir_id_for_typeck_results(self.hir_owner, id);
659 self.data.contains(&id.local_id)
660 }
661}
662
663#[derive(Debug)]
664pub struct LocalSetInContextMut<'a> {
665 hir_owner: OwnerId,
666 data: &'a mut ItemLocalSet,
667}
668
669impl<'a> LocalSetInContextMut<'a> {
670 pub fn is_empty(&self) -> bool {
671 self.data.is_empty()
672 }
673
674 pub fn contains(&self, id: hir::HirId) -> bool {
675 validate_hir_id_for_typeck_results(self.hir_owner, id);
676 self.data.contains(&id.local_id)
677 }
678 pub fn insert(&mut self, id: hir::HirId) -> bool {
679 validate_hir_id_for_typeck_results(self.hir_owner, id);
680 self.data.insert(id.local_id)
681 }
682
683 pub fn remove(&mut self, id: hir::HirId) -> bool {
684 validate_hir_id_for_typeck_results(self.hir_owner, id);
685 self.data.remove(&id.local_id)
686 }
687}
688
689rustc_index::newtype_index! {
690 #[derive(HashStable)]
691 #[encodable]
692 #[debug_format = "UserType({})"]
693 pub struct UserTypeAnnotationIndex {
694 const START_INDEX = 0;
695 }
696}
697
698pub type CanonicalUserTypeAnnotations<'tcx> =
700 IndexVec<UserTypeAnnotationIndex, CanonicalUserTypeAnnotation<'tcx>>;
701
702#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
703pub struct CanonicalUserTypeAnnotation<'tcx> {
704 pub user_ty: Box<CanonicalUserType<'tcx>>,
705 pub span: Span,
706 pub inferred_ty: Ty<'tcx>,
707}
708
709pub type CanonicalUserType<'tcx> = Canonical<'tcx, UserType<'tcx>>;
711
712#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable)]
713#[derive(Eq, Hash, HashStable, TypeFoldable, TypeVisitable)]
714pub struct UserType<'tcx> {
715 pub kind: UserTypeKind<'tcx>,
716 pub bounds: ty::Clauses<'tcx>,
717}
718
719impl<'tcx> UserType<'tcx> {
720 pub fn new(kind: UserTypeKind<'tcx>) -> UserType<'tcx> {
721 UserType { kind, bounds: ty::ListWithCachedTypeInfo::empty() }
722 }
723
724 pub fn new_with_bounds(kind: UserTypeKind<'tcx>, bounds: ty::Clauses<'tcx>) -> UserType<'tcx> {
727 UserType { kind, bounds }
728 }
729}
730
731#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable)]
735#[derive(Eq, Hash, HashStable, TypeFoldable, TypeVisitable)]
736pub enum UserTypeKind<'tcx> {
737 Ty(Ty<'tcx>),
738
739 TypeOf(DefId, UserArgs<'tcx>),
742}
743
744pub trait IsIdentity {
745 fn is_identity(&self) -> bool;
746}
747
748impl<'tcx> IsIdentity for CanonicalUserType<'tcx> {
749 fn is_identity(&self) -> bool {
752 if !self.value.bounds.is_empty() {
753 return false;
754 }
755
756 match self.value.kind {
757 UserTypeKind::Ty(_) => false,
758 UserTypeKind::TypeOf(_, user_args) => {
759 if user_args.user_self_ty.is_some() {
760 return false;
761 }
762
763 iter::zip(user_args.args, BoundVar::ZERO..).all(|(kind, cvar)| {
764 match kind.unpack() {
765 GenericArgKind::Type(ty) => match ty.kind() {
766 ty::Bound(debruijn, b) => {
767 assert_eq!(*debruijn, ty::INNERMOST);
769 cvar == b.var
770 }
771 _ => false,
772 },
773
774 GenericArgKind::Lifetime(r) => match r.kind() {
775 ty::ReBound(debruijn, br) => {
776 assert_eq!(debruijn, ty::INNERMOST);
778 cvar == br.var
779 }
780 _ => false,
781 },
782
783 GenericArgKind::Const(ct) => match ct.kind() {
784 ty::ConstKind::Bound(debruijn, b) => {
785 assert_eq!(debruijn, ty::INNERMOST);
787 cvar == b
788 }
789 _ => false,
790 },
791 }
792 })
793 }
794 }
795 }
796}
797
798impl<'tcx> std::fmt::Display for UserType<'tcx> {
799 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
800 if self.bounds.is_empty() {
801 self.kind.fmt(f)
802 } else {
803 self.kind.fmt(f)?;
804 write!(f, " + ")?;
805 std::fmt::Debug::fmt(&self.bounds, f)
806 }
807 }
808}
809
810impl<'tcx> std::fmt::Display for UserTypeKind<'tcx> {
811 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
812 match self {
813 Self::Ty(arg0) => {
814 ty::print::with_no_trimmed_paths!(write!(f, "Ty({})", arg0))
815 }
816 Self::TypeOf(arg0, arg1) => write!(f, "TypeOf({:?}, {:?})", arg0, arg1),
817 }
818 }
819}
820
821#[derive(TyEncodable, TyDecodable, Debug, HashStable)]
824pub struct Rust2024IncompatiblePatInfo {
825 pub primary_labels: Vec<(Span, String)>,
827 pub bad_modifiers: bool,
829 pub bad_ref_pats: bool,
831 pub suggest_eliding_modes: bool,
833}