Skip to content

Commit 17dbbc9

Browse files
committed
Check & before suggest remove deref when trait_selection
Signed-off-by: xizheyin <[email protected]>
1 parent f46806f commit 17dbbc9

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15251525

15261526
expr = borrowed;
15271527

1528-
if maybe_suggest(suggested_ty, count, suggestions.clone()) {
1528+
if self.tcx.sess.source_map().span_to_snippet(span).unwrap().starts_with("&")
1529+
&& maybe_suggest(suggested_ty, count, suggestions.clone())
1530+
{
15291531
return true;
15301532
}
15311533
}

tests/ui/traits/suggest-remove-deref-issue-140166.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | format_args!("{:?}", FlatMap(&Chars));
66
| |
77
| required by a bound introduced by this call
88
|
9+
= help: the trait `Trait` is implemented for `Chars`
910
note: required for `FlatMap<&Chars>` to implement `Debug`
1011
--> $DIR/suggest-remove-deref-issue-140166.rs:7:16
1112
|
@@ -15,11 +16,6 @@ LL | impl<T: Trait> std::fmt::Debug for FlatMap<T> {
1516
| unsatisfied trait bound introduced here
1617
note: required by a bound in `core::fmt::rt::Argument::<'_>::new_debug`
1718
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
18-
help: consider removing the leading `&`-reference
19-
|
20-
LL - format_args!("{:?}", FlatMap(&Chars));
21-
LL + format_args!("{:?}", latMap(&Chars));
22-
|
2319

2420
error: aborting due to 1 previous error
2521

0 commit comments

Comments
 (0)