@@ -1451,9 +1451,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1451
1451
let ty:: Adt ( callee_adt, _) = callee_ty. peel_refs ( ) . kind ( ) else {
1452
1452
return ;
1453
1453
} ;
1454
- if !self . tcx . is_diagnostic_item ( sym:: Option , callee_adt. did ( ) ) {
1454
+ let adt_name = if self . tcx . is_diagnostic_item ( sym:: Option , callee_adt. did ( ) ) {
1455
+ "Option"
1456
+ } else if self . tcx . is_diagnostic_item ( sym:: Result , callee_adt. did ( ) ) {
1457
+ "Result"
1458
+ } else {
1455
1459
return ;
1456
- }
1460
+ } ;
1457
1461
1458
1462
if call_ident. map_or ( true , |ident| ident. name != sym:: unwrap_or) {
1459
1463
return ;
@@ -1484,14 +1488,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1484
1488
Ok ( snip) => ( snip, Applicability :: MachineApplicable ) ,
1485
1489
Err ( _) => ( "/* _ */" . to_owned ( ) , Applicability :: MaybeIncorrect ) ,
1486
1490
} ;
1487
- let sugg = & format ! ( "map_or({provided_snip}, |v| v)" ) ;
1488
- err. span_suggestion_verbose (
1489
- error_span,
1490
- "use `Option::map_or` to deref inner value of `Option`" ,
1491
- sugg,
1492
- applicability,
1493
- ) ;
1494
- return ;
1491
+ let sugg = format ! ( "map_or({provided_snip}, |v| v)" ) ;
1492
+ let msg = format ! ( "use `{adt_name}::map_or` to deref inner value of `{adt_name}`" ) ;
1493
+ err. span_suggestion_verbose ( error_span, msg, sugg, applicability) ;
1495
1494
}
1496
1495
1497
1496
/// Suggest wrapping the block in square brackets instead of curly braces
0 commit comments