@@ -31,19 +31,31 @@ pub(super) fn hints(
31
31
return None ;
32
32
}
33
33
34
- // These inherit from the inner expression which would result in duplicate hints
35
- if let ast:: Expr :: ParenExpr ( _)
36
- | ast:: Expr :: IfExpr ( _)
37
- | ast:: Expr :: BlockExpr ( _)
38
- | ast:: Expr :: MatchExpr ( _) = expr
39
- {
34
+ // ParenExpr resolve to their contained expressions HIR so they will dupe these hints
35
+ if let ast:: Expr :: ParenExpr ( _) = expr {
40
36
return None ;
41
37
}
38
+ if let ast:: Expr :: BlockExpr ( b) = expr {
39
+ if !b. is_standalone ( ) {
40
+ return None ;
41
+ }
42
+ }
42
43
43
44
let descended = sema. descend_node_into_attributes ( expr. clone ( ) ) . pop ( ) ;
44
45
let desc_expr = descended. as_ref ( ) . unwrap_or ( expr) ;
45
46
let adjustments = sema. expr_adjustments ( desc_expr) . filter ( |it| !it. is_empty ( ) ) ?;
46
47
48
+ if let ast:: Expr :: BlockExpr ( _) | ast:: Expr :: IfExpr ( _) | ast:: Expr :: MatchExpr ( _) = desc_expr {
49
+ if let [ Adjustment { kind : Adjust :: Deref ( _) , source, .. } , Adjustment { kind : Adjust :: Borrow ( _) , source : _, target } ] =
50
+ & * adjustments
51
+ {
52
+ // Don't show unnecessary reborrows for these, they will just repeat the inner ones again
53
+ if source == target {
54
+ return None ;
55
+ }
56
+ }
57
+ }
58
+
47
59
let ( postfix, needs_outer_parens, needs_inner_parens) =
48
60
mode_and_needs_parens_for_adjustment_hints ( expr, config. adjustment_hints_mode ) ;
49
61
@@ -67,6 +79,7 @@ pub(super) fn hints(
67
79
68
80
for Adjustment { source, target, kind } in iter {
69
81
if source == target {
82
+ cov_mark:: hit!( same_type_adjustment) ;
70
83
continue ;
71
84
}
72
85
@@ -251,7 +264,7 @@ mod tests {
251
264
check_with_config (
252
265
InlayHintsConfig { adjustment_hints : AdjustmentHints :: Always , ..DISABLED_CONFIG } ,
253
266
r#"
254
- //- minicore: coerce_unsized, fn
267
+ //- minicore: coerce_unsized, fn, eq
255
268
fn main() {
256
269
let _: u32 = loop {};
257
270
//^^^^^^^<never-to-any>
@@ -332,7 +345,7 @@ fn main() {
332
345
loop {}
333
346
//^^^^^^^<never-to-any>
334
347
};
335
- let _: &mut [u32] = match () { () => &mut [] }
348
+ let _: &mut [u32] = match () { () => &mut [] };
336
349
//^^^^^^^<unsize>
337
350
//^^^^^^^&mut $
338
351
//^^^^^^^*
@@ -341,6 +354,12 @@ fn main() {
341
354
//^^^^^^^^^^<unsize>
342
355
//^^^^^^^^^^&mut $
343
356
//^^^^^^^^^^*
357
+ () == ();
358
+ // ^^&
359
+ // ^^&
360
+ (()) == {()};
361
+ // ^^&
362
+ // ^^^^&
344
363
}
345
364
346
365
#[derive(Copy, Clone)]
@@ -363,7 +382,7 @@ impl Struct {
363
382
..DISABLED_CONFIG
364
383
} ,
365
384
r#"
366
- //- minicore: coerce_unsized, fn
385
+ //- minicore: coerce_unsized, fn, eq
367
386
fn main() {
368
387
369
388
Struct.consume();
@@ -419,7 +438,7 @@ fn main() {
419
438
loop {}
420
439
//^^^^^^^.<never-to-any>
421
440
};
422
- let _: &mut [u32] = match () { () => &mut [] }
441
+ let _: &mut [u32] = match () { () => &mut [] };
423
442
//^^^^^^^(
424
443
//^^^^^^^)
425
444
//^^^^^^^.*
@@ -432,6 +451,12 @@ fn main() {
432
451
//^^^^^^^^^^.*
433
452
//^^^^^^^^^^.&mut
434
453
//^^^^^^^^^^.<unsize>
454
+ () == ();
455
+ // ^^.&
456
+ // ^^.&
457
+ (()) == {()};
458
+ // ^^.&
459
+ // ^^^^.&
435
460
}
436
461
437
462
#[derive(Copy, Clone)]
@@ -499,6 +524,7 @@ fn main() {
499
524
500
525
#[ test]
501
526
fn never_to_never_is_never_shown ( ) {
527
+ cov_mark:: check!( same_type_adjustment) ;
502
528
check_with_config (
503
529
InlayHintsConfig { adjustment_hints : AdjustmentHints :: Always , ..DISABLED_CONFIG } ,
504
530
r#"
0 commit comments