@@ -520,26 +520,39 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
520520 // Otherwise there may be def_map borrow conflicts
521521 let def = cx. tcx . def_map . borrow ( ) [ & expr. id ] . full_def ( ) ;
522522 let ( def_id, kind) = match def {
523- // A variant constructor.
524- def:: DefVariant ( _, def_id, false ) => ( def_id, ItemKind :: Function ) ,
525523 // A regular function.
526524 def:: DefFn ( def_id, _) => ( def_id, ItemKind :: Function ) ,
527525 def:: DefMethod ( def_id) => ( def_id, ItemKind :: Method ) ,
528- def:: DefStruct ( def_id) => {
529- match cx. tcx . node_id_to_type ( expr. id ) . sty {
530- // A tuple-struct constructor.
531- ty:: TyBareFn ( ..) => ( def_id, ItemKind :: Function ) ,
532- // This is a special case: a unit struct which is used as a value. We return a
533- // completely different ExprKind here to account for this special case.
534- ty:: TyStruct ( adt_def, substs) => return ExprKind :: Adt {
526+ def:: DefStruct ( def_id) => match cx. tcx . node_id_to_type ( expr. id ) . sty {
527+ // A tuple-struct constructor.
528+ ty:: TyBareFn ( ..) => ( def_id, ItemKind :: Function ) ,
529+ // This is a special case: a unit struct which is used as a value. We return a
530+ // completely different ExprKind here to account for this special case.
531+ ty:: TyStruct ( adt_def, substs) => return ExprKind :: Adt {
532+ adt_def : adt_def,
533+ variant_index : 0 ,
534+ substs : substs,
535+ fields : vec ! [ ] ,
536+ base : None
537+ } ,
538+ ref sty => panic ! ( "unexpected sty: {:?}" , sty)
539+ } ,
540+ def:: DefVariant ( enum_id, variant_id, false ) => match cx. tcx . node_id_to_type ( expr. id ) . sty {
541+ // A variant constructor.
542+ ty:: TyBareFn ( ..) => ( variant_id, ItemKind :: Function ) ,
543+ // A unit variant, similar special case to the struct case above.
544+ ty:: TyEnum ( adt_def, substs) => {
545+ debug_assert ! ( adt_def. did == enum_id) ;
546+ let index = adt_def. variant_index_with_id ( variant_id) ;
547+ return ExprKind :: Adt {
535548 adt_def : adt_def,
536- variant_index : 0 ,
537549 substs : substs,
550+ variant_index : index,
538551 fields : vec ! [ ] ,
539552 base : None
540- } ,
541- ref sty => panic ! ( "unexpected sty: {:?}" , sty )
542- }
553+ } ;
554+ } ,
555+ ref sty => panic ! ( "unexpected sty: {:?}" , sty )
543556 } ,
544557 def:: DefConst ( def_id) |
545558 def:: DefAssociatedConst ( def_id) => {
0 commit comments