@@ -28,7 +28,7 @@ use rustc_middle::ty::{
2828 TyCtxt , UpvarArgs ,
2929} ;
3030use rustc_span:: def_id:: LocalDefId ;
31- use rustc_span:: { sym , ErrorGuaranteed , Span , Symbol , DUMMY_SP } ;
31+ use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
3232use rustc_target:: abi:: { FieldIdx , Integer , Size , VariantIdx } ;
3333use rustc_target:: asm:: InlineAsmRegOrRegClass ;
3434use tracing:: instrument;
@@ -597,10 +597,6 @@ pub struct Pat<'tcx> {
597597}
598598
599599impl < ' tcx > Pat < ' tcx > {
600- pub fn wildcard_from_ty ( ty : Ty < ' tcx > ) -> Self {
601- Pat { ty, span : DUMMY_SP , kind : PatKind :: Wild }
602- }
603-
604600 pub fn simple_ident ( & self ) -> Option < Symbol > {
605601 match self . kind {
606602 PatKind :: Binding {
@@ -1073,159 +1069,6 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10731069 }
10741070}
10751071
1076- impl < ' tcx > fmt:: Display for Pat < ' tcx > {
1077- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1078- // Printing lists is a chore.
1079- let mut first = true ;
1080- let mut start_or_continue = |s| {
1081- if first {
1082- first = false ;
1083- ""
1084- } else {
1085- s
1086- }
1087- } ;
1088- let mut start_or_comma = || start_or_continue ( ", " ) ;
1089-
1090- match self . kind {
1091- PatKind :: Wild => write ! ( f, "_" ) ,
1092- PatKind :: Never => write ! ( f, "!" ) ,
1093- PatKind :: AscribeUserType { ref subpattern, .. } => write ! ( f, "{subpattern}: _" ) ,
1094- PatKind :: Binding { name, mode, ref subpattern, .. } => {
1095- f. write_str ( mode. prefix_str ( ) ) ?;
1096- write ! ( f, "{name}" ) ?;
1097- if let Some ( ref subpattern) = * subpattern {
1098- write ! ( f, " @ {subpattern}" ) ?;
1099- }
1100- Ok ( ( ) )
1101- }
1102- PatKind :: Variant { ref subpatterns, .. } | PatKind :: Leaf { ref subpatterns } => {
1103- let variant_and_name = match self . kind {
1104- PatKind :: Variant { adt_def, variant_index, .. } => ty:: tls:: with ( |tcx| {
1105- let variant = adt_def. variant ( variant_index) ;
1106- let adt_did = adt_def. did ( ) ;
1107- let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
1108- || tcx. get_diagnostic_item ( sym:: Result ) == Some ( adt_did)
1109- {
1110- variant. name . to_string ( )
1111- } else {
1112- format ! ( "{}::{}" , tcx. def_path_str( adt_def. did( ) ) , variant. name)
1113- } ;
1114- Some ( ( variant, name) )
1115- } ) ,
1116- _ => self . ty . ty_adt_def ( ) . and_then ( |adt_def| {
1117- if !adt_def. is_enum ( ) {
1118- ty:: tls:: with ( |tcx| {
1119- Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) )
1120- } )
1121- } else {
1122- None
1123- }
1124- } ) ,
1125- } ;
1126-
1127- if let Some ( ( variant, name) ) = & variant_and_name {
1128- write ! ( f, "{name}" ) ?;
1129-
1130- // Only for Adt we can have `S {...}`,
1131- // which we handle separately here.
1132- if variant. ctor . is_none ( ) {
1133- write ! ( f, " {{ " ) ?;
1134-
1135- let mut printed = 0 ;
1136- for p in subpatterns {
1137- if let PatKind :: Wild = p. pattern . kind {
1138- continue ;
1139- }
1140- let name = variant. fields [ p. field ] . name ;
1141- write ! ( f, "{}{}: {}" , start_or_comma( ) , name, p. pattern) ?;
1142- printed += 1 ;
1143- }
1144-
1145- let is_union = self . ty . ty_adt_def ( ) . is_some_and ( |adt| adt. is_union ( ) ) ;
1146- if printed < variant. fields . len ( ) && ( !is_union || printed == 0 ) {
1147- write ! ( f, "{}.." , start_or_comma( ) ) ?;
1148- }
1149-
1150- return write ! ( f, " }}" ) ;
1151- }
1152- }
1153-
1154- let num_fields =
1155- variant_and_name. as_ref ( ) . map_or ( subpatterns. len ( ) , |( v, _) | v. fields . len ( ) ) ;
1156- if num_fields != 0 || variant_and_name. is_none ( ) {
1157- write ! ( f, "(" ) ?;
1158- for i in 0 ..num_fields {
1159- write ! ( f, "{}" , start_or_comma( ) ) ?;
1160-
1161- // Common case: the field is where we expect it.
1162- if let Some ( p) = subpatterns. get ( i) {
1163- if p. field . index ( ) == i {
1164- write ! ( f, "{}" , p. pattern) ?;
1165- continue ;
1166- }
1167- }
1168-
1169- // Otherwise, we have to go looking for it.
1170- if let Some ( p) = subpatterns. iter ( ) . find ( |p| p. field . index ( ) == i) {
1171- write ! ( f, "{}" , p. pattern) ?;
1172- } else {
1173- write ! ( f, "_" ) ?;
1174- }
1175- }
1176- write ! ( f, ")" ) ?;
1177- }
1178-
1179- Ok ( ( ) )
1180- }
1181- PatKind :: Deref { ref subpattern } => {
1182- match self . ty . kind ( ) {
1183- ty:: Adt ( def, _) if def. is_box ( ) => write ! ( f, "box " ) ?,
1184- ty:: Ref ( _, _, mutbl) => {
1185- write ! ( f, "&{}" , mutbl. prefix_str( ) ) ?;
1186- }
1187- _ => bug ! ( "{} is a bad Deref pattern type" , self . ty) ,
1188- }
1189- write ! ( f, "{subpattern}" )
1190- }
1191- PatKind :: DerefPattern { ref subpattern, .. } => {
1192- write ! ( f, "deref!({subpattern})" )
1193- }
1194- PatKind :: Constant { value } => write ! ( f, "{value}" ) ,
1195- PatKind :: InlineConstant { def : _, ref subpattern } => {
1196- write ! ( f, "{} (from inline const)" , subpattern)
1197- }
1198- PatKind :: Range ( ref range) => write ! ( f, "{range}" ) ,
1199- PatKind :: Slice { ref prefix, ref slice, ref suffix }
1200- | PatKind :: Array { ref prefix, ref slice, ref suffix } => {
1201- write ! ( f, "[" ) ?;
1202- for p in prefix. iter ( ) {
1203- write ! ( f, "{}{}" , start_or_comma( ) , p) ?;
1204- }
1205- if let Some ( ref slice) = * slice {
1206- write ! ( f, "{}" , start_or_comma( ) ) ?;
1207- match slice. kind {
1208- PatKind :: Wild => { }
1209- _ => write ! ( f, "{slice}" ) ?,
1210- }
1211- write ! ( f, ".." ) ?;
1212- }
1213- for p in suffix. iter ( ) {
1214- write ! ( f, "{}{}" , start_or_comma( ) , p) ?;
1215- }
1216- write ! ( f, "]" )
1217- }
1218- PatKind :: Or { ref pats } => {
1219- for pat in pats. iter ( ) {
1220- write ! ( f, "{}{}" , start_or_continue( " | " ) , pat) ?;
1221- }
1222- Ok ( ( ) )
1223- }
1224- PatKind :: Error ( _) => write ! ( f, "<error>" ) ,
1225- }
1226- }
1227- }
1228-
12291072// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
12301073#[ cfg( target_pointer_width = "64" ) ]
12311074mod size_asserts {
0 commit comments