Skip to content

Commit bd88f3e

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

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15161516
} else {
15171517
expr.span.with_hi(expr.span.lo() + BytePos(1))
15181518
};
1519+
1520+
match self.tcx.sess.source_map().span_to_snippet(span) {
1521+
Ok(snippet) if snippet.starts_with("&") => {}
1522+
_ => break 'outer,
1523+
}
1524+
15191525
suggestions.push((span, String::new()));
15201526

15211527
let ty::Ref(_, inner_ty, _) = suggested_ty.kind() else {

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

+1-5
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)