Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
} else {
expr.span.with_hi(expr.span.lo() + BytePos(1))
};

match self.tcx.sess.source_map().span_to_snippet(span) {
Ok(snippet) if snippet.starts_with("&") => {}
_ => break 'outer,
}

suggestions.push((span, String::new()));

let ty::Ref(_, inner_ty, _) = suggested_ty.kind() else {
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/traits/suggest-remove-deref-issue-140166.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Trait {}

struct Chars;
impl Trait for Chars {}

struct FlatMap<T>(T);
impl<T: Trait> std::fmt::Debug for FlatMap<T> {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
unimplemented!()
}
}

fn lol() {
format_args!("{:?}", FlatMap(&Chars));
//~^ ERROR the trait bound `&Chars: Trait` is not satisfied [E0277]
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/traits/suggest-remove-deref-issue-140166.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0277]: the trait bound `&Chars: Trait` is not satisfied
--> $DIR/suggest-remove-deref-issue-140166.rs:14:26
|
LL | format_args!("{:?}", FlatMap(&Chars));
| ---- ^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `&Chars`
| |
| required by a bound introduced by this call
|
= help: the trait `Trait` is implemented for `Chars`
note: required for `FlatMap<&Chars>` to implement `Debug`
--> $DIR/suggest-remove-deref-issue-140166.rs:7:16
|
LL | impl<T: Trait> std::fmt::Debug for FlatMap<T> {
| ----- ^^^^^^^^^^^^^^^ ^^^^^^^^^^
| |
| unsatisfied trait bound introduced here
note: required by a bound in `core::fmt::rt::Argument::<'_>::new_debug`
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading