Skip to content

Commit d8f5b14

Browse files
committed
Remove conditional delay_as_bug from "missing dyn error"
1 parent 84be44b commit d8f5b14

14 files changed

+107
-124
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
6868
let label = "add `dyn` keyword before this trait";
6969
let mut diag =
7070
rustc_errors::struct_span_code_err!(tcx.dcx(), self_ty.span, E0782, "{}", msg);
71-
let mut downgrade = false;
7271
if self_ty.span.can_be_used_for_suggestions() {
73-
let should_downgrade = self.maybe_suggest_impl_trait(self_ty, &mut diag);
74-
downgrade = should_downgrade;
72+
self.maybe_suggest_impl_trait(self_ty, &mut diag);
7573
if object_safe {
7674
// Only emit this suggestion if the trait is object safe.
7775
diag.multipart_suggestion_verbose(
@@ -91,14 +89,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
9189
// Check if the impl trait that we are considering is an impl of a local trait.
9290
self.maybe_suggest_blanket_trait_impl(self_ty, &mut diag);
9391
self.maybe_suggest_assoc_ty_bound(self_ty, &mut diag);
94-
if downgrade {
95-
// FIXME: Delayed bugs and stashing are not compatible, so we paper over it here by
96-
// consuming the diagnostic without emitting it, instead of downgrading it.
97-
diag.delay_as_bug();
98-
None
99-
} else {
100-
diag.stash(self_ty.span, StashKey::TraitMissingMethod)
101-
}
92+
diag.stash(self_ty.span, StashKey::TraitMissingMethod)
10293
} else {
10394
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, |lint| {
10495
lint.primary_message("trait objects without an explicit `dyn` are deprecated");
Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
1-
error[E0038]: the trait `Copy` cannot be made into an object
1+
error[E0782]: trait objects must include the `dyn` keyword
22
--> $DIR/avoid-ice-on-warning-2.rs:4:13
33
|
44
LL | fn id<F>(f: Copy) -> usize {
5-
| ^^^^ `Copy` cannot be made into an object
5+
| ^^^^
66
|
7-
= note: the trait cannot be made into an object because it requires `Self: Sized`
8-
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
9-
10-
error[E0618]: expected function, found `(dyn Copy + 'static)`
11-
--> $DIR/avoid-ice-on-warning-2.rs:11:5
12-
|
13-
LL | fn id<F>(f: Copy) -> usize {
14-
| - `f` has type `(dyn Copy + 'static)`
15-
...
16-
LL | f()
17-
| ^--
18-
| |
19-
| call expression requires function
20-
21-
error[E0277]: the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
22-
--> $DIR/avoid-ice-on-warning-2.rs:4:10
7+
= note: `Copy` it is not object safe, so it can't be `dyn`
8+
help: use a new generic type parameter, constrained by `Copy`
239
|
24-
LL | fn id<F>(f: Copy) -> usize {
25-
| ^ doesn't have a size known at compile-time
26-
|
27-
= help: the trait `Sized` is not implemented for `(dyn Copy + 'static)`
28-
= help: unsized fn params are gated as an unstable feature
29-
help: you can use `impl Trait` as the argument type
10+
LL | fn id<F, T: Copy>(f: T) -> usize {
11+
| +++++++++ ~
12+
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
3013
|
3114
LL | fn id<F>(f: impl Copy) -> usize {
3215
| ++++
33-
help: function arguments must have a statically known size, borrowed types always have a known size
34-
|
35-
LL | fn id<F>(f: &dyn Copy) -> usize {
36-
| ++++
3716

38-
error: aborting due to 3 previous errors
17+
error: aborting due to 1 previous error
3918

40-
Some errors have detailed explanations: E0038, E0277, E0618.
41-
For more information about an error, try `rustc --explain E0038`.
19+
For more information about this error, try `rustc --explain E0782`.

tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | fn id<F>(f: Copy) -> usize {
3030
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
3131

3232
error[E0618]: expected function, found `(dyn Copy + 'static)`
33-
--> $DIR/avoid-ice-on-warning-2.rs:11:5
33+
--> $DIR/avoid-ice-on-warning-2.rs:12:5
3434
|
3535
LL | fn id<F>(f: Copy) -> usize {
3636
| - `f` has type `(dyn Copy + 'static)`

tests/ui/object-safety/avoid-ice-on-warning-2.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
//@[old] edition:2015
33
//@[new] edition:2021
44
fn id<F>(f: Copy) -> usize {
5-
//~^ ERROR the trait `Copy` cannot be made into an object
6-
//~| ERROR: the size for values of type `(dyn Copy + 'static)`
5+
//[new]~^ ERROR trait objects must include the `dyn` keyword
6+
//[old]~^^ ERROR the trait `Copy` cannot be made into an object
7+
//[old]~| ERROR the size for values of type `(dyn Copy + 'static)` cannot be known at compilation time
78
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
89
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
910
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
1011
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
1112
f()
12-
//~^ ERROR: expected function, found `(dyn Copy + 'static)`
13+
//[old]~^ ERROR: expected function, found `(dyn Copy + 'static)`
1314
}
1415
fn main() {}
Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
1-
error[E0038]: the trait `A` cannot be made into an object
2-
--> $DIR/avoid-ice-on-warning-3.rs:4:19
1+
error[E0782]: trait objects must include the `dyn` keyword
2+
--> $DIR/avoid-ice-on-warning-3.rs:14:19
33
|
4-
LL | trait B { fn f(a: A) -> A; }
5-
| ^ `A` cannot be made into an object
4+
LL | trait A { fn g(b: B) -> B; }
5+
| ^
66
|
7-
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8-
--> $DIR/avoid-ice-on-warning-3.rs:12:14
7+
= note: `B` it is not object safe, so it can't be `dyn`
8+
help: use a new generic type parameter, constrained by `B`
9+
|
10+
LL | trait A { fn g<T: B>(b: T) -> B; }
11+
| ++++++ ~
12+
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
13+
|
14+
LL | trait A { fn g(b: impl B) -> B; }
15+
| ++++
16+
17+
error[E0782]: trait objects must include the `dyn` keyword
18+
--> $DIR/avoid-ice-on-warning-3.rs:14:25
919
|
1020
LL | trait A { fn g(b: B) -> B; }
11-
| - ^ ...because associated function `g` has no `self` parameter
12-
| |
13-
| this trait cannot be made into an object...
14-
help: consider turning `g` into a method by giving it a `&self` argument
21+
| ^
1522
|
16-
LL | trait A { fn g(&self, b: B) -> B; }
17-
| ++++++
18-
help: alternatively, consider constraining `g` so it does not apply to trait objects
23+
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
1924
|
20-
LL | trait A { fn g(b: B) -> B where Self: Sized; }
21-
| +++++++++++++++++
25+
LL | trait A { fn g(b: B) -> impl B; }
26+
| ++++
2227

23-
error[E0038]: the trait `B` cannot be made into an object
24-
--> $DIR/avoid-ice-on-warning-3.rs:12:19
28+
error[E0782]: trait objects must include the `dyn` keyword
29+
--> $DIR/avoid-ice-on-warning-3.rs:4:19
2530
|
26-
LL | trait A { fn g(b: B) -> B; }
27-
| ^ `B` cannot be made into an object
31+
LL | trait B { fn f(a: A) -> A; }
32+
| ^
2833
|
29-
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
30-
--> $DIR/avoid-ice-on-warning-3.rs:4:14
34+
= note: `A` it is not object safe, so it can't be `dyn`
35+
help: use a new generic type parameter, constrained by `A`
36+
|
37+
LL | trait B { fn f<T: A>(a: T) -> A; }
38+
| ++++++ ~
39+
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
40+
|
41+
LL | trait B { fn f(a: impl A) -> A; }
42+
| ++++
43+
44+
error[E0782]: trait objects must include the `dyn` keyword
45+
--> $DIR/avoid-ice-on-warning-3.rs:4:25
3146
|
3247
LL | trait B { fn f(a: A) -> A; }
33-
| - ^ ...because associated function `f` has no `self` parameter
34-
| |
35-
| this trait cannot be made into an object...
36-
help: consider turning `f` into a method by giving it a `&self` argument
48+
| ^
3749
|
38-
LL | trait B { fn f(&self, a: A) -> A; }
39-
| ++++++
40-
help: alternatively, consider constraining `f` so it does not apply to trait objects
50+
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
4151
|
42-
LL | trait B { fn f(a: A) -> A where Self: Sized; }
43-
| +++++++++++++++++
52+
LL | trait B { fn f(a: A) -> impl A; }
53+
| ++++
4454

45-
error: aborting due to 2 previous errors
55+
error: aborting due to 4 previous errors
4656

47-
For more information about this error, try `rustc --explain E0038`.
57+
For more information about this error, try `rustc --explain E0782`.

tests/ui/object-safety/avoid-ice-on-warning-3.old.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trait objects without an explicit `dyn` are deprecated
2-
--> $DIR/avoid-ice-on-warning-3.rs:12:19
2+
--> $DIR/avoid-ice-on-warning-3.rs:14:19
33
|
44
LL | trait A { fn g(b: B) -> B; }
55
| ^
@@ -10,7 +10,7 @@ LL | trait A { fn g(b: B) -> B; }
1010
= note: `#[warn(bare_trait_objects)]` on by default
1111

1212
warning: trait objects without an explicit `dyn` are deprecated
13-
--> $DIR/avoid-ice-on-warning-3.rs:12:25
13+
--> $DIR/avoid-ice-on-warning-3.rs:14:25
1414
|
1515
LL | trait A { fn g(b: B) -> B; }
1616
| ^
@@ -57,7 +57,7 @@ LL | trait B { fn f(a: A) -> A; }
5757
| ^ `A` cannot be made into an object
5858
|
5959
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
60-
--> $DIR/avoid-ice-on-warning-3.rs:12:14
60+
--> $DIR/avoid-ice-on-warning-3.rs:14:14
6161
|
6262
LL | trait A { fn g(b: B) -> B; }
6363
| - ^ ...because associated function `g` has no `self` parameter
@@ -73,7 +73,7 @@ LL | trait A { fn g(b: B) -> B where Self: Sized; }
7373
| +++++++++++++++++
7474

7575
warning: trait objects without an explicit `dyn` are deprecated
76-
--> $DIR/avoid-ice-on-warning-3.rs:12:19
76+
--> $DIR/avoid-ice-on-warning-3.rs:14:19
7777
|
7878
LL | trait A { fn g(b: B) -> B; }
7979
| ^
@@ -84,7 +84,7 @@ LL | trait A { fn g(b: B) -> B; }
8484
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8585

8686
error[E0038]: the trait `B` cannot be made into an object
87-
--> $DIR/avoid-ice-on-warning-3.rs:12:19
87+
--> $DIR/avoid-ice-on-warning-3.rs:14:19
8888
|
8989
LL | trait A { fn g(b: B) -> B; }
9090
| ^ `B` cannot be made into an object

tests/ui/object-safety/avoid-ice-on-warning-3.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
//@[old] edition:2015
33
//@[new] edition:2021
44
trait B { fn f(a: A) -> A; }
5-
//~^ ERROR the trait `A` cannot be made into an object
5+
//[new]~^ ERROR trait objects must include the `dyn` keyword
6+
//[new]~| ERROR trait objects must include the `dyn` keyword
7+
//[old]~^^^ ERROR the trait `A` cannot be made into an object
68
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
79
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
810
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
911
//[old]~| WARN this is accepted in the current edition
1012
//[old]~| WARN this is accepted in the current edition
1113
//[old]~| WARN this is accepted in the current edition
1214
trait A { fn g(b: B) -> B; }
13-
//~^ ERROR the trait `B` cannot be made into an object
15+
//[new]~^ ERROR trait objects must include the `dyn` keyword
16+
//[new]~| ERROR trait objects must include the `dyn` keyword
17+
//[old]~^^^ ERROR the trait `B` cannot be made into an object
1418
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
1519
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
1620
//[old]~| WARN trait objects without an explicit `dyn` are deprecated

tests/ui/object-safety/avoid-ice-on-warning.new.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ error[E0405]: cannot find trait `call_that` in this scope
1010
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {}
1111
| ^^^^^^^^^ not found in this scope
1212

13-
error: aborting due to 2 previous errors
13+
error[E0782]: trait objects must include the `dyn` keyword
14+
--> $DIR/avoid-ice-on-warning.rs:4:25
15+
|
16+
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {}
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
|
19+
help: `Fn(&str) + call_that` is not object safe, use `impl Fn(&str) + call_that` to return an opaque type, as long as you return a single underlying type
20+
|
21+
LL | fn call_this<F>(f: F) : impl Fn(&str) + call_that {}
22+
| ++++
23+
24+
error: aborting due to 3 previous errors
1425

15-
For more information about this error, try `rustc --explain E0405`.
26+
Some errors have detailed explanations: E0405, E0782.
27+
For more information about an error, try `rustc --explain E0405`.

tests/ui/object-safety/avoid-ice-on-warning.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
fn call_this<F>(f: F) : Fn(&str) + call_that {}
55
//~^ ERROR return types are denoted using `->`
66
//~| ERROR cannot find trait `call_that` in this scope
7+
//[new]~| ERROR trait objects must include the `dyn` keyword
78
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
89
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
910
fn main() {}

tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
//@[new] run-rustfix
55
#![deny(bare_trait_objects)]
66
fn ord_prefer_dot(s: String) -> impl Ord {
7-
//~^ ERROR the trait `Ord` cannot be made into an object
7+
//[new]~^ ERROR trait objects must include the `dyn` keyword
8+
//[old]~^^ ERROR the trait `Ord` cannot be made into an object
89
//[old]~| ERROR trait objects without an explicit `dyn` are deprecated
910
//[old]~| WARNING this is accepted in the current edition (Rust 2015)
1011
(s.starts_with("."), s)

0 commit comments

Comments
 (0)