@@ -23,7 +23,7 @@ use rustc_middle::ty::subst::SubstsRef;
2323use rustc_middle:: ty:: { self , AdtDef , Ty , UpvarSubsts } ;
2424use rustc_middle:: ty:: { CanonicalUserType , CanonicalUserTypeAnnotation } ;
2525use rustc_span:: def_id:: LocalDefId ;
26- use rustc_span:: { Span , Symbol , DUMMY_SP } ;
26+ use rustc_span:: { sym , Span , Symbol , DUMMY_SP } ;
2727use rustc_target:: abi:: VariantIdx ;
2828use rustc_target:: asm:: InlineAsmRegOrRegClass ;
2929use std:: fmt;
@@ -695,17 +695,32 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
695695 Ok ( ( ) )
696696 }
697697 PatKind :: Variant { ref subpatterns, .. } | PatKind :: Leaf { ref subpatterns } => {
698- let variant = match self . kind {
699- PatKind :: Variant { adt_def, variant_index, .. } => {
700- Some ( adt_def. variant ( variant_index) )
701- }
702- _ => self . ty . ty_adt_def ( ) . and_then ( |adt| {
703- if !adt. is_enum ( ) { Some ( adt. non_enum_variant ( ) ) } else { None }
698+ let variant_and_name = match self . kind {
699+ PatKind :: Variant { adt_def, variant_index, .. } => ty:: tls:: with ( |tcx| {
700+ let variant = adt_def. variant ( variant_index) ;
701+ let adt_did = adt_def. did ( ) ;
702+ let name = if tcx. get_diagnostic_item ( sym:: Option ) == Some ( adt_did)
703+ || tcx. get_diagnostic_item ( sym:: Result ) == Some ( adt_did)
704+ {
705+ variant. name . to_string ( )
706+ } else {
707+ format ! ( "{}::{}" , tcx. def_path_str( adt_def. did( ) ) , variant. name)
708+ } ;
709+ Some ( ( variant, name) )
710+ } ) ,
711+ _ => self . ty . ty_adt_def ( ) . and_then ( |adt_def| {
712+ if !adt_def. is_enum ( ) {
713+ ty:: tls:: with ( |tcx| {
714+ Some ( ( adt_def. non_enum_variant ( ) , tcx. def_path_str ( adt_def. did ( ) ) ) )
715+ } )
716+ } else {
717+ None
718+ }
704719 } ) ,
705720 } ;
706721
707- if let Some ( variant) = variant {
708- write ! ( f, "{}" , variant . name) ?;
722+ if let Some ( ( variant, name ) ) = & variant_and_name {
723+ write ! ( f, "{}" , name) ?;
709724
710725 // Only for Adt we can have `S {...}`,
711726 // which we handle separately here.
@@ -730,8 +745,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
730745 }
731746 }
732747
733- let num_fields = variant. map_or ( subpatterns. len ( ) , |v| v. fields . len ( ) ) ;
734- if num_fields != 0 || variant. is_none ( ) {
748+ let num_fields =
749+ variant_and_name. as_ref ( ) . map_or ( subpatterns. len ( ) , |( v, _) | v. fields . len ( ) ) ;
750+ if num_fields != 0 || variant_and_name. is_none ( ) {
735751 write ! ( f, "(" ) ?;
736752 for i in 0 ..num_fields {
737753 write ! ( f, "{}" , start_or_comma( ) ) ?;
0 commit comments