@@ -44,7 +44,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
4444use rustc_middle:: ty:: error:: ExpectedFound ;
4545use rustc_middle:: ty:: error:: TypeError :: { FieldMisMatch , Sorts } ;
4646use rustc_middle:: ty:: subst:: SubstsRef ;
47- use rustc_middle:: ty:: { self , AdtKind , Ty , TypeFoldable } ;
47+ use rustc_middle:: ty:: { self , AdtKind , DefIdTree , Ty , TypeFoldable } ;
4848use rustc_session:: parse:: feature_err;
4949use rustc_span:: hygiene:: DesugaringKind ;
5050use rustc_span:: lev_distance:: find_best_match_for_name;
@@ -2034,17 +2034,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20342034 base : & ' tcx hir:: Expr < ' tcx > ,
20352035 def_id : DefId ,
20362036 ) {
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+ } ;
20462046
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+ }
20482057 }
20492058 }
20502059
0 commit comments