1use std::borrow::Cow;
3use std::fmt;
4
5use rustc_abi::ExternAbi;
6use rustc_ast::attr::AttributeExt;
7use rustc_ast::token::DocFragmentKind;
8use rustc_ast::util::parser::ExprPrecedence;
9use rustc_ast::{
10 self as ast, FloatTy, InlineAsmOptions, InlineAsmTemplatePiece, IntTy, Label, LitIntType,
11 LitKind, TraitObjectSyntax, UintTy, UnsafeBinderCastKind, join_path_idents,
12};
13pub use rustc_ast::{
14 AssignOp, AssignOpKind, AttrId, AttrStyle, BinOp, BinOpKind, BindingMode, BorrowKind,
15 BoundConstness, BoundPolarity, ByRef, CaptureBy, DelimArgs, ImplPolarity, IsAuto,
16 MetaItemInner, MetaItemLit, Movability, Mutability, Pinnedness, UnOp,
17};
18use rustc_data_structures::fingerprint::Fingerprint;
19use rustc_data_structures::sorted_map::SortedMap;
20use rustc_data_structures::tagged_ptr::TaggedRef;
21use rustc_error_messages::{DiagArgValue, IntoDiagArg};
22use rustc_index::IndexVec;
23use rustc_macros::{Decodable, Encodable, HashStable_Generic};
24use rustc_span::def_id::LocalDefId;
25use rustc_span::source_map::Spanned;
26use rustc_span::{
27 BytePos, DUMMY_SP, DesugaringKind, ErrorGuaranteed, Ident, Span, Symbol, kw, sym,
28};
29use rustc_target::asm::InlineAsmRegOrRegClass;
30use smallvec::SmallVec;
31use thin_vec::ThinVec;
32use tracing::debug;
33
34use crate::attrs::AttributeKind;
35use crate::def::{CtorKind, DefKind, MacroKinds, PerNS, Res};
36use crate::def_id::{DefId, LocalDefIdMap};
37pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId};
38use crate::intravisit::{FnKind, VisitorExt};
39use crate::lints::DelayedLints;
40
41#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
42pub enum AngleBrackets {
43 Missing,
45 Empty,
47 Full,
49}
50
51#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
52pub enum LifetimeSource {
53 Reference,
55
56 Path { angle_brackets: AngleBrackets },
59
60 OutlivesBound,
62
63 PreciseCapturing,
65
66 Other,
73}
74
75#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
76pub enum LifetimeSyntax {
77 Implicit,
79
80 ExplicitAnonymous,
82
83 ExplicitBound,
85}
86
87impl From<Ident> for LifetimeSyntax {
88 fn from(ident: Ident) -> Self {
89 let name = ident.name;
90
91 if name == sym::empty {
92 unreachable!("A lifetime name should never be empty");
93 } else if name == kw::UnderscoreLifetime {
94 LifetimeSyntax::ExplicitAnonymous
95 } else {
96 debug_assert!(name.as_str().starts_with('\''));
97 LifetimeSyntax::ExplicitBound
98 }
99 }
100}
101
102#[derive(Debug, Copy, Clone, HashStable_Generic)]
153#[repr(align(4))]
158pub struct Lifetime {
159 #[stable_hasher(ignore)]
160 pub hir_id: HirId,
161
162 pub ident: Ident,
166
167 pub kind: LifetimeKind,
169
170 pub source: LifetimeSource,
173
174 pub syntax: LifetimeSyntax,
177}
178
179#[derive(Debug, Copy, Clone, HashStable_Generic)]
180pub enum ParamName {
181 Plain(Ident),
183
184 Error(Ident),
190
191 Fresh,
206}
207
208impl ParamName {
209 pub fn ident(&self) -> Ident {
210 match *self {
211 ParamName::Plain(ident) | ParamName::Error(ident) => ident,
212 ParamName::Fresh => Ident::with_dummy_span(kw::UnderscoreLifetime),
213 }
214 }
215}
216
217#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
218pub enum LifetimeKind {
219 Param(LocalDefId),
221
222 ImplicitObjectLifetimeDefault,
234
235 Error,
238
239 Infer,
243
244 Static,
246}
247
248impl LifetimeKind {
249 fn is_elided(&self) -> bool {
250 match self {
251 LifetimeKind::ImplicitObjectLifetimeDefault | LifetimeKind::Infer => true,
252
253 LifetimeKind::Error | LifetimeKind::Param(..) | LifetimeKind::Static => false,
258 }
259 }
260}
261
262impl fmt::Display for Lifetime {
263 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
264 self.ident.name.fmt(f)
265 }
266}
267
268impl Lifetime {
269 pub fn new(
270 hir_id: HirId,
271 ident: Ident,
272 kind: LifetimeKind,
273 source: LifetimeSource,
274 syntax: LifetimeSyntax,
275 ) -> Lifetime {
276 let lifetime = Lifetime { hir_id, ident, kind, source, syntax };
277
278 #[cfg(debug_assertions)]
280 match (lifetime.is_elided(), lifetime.is_anonymous()) {
281 (false, false) => {} (false, true) => {} (true, true) => {} (true, false) => panic!("bad Lifetime"),
285 }
286
287 lifetime
288 }
289
290 pub fn is_elided(&self) -> bool {
291 self.kind.is_elided()
292 }
293
294 pub fn is_anonymous(&self) -> bool {
295 self.ident.name == kw::UnderscoreLifetime
296 }
297
298 pub fn is_implicit(&self) -> bool {
299 matches!(self.syntax, LifetimeSyntax::Implicit)
300 }
301
302 pub fn is_static(&self) -> bool {
303 self.kind == LifetimeKind::Static
304 }
305
306 pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
307 use LifetimeSource::*;
308 use LifetimeSyntax::*;
309
310 debug_assert!(new_lifetime.starts_with('\''));
311
312 match (self.syntax, self.source) {
313 (ExplicitBound | ExplicitAnonymous, _) => (self.ident.span, format!("{new_lifetime}")),
315
316 (Implicit, Path { angle_brackets: AngleBrackets::Full }) => {
318 (self.ident.span, format!("{new_lifetime}, "))
319 }
320
321 (Implicit, Path { angle_brackets: AngleBrackets::Empty }) => {
323 (self.ident.span, format!("{new_lifetime}"))
324 }
325
326 (Implicit, Path { angle_brackets: AngleBrackets::Missing }) => {
328 (self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
329 }
330
331 (Implicit, Reference) => (self.ident.span, format!("{new_lifetime} ")),
333
334 (Implicit, source) => {
335 unreachable!("can't suggest for a implicit lifetime of {source:?}")
336 }
337 }
338 }
339}
340
341#[derive(Debug, Clone, Copy, HashStable_Generic)]
345pub struct Path<'hir, R = Res> {
346 pub span: Span,
347 pub res: R,
349 pub segments: &'hir [PathSegment<'hir>],
351}
352
353pub type UsePath<'hir> = Path<'hir, PerNS<Option<Res>>>;
355
356impl Path<'_> {
357 pub fn is_global(&self) -> bool {
358 self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
359 }
360}
361
362#[derive(Debug, Clone, Copy, HashStable_Generic)]
365pub struct PathSegment<'hir> {
366 pub ident: Ident,
368 #[stable_hasher(ignore)]
369 pub hir_id: HirId,
370 pub res: Res,
371
372 pub args: Option<&'hir GenericArgs<'hir>>,
378
379 pub infer_args: bool,
384}
385
386impl<'hir> PathSegment<'hir> {
387 pub fn new(ident: Ident, hir_id: HirId, res: Res) -> PathSegment<'hir> {
389 PathSegment { ident, hir_id, res, infer_args: true, args: None }
390 }
391
392 pub fn invalid() -> Self {
393 Self::new(Ident::dummy(), HirId::INVALID, Res::Err)
394 }
395
396 pub fn args(&self) -> &GenericArgs<'hir> {
397 if let Some(ref args) = self.args {
398 args
399 } else {
400 const DUMMY: &GenericArgs<'_> = &GenericArgs::none();
401 DUMMY
402 }
403 }
404}
405
406#[derive(Clone, Copy, Debug, HashStable_Generic)]
407pub enum ConstItemRhs<'hir> {
408 Body(BodyId),
409 TypeConst(&'hir ConstArg<'hir>),
410}
411
412impl<'hir> ConstItemRhs<'hir> {
413 pub fn hir_id(&self) -> HirId {
414 match self {
415 ConstItemRhs::Body(body_id) => body_id.hir_id,
416 ConstItemRhs::TypeConst(ct_arg) => ct_arg.hir_id,
417 }
418 }
419
420 pub fn span<'tcx>(&self, tcx: impl crate::intravisit::HirTyCtxt<'tcx>) -> Span {
421 match self {
422 ConstItemRhs::Body(body_id) => tcx.hir_body(*body_id).value.span,
423 ConstItemRhs::TypeConst(ct_arg) => ct_arg.span(),
424 }
425 }
426}
427
428#[derive(Clone, Copy, Debug, HashStable_Generic)]
442#[repr(C)]
443pub struct ConstArg<'hir, Unambig = ()> {
444 #[stable_hasher(ignore)]
445 pub hir_id: HirId,
446 pub kind: ConstArgKind<'hir, Unambig>,
447}
448
449impl<'hir> ConstArg<'hir, AmbigArg> {
450 pub fn as_unambig_ct(&self) -> &ConstArg<'hir> {
461 let ptr = self as *const ConstArg<'hir, AmbigArg> as *const ConstArg<'hir, ()>;
464 unsafe { &*ptr }
465 }
466}
467
468impl<'hir> ConstArg<'hir> {
469 pub fn try_as_ambig_ct(&self) -> Option<&ConstArg<'hir, AmbigArg>> {
475 if let ConstArgKind::Infer(_, ()) = self.kind {
476 return None;
477 }
478
479 let ptr = self as *const ConstArg<'hir> as *const ConstArg<'hir, AmbigArg>;
483 Some(unsafe { &*ptr })
484 }
485}
486
487impl<'hir, Unambig> ConstArg<'hir, Unambig> {
488 pub fn anon_const_hir_id(&self) -> Option<HirId> {
489 match self.kind {
490 ConstArgKind::Anon(ac) => Some(ac.hir_id),
491 _ => None,
492 }
493 }
494
495 pub fn span(&self) -> Span {
496 match self.kind {
497 ConstArgKind::Path(path) => path.span(),
498 ConstArgKind::Anon(anon) => anon.span,
499 ConstArgKind::Error(span, _) => span,
500 ConstArgKind::Infer(span, _) => span,
501 }
502 }
503}
504
505#[derive(Clone, Copy, Debug, HashStable_Generic)]
507#[repr(u8, C)]
508pub enum ConstArgKind<'hir, Unambig = ()> {
509 Path(QPath<'hir>),
515 Anon(&'hir AnonConst),
516 Error(Span, ErrorGuaranteed),
518 Infer(Span, Unambig),
521}
522
523#[derive(Clone, Copy, Debug, HashStable_Generic)]
524pub struct InferArg {
525 #[stable_hasher(ignore)]
526 pub hir_id: HirId,
527 pub span: Span,
528}
529
530impl InferArg {
531 pub fn to_ty(&self) -> Ty<'static> {
532 Ty { kind: TyKind::Infer(()), span: self.span, hir_id: self.hir_id }
533 }
534}
535
536#[derive(Debug, Clone, Copy, HashStable_Generic)]
537pub enum GenericArg<'hir> {
538 Lifetime(&'hir Lifetime),
539 Type(&'hir Ty<'hir, AmbigArg>),
540 Const(&'hir ConstArg<'hir, AmbigArg>),
541 Infer(InferArg),
551}
552
553impl GenericArg<'_> {
554 pub fn span(&self) -> Span {
555 match self {
556 GenericArg::Lifetime(l) => l.ident.span,
557 GenericArg::Type(t) => t.span,
558 GenericArg::Const(c) => c.span(),
559 GenericArg::Infer(i) => i.span,
560 }
561 }
562
563 pub fn hir_id(&self) -> HirId {
564 match self {
565 GenericArg::Lifetime(l) => l.hir_id,
566 GenericArg::Type(t) => t.hir_id,
567 GenericArg::Const(c) => c.hir_id,
568 GenericArg::Infer(i) => i.hir_id,
569 }
570 }
571
572 pub fn descr(&self) -> &'static str {
573 match self {
574 GenericArg::Lifetime(_) => "lifetime",
575 GenericArg::Type(_) => "type",
576 GenericArg::Const(_) => "constant",
577 GenericArg::Infer(_) => "placeholder",
578 }
579 }
580
581 pub fn to_ord(&self) -> ast::ParamKindOrd {
582 match self {
583 GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
584 GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => {
585 ast::ParamKindOrd::TypeOrConst
586 }
587 }
588 }
589
590 pub fn is_ty_or_const(&self) -> bool {
591 match self {
592 GenericArg::Lifetime(_) => false,
593 GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => true,
594 }
595 }
596}
597
598#[derive(Debug, Clone, Copy, HashStable_Generic)]
600pub struct GenericArgs<'hir> {
601 pub args: &'hir [GenericArg<'hir>],
603 pub constraints: &'hir [AssocItemConstraint<'hir>],
605 pub parenthesized: GenericArgsParentheses,
610 pub span_ext: Span,
623}
624
625impl<'hir> GenericArgs<'hir> {
626 pub const fn none() -> Self {
627 Self {
628 args: &[],
629 constraints: &[],
630 parenthesized: GenericArgsParentheses::No,
631 span_ext: DUMMY_SP,
632 }
633 }
634
635 pub fn paren_sugar_inputs_output(&self) -> Option<(&[Ty<'hir>], &Ty<'hir>)> {
640 if self.parenthesized != GenericArgsParentheses::ParenSugar {
641 return None;
642 }
643
644 let inputs = self
645 .args
646 .iter()
647 .find_map(|arg| {
648 let GenericArg::Type(ty) = arg else { return None };
649 let TyKind::Tup(tys) = &ty.kind else { return None };
650 Some(tys)
651 })
652 .unwrap();
653
654 Some((inputs, self.paren_sugar_output_inner()))
655 }
656
657 pub fn paren_sugar_output(&self) -> Option<&Ty<'hir>> {
662 (self.parenthesized == GenericArgsParentheses::ParenSugar)
663 .then(|| self.paren_sugar_output_inner())
664 }
665
666 fn paren_sugar_output_inner(&self) -> &Ty<'hir> {
667 let [constraint] = self.constraints.try_into().unwrap();
668 debug_assert_eq!(constraint.ident.name, sym::Output);
669 constraint.ty().unwrap()
670 }
671
672 pub fn has_err(&self) -> Option<ErrorGuaranteed> {
673 self.args
674 .iter()
675 .find_map(|arg| {
676 let GenericArg::Type(ty) = arg else { return None };
677 let TyKind::Err(guar) = ty.kind else { return None };
678 Some(guar)
679 })
680 .or_else(|| {
681 self.constraints.iter().find_map(|constraint| {
682 let TyKind::Err(guar) = constraint.ty()?.kind else { return None };
683 Some(guar)
684 })
685 })
686 }
687
688 #[inline]
689 pub fn num_lifetime_params(&self) -> usize {
690 self.args.iter().filter(|arg| matches!(arg, GenericArg::Lifetime(_))).count()
691 }
692
693 #[inline]
694 pub fn has_lifetime_params(&self) -> bool {
695 self.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
696 }
697
698 #[inline]
699 pub fn num_generic_params(&self) -> usize {
702 self.args.iter().filter(|arg| !matches!(arg, GenericArg::Lifetime(_))).count()
703 }
704
705 pub fn span(&self) -> Option<Span> {
711 let span_ext = self.span_ext()?;
712 Some(span_ext.with_lo(span_ext.lo() + BytePos(1)).with_hi(span_ext.hi() - BytePos(1)))
713 }
714
715 pub fn span_ext(&self) -> Option<Span> {
717 Some(self.span_ext).filter(|span| !span.is_empty())
718 }
719
720 pub fn is_empty(&self) -> bool {
721 self.args.is_empty()
722 }
723}
724
725#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
726pub enum GenericArgsParentheses {
727 No,
728 ReturnTypeNotation,
731 ParenSugar,
733}
734
735#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
737pub struct TraitBoundModifiers {
738 pub constness: BoundConstness,
739 pub polarity: BoundPolarity,
740}
741
742impl TraitBoundModifiers {
743 pub const NONE: Self =
744 TraitBoundModifiers { constness: BoundConstness::Never, polarity: BoundPolarity::Positive };
745}
746
747#[derive(Clone, Copy, Debug, HashStable_Generic)]
748pub enum GenericBound<'hir> {
749 Trait(PolyTraitRef<'hir>),
750 Outlives(&'hir Lifetime),
751 Use(&'hir [PreciseCapturingArg<'hir>], Span),
752}
753
754impl GenericBound<'_> {
755 pub fn trait_ref(&self) -> Option<&TraitRef<'_>> {
756 match self {
757 GenericBound::Trait(data) => Some(&data.trait_ref),
758 _ => None,
759 }
760 }
761
762 pub fn span(&self) -> Span {
763 match self {
764 GenericBound::Trait(t, ..) => t.span,
765 GenericBound::Outlives(l) => l.ident.span,
766 GenericBound::Use(_, span) => *span,
767 }
768 }
769}
770
771pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>];
772
773#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, Debug)]
774pub enum MissingLifetimeKind {
775 Underscore,
777 Ampersand,
779 Comma,
781 Brackets,
783}
784
785#[derive(Copy, Clone, Debug, HashStable_Generic)]
786pub enum LifetimeParamKind {
787 Explicit,
790
791 Elided(MissingLifetimeKind),
794
795 Error,
797}
798
799#[derive(Debug, Clone, Copy, HashStable_Generic)]
800pub enum GenericParamKind<'hir> {
801 Lifetime {
803 kind: LifetimeParamKind,
804 },
805 Type {
806 default: Option<&'hir Ty<'hir>>,
807 synthetic: bool,
808 },
809 Const {
810 ty: &'hir Ty<'hir>,
811 default: Option<&'hir ConstArg<'hir>>,
813 },
814}
815
816#[derive(Debug, Clone, Copy, HashStable_Generic)]
817pub struct GenericParam<'hir> {
818 #[stable_hasher(ignore)]
819 pub hir_id: HirId,
820 pub def_id: LocalDefId,
821 pub name: ParamName,
822 pub span: Span,
823 pub pure_wrt_drop: bool,
824 pub kind: GenericParamKind<'hir>,
825 pub colon_span: Option<Span>,
826 pub source: GenericParamSource,
827}
828
829impl<'hir> GenericParam<'hir> {
830 pub fn is_impl_trait(&self) -> bool {
834 matches!(self.kind, GenericParamKind::Type { synthetic: true, .. })
835 }
836
837 pub fn is_elided_lifetime(&self) -> bool {
841 matches!(self.kind, GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided(_) })
842 }
843}
844
845#[derive(Debug, Clone, Copy, HashStable_Generic)]
852pub enum GenericParamSource {
853 Generics,
855 Binder,
857}
858
859#[derive(Default)]
860pub struct GenericParamCount {
861 pub lifetimes: usize,
862 pub types: usize,
863 pub consts: usize,
864 pub infer: usize,
865}
866
867#[derive(Debug, Clone, Copy, HashStable_Generic)]
870pub struct Generics<'hir> {
871 pub params: &'hir [GenericParam<'hir>],
872 pub predicates: &'hir [WherePredicate<'hir>],
873 pub has_where_clause_predicates: bool,
874 pub where_clause_span: Span,
875 pub span: Span,
876}
877
878impl<'hir> Generics<'hir> {
879 pub const fn empty() -> &'hir Generics<'hir> {
880 const NOPE: Generics<'_> = Generics {
881 params: &[],
882 predicates: &[],
883 has_where_clause_predicates: false,
884 where_clause_span: DUMMY_SP,
885 span: DUMMY_SP,
886 };
887 &NOPE
888 }
889
890 pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'hir>> {
891 self.params.iter().find(|¶m| name == param.name.ident().name)
892 }
893
894 pub fn span_for_lifetime_suggestion(&self) -> Option<Span> {
896 if let Some(first) = self.params.first()
897 && self.span.contains(first.span)
898 {
899 Some(first.span.shrink_to_lo())
902 } else {
903 None
904 }
905 }
906
907 pub fn span_for_param_suggestion(&self) -> Option<Span> {
909 self.params.iter().any(|p| self.span.contains(p.span)).then(|| {
910 self.span.with_lo(self.span.hi() - BytePos(1)).shrink_to_lo()
913 })
914 }
915
916 pub fn tail_span_for_predicate_suggestion(&self) -> Span {
919 let end = self.where_clause_span.shrink_to_hi();
920 if self.has_where_clause_predicates {
921 self.predicates
922 .iter()
923 .rfind(|&p| p.kind.in_where_clause())
924 .map_or(end, |p| p.span)
925 .shrink_to_hi()
926 .to(end)
927 } else {
928 end
929 }
930 }
931
932 pub fn add_where_or_trailing_comma(&self) -> &'static str {
933 if self.has_where_clause_predicates {
934 ","
935 } else if self.where_clause_span.is_empty() {
936 " where"
937 } else {
938 ""
940 }
941 }
942
943 pub fn bounds_for_param(
944 &self,
945 param_def_id: LocalDefId,
946 ) -> impl Iterator<Item = &WhereBoundPredicate<'hir>> {
947 self.predicates.iter().filter_map(move |pred| match pred.kind {
948 WherePredicateKind::BoundPredicate(bp)
949 if bp.is_param_bound(param_def_id.to_def_id()) =>
950 {
951 Some(bp)
952 }
953 _ => None,
954 })
955 }
956
957 pub fn outlives_for_param(
958 &self,
959 param_def_id: LocalDefId,
960 ) -> impl Iterator<Item = &WhereRegionPredicate<'_>> {
961 self.predicates.iter().filter_map(move |pred| match pred.kind {
962 WherePredicateKind::RegionPredicate(rp) if rp.is_param_bound(param_def_id) => Some(rp),
963 _ => None,
964 })
965 }
966
967 pub fn bounds_span_for_suggestions(
978 &self,
979 param_def_id: LocalDefId,
980 ) -> Option<(Span, Option<Span>)> {
981 self.bounds_for_param(param_def_id).flat_map(|bp| bp.bounds.iter().rev()).find_map(
982 |bound| {
983 let span_for_parentheses = if let Some(trait_ref) = bound.trait_ref()
984 && let [.., segment] = trait_ref.path.segments
985 && let Some(ret_ty) = segment.args().paren_sugar_output()
986 && let ret_ty = ret_ty.peel_refs()
987 && let TyKind::TraitObject(_, tagged_ptr) = ret_ty.kind
988 && let TraitObjectSyntax::Dyn = tagged_ptr.tag()
989 && ret_ty.span.can_be_used_for_suggestions()
990 {
991 Some(ret_ty.span)
992 } else {
993 None
994 };
995
996 span_for_parentheses.map_or_else(
997 || {
998 let bs = bound.span();
1001 bs.can_be_used_for_suggestions().then(|| (bs.shrink_to_hi(), None))
1002 },
1003 |span| Some((span.shrink_to_hi(), Some(span.shrink_to_lo()))),
1004 )
1005 },
1006 )
1007 }
1008
1009 pub fn span_for_predicate_removal(&self, pos: usize) -> Span {
1010 let predicate = &self.predicates[pos];
1011 let span = predicate.span;
1012
1013 if !predicate.kind.in_where_clause() {
1014 return span;
1017 }
1018
1019 if pos < self.predicates.len() - 1 {
1021 let next_pred = &self.predicates[pos + 1];
1022 if next_pred.kind.in_where_clause() {
1023 return span.until(next_pred.span);
1026 }
1027 }
1028
1029 if pos > 0 {
1030 let prev_pred = &self.predicates[pos - 1];
1031 if prev_pred.kind.in_where_clause() {
1032 return prev_pred.span.shrink_to_hi().to(span);
1035 }
1036 }
1037
1038 self.where_clause_span
1042 }
1043
1044 pub fn span_for_bound_removal(&self, predicate_pos: usize, bound_pos: usize) -> Span {
1045 let predicate = &self.predicates[predicate_pos];
1046 let bounds = predicate.kind.bounds();
1047
1048 if bounds.len() == 1 {
1049 return self.span_for_predicate_removal(predicate_pos);
1050 }
1051
1052 let bound_span = bounds[bound_pos].span();
1053 if bound_pos < bounds.len() - 1 {
1054 bound_span.to(bounds[bound_pos + 1].span().shrink_to_lo())
1060 } else {
1061 bound_span.with_lo(bounds[bound_pos - 1].span().hi())
1067 }
1068 }
1069}
1070
1071#[derive(Debug, Clone, Copy, HashStable_Generic)]
1073pub struct WherePredicate<'hir> {
1074 #[stable_hasher(ignore)]
1075 pub hir_id: HirId,
1076 pub span: Span,
1077 pub kind: &'hir WherePredicateKind<'hir>,
1078}
1079
1080#[derive(Debug, Clone, Copy, HashStable_Generic)]
1082pub enum WherePredicateKind<'hir> {
1083 BoundPredicate(WhereBoundPredicate<'hir>),
1085 RegionPredicate(WhereRegionPredicate<'hir>),
1087 EqPredicate(WhereEqPredicate<'hir>),
1089}
1090
1091impl<'hir> WherePredicateKind<'hir> {
1092 pub fn in_where_clause(&self) -> bool {
1093 match self {
1094 WherePredicateKind::BoundPredicate(p) => p.origin == PredicateOrigin::WhereClause,
1095 WherePredicateKind::RegionPredicate(p) => p.in_where_clause,
1096 WherePredicateKind::EqPredicate(_) => false,
1097 }
1098 }
1099
1100 pub fn bounds(&self) -> GenericBounds<'hir> {
1101 match self {
1102 WherePredicateKind::BoundPredicate(p) => p.bounds,
1103 WherePredicateKind::RegionPredicate(p) => p.bounds,
1104 WherePredicateKind::EqPredicate(_) => &[],
1105 }
1106 }
1107}
1108
1109#[derive(Copy, Clone, Debug, HashStable_Generic, PartialEq, Eq)]
1110pub enum PredicateOrigin {
1111 WhereClause,
1112 GenericParam,
1113 ImplTrait,
1114}
1115
1116#[derive(Debug, Clone, Copy, HashStable_Generic)]
1118pub struct WhereBoundPredicate<'hir> {
1119 pub origin: PredicateOrigin,
1121 pub bound_generic_params: &'hir [GenericParam<'hir>],
1123 pub bounded_ty: &'hir Ty<'hir>,
1125 pub bounds: GenericBounds<'hir>,
1127}
1128
1129impl<'hir> WhereBoundPredicate<'hir> {
1130 pub fn is_param_bound(&self, param_def_id: DefId) -> bool {
1132 self.bounded_ty.as_generic_param().is_some_and(|(def_id, _)| def_id == param_def_id)
1133 }
1134}
1135
1136#[derive(Debug, Clone, Copy, HashStable_Generic)]
1138pub struct WhereRegionPredicate<'hir> {
1139 pub in_where_clause: bool,
1140 pub lifetime: &'hir Lifetime,
1141 pub bounds: GenericBounds<'hir>,
1142}
1143
1144impl<'hir> WhereRegionPredicate<'hir> {
1145 fn is_param_bound(&self, param_def_id: LocalDefId) -> bool {
1147 self.lifetime.kind == LifetimeKind::Param(param_def_id)
1148 }
1149}
1150
1151#[derive(Debug, Clone, Copy, HashStable_Generic)]
1153pub struct WhereEqPredicate<'hir> {
1154 pub lhs_ty: &'hir Ty<'hir>,
1155 pub rhs_ty: &'hir Ty<'hir>,
1156}
1157
1158#[derive(Clone, Copy, Debug)]
1162pub struct ParentedNode<'tcx> {
1163 pub parent: ItemLocalId,
1164 pub node: Node<'tcx>,
1165}
1166
1167#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)]
1169pub enum AttrArgs {
1170 Empty,
1172 Delimited(DelimArgs),
1174 Eq {
1176 eq_span: Span,
1178 expr: MetaItemLit,
1180 },
1181}
1182
1183#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)]
1184pub struct AttrPath {
1185 pub segments: Box<[Ident]>,
1186 pub span: Span,
1187}
1188
1189impl IntoDiagArg for AttrPath {
1190 fn into_diag_arg(self, path: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1191 self.to_string().into_diag_arg(path)
1192 }
1193}
1194
1195impl AttrPath {
1196 pub fn from_ast(path: &ast::Path, lower_span: impl Copy + Fn(Span) -> Span) -> Self {
1197 AttrPath {
1198 segments: path
1199 .segments
1200 .iter()
1201 .map(|i| Ident { name: i.ident.name, span: lower_span(i.ident.span) })
1202 .collect::<Vec<_>>()
1203 .into_boxed_slice(),
1204 span: lower_span(path.span),
1205 }
1206 }
1207}
1208
1209impl fmt::Display for AttrPath {
1210 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1211 write!(f, "{}", join_path_idents(&self.segments))
1212 }
1213}
1214
1215#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)]
1216pub struct AttrItem {
1217 pub path: AttrPath,
1219 pub args: AttrArgs,
1220 pub id: HashIgnoredAttrId,
1221 pub style: AttrStyle,
1224 pub span: Span,
1226}
1227
1228#[derive(Copy, Debug, Encodable, Decodable, Clone)]
1231pub struct HashIgnoredAttrId {
1232 pub attr_id: AttrId,
1233}
1234
1235#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)]
1236pub enum Attribute {
1237 Parsed(AttributeKind),
1243
1244 Unparsed(Box<AttrItem>),
1247}
1248
1249impl Attribute {
1250 pub fn get_normal_item(&self) -> &AttrItem {
1251 match &self {
1252 Attribute::Unparsed(normal) => &normal,
1253 _ => panic!("unexpected parsed attribute"),
1254 }
1255 }
1256
1257 pub fn unwrap_normal_item(self) -> AttrItem {
1258 match self {
1259 Attribute::Unparsed(normal) => *normal,
1260 _ => panic!("unexpected parsed attribute"),
1261 }
1262 }
1263
1264 pub fn value_lit(&self) -> Option<&MetaItemLit> {
1265 match &self {
1266 Attribute::Unparsed(n) => match n.as_ref() {
1267 AttrItem { args: AttrArgs::Eq { eq_span: _, expr }, .. } => Some(expr),
1268 _ => None,
1269 },
1270 _ => None,
1271 }
1272 }
1273
1274 pub fn is_parsed_attr(&self) -> bool {
1275 match self {
1276 Attribute::Parsed(_) => true,
1277 Attribute::Unparsed(_) => false,
1278 }
1279 }
1280}
1281
1282impl AttributeExt for Attribute {
1283 #[inline]
1284 fn id(&self) -> AttrId {
1285 match &self {
1286 Attribute::Unparsed(u) => u.id.attr_id,
1287 _ => panic!(),
1288 }
1289 }
1290
1291 #[inline]
1292 fn meta_item_list(&self) -> Option<ThinVec<ast::MetaItemInner>> {
1293 match &self {
1294 Attribute::Unparsed(n) => match n.as_ref() {
1295 AttrItem { args: AttrArgs::Delimited(d), .. } => {
1296 ast::MetaItemKind::list_from_tokens(d.tokens.clone())
1297 }
1298 _ => None,
1299 },
1300 _ => None,
1301 }
1302 }
1303
1304 #[inline]
1305 fn value_str(&self) -> Option<Symbol> {
1306 self.value_lit().and_then(|x| x.value_str())
1307 }
1308
1309 #[inline]
1310 fn value_span(&self) -> Option<Span> {
1311 self.value_lit().map(|i| i.span)
1312 }
1313
1314 #[inline]
1316 fn ident(&self) -> Option<Ident> {
1317 match &self {
1318 Attribute::Unparsed(n) => {
1319 if let [ident] = n.path.segments.as_ref() {
1320 Some(*ident)
1321 } else {
1322 None
1323 }
1324 }
1325 _ => None,
1326 }
1327 }
1328
1329 #[inline]
1330 fn path_matches(&self, name: &[Symbol]) -> bool {
1331 match &self {
1332 Attribute::Unparsed(n) => n.path.segments.iter().map(|ident| &ident.name).eq(name),
1333 _ => false,
1334 }
1335 }
1336
1337 #[inline]
1338 fn is_doc_comment(&self) -> Option<Span> {
1339 if let Attribute::Parsed(AttributeKind::DocComment { span, .. }) = self {
1340 Some(*span)
1341 } else {
1342 None
1343 }
1344 }
1345
1346 #[inline]
1347 fn span(&self) -> Span {
1348 match &self {
1349 Attribute::Unparsed(u) => u.span,
1350 Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
1352 Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
1353 a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
1354 }
1355 }
1356
1357 #[inline]
1358 fn is_word(&self) -> bool {
1359 match &self {
1360 Attribute::Unparsed(n) => {
1361 matches!(n.args, AttrArgs::Empty)
1362 }
1363 _ => false,
1364 }
1365 }
1366
1367 #[inline]
1368 fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> {
1369 match &self {
1370 Attribute::Unparsed(n) => Some(n.path.segments.iter().copied().collect()),
1371 _ => None,
1372 }
1373 }
1374
1375 #[inline]
1376 fn doc_str(&self) -> Option<Symbol> {
1377 match &self {
1378 Attribute::Parsed(AttributeKind::DocComment { comment, .. }) => Some(*comment),
1379 _ => None,
1380 }
1381 }
1382
1383 fn is_automatically_derived_attr(&self) -> bool {
1384 matches!(self, Attribute::Parsed(AttributeKind::AutomaticallyDerived(..)))
1385 }
1386
1387 #[inline]
1388 fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind)> {
1389 match &self {
1390 Attribute::Parsed(AttributeKind::DocComment { kind, comment, .. }) => {
1391 Some((*comment, *kind))
1392 }
1393 _ => None,
1394 }
1395 }
1396
1397 fn doc_resolution_scope(&self) -> Option<AttrStyle> {
1398 match self {
1399 Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
1400 Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
1401 Some(attr.style)
1402 }
1403 _ => None,
1404 }
1405 }
1406
1407 fn is_proc_macro_attr(&self) -> bool {
1408 matches!(
1409 self,
1410 Attribute::Parsed(
1411 AttributeKind::ProcMacro(..)
1412 | AttributeKind::ProcMacroAttribute(..)
1413 | AttributeKind::ProcMacroDerive { .. }
1414 )
1415 )
1416 }
1417
1418 fn is_doc_hidden(&self) -> bool {
1419 matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.hidden.is_some())
1420 }
1421
1422 fn is_doc_keyword_or_attribute(&self) -> bool {
1423 matches!(self, Attribute::Parsed(AttributeKind::Doc(d)) if d.attribute.is_some() || d.keyword.is_some())
1424 }
1425}
1426
1427impl Attribute {
1429 #[inline]
1430 pub fn id(&self) -> AttrId {
1431 AttributeExt::id(self)
1432 }
1433
1434 #[inline]
1435 pub fn name(&self) -> Option<Symbol> {
1436 AttributeExt::name(self)
1437 }
1438
1439 #[inline]
1440 pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
1441 AttributeExt::meta_item_list(self)
1442 }
1443
1444 #[inline]
1445 pub fn value_str(&self) -> Option<Symbol> {
1446 AttributeExt::value_str(self)
1447 }
1448
1449 #[inline]
1450 pub fn value_span(&self) -> Option<Span> {
1451 AttributeExt::value_span(self)
1452 }
1453
1454 #[inline]
1455 pub fn ident(&self) -> Option<Ident> {
1456 AttributeExt::ident(self)
1457 }
1458
1459 #[inline]
1460 pub fn path_matches(&self, name: &[Symbol]) -> bool {
1461 AttributeExt::path_matches(self, name)
1462 }
1463
1464 #[inline]
1465 pub fn is_doc_comment(&self) -> Option<Span> {
1466 AttributeExt::is_doc_comment(self)
1467 }
1468
1469 #[inline]
1470 pub fn has_name(&self, name: Symbol) -> bool {
1471 AttributeExt::has_name(self, name)
1472 }
1473
1474 #[inline]
1475 pub fn has_any_name(&self, names: &[Symbol]) -> bool {
1476 AttributeExt::has_any_name(self, names)
1477 }
1478
1479 #[inline]
1480 pub fn span(&self) -> Span {
1481 AttributeExt::span(self)
1482 }
1483
1484 #[inline]
1485 pub fn is_word(&self) -> bool {
1486 AttributeExt::is_word(self)
1487 }
1488
1489 #[inline]
1490 pub fn path(&self) -> SmallVec<[Symbol; 1]> {
1491 AttributeExt::path(self)
1492 }
1493
1494 #[inline]
1495 pub fn ident_path(&self) -> Option<SmallVec<[Ident; 1]>> {
1496 AttributeExt::ident_path(self)
1497 }
1498
1499 #[inline]
1500 pub fn doc_str(&self) -> Option<Symbol> {
1501 AttributeExt::doc_str(self)
1502 }
1503
1504 #[inline]
1505 pub fn is_proc_macro_attr(&self) -> bool {
1506 AttributeExt::is_proc_macro_attr(self)
1507 }
1508
1509 #[inline]
1510 pub fn doc_str_and_fragment_kind(&self) -> Option<(Symbol, DocFragmentKind)> {
1511 AttributeExt::doc_str_and_fragment_kind(self)
1512 }
1513}
1514
1515#[derive(Debug)]
1517pub struct AttributeMap<'tcx> {
1518 pub map: SortedMap<ItemLocalId, &'tcx [Attribute]>,
1519 pub define_opaque: Option<&'tcx [(Span, LocalDefId)]>,
1521 pub opt_hash: Option<Fingerprint>,
1523}
1524
1525impl<'tcx> AttributeMap<'tcx> {
1526 pub const EMPTY: &'static AttributeMap<'static> = &AttributeMap {
1527 map: SortedMap::new(),
1528 opt_hash: Some(Fingerprint::ZERO),
1529 define_opaque: None,
1530 };
1531
1532 #[inline]
1533 pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] {
1534 self.map.get(&id).copied().unwrap_or(&[])
1535 }
1536}
1537
1538pub struct OwnerNodes<'tcx> {
1542 pub opt_hash_including_bodies: Option<Fingerprint>,
1545 pub nodes: IndexVec<ItemLocalId, ParentedNode<'tcx>>,
1550 pub bodies: SortedMap<ItemLocalId, &'tcx Body<'tcx>>,
1552}
1553
1554impl<'tcx> OwnerNodes<'tcx> {
1555 pub fn node(&self) -> OwnerNode<'tcx> {
1556 self.nodes[ItemLocalId::ZERO].node.as_owner().unwrap()
1558 }
1559}
1560
1561impl fmt::Debug for OwnerNodes<'_> {
1562 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1563 f.debug_struct("OwnerNodes")
1564 .field("node", &self.nodes[ItemLocalId::ZERO])
1566 .field(
1567 "parents",
1568 &fmt::from_fn(|f| {
1569 f.debug_list()
1570 .entries(self.nodes.iter_enumerated().map(|(id, parented_node)| {
1571 fmt::from_fn(move |f| write!(f, "({id:?}, {:?})", parented_node.parent))
1572 }))
1573 .finish()
1574 }),
1575 )
1576 .field("bodies", &self.bodies)
1577 .field("opt_hash_including_bodies", &self.opt_hash_including_bodies)
1578 .finish()
1579 }
1580}
1581
1582#[derive(Debug, HashStable_Generic)]
1584pub struct OwnerInfo<'hir> {
1585 pub nodes: OwnerNodes<'hir>,
1587 pub parenting: LocalDefIdMap<ItemLocalId>,
1589 pub attrs: AttributeMap<'hir>,
1591 pub trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
1594
1595 pub delayed_lints: DelayedLints,
1598}
1599
1600impl<'tcx> OwnerInfo<'tcx> {
1601 #[inline]
1602 pub fn node(&self) -> OwnerNode<'tcx> {
1603 self.nodes.node()
1604 }
1605}
1606
1607#[derive(Copy, Clone, Debug, HashStable_Generic)]
1608pub enum MaybeOwner<'tcx> {
1609 Owner(&'tcx OwnerInfo<'tcx>),
1610 NonOwner(HirId),
1611 Phantom,
1613}
1614
1615impl<'tcx> MaybeOwner<'tcx> {
1616 pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> {
1617 match self {
1618 MaybeOwner::Owner(i) => Some(i),
1619 MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
1620 }
1621 }
1622
1623 pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> {
1624 self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner"))
1625 }
1626}
1627
1628#[derive(Debug)]
1635pub struct Crate<'hir> {
1636 pub owners: IndexVec<LocalDefId, MaybeOwner<'hir>>,
1637 pub opt_hir_hash: Option<Fingerprint>,
1639}
1640
1641#[derive(Debug, Clone, Copy, HashStable_Generic)]
1642pub struct Closure<'hir> {
1643 pub def_id: LocalDefId,
1644 pub binder: ClosureBinder,
1645 pub constness: Constness,
1646 pub capture_clause: CaptureBy,
1647 pub bound_generic_params: &'hir [GenericParam<'hir>],
1648 pub fn_decl: &'hir FnDecl<'hir>,
1649 pub body: BodyId,
1650 pub fn_decl_span: Span,
1652 pub fn_arg_span: Option<Span>,
1654 pub kind: ClosureKind,
1655}
1656
1657#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)]
1658pub enum ClosureKind {
1659 Closure,
1661 Coroutine(CoroutineKind),
1666 CoroutineClosure(CoroutineDesugaring),
1671}
1672
1673#[derive(Debug, Clone, Copy, HashStable_Generic)]
1677pub struct Block<'hir> {
1678 pub stmts: &'hir [Stmt<'hir>],
1680 pub expr: Option<&'hir Expr<'hir>>,
1683 #[stable_hasher(ignore)]
1684 pub hir_id: HirId,
1685 pub rules: BlockCheckMode,
1687 pub span: Span,
1689 pub targeted_by_break: bool,
1693}
1694
1695impl<'hir> Block<'hir> {
1696 pub fn innermost_block(&self) -> &Block<'hir> {
1697 let mut block = self;
1698 while let Some(Expr { kind: ExprKind::Block(inner_block, _), .. }) = block.expr {
1699 block = inner_block;
1700 }
1701 block
1702 }
1703}
1704
1705#[derive(Debug, Clone, Copy, HashStable_Generic)]
1706pub struct TyPat<'hir> {
1707 #[stable_hasher(ignore)]
1708 pub hir_id: HirId,
1709 pub kind: TyPatKind<'hir>,
1710 pub span: Span,
1711}
1712
1713#[derive(Debug, Clone, Copy, HashStable_Generic)]
1714pub struct Pat<'hir> {
1715 #[stable_hasher(ignore)]
1716 pub hir_id: HirId,
1717 pub kind: PatKind<'hir>,
1718 pub span: Span,
1719 pub default_binding_modes: bool,
1722}
1723
1724impl<'hir> Pat<'hir> {
1725 fn walk_short_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) -> bool {
1726 if !it(self) {
1727 return false;
1728 }
1729
1730 use PatKind::*;
1731 match self.kind {
1732 Missing => unreachable!(),
1733 Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => true,
1734 Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => {
1735 s.walk_short_(it)
1736 }
1737 Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
1738 TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
1739 Slice(before, slice, after) => {
1740 before.iter().chain(slice).chain(after.iter()).all(|p| p.walk_short_(it))
1741 }
1742 }
1743 }
1744
1745 pub fn walk_short(&self, mut it: impl FnMut(&Pat<'hir>) -> bool) -> bool {
1752 self.walk_short_(&mut it)
1753 }
1754
1755 fn walk_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) {
1756 if !it(self) {
1757 return;
1758 }
1759
1760 use PatKind::*;
1761 match self.kind {
1762 Missing | Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => {}
1763 Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
1764 Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
1765 TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
1766 Slice(before, slice, after) => {
1767 before.iter().chain(slice).chain(after.iter()).for_each(|p| p.walk_(it))
1768 }
1769 }
1770 }
1771
1772 pub fn walk(&self, mut it: impl FnMut(&Pat<'hir>) -> bool) {
1776 self.walk_(&mut it)
1777 }
1778
1779 pub fn walk_always(&self, mut it: impl FnMut(&Pat<'_>)) {
1783 self.walk(|p| {
1784 it(p);
1785 true
1786 })
1787 }
1788
1789 pub fn is_never_pattern(&self) -> bool {
1791 let mut is_never_pattern = false;
1792 self.walk(|pat| match &pat.kind {
1793 PatKind::Never => {
1794 is_never_pattern = true;
1795 false
1796 }
1797 PatKind::Or(s) => {
1798 is_never_pattern = s.iter().all(|p| p.is_never_pattern());
1799 false
1800 }
1801 _ => true,
1802 });
1803 is_never_pattern
1804 }
1805
1806 pub fn is_guaranteed_to_constitute_read_for_never(&self) -> bool {
1815 match self.kind {
1816 PatKind::Wild => false,
1818
1819 PatKind::Guard(pat, _) => pat.is_guaranteed_to_constitute_read_for_never(),
1822
1823 PatKind::Or(subpats) => {
1832 subpats.iter().all(|pat| pat.is_guaranteed_to_constitute_read_for_never())
1833 }
1834
1835 PatKind::Never => true,
1837
1838 PatKind::Missing
1841 | PatKind::Binding(_, _, _, _)
1842 | PatKind::Struct(_, _, _)
1843 | PatKind::TupleStruct(_, _, _)
1844 | PatKind::Tuple(_, _)
1845 | PatKind::Box(_)
1846 | PatKind::Ref(_, _, _)
1847 | PatKind::Deref(_)
1848 | PatKind::Expr(_)
1849 | PatKind::Range(_, _, _)
1850 | PatKind::Slice(_, _, _)
1851 | PatKind::Err(_) => true,
1852 }
1853 }
1854}
1855
1856#[derive(Debug, Clone, Copy, HashStable_Generic)]
1862pub struct PatField<'hir> {
1863 #[stable_hasher(ignore)]
1864 pub hir_id: HirId,
1865 pub ident: Ident,
1867 pub pat: &'hir Pat<'hir>,
1869 pub is_shorthand: bool,
1870 pub span: Span,
1871}
1872
1873#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic, Hash, Eq, Encodable, Decodable)]
1874pub enum RangeEnd {
1875 Included,
1876 Excluded,
1877}
1878
1879impl fmt::Display for RangeEnd {
1880 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1881 f.write_str(match self {
1882 RangeEnd::Included => "..=",
1883 RangeEnd::Excluded => "..",
1884 })
1885 }
1886}
1887
1888#[derive(Clone, Copy, PartialEq, Eq, Hash, HashStable_Generic)]
1892pub struct DotDotPos(u32);
1893
1894impl DotDotPos {
1895 pub fn new(n: Option<usize>) -> Self {
1897 match n {
1898 Some(n) => {
1899 assert!(n < u32::MAX as usize);
1900 Self(n as u32)
1901 }
1902 None => Self(u32::MAX),
1903 }
1904 }
1905
1906 pub fn as_opt_usize(&self) -> Option<usize> {
1907 if self.0 == u32::MAX { None } else { Some(self.0 as usize) }
1908 }
1909}
1910
1911impl fmt::Debug for DotDotPos {
1912 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1913 self.as_opt_usize().fmt(f)
1914 }
1915}
1916
1917#[derive(Debug, Clone, Copy, HashStable_Generic)]
1918pub struct PatExpr<'hir> {
1919 #[stable_hasher(ignore)]
1920 pub hir_id: HirId,
1921 pub span: Span,
1922 pub kind: PatExprKind<'hir>,
1923}
1924
1925#[derive(Debug, Clone, Copy, HashStable_Generic)]
1926pub enum PatExprKind<'hir> {
1927 Lit {
1928 lit: Lit,
1929 negated: bool,
1932 },
1933 ConstBlock(ConstBlock),
1934 Path(QPath<'hir>),
1936}
1937
1938#[derive(Debug, Clone, Copy, HashStable_Generic)]
1939pub enum TyPatKind<'hir> {
1940 Range(&'hir ConstArg<'hir>, &'hir ConstArg<'hir>),
1942
1943 NotNull,
1945
1946 Or(&'hir [TyPat<'hir>]),
1948
1949 Err(ErrorGuaranteed),
1951}
1952
1953#[derive(Debug, Clone, Copy, HashStable_Generic)]
1954pub enum PatKind<'hir> {
1955 Missing,
1957
1958 Wild,
1960
1961 Binding(BindingMode, HirId, Ident, Option<&'hir Pat<'hir>>),
1972
1973 Struct(QPath<'hir>, &'hir [PatField<'hir>], Option<Span>),
1976
1977 TupleStruct(QPath<'hir>, &'hir [Pat<'hir>], DotDotPos),
1981
1982 Or(&'hir [Pat<'hir>]),
1985
1986 Never,
1988
1989 Tuple(&'hir [Pat<'hir>], DotDotPos),
1993
1994 Box(&'hir Pat<'hir>),
1996
1997 Deref(&'hir Pat<'hir>),
1999
2000 Ref(&'hir Pat<'hir>, Pinnedness, Mutability),
2002
2003 Expr(&'hir PatExpr<'hir>),
2005
2006 Guard(&'hir Pat<'hir>, &'hir Expr<'hir>),
2008
2009 Range(Option<&'hir PatExpr<'hir>>, Option<&'hir PatExpr<'hir>>, RangeEnd),
2011
2012 Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]),
2022
2023 Err(ErrorGuaranteed),
2025}
2026
2027#[derive(Debug, Clone, Copy, HashStable_Generic)]
2029pub struct Stmt<'hir> {
2030 #[stable_hasher(ignore)]
2031 pub hir_id: HirId,
2032 pub kind: StmtKind<'hir>,
2033 pub span: Span,
2034}
2035
2036#[derive(Debug, Clone, Copy, HashStable_Generic)]
2038pub enum StmtKind<'hir> {
2039 Let(&'hir LetStmt<'hir>),
2041
2042 Item(ItemId),
2044
2045 Expr(&'hir Expr<'hir>),
2047
2048 Semi(&'hir Expr<'hir>),
2050}
2051
2052#[derive(Debug, Clone, Copy, HashStable_Generic)]
2054pub struct LetStmt<'hir> {
2055 pub super_: Option<Span>,
2057 pub pat: &'hir Pat<'hir>,
2058 pub ty: Option<&'hir Ty<'hir>>,
2060 pub init: Option<&'hir Expr<'hir>>,
2062 pub els: Option<&'hir Block<'hir>>,
2064 #[stable_hasher(ignore)]
2065 pub hir_id: HirId,
2066 pub span: Span,
2067 pub source: LocalSource,
2071}
2072
2073#[derive(Debug, Clone, Copy, HashStable_Generic)]
2076pub struct Arm<'hir> {
2077 #[stable_hasher(ignore)]
2078 pub hir_id: HirId,
2079 pub span: Span,
2080 pub pat: &'hir Pat<'hir>,
2082 pub guard: Option<&'hir Expr<'hir>>,
2084 pub body: &'hir Expr<'hir>,
2086}
2087
2088#[derive(Debug, Clone, Copy, HashStable_Generic)]
2094pub struct LetExpr<'hir> {
2095 pub span: Span,
2096 pub pat: &'hir Pat<'hir>,
2097 pub ty: Option<&'hir Ty<'hir>>,
2098 pub init: &'hir Expr<'hir>,
2099 pub recovered: ast::Recovered,
2102}
2103
2104#[derive(Debug, Clone, Copy, HashStable_Generic)]
2105pub struct ExprField<'hir> {
2106 #[stable_hasher(ignore)]
2107 pub hir_id: HirId,
2108 pub ident: Ident,
2109 pub expr: &'hir Expr<'hir>,
2110 pub span: Span,
2111 pub is_shorthand: bool,
2112}
2113
2114#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
2115pub enum BlockCheckMode {
2116 DefaultBlock,
2117 UnsafeBlock(UnsafeSource),
2118}
2119
2120#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
2121pub enum UnsafeSource {
2122 CompilerGenerated,
2123 UserProvided,
2124}
2125
2126#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
2127pub struct BodyId {
2128 pub hir_id: HirId,
2129}
2130
2131#[derive(Debug, Clone, Copy, HashStable_Generic)]
2153pub struct Body<'hir> {
2154 pub params: &'hir [Param<'hir>],
2155 pub value: &'hir Expr<'hir>,
2156}
2157
2158impl<'hir> Body<'hir> {
2159 pub fn id(&self) -> BodyId {
2160 BodyId { hir_id: self.value.hir_id }
2161 }
2162}
2163
2164#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)]
2166pub enum CoroutineKind {
2167 Desugared(CoroutineDesugaring, CoroutineSource),
2169
2170 Coroutine(Movability),
2172}
2173
2174impl CoroutineKind {
2175 pub fn movability(self) -> Movability {
2176 match self {
2177 CoroutineKind::Desugared(CoroutineDesugaring::Async, _)
2178 | CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _) => Movability::Static,
2179 CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => Movability::Movable,
2180 CoroutineKind::Coroutine(mov) => mov,
2181 }
2182 }
2183
2184 pub fn is_fn_like(self) -> bool {
2185 matches!(self, CoroutineKind::Desugared(_, CoroutineSource::Fn))
2186 }
2187
2188 pub fn to_plural_string(&self) -> String {
2189 match self {
2190 CoroutineKind::Desugared(d, CoroutineSource::Fn) => format!("{d:#}fn bodies"),
2191 CoroutineKind::Desugared(d, CoroutineSource::Block) => format!("{d:#}blocks"),
2192 CoroutineKind::Desugared(d, CoroutineSource::Closure) => format!("{d:#}closure bodies"),
2193 CoroutineKind::Coroutine(_) => "coroutines".to_string(),
2194 }
2195 }
2196}
2197
2198impl fmt::Display for CoroutineKind {
2199 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2200 match self {
2201 CoroutineKind::Desugared(d, k) => {
2202 d.fmt(f)?;
2203 k.fmt(f)
2204 }
2205 CoroutineKind::Coroutine(_) => f.write_str("coroutine"),
2206 }
2207 }
2208}
2209
2210#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy, HashStable_Generic, Encodable, Decodable)]
2216pub enum CoroutineSource {
2217 Block,
2219
2220 Closure,
2222
2223 Fn,
2225}
2226
2227impl fmt::Display for CoroutineSource {
2228 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2229 match self {
2230 CoroutineSource::Block => "block",
2231 CoroutineSource::Closure => "closure body",
2232 CoroutineSource::Fn => "fn body",
2233 }
2234 .fmt(f)
2235 }
2236}
2237
2238#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash, HashStable_Generic, Encodable, Decodable)]
2239pub enum CoroutineDesugaring {
2240 Async,
2242
2243 Gen,
2245
2246 AsyncGen,
2249}
2250
2251impl fmt::Display for CoroutineDesugaring {
2252 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2253 match self {
2254 CoroutineDesugaring::Async => {
2255 if f.alternate() {
2256 f.write_str("`async` ")?;
2257 } else {
2258 f.write_str("async ")?
2259 }
2260 }
2261 CoroutineDesugaring::Gen => {
2262 if f.alternate() {
2263 f.write_str("`gen` ")?;
2264 } else {
2265 f.write_str("gen ")?
2266 }
2267 }
2268 CoroutineDesugaring::AsyncGen => {
2269 if f.alternate() {
2270 f.write_str("`async gen` ")?;
2271 } else {
2272 f.write_str("async gen ")?
2273 }
2274 }
2275 }
2276
2277 Ok(())
2278 }
2279}
2280
2281#[derive(Copy, Clone, Debug)]
2282pub enum BodyOwnerKind {
2283 Fn,
2285
2286 Closure,
2288
2289 Const { inline: bool },
2291
2292 Static(Mutability),
2294
2295 GlobalAsm,
2297}
2298
2299impl BodyOwnerKind {
2300 pub fn is_fn_or_closure(self) -> bool {
2301 match self {
2302 BodyOwnerKind::Fn | BodyOwnerKind::Closure => true,
2303 BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(_) | BodyOwnerKind::GlobalAsm => {
2304 false
2305 }
2306 }
2307 }
2308}
2309
2310#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2312pub enum ConstContext {
2313 ConstFn,
2315
2316 Static(Mutability),
2318
2319 Const { inline: bool },
2329}
2330
2331impl ConstContext {
2332 pub fn keyword_name(self) -> &'static str {
2336 match self {
2337 Self::Const { .. } => "const",
2338 Self::Static(Mutability::Not) => "static",
2339 Self::Static(Mutability::Mut) => "static mut",
2340 Self::ConstFn => "const fn",
2341 }
2342 }
2343}
2344
2345impl fmt::Display for ConstContext {
2348 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2349 match *self {
2350 Self::Const { .. } => write!(f, "constant"),
2351 Self::Static(_) => write!(f, "static"),
2352 Self::ConstFn => write!(f, "constant function"),
2353 }
2354 }
2355}
2356
2357impl IntoDiagArg for ConstContext {
2358 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
2359 DiagArgValue::Str(Cow::Borrowed(match self {
2360 ConstContext::ConstFn => "const_fn",
2361 ConstContext::Static(_) => "static",
2362 ConstContext::Const { .. } => "const",
2363 }))
2364 }
2365}
2366
2367pub type Lit = Spanned<LitKind>;
2369
2370#[derive(Copy, Clone, Debug, HashStable_Generic)]
2379pub struct AnonConst {
2380 #[stable_hasher(ignore)]
2381 pub hir_id: HirId,
2382 pub def_id: LocalDefId,
2383 pub body: BodyId,
2384 pub span: Span,
2385}
2386
2387#[derive(Copy, Clone, Debug, HashStable_Generic)]
2389pub struct ConstBlock {
2390 #[stable_hasher(ignore)]
2391 pub hir_id: HirId,
2392 pub def_id: LocalDefId,
2393 pub body: BodyId,
2394}
2395
2396#[derive(Debug, Clone, Copy, HashStable_Generic)]
2405pub struct Expr<'hir> {
2406 #[stable_hasher(ignore)]
2407 pub hir_id: HirId,
2408 pub kind: ExprKind<'hir>,
2409 pub span: Span,
2410}
2411
2412impl Expr<'_> {
2413 pub fn precedence(&self, has_attr: &dyn Fn(HirId) -> bool) -> ExprPrecedence {
2414 let prefix_attrs_precedence = || -> ExprPrecedence {
2415 if has_attr(self.hir_id) { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
2416 };
2417
2418 match &self.kind {
2419 ExprKind::Closure(closure) => {
2420 match closure.fn_decl.output {
2421 FnRetTy::DefaultReturn(_) => ExprPrecedence::Jump,
2422 FnRetTy::Return(_) => prefix_attrs_precedence(),
2423 }
2424 }
2425
2426 ExprKind::Break(..)
2427 | ExprKind::Ret(..)
2428 | ExprKind::Yield(..)
2429 | ExprKind::Become(..) => ExprPrecedence::Jump,
2430
2431 ExprKind::Binary(op, ..) => op.node.precedence(),
2433 ExprKind::Cast(..) => ExprPrecedence::Cast,
2434
2435 ExprKind::Assign(..) |
2436 ExprKind::AssignOp(..) => ExprPrecedence::Assign,
2437
2438 ExprKind::AddrOf(..)
2440 | ExprKind::Let(..)
2445 | ExprKind::Unary(..) => ExprPrecedence::Prefix,
2446
2447 ExprKind::Array(_)
2449 | ExprKind::Block(..)
2450 | ExprKind::Call(..)
2451 | ExprKind::ConstBlock(_)
2452 | ExprKind::Continue(..)
2453 | ExprKind::Field(..)
2454 | ExprKind::If(..)
2455 | ExprKind::Index(..)
2456 | ExprKind::InlineAsm(..)
2457 | ExprKind::Lit(_)
2458 | ExprKind::Loop(..)
2459 | ExprKind::Match(..)
2460 | ExprKind::MethodCall(..)
2461 | ExprKind::OffsetOf(..)
2462 | ExprKind::Path(..)
2463 | ExprKind::Repeat(..)
2464 | ExprKind::Struct(..)
2465 | ExprKind::Tup(_)
2466 | ExprKind::Type(..)
2467 | ExprKind::UnsafeBinderCast(..)
2468 | ExprKind::Use(..)
2469 | ExprKind::Err(_) => prefix_attrs_precedence(),
2470
2471 ExprKind::DropTemps(expr, ..) => expr.precedence(has_attr),
2472 }
2473 }
2474
2475 pub fn is_syntactic_place_expr(&self) -> bool {
2480 self.is_place_expr(|_| true)
2481 }
2482
2483 pub fn is_place_expr(&self, mut allow_projections_from: impl FnMut(&Self) -> bool) -> bool {
2488 match self.kind {
2489 ExprKind::Path(QPath::Resolved(_, ref path)) => {
2490 matches!(path.res, Res::Local(..) | Res::Def(DefKind::Static { .. }, _) | Res::Err)
2491 }
2492
2493 ExprKind::Type(ref e, _) => e.is_place_expr(allow_projections_from),
2497
2498 ExprKind::UnsafeBinderCast(_, e, _) => e.is_place_expr(allow_projections_from),
2500
2501 ExprKind::Unary(UnOp::Deref, _) => true,
2502
2503 ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _, _) => {
2504 allow_projections_from(base) || base.is_place_expr(allow_projections_from)
2505 }
2506
2507 ExprKind::Err(_guar)
2509 | ExprKind::Let(&LetExpr { recovered: ast::Recovered::Yes(_guar), .. }) => true,
2510
2511 ExprKind::Path(QPath::TypeRelative(..))
2514 | ExprKind::Call(..)
2515 | ExprKind::MethodCall(..)
2516 | ExprKind::Use(..)
2517 | ExprKind::Struct(..)
2518 | ExprKind::Tup(..)
2519 | ExprKind::If(..)
2520 | ExprKind::Match(..)
2521 | ExprKind::Closure { .. }
2522 | ExprKind::Block(..)
2523 | ExprKind::Repeat(..)
2524 | ExprKind::Array(..)
2525 | ExprKind::Break(..)
2526 | ExprKind::Continue(..)
2527 | ExprKind::Ret(..)
2528 | ExprKind::Become(..)
2529 | ExprKind::Let(..)
2530 | ExprKind::Loop(..)
2531 | ExprKind::Assign(..)
2532 | ExprKind::InlineAsm(..)
2533 | ExprKind::OffsetOf(..)
2534 | ExprKind::AssignOp(..)
2535 | ExprKind::Lit(_)
2536 | ExprKind::ConstBlock(..)
2537 | ExprKind::Unary(..)
2538 | ExprKind::AddrOf(..)
2539 | ExprKind::Binary(..)
2540 | ExprKind::Yield(..)
2541 | ExprKind::Cast(..)
2542 | ExprKind::DropTemps(..) => false,
2543 }
2544 }
2545
2546 pub fn range_span(&self) -> Option<Span> {
2549 is_range_literal(self).then(|| self.span.parent_callsite().unwrap())
2550 }
2551
2552 pub fn is_size_lit(&self) -> bool {
2555 matches!(
2556 self.kind,
2557 ExprKind::Lit(Lit {
2558 node: LitKind::Int(_, LitIntType::Unsuffixed | LitIntType::Unsigned(UintTy::Usize)),
2559 ..
2560 })
2561 )
2562 }
2563
2564 pub fn peel_drop_temps(&self) -> &Self {
2570 let mut expr = self;
2571 while let ExprKind::DropTemps(inner) = &expr.kind {
2572 expr = inner;
2573 }
2574 expr
2575 }
2576
2577 pub fn peel_blocks(&self) -> &Self {
2578 let mut expr = self;
2579 while let ExprKind::Block(Block { expr: Some(inner), .. }, _) = &expr.kind {
2580 expr = inner;
2581 }
2582 expr
2583 }
2584
2585 pub fn peel_borrows(&self) -> &Self {
2586 let mut expr = self;
2587 while let ExprKind::AddrOf(.., inner) = &expr.kind {
2588 expr = inner;
2589 }
2590 expr
2591 }
2592
2593 pub fn can_have_side_effects(&self) -> bool {
2594 match self.peel_drop_temps().kind {
2595 ExprKind::Path(_) | ExprKind::Lit(_) | ExprKind::OffsetOf(..) | ExprKind::Use(..) => {
2596 false
2597 }
2598 ExprKind::Type(base, _)
2599 | ExprKind::Unary(_, base)
2600 | ExprKind::Field(base, _)
2601 | ExprKind::Index(base, _, _)
2602 | ExprKind::AddrOf(.., base)
2603 | ExprKind::Cast(base, _)
2604 | ExprKind::UnsafeBinderCast(_, base, _) => {
2605 base.can_have_side_effects()
2609 }
2610 ExprKind::Struct(_, fields, init) => {
2611 let init_side_effects = match init {
2612 StructTailExpr::Base(init) => init.can_have_side_effects(),
2613 StructTailExpr::DefaultFields(_) | StructTailExpr::None => false,
2614 };
2615 fields.iter().map(|field| field.expr).any(|e| e.can_have_side_effects())
2616 || init_side_effects
2617 }
2618
2619 ExprKind::Array(args)
2620 | ExprKind::Tup(args)
2621 | ExprKind::Call(
2622 Expr {
2623 kind:
2624 ExprKind::Path(QPath::Resolved(
2625 None,
2626 Path { res: Res::Def(DefKind::Ctor(_, CtorKind::Fn), _), .. },
2627 )),
2628 ..
2629 },
2630 args,
2631 ) => args.iter().any(|arg| arg.can_have_side_effects()),
2632 ExprKind::If(..)
2633 | ExprKind::Match(..)
2634 | ExprKind::MethodCall(..)
2635 | ExprKind::Call(..)
2636 | ExprKind::Closure { .. }
2637 | ExprKind::Block(..)
2638 | ExprKind::Repeat(..)
2639 | ExprKind::Break(..)
2640 | ExprKind::Continue(..)
2641 | ExprKind::Ret(..)
2642 | ExprKind::Become(..)
2643 | ExprKind::Let(..)
2644 | ExprKind::Loop(..)
2645 | ExprKind::Assign(..)
2646 | ExprKind::InlineAsm(..)
2647 | ExprKind::AssignOp(..)
2648 | ExprKind::ConstBlock(..)
2649 | ExprKind::Binary(..)
2650 | ExprKind::Yield(..)
2651 | ExprKind::DropTemps(..)
2652 | ExprKind::Err(_) => true,
2653 }
2654 }
2655
2656 pub fn is_approximately_pattern(&self) -> bool {
2658 match &self.kind {
2659 ExprKind::Array(_)
2660 | ExprKind::Call(..)
2661 | ExprKind::Tup(_)
2662 | ExprKind::Lit(_)
2663 | ExprKind::Path(_)
2664 | ExprKind::Struct(..) => true,
2665 _ => false,
2666 }
2667 }
2668
2669 pub fn equivalent_for_indexing(&self, other: &Expr<'_>) -> bool {
2674 match (self.kind, other.kind) {
2675 (ExprKind::Lit(lit1), ExprKind::Lit(lit2)) => lit1.node == lit2.node,
2676 (
2677 ExprKind::Path(QPath::Resolved(None, path1)),
2678 ExprKind::Path(QPath::Resolved(None, path2)),
2679 ) => path1.res == path2.res,
2680 (
2681 ExprKind::Struct(
2682 &QPath::Resolved(None, &Path { res: Res::Def(_, path1_def_id), .. }),
2683 args1,
2684 StructTailExpr::None,
2685 ),
2686 ExprKind::Struct(
2687 &QPath::Resolved(None, &Path { res: Res::Def(_, path2_def_id), .. }),
2688 args2,
2689 StructTailExpr::None,
2690 ),
2691 ) => {
2692 path2_def_id == path1_def_id
2693 && is_range_literal(self)
2694 && is_range_literal(other)
2695 && std::iter::zip(args1, args2)
2696 .all(|(a, b)| a.expr.equivalent_for_indexing(b.expr))
2697 }
2698 _ => false,
2699 }
2700 }
2701
2702 pub fn method_ident(&self) -> Option<Ident> {
2703 match self.kind {
2704 ExprKind::MethodCall(receiver_method, ..) => Some(receiver_method.ident),
2705 ExprKind::Unary(_, expr) | ExprKind::AddrOf(.., expr) => expr.method_ident(),
2706 _ => None,
2707 }
2708 }
2709}
2710
2711pub fn is_range_literal(expr: &Expr<'_>) -> bool {
2714 if let ExprKind::Struct(QPath::Resolved(None, path), _, StructTailExpr::None) = expr.kind
2715 && let [.., segment] = path.segments
2716 && let sym::RangeFrom
2717 | sym::RangeFull
2718 | sym::Range
2719 | sym::RangeToInclusive
2720 | sym::RangeTo
2721 | sym::RangeFromCopy
2722 | sym::RangeCopy
2723 | sym::RangeInclusiveCopy
2724 | sym::RangeToInclusiveCopy = segment.ident.name
2725 && expr.span.is_desugaring(DesugaringKind::RangeExpr)
2726 {
2727 true
2728 } else if let ExprKind::Call(func, _) = &expr.kind
2729 && let ExprKind::Path(QPath::Resolved(None, path)) = func.kind
2730 && let [.., segment] = path.segments
2731 && let sym::range_inclusive_new = segment.ident.name
2732 && expr.span.is_desugaring(DesugaringKind::RangeExpr)
2733 {
2734 true
2735 } else {
2736 false
2737 }
2738}
2739
2740pub fn expr_needs_parens(expr: &Expr<'_>) -> bool {
2747 match expr.kind {
2748 ExprKind::Cast(_, _) | ExprKind::Binary(_, _, _) => true,
2750 _ if is_range_literal(expr) => true,
2752 _ => false,
2753 }
2754}
2755
2756#[derive(Debug, Clone, Copy, HashStable_Generic)]
2757pub enum ExprKind<'hir> {
2758 ConstBlock(ConstBlock),
2760 Array(&'hir [Expr<'hir>]),
2762 Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]),
2769 MethodCall(&'hir PathSegment<'hir>, &'hir Expr<'hir>, &'hir [Expr<'hir>], Span),
2786 Use(&'hir Expr<'hir>, Span),
2788 Tup(&'hir [Expr<'hir>]),
2790 Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>),
2792 Unary(UnOp, &'hir Expr<'hir>),
2794 Lit(Lit),
2796 Cast(&'hir Expr<'hir>, &'hir Ty<'hir>),
2798 Type(&'hir Expr<'hir>, &'hir Ty<'hir>),
2800 DropTemps(&'hir Expr<'hir>),
2806 Let(&'hir LetExpr<'hir>),
2811 If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>),
2820 Loop(&'hir Block<'hir>, Option<Label>, LoopSource, Span),
2826 Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource),
2829 Closure(&'hir Closure<'hir>),
2836 Block(&'hir Block<'hir>, Option<Label>),
2838
2839 Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span),
2841 AssignOp(AssignOp, &'hir Expr<'hir>, &'hir Expr<'hir>),
2845 Field(&'hir Expr<'hir>, Ident),
2847 Index(&'hir Expr<'hir>, &'hir Expr<'hir>, Span),
2851
2852 Path(QPath<'hir>),
2854
2855 AddrOf(BorrowKind, Mutability, &'hir Expr<'hir>),
2857 Break(Destination, Option<&'hir Expr<'hir>>),
2859 Continue(Destination),
2861 Ret(Option<&'hir Expr<'hir>>),
2863 Become(&'hir Expr<'hir>),
2865
2866 InlineAsm(&'hir InlineAsm<'hir>),
2868
2869 OffsetOf(&'hir Ty<'hir>, &'hir [Ident]),
2871
2872 Struct(&'hir QPath<'hir>, &'hir [ExprField<'hir>], StructTailExpr<'hir>),
2877
2878 Repeat(&'hir Expr<'hir>, &'hir ConstArg<'hir>),
2883
2884 Yield(&'hir Expr<'hir>, YieldSource),
2886
2887 UnsafeBinderCast(UnsafeBinderCastKind, &'hir Expr<'hir>, Option<&'hir Ty<'hir>>),
2890
2891 Err(rustc_span::ErrorGuaranteed),
2893}
2894
2895#[derive(Debug, Clone, Copy, HashStable_Generic)]
2896pub enum StructTailExpr<'hir> {
2897 None,
2899 Base(&'hir Expr<'hir>),
2902 DefaultFields(Span),
2906}
2907
2908#[derive(Debug, Clone, Copy, HashStable_Generic)]
2914pub enum QPath<'hir> {
2915 Resolved(Option<&'hir Ty<'hir>>, &'hir Path<'hir>),
2922
2923 TypeRelative(&'hir Ty<'hir>, &'hir PathSegment<'hir>),
2930}
2931
2932impl<'hir> QPath<'hir> {
2933 pub fn span(&self) -> Span {
2935 match *self {
2936 QPath::Resolved(_, path) => path.span,
2937 QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
2938 }
2939 }
2940
2941 pub fn qself_span(&self) -> Span {
2944 match *self {
2945 QPath::Resolved(_, path) => path.span,
2946 QPath::TypeRelative(qself, _) => qself.span,
2947 }
2948 }
2949}
2950
2951#[derive(Copy, Clone, Debug, HashStable_Generic)]
2953pub enum LocalSource {
2954 Normal,
2956 AsyncFn,
2967 AwaitDesugar,
2969 AssignDesugar,
2971 Contract,
2973}
2974
2975#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic, Encodable, Decodable)]
2977pub enum MatchSource {
2978 Normal,
2980 Postfix,
2982 ForLoopDesugar,
2984 TryDesugar(HirId),
2986 AwaitDesugar,
2988 FormatArgs,
2990}
2991
2992impl MatchSource {
2993 #[inline]
2994 pub const fn name(self) -> &'static str {
2995 use MatchSource::*;
2996 match self {
2997 Normal => "match",
2998 Postfix => ".match",
2999 ForLoopDesugar => "for",
3000 TryDesugar(_) => "?",
3001 AwaitDesugar => ".await",
3002 FormatArgs => "format_args!()",
3003 }
3004 }
3005}
3006
3007#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
3009pub enum LoopSource {
3010 Loop,
3012 While,
3014 ForLoop,
3016}
3017
3018impl LoopSource {
3019 pub fn name(self) -> &'static str {
3020 match self {
3021 LoopSource::Loop => "loop",
3022 LoopSource::While => "while",
3023 LoopSource::ForLoop => "for",
3024 }
3025 }
3026}
3027
3028#[derive(Copy, Clone, Debug, PartialEq, HashStable_Generic)]
3029pub enum LoopIdError {
3030 OutsideLoopScope,
3031 UnlabeledCfInWhileCondition,
3032 UnresolvedLabel,
3033}
3034
3035impl fmt::Display for LoopIdError {
3036 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3037 f.write_str(match self {
3038 LoopIdError::OutsideLoopScope => "not inside loop scope",
3039 LoopIdError::UnlabeledCfInWhileCondition => {
3040 "unlabeled control flow (break or continue) in while condition"
3041 }
3042 LoopIdError::UnresolvedLabel => "label not found",
3043 })
3044 }
3045}
3046
3047#[derive(Copy, Clone, Debug, PartialEq, HashStable_Generic)]
3048pub struct Destination {
3049 pub label: Option<Label>,
3051
3052 pub target_id: Result<HirId, LoopIdError>,
3055}
3056
3057#[derive(Copy, Clone, Debug, HashStable_Generic)]
3059pub enum YieldSource {
3060 Await { expr: Option<HirId> },
3062 Yield,
3064}
3065
3066impl fmt::Display for YieldSource {
3067 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3068 f.write_str(match self {
3069 YieldSource::Await { .. } => "`await`",
3070 YieldSource::Yield => "`yield`",
3071 })
3072 }
3073}
3074
3075#[derive(Debug, Clone, Copy, HashStable_Generic)]
3078pub struct MutTy<'hir> {
3079 pub ty: &'hir Ty<'hir>,
3080 pub mutbl: Mutability,
3081}
3082
3083#[derive(Debug, Clone, Copy, HashStable_Generic)]
3086pub struct FnSig<'hir> {
3087 pub header: FnHeader,
3088 pub decl: &'hir FnDecl<'hir>,
3089 pub span: Span,
3090}
3091
3092#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
3096pub struct TraitItemId {
3097 pub owner_id: OwnerId,
3098}
3099
3100impl TraitItemId {
3101 #[inline]
3102 pub fn hir_id(&self) -> HirId {
3103 HirId::make_owner(self.owner_id.def_id)
3105 }
3106}
3107
3108#[derive(Debug, Clone, Copy, HashStable_Generic)]
3113pub struct TraitItem<'hir> {
3114 pub ident: Ident,
3115 pub owner_id: OwnerId,
3116 pub generics: &'hir Generics<'hir>,
3117 pub kind: TraitItemKind<'hir>,
3118 pub span: Span,
3119 pub defaultness: Defaultness,
3120 pub has_delayed_lints: bool,
3121}
3122
3123macro_rules! expect_methods_self_kind {
3124 ( $( $name:ident, $ret_ty:ty, $pat:pat, $ret_val:expr; )* ) => {
3125 $(
3126 #[track_caller]
3127 pub fn $name(&self) -> $ret_ty {
3128 let $pat = &self.kind else { expect_failed(stringify!($name), self) };
3129 $ret_val
3130 }
3131 )*
3132 }
3133}
3134
3135macro_rules! expect_methods_self {
3136 ( $( $name:ident, $ret_ty:ty, $pat:pat, $ret_val:expr; )* ) => {
3137 $(
3138 #[track_caller]
3139 pub fn $name(&self) -> $ret_ty {
3140 let $pat = self else { expect_failed(stringify!($name), self) };
3141 $ret_val
3142 }
3143 )*
3144 }
3145}
3146
3147#[track_caller]
3148fn expect_failed<T: fmt::Debug>(ident: &'static str, found: T) -> ! {
3149 panic!("{ident}: found {found:?}")
3150}
3151
3152impl<'hir> TraitItem<'hir> {
3153 #[inline]
3154 pub fn hir_id(&self) -> HirId {
3155 HirId::make_owner(self.owner_id.def_id)
3157 }
3158
3159 pub fn trait_item_id(&self) -> TraitItemId {
3160 TraitItemId { owner_id: self.owner_id }
3161 }
3162
3163 expect_methods_self_kind! {
3164 expect_const, (&'hir Ty<'hir>, Option<ConstItemRhs<'hir>>),
3165 TraitItemKind::Const(ty, rhs), (ty, *rhs);
3166
3167 expect_fn, (&FnSig<'hir>, &TraitFn<'hir>),
3168 TraitItemKind::Fn(ty, trfn), (ty, trfn);
3169
3170 expect_type, (GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
3171 TraitItemKind::Type(bounds, ty), (bounds, *ty);
3172 }
3173}
3174
3175#[derive(Debug, Clone, Copy, HashStable_Generic)]
3177pub enum TraitFn<'hir> {
3178 Required(&'hir [Option<Ident>]),
3180
3181 Provided(BodyId),
3183}
3184
3185#[derive(Debug, Clone, Copy, HashStable_Generic)]
3187pub enum TraitItemKind<'hir> {
3188 Const(&'hir Ty<'hir>, Option<ConstItemRhs<'hir>>),
3190 Fn(FnSig<'hir>, TraitFn<'hir>),
3192 Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>),
3195}
3196
3197#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
3201pub struct ImplItemId {
3202 pub owner_id: OwnerId,
3203}
3204
3205impl ImplItemId {
3206 #[inline]
3207 pub fn hir_id(&self) -> HirId {
3208 HirId::make_owner(self.owner_id.def_id)
3210 }
3211}
3212
3213#[derive(Debug, Clone, Copy, HashStable_Generic)]
3217pub struct ImplItem<'hir> {
3218 pub ident: Ident,
3219 pub owner_id: OwnerId,
3220 pub generics: &'hir Generics<'hir>,
3221 pub kind: ImplItemKind<'hir>,
3222 pub impl_kind: ImplItemImplKind,
3223 pub span: Span,
3224 pub has_delayed_lints: bool,
3225}
3226
3227#[derive(Debug, Clone, Copy, HashStable_Generic)]
3228pub enum ImplItemImplKind {
3229 Inherent {
3230 vis_span: Span,
3231 },
3232 Trait {
3233 defaultness: Defaultness,
3234 trait_item_def_id: Result<DefId, ErrorGuaranteed>,
3236 },
3237}
3238
3239impl<'hir> ImplItem<'hir> {
3240 #[inline]
3241 pub fn hir_id(&self) -> HirId {
3242 HirId::make_owner(self.owner_id.def_id)
3244 }
3245
3246 pub fn impl_item_id(&self) -> ImplItemId {
3247 ImplItemId { owner_id: self.owner_id }
3248 }
3249
3250 pub fn vis_span(&self) -> Option<Span> {
3251 match self.impl_kind {
3252 ImplItemImplKind::Trait { .. } => None,
3253 ImplItemImplKind::Inherent { vis_span, .. } => Some(vis_span),
3254 }
3255 }
3256
3257 expect_methods_self_kind! {
3258 expect_const, (&'hir Ty<'hir>, ConstItemRhs<'hir>), ImplItemKind::Const(ty, rhs), (ty, *rhs);
3259 expect_fn, (&FnSig<'hir>, BodyId), ImplItemKind::Fn(ty, body), (ty, *body);
3260 expect_type, &'hir Ty<'hir>, ImplItemKind::Type(ty), ty;
3261 }
3262}
3263
3264#[derive(Debug, Clone, Copy, HashStable_Generic)]
3266pub enum ImplItemKind<'hir> {
3267 Const(&'hir Ty<'hir>, ConstItemRhs<'hir>),
3270 Fn(FnSig<'hir>, BodyId),
3272 Type(&'hir Ty<'hir>),
3274}
3275
3276#[derive(Debug, Clone, Copy, HashStable_Generic)]
3287pub struct AssocItemConstraint<'hir> {
3288 #[stable_hasher(ignore)]
3289 pub hir_id: HirId,
3290 pub ident: Ident,
3291 pub gen_args: &'hir GenericArgs<'hir>,
3292 pub kind: AssocItemConstraintKind<'hir>,
3293 pub span: Span,
3294}
3295
3296impl<'hir> AssocItemConstraint<'hir> {
3297 pub fn ty(self) -> Option<&'hir Ty<'hir>> {
3299 match self.kind {
3300 AssocItemConstraintKind::Equality { term: Term::Ty(ty) } => Some(ty),
3301 _ => None,
3302 }
3303 }
3304
3305 pub fn ct(self) -> Option<&'hir ConstArg<'hir>> {
3307 match self.kind {
3308 AssocItemConstraintKind::Equality { term: Term::Const(ct) } => Some(ct),
3309 _ => None,
3310 }
3311 }
3312}
3313
3314#[derive(Debug, Clone, Copy, HashStable_Generic)]
3315pub enum Term<'hir> {
3316 Ty(&'hir Ty<'hir>),
3317 Const(&'hir ConstArg<'hir>),
3318}
3319
3320impl<'hir> From<&'hir Ty<'hir>> for Term<'hir> {
3321 fn from(ty: &'hir Ty<'hir>) -> Self {
3322 Term::Ty(ty)
3323 }
3324}
3325
3326impl<'hir> From<&'hir ConstArg<'hir>> for Term<'hir> {
3327 fn from(c: &'hir ConstArg<'hir>) -> Self {
3328 Term::Const(c)
3329 }
3330}
3331
3332#[derive(Debug, Clone, Copy, HashStable_Generic)]
3334pub enum AssocItemConstraintKind<'hir> {
3335 Equality { term: Term<'hir> },
3342 Bound { bounds: &'hir [GenericBound<'hir>] },
3344}
3345
3346impl<'hir> AssocItemConstraintKind<'hir> {
3347 pub fn descr(&self) -> &'static str {
3348 match self {
3349 AssocItemConstraintKind::Equality { .. } => "binding",
3350 AssocItemConstraintKind::Bound { .. } => "constraint",
3351 }
3352 }
3353}
3354
3355#[derive(Debug, Clone, Copy, HashStable_Generic)]
3359pub enum AmbigArg {}
3360
3361#[derive(Debug, Clone, Copy, HashStable_Generic)]
3366#[repr(C)]
3367pub struct Ty<'hir, Unambig = ()> {
3368 #[stable_hasher(ignore)]
3369 pub hir_id: HirId,
3370 pub span: Span,
3371 pub kind: TyKind<'hir, Unambig>,
3372}
3373
3374impl<'hir> Ty<'hir, AmbigArg> {
3375 pub fn as_unambig_ty(&self) -> &Ty<'hir> {
3386 let ptr = self as *const Ty<'hir, AmbigArg> as *const Ty<'hir, ()>;
3389 unsafe { &*ptr }
3390 }
3391}
3392
3393impl<'hir> Ty<'hir> {
3394 pub fn try_as_ambig_ty(&self) -> Option<&Ty<'hir, AmbigArg>> {
3400 if let TyKind::Infer(()) = self.kind {
3401 return None;
3402 }
3403
3404 let ptr = self as *const Ty<'hir> as *const Ty<'hir, AmbigArg>;
3408 Some(unsafe { &*ptr })
3409 }
3410}
3411
3412impl<'hir> Ty<'hir, AmbigArg> {
3413 pub fn peel_refs(&self) -> &Ty<'hir> {
3414 let mut final_ty = self.as_unambig_ty();
3415 while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
3416 final_ty = ty;
3417 }
3418 final_ty
3419 }
3420}
3421
3422impl<'hir> Ty<'hir> {
3423 pub fn peel_refs(&self) -> &Self {
3424 let mut final_ty = self;
3425 while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
3426 final_ty = ty;
3427 }
3428 final_ty
3429 }
3430
3431 pub fn as_generic_param(&self) -> Option<(DefId, Ident)> {
3433 let TyKind::Path(QPath::Resolved(None, path)) = self.kind else {
3434 return None;
3435 };
3436 let [segment] = &path.segments else {
3437 return None;
3438 };
3439 match path.res {
3440 Res::Def(DefKind::TyParam, def_id) | Res::SelfTyParam { trait_: def_id } => {
3441 Some((def_id, segment.ident))
3442 }
3443 _ => None,
3444 }
3445 }
3446
3447 pub fn find_self_aliases(&self) -> Vec<Span> {
3448 use crate::intravisit::Visitor;
3449 struct MyVisitor(Vec<Span>);
3450 impl<'v> Visitor<'v> for MyVisitor {
3451 fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) {
3452 if matches!(
3453 &t.kind,
3454 TyKind::Path(QPath::Resolved(
3455 _,
3456 Path { res: crate::def::Res::SelfTyAlias { .. }, .. },
3457 ))
3458 ) {
3459 self.0.push(t.span);
3460 return;
3461 }
3462 crate::intravisit::walk_ty(self, t);
3463 }
3464 }
3465
3466 let mut my_visitor = MyVisitor(vec![]);
3467 my_visitor.visit_ty_unambig(self);
3468 my_visitor.0
3469 }
3470
3471 pub fn is_suggestable_infer_ty(&self) -> bool {
3474 fn are_suggestable_generic_args(generic_args: &[GenericArg<'_>]) -> bool {
3475 generic_args.iter().any(|arg| match arg {
3476 GenericArg::Type(ty) => ty.as_unambig_ty().is_suggestable_infer_ty(),
3477 GenericArg::Infer(_) => true,
3478 _ => false,
3479 })
3480 }
3481 debug!(?self);
3482 match &self.kind {
3483 TyKind::Infer(()) => true,
3484 TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
3485 TyKind::Array(ty, length) => {
3486 ty.is_suggestable_infer_ty() || matches!(length.kind, ConstArgKind::Infer(..))
3487 }
3488 TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
3489 TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),
3490 TyKind::Path(QPath::TypeRelative(ty, segment)) => {
3491 ty.is_suggestable_infer_ty() || are_suggestable_generic_args(segment.args().args)
3492 }
3493 TyKind::Path(QPath::Resolved(ty_opt, Path { segments, .. })) => {
3494 ty_opt.is_some_and(Self::is_suggestable_infer_ty)
3495 || segments
3496 .iter()
3497 .any(|segment| are_suggestable_generic_args(segment.args().args))
3498 }
3499 _ => false,
3500 }
3501 }
3502}
3503
3504#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)]
3506pub enum PrimTy {
3507 Int(IntTy),
3508 Uint(UintTy),
3509 Float(FloatTy),
3510 Str,
3511 Bool,
3512 Char,
3513}
3514
3515impl PrimTy {
3516 pub const ALL: [Self; 19] = [
3518 Self::Int(IntTy::I8),
3520 Self::Int(IntTy::I16),
3521 Self::Int(IntTy::I32),
3522 Self::Int(IntTy::I64),
3523 Self::Int(IntTy::I128),
3524 Self::Int(IntTy::Isize),
3525 Self::Uint(UintTy::U8),
3526 Self::Uint(UintTy::U16),
3527 Self::Uint(UintTy::U32),
3528 Self::Uint(UintTy::U64),
3529 Self::Uint(UintTy::U128),
3530 Self::Uint(UintTy::Usize),
3531 Self::Float(FloatTy::F16),
3532 Self::Float(FloatTy::F32),
3533 Self::Float(FloatTy::F64),
3534 Self::Float(FloatTy::F128),
3535 Self::Bool,
3536 Self::Char,
3537 Self::Str,
3538 ];
3539
3540 pub fn name_str(self) -> &'static str {
3544 match self {
3545 PrimTy::Int(i) => i.name_str(),
3546 PrimTy::Uint(u) => u.name_str(),
3547 PrimTy::Float(f) => f.name_str(),
3548 PrimTy::Str => "str",
3549 PrimTy::Bool => "bool",
3550 PrimTy::Char => "char",
3551 }
3552 }
3553
3554 pub fn name(self) -> Symbol {
3555 match self {
3556 PrimTy::Int(i) => i.name(),
3557 PrimTy::Uint(u) => u.name(),
3558 PrimTy::Float(f) => f.name(),
3559 PrimTy::Str => sym::str,
3560 PrimTy::Bool => sym::bool,
3561 PrimTy::Char => sym::char,
3562 }
3563 }
3564
3565 pub fn from_name(name: Symbol) -> Option<Self> {
3568 let ty = match name {
3569 sym::i8 => Self::Int(IntTy::I8),
3571 sym::i16 => Self::Int(IntTy::I16),
3572 sym::i32 => Self::Int(IntTy::I32),
3573 sym::i64 => Self::Int(IntTy::I64),
3574 sym::i128 => Self::Int(IntTy::I128),
3575 sym::isize => Self::Int(IntTy::Isize),
3576 sym::u8 => Self::Uint(UintTy::U8),
3577 sym::u16 => Self::Uint(UintTy::U16),
3578 sym::u32 => Self::Uint(UintTy::U32),
3579 sym::u64 => Self::Uint(UintTy::U64),
3580 sym::u128 => Self::Uint(UintTy::U128),
3581 sym::usize => Self::Uint(UintTy::Usize),
3582 sym::f16 => Self::Float(FloatTy::F16),
3583 sym::f32 => Self::Float(FloatTy::F32),
3584 sym::f64 => Self::Float(FloatTy::F64),
3585 sym::f128 => Self::Float(FloatTy::F128),
3586 sym::bool => Self::Bool,
3587 sym::char => Self::Char,
3588 sym::str => Self::Str,
3589 _ => return None,
3590 };
3591 Some(ty)
3592 }
3593}
3594
3595#[derive(Debug, Clone, Copy, HashStable_Generic)]
3596pub struct FnPtrTy<'hir> {
3597 pub safety: Safety,
3598 pub abi: ExternAbi,
3599 pub generic_params: &'hir [GenericParam<'hir>],
3600 pub decl: &'hir FnDecl<'hir>,
3601 pub param_idents: &'hir [Option<Ident>],
3604}
3605
3606#[derive(Debug, Clone, Copy, HashStable_Generic)]
3607pub struct UnsafeBinderTy<'hir> {
3608 pub generic_params: &'hir [GenericParam<'hir>],
3609 pub inner_ty: &'hir Ty<'hir>,
3610}
3611
3612#[derive(Debug, Clone, Copy, HashStable_Generic)]
3613pub struct OpaqueTy<'hir> {
3614 #[stable_hasher(ignore)]
3615 pub hir_id: HirId,
3616 pub def_id: LocalDefId,
3617 pub bounds: GenericBounds<'hir>,
3618 pub origin: OpaqueTyOrigin<LocalDefId>,
3619 pub span: Span,
3620}
3621
3622#[derive(Debug, Clone, Copy, HashStable_Generic, Encodable, Decodable)]
3623pub enum PreciseCapturingArgKind<T, U> {
3624 Lifetime(T),
3625 Param(U),
3627}
3628
3629pub type PreciseCapturingArg<'hir> =
3630 PreciseCapturingArgKind<&'hir Lifetime, PreciseCapturingNonLifetimeArg>;
3631
3632impl PreciseCapturingArg<'_> {
3633 pub fn hir_id(self) -> HirId {
3634 match self {
3635 PreciseCapturingArg::Lifetime(lt) => lt.hir_id,
3636 PreciseCapturingArg::Param(param) => param.hir_id,
3637 }
3638 }
3639
3640 pub fn name(self) -> Symbol {
3641 match self {
3642 PreciseCapturingArg::Lifetime(lt) => lt.ident.name,
3643 PreciseCapturingArg::Param(param) => param.ident.name,
3644 }
3645 }
3646}
3647
3648#[derive(Debug, Clone, Copy, HashStable_Generic)]
3653pub struct PreciseCapturingNonLifetimeArg {
3654 #[stable_hasher(ignore)]
3655 pub hir_id: HirId,
3656 pub ident: Ident,
3657 pub res: Res,
3658}
3659
3660#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3661#[derive(HashStable_Generic, Encodable, Decodable)]
3662pub enum RpitContext {
3663 Trait,
3664 TraitImpl,
3665}
3666
3667#[derive(Copy, Clone, PartialEq, Eq, Debug)]
3669#[derive(HashStable_Generic, Encodable, Decodable)]
3670pub enum OpaqueTyOrigin<D> {
3671 FnReturn {
3673 parent: D,
3675 in_trait_or_impl: Option<RpitContext>,
3677 },
3678 AsyncFn {
3680 parent: D,
3682 in_trait_or_impl: Option<RpitContext>,
3684 },
3685 TyAlias {
3687 parent: D,
3689 in_assoc_ty: bool,
3691 },
3692}
3693
3694#[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable_Generic)]
3695pub enum InferDelegationKind {
3696 Input(usize),
3697 Output,
3698}
3699
3700#[repr(u8, C)]
3706#[derive(Debug, Clone, Copy, HashStable_Generic)]
3707pub enum TyKind<'hir, Unambig = ()> {
3708 InferDelegation(DefId, InferDelegationKind),
3710 Slice(&'hir Ty<'hir>),
3712 Array(&'hir Ty<'hir>, &'hir ConstArg<'hir>),
3714 Ptr(MutTy<'hir>),
3716 Ref(&'hir Lifetime, MutTy<'hir>),
3718 FnPtr(&'hir FnPtrTy<'hir>),
3720 UnsafeBinder(&'hir UnsafeBinderTy<'hir>),
3722 Never,
3724 Tup(&'hir [Ty<'hir>]),
3726 Path(QPath<'hir>),
3731 OpaqueDef(&'hir OpaqueTy<'hir>),
3733 TraitAscription(GenericBounds<'hir>),
3735 TraitObject(&'hir [PolyTraitRef<'hir>], TaggedRef<'hir, Lifetime, TraitObjectSyntax>),
3741 Err(rustc_span::ErrorGuaranteed),
3743 Pat(&'hir Ty<'hir>, &'hir TyPat<'hir>),
3745 Infer(Unambig),
3751}
3752
3753#[derive(Debug, Clone, Copy, HashStable_Generic)]
3754pub enum InlineAsmOperand<'hir> {
3755 In {
3756 reg: InlineAsmRegOrRegClass,
3757 expr: &'hir Expr<'hir>,
3758 },
3759 Out {
3760 reg: InlineAsmRegOrRegClass,
3761 late: bool,
3762 expr: Option<&'hir Expr<'hir>>,
3763 },
3764 InOut {
3765 reg: InlineAsmRegOrRegClass,
3766 late: bool,
3767 expr: &'hir Expr<'hir>,
3768 },
3769 SplitInOut {
3770 reg: InlineAsmRegOrRegClass,
3771 late: bool,
3772 in_expr: &'hir Expr<'hir>,
3773 out_expr: Option<&'hir Expr<'hir>>,
3774 },
3775 Const {
3776 anon_const: ConstBlock,
3777 },
3778 SymFn {
3779 expr: &'hir Expr<'hir>,
3780 },
3781 SymStatic {
3782 path: QPath<'hir>,
3783 def_id: DefId,
3784 },
3785 Label {
3786 block: &'hir Block<'hir>,
3787 },
3788}
3789
3790impl<'hir> InlineAsmOperand<'hir> {
3791 pub fn reg(&self) -> Option<InlineAsmRegOrRegClass> {
3792 match *self {
3793 Self::In { reg, .. }
3794 | Self::Out { reg, .. }
3795 | Self::InOut { reg, .. }
3796 | Self::SplitInOut { reg, .. } => Some(reg),
3797 Self::Const { .. }
3798 | Self::SymFn { .. }
3799 | Self::SymStatic { .. }
3800 | Self::Label { .. } => None,
3801 }
3802 }
3803
3804 pub fn is_clobber(&self) -> bool {
3805 matches!(
3806 self,
3807 InlineAsmOperand::Out { reg: InlineAsmRegOrRegClass::Reg(_), late: _, expr: None }
3808 )
3809 }
3810}
3811
3812#[derive(Debug, Clone, Copy, HashStable_Generic)]
3813pub struct InlineAsm<'hir> {
3814 pub asm_macro: ast::AsmMacro,
3815 pub template: &'hir [InlineAsmTemplatePiece],
3816 pub template_strs: &'hir [(Symbol, Option<Symbol>, Span)],
3817 pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
3818 pub options: InlineAsmOptions,
3819 pub line_spans: &'hir [Span],
3820}
3821
3822impl InlineAsm<'_> {
3823 pub fn contains_label(&self) -> bool {
3824 self.operands.iter().any(|x| matches!(x.0, InlineAsmOperand::Label { .. }))
3825 }
3826}
3827
3828#[derive(Debug, Clone, Copy, HashStable_Generic)]
3830pub struct Param<'hir> {
3831 #[stable_hasher(ignore)]
3832 pub hir_id: HirId,
3833 pub pat: &'hir Pat<'hir>,
3834 pub ty_span: Span,
3835 pub span: Span,
3836}
3837
3838#[derive(Debug, Clone, Copy, HashStable_Generic)]
3840pub struct FnDecl<'hir> {
3841 pub inputs: &'hir [Ty<'hir>],
3845 pub output: FnRetTy<'hir>,
3846 pub c_variadic: bool,
3847 pub implicit_self: ImplicitSelfKind,
3849 pub lifetime_elision_allowed: bool,
3851}
3852
3853impl<'hir> FnDecl<'hir> {
3854 pub fn opt_delegation_sig_id(&self) -> Option<DefId> {
3855 if let FnRetTy::Return(ty) = self.output
3856 && let TyKind::InferDelegation(sig_id, _) = ty.kind
3857 {
3858 return Some(sig_id);
3859 }
3860 None
3861 }
3862}
3863
3864#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
3866pub enum ImplicitSelfKind {
3867 Imm,
3869 Mut,
3871 RefImm,
3873 RefMut,
3875 None,
3878}
3879
3880impl ImplicitSelfKind {
3881 pub fn has_implicit_self(&self) -> bool {
3883 !matches!(*self, ImplicitSelfKind::None)
3884 }
3885}
3886
3887#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
3888pub enum IsAsync {
3889 Async(Span),
3890 NotAsync,
3891}
3892
3893impl IsAsync {
3894 pub fn is_async(self) -> bool {
3895 matches!(self, IsAsync::Async(_))
3896 }
3897}
3898
3899#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
3900#[derive(Default)]
3901pub enum Defaultness {
3902 Default {
3903 has_value: bool,
3904 },
3905 #[default]
3906 Final,
3907}
3908
3909impl Defaultness {
3910 pub fn has_value(&self) -> bool {
3911 match *self {
3912 Defaultness::Default { has_value } => has_value,
3913 Defaultness::Final => true,
3914 }
3915 }
3916
3917 pub fn is_final(&self) -> bool {
3918 *self == Defaultness::Final
3919 }
3920
3921 pub fn is_default(&self) -> bool {
3922 matches!(*self, Defaultness::Default { .. })
3923 }
3924}
3925
3926#[derive(Debug, Clone, Copy, HashStable_Generic)]
3927pub enum FnRetTy<'hir> {
3928 DefaultReturn(Span),
3934 Return(&'hir Ty<'hir>),
3936}
3937
3938impl<'hir> FnRetTy<'hir> {
3939 #[inline]
3940 pub fn span(&self) -> Span {
3941 match *self {
3942 Self::DefaultReturn(span) => span,
3943 Self::Return(ref ty) => ty.span,
3944 }
3945 }
3946
3947 pub fn is_suggestable_infer_ty(&self) -> Option<&'hir Ty<'hir>> {
3948 if let Self::Return(ty) = self
3949 && ty.is_suggestable_infer_ty()
3950 {
3951 return Some(*ty);
3952 }
3953 None
3954 }
3955}
3956
3957#[derive(Copy, Clone, Debug, HashStable_Generic)]
3959pub enum ClosureBinder {
3960 Default,
3962 For { span: Span },
3966}
3967
3968#[derive(Debug, Clone, Copy, HashStable_Generic)]
3969pub struct Mod<'hir> {
3970 pub spans: ModSpans,
3971 pub item_ids: &'hir [ItemId],
3972}
3973
3974#[derive(Copy, Clone, Debug, HashStable_Generic)]
3975pub struct ModSpans {
3976 pub inner_span: Span,
3980 pub inject_use_span: Span,
3981}
3982
3983#[derive(Debug, Clone, Copy, HashStable_Generic)]
3984pub struct EnumDef<'hir> {
3985 pub variants: &'hir [Variant<'hir>],
3986}
3987
3988#[derive(Debug, Clone, Copy, HashStable_Generic)]
3989pub struct Variant<'hir> {
3990 pub ident: Ident,
3992 #[stable_hasher(ignore)]
3994 pub hir_id: HirId,
3995 pub def_id: LocalDefId,
3996 pub data: VariantData<'hir>,
3998 pub disr_expr: Option<&'hir AnonConst>,
4000 pub span: Span,
4002}
4003
4004#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
4005pub enum UseKind {
4006 Single(Ident),
4013
4014 Glob,
4016
4017 ListStem,
4021}
4022
4023#[derive(Clone, Debug, Copy, HashStable_Generic)]
4030pub struct TraitRef<'hir> {
4031 pub path: &'hir Path<'hir>,
4032 #[stable_hasher(ignore)]
4034 pub hir_ref_id: HirId,
4035}
4036
4037impl TraitRef<'_> {
4038 pub fn trait_def_id(&self) -> Option<DefId> {
4040 match self.path.res {
4041 Res::Def(DefKind::Trait | DefKind::TraitAlias, did) => Some(did),
4042 Res::Err => None,
4043 res => panic!("{res:?} did not resolve to a trait or trait alias"),
4044 }
4045 }
4046}
4047
4048#[derive(Clone, Debug, Copy, HashStable_Generic)]
4049pub struct PolyTraitRef<'hir> {
4050 pub bound_generic_params: &'hir [GenericParam<'hir>],
4052
4053 pub modifiers: TraitBoundModifiers,
4057
4058 pub trait_ref: TraitRef<'hir>,
4060
4061 pub span: Span,
4062}
4063
4064#[derive(Debug, Clone, Copy, HashStable_Generic)]
4065pub struct FieldDef<'hir> {
4066 pub span: Span,
4067 pub vis_span: Span,
4068 pub ident: Ident,
4069 #[stable_hasher(ignore)]
4070 pub hir_id: HirId,
4071 pub def_id: LocalDefId,
4072 pub ty: &'hir Ty<'hir>,
4073 pub safety: Safety,
4074 pub default: Option<&'hir AnonConst>,
4075}
4076
4077impl FieldDef<'_> {
4078 pub fn is_positional(&self) -> bool {
4080 self.ident.as_str().as_bytes()[0].is_ascii_digit()
4081 }
4082}
4083
4084#[derive(Debug, Clone, Copy, HashStable_Generic)]
4086pub enum VariantData<'hir> {
4087 Struct { fields: &'hir [FieldDef<'hir>], recovered: ast::Recovered },
4091 Tuple(&'hir [FieldDef<'hir>], #[stable_hasher(ignore)] HirId, LocalDefId),
4095 Unit(#[stable_hasher(ignore)] HirId, LocalDefId),
4099}
4100
4101impl<'hir> VariantData<'hir> {
4102 pub fn fields(&self) -> &'hir [FieldDef<'hir>] {
4104 match *self {
4105 VariantData::Struct { fields, .. } | VariantData::Tuple(fields, ..) => fields,
4106 _ => &[],
4107 }
4108 }
4109
4110 pub fn ctor(&self) -> Option<(CtorKind, HirId, LocalDefId)> {
4111 match *self {
4112 VariantData::Tuple(_, hir_id, def_id) => Some((CtorKind::Fn, hir_id, def_id)),
4113 VariantData::Unit(hir_id, def_id) => Some((CtorKind::Const, hir_id, def_id)),
4114 VariantData::Struct { .. } => None,
4115 }
4116 }
4117
4118 #[inline]
4119 pub fn ctor_kind(&self) -> Option<CtorKind> {
4120 self.ctor().map(|(kind, ..)| kind)
4121 }
4122
4123 #[inline]
4125 pub fn ctor_hir_id(&self) -> Option<HirId> {
4126 self.ctor().map(|(_, hir_id, _)| hir_id)
4127 }
4128
4129 #[inline]
4131 pub fn ctor_def_id(&self) -> Option<LocalDefId> {
4132 self.ctor().map(|(.., def_id)| def_id)
4133 }
4134}
4135
4136#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash, HashStable_Generic)]
4140pub struct ItemId {
4141 pub owner_id: OwnerId,
4142}
4143
4144impl ItemId {
4145 #[inline]
4146 pub fn hir_id(&self) -> HirId {
4147 HirId::make_owner(self.owner_id.def_id)
4149 }
4150}
4151
4152#[derive(Debug, Clone, Copy, HashStable_Generic)]
4161pub struct Item<'hir> {
4162 pub owner_id: OwnerId,
4163 pub kind: ItemKind<'hir>,
4164 pub span: Span,
4165 pub vis_span: Span,
4166 pub has_delayed_lints: bool,
4167 pub eii: bool,
4170}
4171
4172impl<'hir> Item<'hir> {
4173 #[inline]
4174 pub fn hir_id(&self) -> HirId {
4175 HirId::make_owner(self.owner_id.def_id)
4177 }
4178
4179 pub fn item_id(&self) -> ItemId {
4180 ItemId { owner_id: self.owner_id }
4181 }
4182
4183 pub fn is_adt(&self) -> bool {
4186 matches!(self.kind, ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..))
4187 }
4188
4189 pub fn is_struct_or_union(&self) -> bool {
4191 matches!(self.kind, ItemKind::Struct(..) | ItemKind::Union(..))
4192 }
4193
4194 expect_methods_self_kind! {
4195 expect_extern_crate, (Option<Symbol>, Ident),
4196 ItemKind::ExternCrate(s, ident), (*s, *ident);
4197
4198 expect_use, (&'hir UsePath<'hir>, UseKind), ItemKind::Use(p, uk), (p, *uk);
4199
4200 expect_static, (Mutability, Ident, &'hir Ty<'hir>, BodyId),
4201 ItemKind::Static(mutbl, ident, ty, body), (*mutbl, *ident, ty, *body);
4202
4203 expect_const, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, ConstItemRhs<'hir>),
4204 ItemKind::Const(ident, generics, ty, rhs), (*ident, generics, ty, *rhs);
4205
4206 expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
4207 ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
4208
4209 expect_macro, (Ident, &ast::MacroDef, MacroKinds),
4210 ItemKind::Macro(ident, def, mk), (*ident, def, *mk);
4211
4212 expect_mod, (Ident, &'hir Mod<'hir>), ItemKind::Mod(ident, m), (*ident, m);
4213
4214 expect_foreign_mod, (ExternAbi, &'hir [ForeignItemId]),
4215 ItemKind::ForeignMod { abi, items }, (*abi, items);
4216
4217 expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
4218
4219 expect_ty_alias, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
4220 ItemKind::TyAlias(ident, generics, ty), (*ident, generics, ty);
4221
4222 expect_enum, (Ident, &'hir Generics<'hir>, &EnumDef<'hir>),
4223 ItemKind::Enum(ident, generics, def), (*ident, generics, def);
4224
4225 expect_struct, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
4226 ItemKind::Struct(ident, generics, data), (*ident, generics, data);
4227
4228 expect_union, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
4229 ItemKind::Union(ident, generics, data), (*ident, generics, data);
4230
4231 expect_trait,
4232 (
4233 Constness,
4234 IsAuto,
4235 Safety,
4236 Ident,
4237 &'hir Generics<'hir>,
4238 GenericBounds<'hir>,
4239 &'hir [TraitItemId]
4240 ),
4241 ItemKind::Trait(constness, is_auto, safety, ident, generics, bounds, items),
4242 (*constness, *is_auto, *safety, *ident, generics, bounds, items);
4243
4244 expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4245 ItemKind::TraitAlias(constness, ident, generics, bounds), (*constness, *ident, generics, bounds);
4246
4247 expect_impl, &Impl<'hir>, ItemKind::Impl(imp), imp;
4248 }
4249}
4250
4251#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
4252#[derive(Encodable, Decodable, HashStable_Generic, Default)]
4253pub enum Safety {
4254 #[default]
4259 Unsafe,
4260 Safe,
4261}
4262
4263impl Safety {
4264 pub fn prefix_str(self) -> &'static str {
4265 match self {
4266 Self::Unsafe => "unsafe ",
4267 Self::Safe => "",
4268 }
4269 }
4270
4271 #[inline]
4272 pub fn is_unsafe(self) -> bool {
4273 !self.is_safe()
4274 }
4275
4276 #[inline]
4277 pub fn is_safe(self) -> bool {
4278 match self {
4279 Self::Unsafe => false,
4280 Self::Safe => true,
4281 }
4282 }
4283}
4284
4285impl fmt::Display for Safety {
4286 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4287 f.write_str(match *self {
4288 Self::Unsafe => "unsafe",
4289 Self::Safe => "safe",
4290 })
4291 }
4292}
4293
4294#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
4295#[derive(Default)]
4296pub enum Constness {
4297 #[default]
4298 Const,
4299 NotConst,
4300}
4301
4302impl fmt::Display for Constness {
4303 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4304 f.write_str(match *self {
4305 Self::Const => "const",
4306 Self::NotConst => "non-const",
4307 })
4308 }
4309}
4310
4311#[derive(Copy, Clone, Debug, HashStable_Generic, PartialEq, Eq)]
4316pub enum HeaderSafety {
4317 SafeTargetFeatures,
4323 Normal(Safety),
4324}
4325
4326impl From<Safety> for HeaderSafety {
4327 fn from(v: Safety) -> Self {
4328 Self::Normal(v)
4329 }
4330}
4331
4332#[derive(Copy, Clone, Debug, HashStable_Generic)]
4333pub struct FnHeader {
4334 pub safety: HeaderSafety,
4335 pub constness: Constness,
4336 pub asyncness: IsAsync,
4337 pub abi: ExternAbi,
4338}
4339
4340impl FnHeader {
4341 pub fn is_async(&self) -> bool {
4342 matches!(self.asyncness, IsAsync::Async(_))
4343 }
4344
4345 pub fn is_const(&self) -> bool {
4346 matches!(self.constness, Constness::Const)
4347 }
4348
4349 pub fn is_unsafe(&self) -> bool {
4350 self.safety().is_unsafe()
4351 }
4352
4353 pub fn is_safe(&self) -> bool {
4354 self.safety().is_safe()
4355 }
4356
4357 pub fn safety(&self) -> Safety {
4358 match self.safety {
4359 HeaderSafety::SafeTargetFeatures => Safety::Unsafe,
4360 HeaderSafety::Normal(safety) => safety,
4361 }
4362 }
4363}
4364
4365#[derive(Debug, Clone, Copy, HashStable_Generic)]
4366pub enum ItemKind<'hir> {
4367 ExternCrate(Option<Symbol>, Ident),
4371
4372 Use(&'hir UsePath<'hir>, UseKind),
4378
4379 Static(Mutability, Ident, &'hir Ty<'hir>, BodyId),
4381 Const(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, ConstItemRhs<'hir>),
4383 Fn {
4385 sig: FnSig<'hir>,
4386 ident: Ident,
4387 generics: &'hir Generics<'hir>,
4388 body: BodyId,
4389 has_body: bool,
4393 },
4394 Macro(Ident, &'hir ast::MacroDef, MacroKinds),
4396 Mod(Ident, &'hir Mod<'hir>),
4398 ForeignMod { abi: ExternAbi, items: &'hir [ForeignItemId] },
4400 GlobalAsm {
4402 asm: &'hir InlineAsm<'hir>,
4403 fake_body: BodyId,
4409 },
4410 TyAlias(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
4412 Enum(Ident, &'hir Generics<'hir>, EnumDef<'hir>),
4414 Struct(Ident, &'hir Generics<'hir>, VariantData<'hir>),
4416 Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
4418 Trait(
4420 Constness,
4421 IsAuto,
4422 Safety,
4423 Ident,
4424 &'hir Generics<'hir>,
4425 GenericBounds<'hir>,
4426 &'hir [TraitItemId],
4427 ),
4428 TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4430
4431 Impl(Impl<'hir>),
4433}
4434
4435#[derive(Debug, Clone, Copy, HashStable_Generic)]
4440pub struct Impl<'hir> {
4441 pub generics: &'hir Generics<'hir>,
4442 pub of_trait: Option<&'hir TraitImplHeader<'hir>>,
4443 pub self_ty: &'hir Ty<'hir>,
4444 pub items: &'hir [ImplItemId],
4445 pub constness: Constness,
4446}
4447
4448#[derive(Debug, Clone, Copy, HashStable_Generic)]
4449pub struct TraitImplHeader<'hir> {
4450 pub safety: Safety,
4451 pub polarity: ImplPolarity,
4452 pub defaultness: Defaultness,
4453 pub defaultness_span: Option<Span>,
4456 pub trait_ref: TraitRef<'hir>,
4457}
4458
4459impl ItemKind<'_> {
4460 pub fn ident(&self) -> Option<Ident> {
4461 match *self {
4462 ItemKind::ExternCrate(_, ident)
4463 | ItemKind::Use(_, UseKind::Single(ident))
4464 | ItemKind::Static(_, ident, ..)
4465 | ItemKind::Const(ident, ..)
4466 | ItemKind::Fn { ident, .. }
4467 | ItemKind::Macro(ident, ..)
4468 | ItemKind::Mod(ident, ..)
4469 | ItemKind::TyAlias(ident, ..)
4470 | ItemKind::Enum(ident, ..)
4471 | ItemKind::Struct(ident, ..)
4472 | ItemKind::Union(ident, ..)
4473 | ItemKind::Trait(_, _, _, ident, ..)
4474 | ItemKind::TraitAlias(_, ident, ..) => Some(ident),
4475
4476 ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
4477 | ItemKind::ForeignMod { .. }
4478 | ItemKind::GlobalAsm { .. }
4479 | ItemKind::Impl(_) => None,
4480 }
4481 }
4482
4483 pub fn generics(&self) -> Option<&Generics<'_>> {
4484 Some(match self {
4485 ItemKind::Fn { generics, .. }
4486 | ItemKind::TyAlias(_, generics, _)
4487 | ItemKind::Const(_, generics, _, _)
4488 | ItemKind::Enum(_, generics, _)
4489 | ItemKind::Struct(_, generics, _)
4490 | ItemKind::Union(_, generics, _)
4491 | ItemKind::Trait(_, _, _, _, generics, _, _)
4492 | ItemKind::TraitAlias(_, _, generics, _)
4493 | ItemKind::Impl(Impl { generics, .. }) => generics,
4494 _ => return None,
4495 })
4496 }
4497}
4498
4499#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
4503pub struct ForeignItemId {
4504 pub owner_id: OwnerId,
4505}
4506
4507impl ForeignItemId {
4508 #[inline]
4509 pub fn hir_id(&self) -> HirId {
4510 HirId::make_owner(self.owner_id.def_id)
4512 }
4513}
4514
4515#[derive(Debug, Clone, Copy, HashStable_Generic)]
4516pub struct ForeignItem<'hir> {
4517 pub ident: Ident,
4518 pub kind: ForeignItemKind<'hir>,
4519 pub owner_id: OwnerId,
4520 pub span: Span,
4521 pub vis_span: Span,
4522 pub has_delayed_lints: bool,
4523}
4524
4525impl ForeignItem<'_> {
4526 #[inline]
4527 pub fn hir_id(&self) -> HirId {
4528 HirId::make_owner(self.owner_id.def_id)
4530 }
4531
4532 pub fn foreign_item_id(&self) -> ForeignItemId {
4533 ForeignItemId { owner_id: self.owner_id }
4534 }
4535}
4536
4537#[derive(Debug, Clone, Copy, HashStable_Generic)]
4539pub enum ForeignItemKind<'hir> {
4540 Fn(FnSig<'hir>, &'hir [Option<Ident>], &'hir Generics<'hir>),
4547 Static(&'hir Ty<'hir>, Mutability, Safety),
4549 Type,
4551}
4552
4553#[derive(Debug, Copy, Clone, HashStable_Generic)]
4555pub struct Upvar {
4556 pub span: Span,
4558}
4559
4560#[derive(Debug, Clone, HashStable_Generic)]
4564pub struct TraitCandidate {
4565 pub def_id: DefId,
4566 pub import_ids: SmallVec<[LocalDefId; 1]>,
4567}
4568
4569#[derive(Copy, Clone, Debug, HashStable_Generic)]
4570pub enum OwnerNode<'hir> {
4571 Item(&'hir Item<'hir>),
4572 ForeignItem(&'hir ForeignItem<'hir>),
4573 TraitItem(&'hir TraitItem<'hir>),
4574 ImplItem(&'hir ImplItem<'hir>),
4575 Crate(&'hir Mod<'hir>),
4576 Synthetic,
4577}
4578
4579impl<'hir> OwnerNode<'hir> {
4580 pub fn span(&self) -> Span {
4581 match self {
4582 OwnerNode::Item(Item { span, .. })
4583 | OwnerNode::ForeignItem(ForeignItem { span, .. })
4584 | OwnerNode::ImplItem(ImplItem { span, .. })
4585 | OwnerNode::TraitItem(TraitItem { span, .. }) => *span,
4586 OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => *inner_span,
4587 OwnerNode::Synthetic => unreachable!(),
4588 }
4589 }
4590
4591 pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>> {
4592 match self {
4593 OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
4594 | OwnerNode::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
4595 | OwnerNode::Item(Item { kind: ItemKind::Fn { sig: fn_sig, .. }, .. })
4596 | OwnerNode::ForeignItem(ForeignItem {
4597 kind: ForeignItemKind::Fn(fn_sig, _, _), ..
4598 }) => Some(fn_sig),
4599 _ => None,
4600 }
4601 }
4602
4603 pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
4604 match self {
4605 OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
4606 | OwnerNode::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
4607 | OwnerNode::Item(Item { kind: ItemKind::Fn { sig: fn_sig, .. }, .. })
4608 | OwnerNode::ForeignItem(ForeignItem {
4609 kind: ForeignItemKind::Fn(fn_sig, _, _), ..
4610 }) => Some(fn_sig.decl),
4611 _ => None,
4612 }
4613 }
4614
4615 pub fn body_id(&self) -> Option<BodyId> {
4616 match self {
4617 OwnerNode::Item(Item {
4618 kind:
4619 ItemKind::Static(_, _, _, body)
4620 | ItemKind::Const(.., ConstItemRhs::Body(body))
4621 | ItemKind::Fn { body, .. },
4622 ..
4623 })
4624 | OwnerNode::TraitItem(TraitItem {
4625 kind:
4626 TraitItemKind::Fn(_, TraitFn::Provided(body))
4627 | TraitItemKind::Const(_, Some(ConstItemRhs::Body(body))),
4628 ..
4629 })
4630 | OwnerNode::ImplItem(ImplItem {
4631 kind: ImplItemKind::Fn(_, body) | ImplItemKind::Const(_, ConstItemRhs::Body(body)),
4632 ..
4633 }) => Some(*body),
4634 _ => None,
4635 }
4636 }
4637
4638 pub fn generics(self) -> Option<&'hir Generics<'hir>> {
4639 Node::generics(self.into())
4640 }
4641
4642 pub fn def_id(self) -> OwnerId {
4643 match self {
4644 OwnerNode::Item(Item { owner_id, .. })
4645 | OwnerNode::TraitItem(TraitItem { owner_id, .. })
4646 | OwnerNode::ImplItem(ImplItem { owner_id, .. })
4647 | OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id,
4648 OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner,
4649 OwnerNode::Synthetic => unreachable!(),
4650 }
4651 }
4652
4653 pub fn is_impl_block(&self) -> bool {
4655 matches!(self, OwnerNode::Item(Item { kind: ItemKind::Impl(_), .. }))
4656 }
4657
4658 expect_methods_self! {
4659 expect_item, &'hir Item<'hir>, OwnerNode::Item(n), n;
4660 expect_foreign_item, &'hir ForeignItem<'hir>, OwnerNode::ForeignItem(n), n;
4661 expect_impl_item, &'hir ImplItem<'hir>, OwnerNode::ImplItem(n), n;
4662 expect_trait_item, &'hir TraitItem<'hir>, OwnerNode::TraitItem(n), n;
4663 }
4664}
4665
4666impl<'hir> From<&'hir Item<'hir>> for OwnerNode<'hir> {
4667 fn from(val: &'hir Item<'hir>) -> Self {
4668 OwnerNode::Item(val)
4669 }
4670}
4671
4672impl<'hir> From<&'hir ForeignItem<'hir>> for OwnerNode<'hir> {
4673 fn from(val: &'hir ForeignItem<'hir>) -> Self {
4674 OwnerNode::ForeignItem(val)
4675 }
4676}
4677
4678impl<'hir> From<&'hir ImplItem<'hir>> for OwnerNode<'hir> {
4679 fn from(val: &'hir ImplItem<'hir>) -> Self {
4680 OwnerNode::ImplItem(val)
4681 }
4682}
4683
4684impl<'hir> From<&'hir TraitItem<'hir>> for OwnerNode<'hir> {
4685 fn from(val: &'hir TraitItem<'hir>) -> Self {
4686 OwnerNode::TraitItem(val)
4687 }
4688}
4689
4690impl<'hir> From<OwnerNode<'hir>> for Node<'hir> {
4691 fn from(val: OwnerNode<'hir>) -> Self {
4692 match val {
4693 OwnerNode::Item(n) => Node::Item(n),
4694 OwnerNode::ForeignItem(n) => Node::ForeignItem(n),
4695 OwnerNode::ImplItem(n) => Node::ImplItem(n),
4696 OwnerNode::TraitItem(n) => Node::TraitItem(n),
4697 OwnerNode::Crate(n) => Node::Crate(n),
4698 OwnerNode::Synthetic => Node::Synthetic,
4699 }
4700 }
4701}
4702
4703#[derive(Copy, Clone, Debug, HashStable_Generic)]
4704pub enum Node<'hir> {
4705 Param(&'hir Param<'hir>),
4706 Item(&'hir Item<'hir>),
4707 ForeignItem(&'hir ForeignItem<'hir>),
4708 TraitItem(&'hir TraitItem<'hir>),
4709 ImplItem(&'hir ImplItem<'hir>),
4710 Variant(&'hir Variant<'hir>),
4711 Field(&'hir FieldDef<'hir>),
4712 AnonConst(&'hir AnonConst),
4713 ConstBlock(&'hir ConstBlock),
4714 ConstArg(&'hir ConstArg<'hir>),
4715 Expr(&'hir Expr<'hir>),
4716 ExprField(&'hir ExprField<'hir>),
4717 Stmt(&'hir Stmt<'hir>),
4718 PathSegment(&'hir PathSegment<'hir>),
4719 Ty(&'hir Ty<'hir>),
4720 AssocItemConstraint(&'hir AssocItemConstraint<'hir>),
4721 TraitRef(&'hir TraitRef<'hir>),
4722 OpaqueTy(&'hir OpaqueTy<'hir>),
4723 TyPat(&'hir TyPat<'hir>),
4724 Pat(&'hir Pat<'hir>),
4725 PatField(&'hir PatField<'hir>),
4726 PatExpr(&'hir PatExpr<'hir>),
4730 Arm(&'hir Arm<'hir>),
4731 Block(&'hir Block<'hir>),
4732 LetStmt(&'hir LetStmt<'hir>),
4733 Ctor(&'hir VariantData<'hir>),
4736 Lifetime(&'hir Lifetime),
4737 GenericParam(&'hir GenericParam<'hir>),
4738 Crate(&'hir Mod<'hir>),
4739 Infer(&'hir InferArg),
4740 WherePredicate(&'hir WherePredicate<'hir>),
4741 PreciseCapturingNonLifetimeArg(&'hir PreciseCapturingNonLifetimeArg),
4742 Synthetic,
4744 Err(Span),
4745}
4746
4747impl<'hir> Node<'hir> {
4748 pub fn ident(&self) -> Option<Ident> {
4763 match self {
4764 Node::Item(item) => item.kind.ident(),
4765 Node::TraitItem(TraitItem { ident, .. })
4766 | Node::ImplItem(ImplItem { ident, .. })
4767 | Node::ForeignItem(ForeignItem { ident, .. })
4768 | Node::Field(FieldDef { ident, .. })
4769 | Node::Variant(Variant { ident, .. })
4770 | Node::PathSegment(PathSegment { ident, .. }) => Some(*ident),
4771 Node::Lifetime(lt) => Some(lt.ident),
4772 Node::GenericParam(p) => Some(p.name.ident()),
4773 Node::AssocItemConstraint(c) => Some(c.ident),
4774 Node::PatField(f) => Some(f.ident),
4775 Node::ExprField(f) => Some(f.ident),
4776 Node::PreciseCapturingNonLifetimeArg(a) => Some(a.ident),
4777 Node::Param(..)
4778 | Node::AnonConst(..)
4779 | Node::ConstBlock(..)
4780 | Node::ConstArg(..)
4781 | Node::Expr(..)
4782 | Node::Stmt(..)
4783 | Node::Block(..)
4784 | Node::Ctor(..)
4785 | Node::Pat(..)
4786 | Node::TyPat(..)
4787 | Node::PatExpr(..)
4788 | Node::Arm(..)
4789 | Node::LetStmt(..)
4790 | Node::Crate(..)
4791 | Node::Ty(..)
4792 | Node::TraitRef(..)
4793 | Node::OpaqueTy(..)
4794 | Node::Infer(..)
4795 | Node::WherePredicate(..)
4796 | Node::Synthetic
4797 | Node::Err(..) => None,
4798 }
4799 }
4800
4801 pub fn fn_decl(self) -> Option<&'hir FnDecl<'hir>> {
4802 match self {
4803 Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
4804 | Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
4805 | Node::Item(Item { kind: ItemKind::Fn { sig: fn_sig, .. }, .. })
4806 | Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_sig, _, _), .. }) => {
4807 Some(fn_sig.decl)
4808 }
4809 Node::Expr(Expr { kind: ExprKind::Closure(Closure { fn_decl, .. }), .. }) => {
4810 Some(fn_decl)
4811 }
4812 _ => None,
4813 }
4814 }
4815
4816 pub fn impl_block_of_trait(self, trait_def_id: DefId) -> Option<&'hir Impl<'hir>> {
4818 if let Node::Item(Item { kind: ItemKind::Impl(impl_block), .. }) = self
4819 && let Some(of_trait) = impl_block.of_trait
4820 && let Some(trait_id) = of_trait.trait_ref.trait_def_id()
4821 && trait_id == trait_def_id
4822 {
4823 Some(impl_block)
4824 } else {
4825 None
4826 }
4827 }
4828
4829 pub fn fn_sig(self) -> Option<&'hir FnSig<'hir>> {
4830 match self {
4831 Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. })
4832 | Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(fn_sig, _), .. })
4833 | Node::Item(Item { kind: ItemKind::Fn { sig: fn_sig, .. }, .. })
4834 | Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_sig, _, _), .. }) => {
4835 Some(fn_sig)
4836 }
4837 _ => None,
4838 }
4839 }
4840
4841 pub fn ty(self) -> Option<&'hir Ty<'hir>> {
4843 match self {
4844 Node::Item(it) => match it.kind {
4845 ItemKind::TyAlias(_, _, ty)
4846 | ItemKind::Static(_, _, ty, _)
4847 | ItemKind::Const(_, _, ty, _) => Some(ty),
4848 ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
4849 _ => None,
4850 },
4851 Node::TraitItem(it) => match it.kind {
4852 TraitItemKind::Const(ty, _) => Some(ty),
4853 TraitItemKind::Type(_, ty) => ty,
4854 _ => None,
4855 },
4856 Node::ImplItem(it) => match it.kind {
4857 ImplItemKind::Const(ty, _) => Some(ty),
4858 ImplItemKind::Type(ty) => Some(ty),
4859 _ => None,
4860 },
4861 Node::ForeignItem(it) => match it.kind {
4862 ForeignItemKind::Static(ty, ..) => Some(ty),
4863 _ => None,
4864 },
4865 Node::GenericParam(param) => match param.kind {
4866 GenericParamKind::Lifetime { .. } => None,
4867 GenericParamKind::Type { default, .. } => default,
4868 GenericParamKind::Const { ty, .. } => Some(ty),
4869 },
4870 _ => None,
4871 }
4872 }
4873
4874 pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
4875 match self {
4876 Node::Item(Item { kind: ItemKind::TyAlias(_, _, ty), .. }) => Some(ty),
4877 _ => None,
4878 }
4879 }
4880
4881 #[inline]
4882 pub fn associated_body(&self) -> Option<(LocalDefId, BodyId)> {
4883 match self {
4884 Node::Item(Item {
4885 owner_id,
4886 kind:
4887 ItemKind::Const(.., ConstItemRhs::Body(body))
4888 | ItemKind::Static(.., body)
4889 | ItemKind::Fn { body, .. },
4890 ..
4891 })
4892 | Node::TraitItem(TraitItem {
4893 owner_id,
4894 kind:
4895 TraitItemKind::Const(.., Some(ConstItemRhs::Body(body)))
4896 | TraitItemKind::Fn(_, TraitFn::Provided(body)),
4897 ..
4898 })
4899 | Node::ImplItem(ImplItem {
4900 owner_id,
4901 kind: ImplItemKind::Const(.., ConstItemRhs::Body(body)) | ImplItemKind::Fn(_, body),
4902 ..
4903 }) => Some((owner_id.def_id, *body)),
4904
4905 Node::Item(Item {
4906 owner_id, kind: ItemKind::GlobalAsm { asm: _, fake_body }, ..
4907 }) => Some((owner_id.def_id, *fake_body)),
4908
4909 Node::Expr(Expr { kind: ExprKind::Closure(Closure { def_id, body, .. }), .. }) => {
4910 Some((*def_id, *body))
4911 }
4912
4913 Node::AnonConst(constant) => Some((constant.def_id, constant.body)),
4914 Node::ConstBlock(constant) => Some((constant.def_id, constant.body)),
4915
4916 _ => None,
4917 }
4918 }
4919
4920 pub fn body_id(&self) -> Option<BodyId> {
4921 Some(self.associated_body()?.1)
4922 }
4923
4924 pub fn generics(self) -> Option<&'hir Generics<'hir>> {
4925 match self {
4926 Node::ForeignItem(ForeignItem {
4927 kind: ForeignItemKind::Fn(_, _, generics), ..
4928 })
4929 | Node::TraitItem(TraitItem { generics, .. })
4930 | Node::ImplItem(ImplItem { generics, .. }) => Some(generics),
4931 Node::Item(item) => item.kind.generics(),
4932 _ => None,
4933 }
4934 }
4935
4936 pub fn as_owner(self) -> Option<OwnerNode<'hir>> {
4937 match self {
4938 Node::Item(i) => Some(OwnerNode::Item(i)),
4939 Node::ForeignItem(i) => Some(OwnerNode::ForeignItem(i)),
4940 Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)),
4941 Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)),
4942 Node::Crate(i) => Some(OwnerNode::Crate(i)),
4943 Node::Synthetic => Some(OwnerNode::Synthetic),
4944 _ => None,
4945 }
4946 }
4947
4948 pub fn fn_kind(self) -> Option<FnKind<'hir>> {
4949 match self {
4950 Node::Item(i) => match i.kind {
4951 ItemKind::Fn { ident, sig, generics, .. } => {
4952 Some(FnKind::ItemFn(ident, generics, sig.header))
4953 }
4954 _ => None,
4955 },
4956 Node::TraitItem(ti) => match ti.kind {
4957 TraitItemKind::Fn(ref sig, _) => Some(FnKind::Method(ti.ident, sig)),
4958 _ => None,
4959 },
4960 Node::ImplItem(ii) => match ii.kind {
4961 ImplItemKind::Fn(ref sig, _) => Some(FnKind::Method(ii.ident, sig)),
4962 _ => None,
4963 },
4964 Node::Expr(e) => match e.kind {
4965 ExprKind::Closure { .. } => Some(FnKind::Closure),
4966 _ => None,
4967 },
4968 _ => None,
4969 }
4970 }
4971
4972 expect_methods_self! {
4973 expect_param, &'hir Param<'hir>, Node::Param(n), n;
4974 expect_item, &'hir Item<'hir>, Node::Item(n), n;
4975 expect_foreign_item, &'hir ForeignItem<'hir>, Node::ForeignItem(n), n;
4976 expect_trait_item, &'hir TraitItem<'hir>, Node::TraitItem(n), n;
4977 expect_impl_item, &'hir ImplItem<'hir>, Node::ImplItem(n), n;
4978 expect_variant, &'hir Variant<'hir>, Node::Variant(n), n;
4979 expect_field, &'hir FieldDef<'hir>, Node::Field(n), n;
4980 expect_anon_const, &'hir AnonConst, Node::AnonConst(n), n;
4981 expect_inline_const, &'hir ConstBlock, Node::ConstBlock(n), n;
4982 expect_expr, &'hir Expr<'hir>, Node::Expr(n), n;
4983 expect_expr_field, &'hir ExprField<'hir>, Node::ExprField(n), n;
4984 expect_stmt, &'hir Stmt<'hir>, Node::Stmt(n), n;
4985 expect_path_segment, &'hir PathSegment<'hir>, Node::PathSegment(n), n;
4986 expect_ty, &'hir Ty<'hir>, Node::Ty(n), n;
4987 expect_assoc_item_constraint, &'hir AssocItemConstraint<'hir>, Node::AssocItemConstraint(n), n;
4988 expect_trait_ref, &'hir TraitRef<'hir>, Node::TraitRef(n), n;
4989 expect_opaque_ty, &'hir OpaqueTy<'hir>, Node::OpaqueTy(n), n;
4990 expect_pat, &'hir Pat<'hir>, Node::Pat(n), n;
4991 expect_pat_field, &'hir PatField<'hir>, Node::PatField(n), n;
4992 expect_arm, &'hir Arm<'hir>, Node::Arm(n), n;
4993 expect_block, &'hir Block<'hir>, Node::Block(n), n;
4994 expect_let_stmt, &'hir LetStmt<'hir>, Node::LetStmt(n), n;
4995 expect_ctor, &'hir VariantData<'hir>, Node::Ctor(n), n;
4996 expect_lifetime, &'hir Lifetime, Node::Lifetime(n), n;
4997 expect_generic_param, &'hir GenericParam<'hir>, Node::GenericParam(n), n;
4998 expect_crate, &'hir Mod<'hir>, Node::Crate(n), n;
4999 expect_infer, &'hir InferArg, Node::Infer(n), n;
5000 expect_closure, &'hir Closure<'hir>, Node::Expr(Expr { kind: ExprKind::Closure(n), .. }), n;
5001 }
5002}
5003
5004#[cfg(target_pointer_width = "64")]
5006mod size_asserts {
5007 use rustc_data_structures::static_assert_size;
5008
5009 use super::*;
5010 static_assert_size!(Block<'_>, 48);
5012 static_assert_size!(Body<'_>, 24);
5013 static_assert_size!(Expr<'_>, 64);
5014 static_assert_size!(ExprKind<'_>, 48);
5015 static_assert_size!(FnDecl<'_>, 40);
5016 static_assert_size!(ForeignItem<'_>, 96);
5017 static_assert_size!(ForeignItemKind<'_>, 56);
5018 static_assert_size!(GenericArg<'_>, 16);
5019 static_assert_size!(GenericBound<'_>, 64);
5020 static_assert_size!(Generics<'_>, 56);
5021 static_assert_size!(Impl<'_>, 48);
5022 static_assert_size!(ImplItem<'_>, 88);
5023 static_assert_size!(ImplItemKind<'_>, 40);
5024 static_assert_size!(Item<'_>, 88);
5025 static_assert_size!(ItemKind<'_>, 64);
5026 static_assert_size!(LetStmt<'_>, 64);
5027 static_assert_size!(Param<'_>, 32);
5028 static_assert_size!(Pat<'_>, 80);
5029 static_assert_size!(PatKind<'_>, 56);
5030 static_assert_size!(Path<'_>, 40);
5031 static_assert_size!(PathSegment<'_>, 48);
5032 static_assert_size!(QPath<'_>, 24);
5033 static_assert_size!(Res, 12);
5034 static_assert_size!(Stmt<'_>, 32);
5035 static_assert_size!(StmtKind<'_>, 16);
5036 static_assert_size!(TraitImplHeader<'_>, 48);
5037 static_assert_size!(TraitItem<'_>, 88);
5038 static_assert_size!(TraitItemKind<'_>, 48);
5039 static_assert_size!(Ty<'_>, 48);
5040 static_assert_size!(TyKind<'_>, 32);
5041 }
5043
5044#[cfg(test)]
5045mod tests;