@@ -1342,23 +1342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13421342 } else if field. name == kw:: Invalid {
13431343 self . tcx ( ) . types . err
13441344 } else if self . method_exists ( field, expr_t, expr. hir_id , true ) {
1345- let mut err = type_error_struct ! ( self . tcx( ) . sess, field. span, expr_t, E0615 ,
1346- "attempted to take value of method `{}` on type `{}`" ,
1347- field, expr_t) ;
1348-
1349- if !self . expr_in_place ( expr. hir_id ) {
1350- self . suggest_method_call (
1351- & mut err,
1352- "use parentheses to call the method" ,
1353- field,
1354- expr_t,
1355- expr. hir_id
1356- ) ;
1357- } else {
1358- err. help ( "methods are immutable and cannot be assigned to" ) ;
1359- }
1360-
1361- err. emit ( ) ;
1345+ self . ban_take_value_of_method ( expr, expr_t, field) ;
13621346 self . tcx ( ) . types . err
13631347 } else {
13641348 if !expr_t. is_primitive_ty ( ) {
@@ -1436,9 +1420,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14361420 expr : & ' tcx hir:: Expr ,
14371421 expr_t : Ty < ' tcx > ,
14381422 field : ast:: Ident ,
1439- def_id : DefId ,
1423+ base_did : DefId ,
14401424 ) {
1441- let struct_path = self . tcx ( ) . def_path_str ( def_id ) ;
1425+ let struct_path = self . tcx ( ) . def_path_str ( base_did ) ;
14421426 let mut err = struct_span_err ! (
14431427 self . tcx( ) . sess,
14441428 expr. span,
@@ -1462,6 +1446,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14621446 err. emit ( ) ;
14631447 }
14641448
1449+ fn ban_take_value_of_method ( & self , expr : & ' tcx hir:: Expr , expr_t : Ty < ' tcx > , field : ast:: Ident ) {
1450+ let mut err = type_error_struct ! (
1451+ self . tcx( ) . sess,
1452+ field. span,
1453+ expr_t,
1454+ E0615 ,
1455+ "attempted to take value of method `{}` on type `{}`" ,
1456+ field,
1457+ expr_t
1458+ ) ;
1459+
1460+ if !self . expr_in_place ( expr. hir_id ) {
1461+ self . suggest_method_call (
1462+ & mut err,
1463+ "use parentheses to call the method" ,
1464+ field,
1465+ expr_t,
1466+ expr. hir_id
1467+ ) ;
1468+ } else {
1469+ err. help ( "methods are immutable and cannot be assigned to" ) ;
1470+ }
1471+
1472+ err. emit ( ) ;
1473+ }
1474+
14651475 fn no_such_field_err < T : Display > ( & self , span : Span , field : T , expr_t : & ty:: TyS < ' _ > )
14661476 -> DiagnosticBuilder < ' _ > {
14671477 type_error_struct ! ( self . tcx( ) . sess, span, expr_t, E0609 ,
0 commit comments