Skip to content

Commit 60ec3b7

Browse files
authored
Unrolled build for rust-lang#140736
Rollup merge of rust-lang#140736 - xizheyin:issue-140166, r=petrochenkov trait selection: check `&` before suggest remove deref FIxes rust-lang#140166 r? compiler
2 parents e964cca + bd88f3e commit 60ec3b7

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
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 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait Trait {}
2+
3+
struct Chars;
4+
impl Trait for Chars {}
5+
6+
struct FlatMap<T>(T);
7+
impl<T: Trait> std::fmt::Debug for FlatMap<T> {
8+
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9+
unimplemented!()
10+
}
11+
}
12+
13+
fn lol() {
14+
format_args!("{:?}", FlatMap(&Chars));
15+
//~^ ERROR the trait bound `&Chars: Trait` is not satisfied [E0277]
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0277]: the trait bound `&Chars: Trait` is not satisfied
2+
--> $DIR/suggest-remove-deref-issue-140166.rs:14:26
3+
|
4+
LL | format_args!("{:?}", FlatMap(&Chars));
5+
| ---- ^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `&Chars`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Trait` is implemented for `Chars`
10+
note: required for `FlatMap<&Chars>` to implement `Debug`
11+
--> $DIR/suggest-remove-deref-issue-140166.rs:7:16
12+
|
13+
LL | impl<T: Trait> std::fmt::Debug for FlatMap<T> {
14+
| ----- ^^^^^^^^^^^^^^^ ^^^^^^^^^^
15+
| |
16+
| unsatisfied trait bound introduced here
17+
note: required by a bound in `core::fmt::rt::Argument::<'_>::new_debug`
18+
--> $SRC_DIR/core/src/fmt/rt.rs:LL:COL
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)