Skip to content

Commit b4d06bf

Browse files
authored
Rollup merge of rust-lang#88657 - camelid:fix-dyn-sugg, r=m-ou-se
Fix 2021 `dyn` suggestion that used code as label The arguments to `span_suggestion` were in the wrong order, so the error looked like this: error[E0783]: trait objects without an explicit `dyn` are deprecated --> src/test/ui/editions/dyn-trait-sugg-2021.rs:10:5 | 10 | Foo::hi(123); | ^^^ help: <dyn Foo>: `use `dyn`` Now the error looks like this, as expected: error[E0783]: trait objects without an explicit `dyn` are deprecated --> src/test/ui/editions/dyn-trait-sugg-2021.rs:10:5 | 10 | Foo::hi(123); | ^^^ help: use `dyn`: `<dyn Foo>` This issue was only present in the 2021 error; the 2018 lint was correct. r? `@m-ou-se`
2 parents 5fdc8eb + 486d79f commit b4d06bf

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
945945
Ok(s) if s.starts_with('<') => sugg,
946946
_ => format!("<{}>", sugg),
947947
};
948-
let replace = String::from("use `dyn`");
948+
let sugg_label = "use `dyn`";
949949
if self.sess().edition() >= Edition::Edition2021 {
950950
let mut err = rustc_errors::struct_span_err!(
951951
self.sess(),
@@ -956,8 +956,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
956956
);
957957
err.span_suggestion(
958958
self_ty.span,
959-
&sugg,
960-
replace,
959+
sugg_label,
960+
sugg,
961961
Applicability::MachineApplicable,
962962
)
963963
.emit();
@@ -968,7 +968,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
968968
self_ty.span,
969969
|lint| {
970970
let mut db = lint.build(msg);
971-
db.span_suggestion(self_ty.span, &replace, sugg, app);
971+
db.span_suggestion(self_ty.span, sugg_label, sugg, app);
972972
db.emit()
973973
},
974974
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition:2021
2+
3+
trait Foo<T> {}
4+
5+
impl<T> dyn Foo<T> {
6+
fn hi(_x: T) {}
7+
}
8+
9+
fn main() {
10+
Foo::hi(123);
11+
//~^ ERROR trait objects without an explicit `dyn` are deprecated
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0783]: trait objects without an explicit `dyn` are deprecated
2+
--> $DIR/dyn-trait-sugg-2021.rs:10:5
3+
|
4+
LL | Foo::hi(123);
5+
| ^^^ help: use `dyn`: `<dyn Foo>`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0783`.

0 commit comments

Comments
 (0)