@@ -1342,23 +1342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1342
1342
} else if field. name == kw:: Invalid {
1343
1343
self . tcx ( ) . types . err
1344
1344
} 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) ;
1362
1346
self . tcx ( ) . types . err
1363
1347
} else {
1364
1348
if !expr_t. is_primitive_ty ( ) {
@@ -1436,9 +1420,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1436
1420
expr : & ' tcx hir:: Expr ,
1437
1421
expr_t : Ty < ' tcx > ,
1438
1422
field : ast:: Ident ,
1439
- def_id : DefId ,
1423
+ base_did : DefId ,
1440
1424
) {
1441
- let struct_path = self . tcx ( ) . def_path_str ( def_id ) ;
1425
+ let struct_path = self . tcx ( ) . def_path_str ( base_did ) ;
1442
1426
let mut err = struct_span_err ! (
1443
1427
self . tcx( ) . sess,
1444
1428
expr. span,
@@ -1462,6 +1446,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1462
1446
err. emit ( ) ;
1463
1447
}
1464
1448
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
+
1465
1475
fn no_such_field_err < T : Display > ( & self , span : Span , field : T , expr_t : & ty:: TyS < ' _ > )
1466
1476
-> DiagnosticBuilder < ' _ > {
1467
1477
type_error_struct ! ( self . tcx( ) . sess, span, expr_t, E0609 ,
0 commit comments