@@ -44,7 +44,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
44
44
use rustc_middle:: ty:: error:: ExpectedFound ;
45
45
use rustc_middle:: ty:: error:: TypeError :: { FieldMisMatch , Sorts } ;
46
46
use rustc_middle:: ty:: subst:: SubstsRef ;
47
- use rustc_middle:: ty:: { self , AdtKind , Ty , TypeFoldable } ;
47
+ use rustc_middle:: ty:: { self , AdtKind , DefIdTree , Ty , TypeFoldable } ;
48
48
use rustc_session:: parse:: feature_err;
49
49
use rustc_span:: hygiene:: DesugaringKind ;
50
50
use rustc_span:: lev_distance:: find_best_match_for_name;
@@ -2034,17 +2034,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2034
2034
base : & ' tcx hir:: Expr < ' tcx > ,
2035
2035
def_id : DefId ,
2036
2036
) {
2037
- let local_id = def_id. expect_local ( ) ;
2038
- let hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( local_id) ;
2039
- let node = self . tcx . hir ( ) . get ( hir_id) ;
2040
-
2041
- if let Some ( fields) = node. tuple_fields ( ) {
2042
- let kind = match self . tcx . opt_def_kind ( local_id) {
2043
- Some ( DefKind :: Ctor ( of, _) ) => of,
2044
- _ => return ,
2045
- } ;
2037
+ if let Some ( local_id) = def_id. as_local ( ) {
2038
+ let hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( local_id) ;
2039
+ let node = self . tcx . hir ( ) . get ( hir_id) ;
2040
+
2041
+ if let Some ( fields) = node. tuple_fields ( ) {
2042
+ let kind = match self . tcx . opt_def_kind ( local_id) {
2043
+ Some ( DefKind :: Ctor ( of, _) ) => of,
2044
+ _ => return ,
2045
+ } ;
2046
2046
2047
- suggest_call_constructor ( base. span , kind, fields. len ( ) , err) ;
2047
+ suggest_call_constructor ( base. span , kind, fields. len ( ) , err) ;
2048
+ }
2049
+ } else {
2050
+ // The logic here isn't smart but `associated_item_def_ids`
2051
+ // doesn't work nicely on local.
2052
+ if let DefKind :: Ctor ( of, _) = self . tcx . def_kind ( def_id) {
2053
+ let parent_def_id = self . tcx . parent ( def_id) ;
2054
+ let fields = self . tcx . associated_item_def_ids ( parent_def_id) ;
2055
+ suggest_call_constructor ( base. span , of, fields. len ( ) , err) ;
2056
+ }
2048
2057
}
2049
2058
}
2050
2059
0 commit comments