You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#120275 - estebank:issue-120241, r=fmease
Avoid ICE in trait without `dyn` lint
Do not attempt to provide an accurate suggestion for `impl Trait` in bare trait types when linting. Instead, only do the object safety check when an E0782 is already going to be emitted in the 2021 edition.
Fixrust-lang#120241.
error[E0038]: the trait `Copy` cannot be made into an object
2
+
--> $DIR/avoid-ice-on-warning-2.rs:4:13
3
+
|
4
+
LL | fn id<F>(f: Copy) -> usize {
5
+
| ^^^^ `Copy` cannot be made into an object
6
+
|
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: aborting due to 1 previous error
11
+
12
+
For more information about this error, try `rustc --explain E0038`.
Copy file name to clipboardexpand all lines: tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr
+9-19
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,33 @@
1
1
warning: trait objects without an explicit `dyn` are deprecated
2
-
--> $DIR/avoid-ice-on-warning-2.rs:1:13
2
+
--> $DIR/avoid-ice-on-warning-2.rs:4:13
3
3
|
4
4
LL | fn id<F>(f: Copy) -> usize {
5
5
| ^^^^
6
6
|
7
7
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
8
8
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
9
-
= note: `Copy` it is not object safe, so it can't be `dyn`
10
9
= note: `#[warn(bare_trait_objects)]` on by default
11
-
help: use a new generic type parameter, constrained by `Copy`
10
+
help: use `dyn`
12
11
|
13
-
LL | fn id<F, T: Copy>(f: T) -> usize {
14
-
| +++++++++ ~
15
-
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
16
-
|
17
-
LL | fn id<F>(f: impl Copy) -> usize {
18
-
| ++++
12
+
LL | fn id<F>(f: dyn Copy) -> usize {
13
+
| +++
19
14
20
15
warning: trait objects without an explicit `dyn` are deprecated
21
-
--> $DIR/avoid-ice-on-warning-2.rs:1:13
16
+
--> $DIR/avoid-ice-on-warning-2.rs:4:13
22
17
|
23
18
LL | fn id<F>(f: Copy) -> usize {
24
19
| ^^^^
25
20
|
26
21
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
27
22
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
28
-
= note: `Copy` it is not object safe, so it can't be `dyn`
29
23
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
30
-
help: use a new generic type parameter, constrained by `Copy`
31
-
|
32
-
LL | fn id<F, T: Copy>(f: T) -> usize {
33
-
| +++++++++ ~
34
-
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
24
+
help: use `dyn`
35
25
|
36
-
LL | fn id<F>(f: impl Copy) -> usize {
37
-
| ++++
26
+
LL | fn id<F>(f: dyn Copy) -> usize {
27
+
| +++
38
28
39
29
error[E0038]: the trait `Copy` cannot be made into an object
error[E0038]: the trait `A` cannot be made into an object
2
+
--> $DIR/avoid-ice-on-warning-3.rs:4:19
3
+
|
4
+
LL | trait B { fn f(a: A) -> A; }
5
+
| ^ `A` cannot be made into an object
6
+
|
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
9
+
|
10
+
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
15
+
|
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
19
+
|
20
+
LL | trait A { fn g(b: B) -> B where Self: Sized; }
21
+
| +++++++++++++++++
22
+
23
+
error[E0038]: the trait `B` cannot be made into an object
24
+
--> $DIR/avoid-ice-on-warning-3.rs:12:19
25
+
|
26
+
LL | trait A { fn g(b: B) -> B; }
27
+
| ^ `B` cannot be made into an object
28
+
|
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
31
+
|
32
+
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
37
+
|
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
41
+
|
42
+
LL | trait B { fn f(a: A) -> A where Self: Sized; }
43
+
| +++++++++++++++++
44
+
45
+
error: aborting due to 2 previous errors
46
+
47
+
For more information about this error, try `rustc --explain E0038`.
Copy file name to clipboardexpand all lines: tests/ui/object-safety/avoid-ice-on-warning-3.old.stderr
+32-52
Original file line number
Diff line number
Diff line change
@@ -1,93 +1,78 @@
1
1
warning: trait objects without an explicit `dyn` are deprecated
2
-
--> $DIR/avoid-ice-on-warning-3.rs:9:19
2
+
--> $DIR/avoid-ice-on-warning-3.rs:4:19
3
3
|
4
-
LL | trait A { fn g(b: B) -> B; }
4
+
LL | trait B { fn f(a: A) -> A; }
5
5
| ^
6
6
|
7
7
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
8
8
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
9
-
= note: `B` it is not object safe, so it can't be `dyn`
10
9
= note: `#[warn(bare_trait_objects)]` on by default
11
-
help: use a new generic type parameter, constrained by `B`
12
-
|
13
-
LL | trait A { fn g<T: B>(b: T) -> B; }
14
-
| ++++++ ~
15
-
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
10
+
help: use `dyn`
16
11
|
17
-
LL | trait A { fn g(b: impl B) -> B; }
18
-
| ++++
12
+
LL | trait B { fn f(a: dyn A) -> A; }
13
+
| +++
19
14
20
15
warning: trait objects without an explicit `dyn` are deprecated
21
-
--> $DIR/avoid-ice-on-warning-3.rs:9:25
16
+
--> $DIR/avoid-ice-on-warning-3.rs:4:25
22
17
|
23
-
LL | trait A { fn g(b: B) -> B; }
18
+
LL | trait B { fn f(a: A) -> A; }
24
19
| ^
25
20
|
26
21
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
27
22
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
28
-
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
23
+
help: use `dyn`
29
24
|
30
-
LL | trait A { fn g(b: B) -> impl B; }
31
-
| ++++
25
+
LL | trait B { fn f(a: A) -> dyn A; }
26
+
| +++
32
27
33
28
warning: trait objects without an explicit `dyn` are deprecated
34
-
--> $DIR/avoid-ice-on-warning-3.rs:1:19
29
+
--> $DIR/avoid-ice-on-warning-3.rs:12:19
35
30
|
36
-
LL | trait B { fn f(a: A) -> A; }
31
+
LL | trait A { fn g(b: B) -> B; }
37
32
| ^
38
33
|
39
34
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
40
35
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
41
-
= note: `A` it is not object safe, so it can't be `dyn`
42
-
help: use a new generic type parameter, constrained by `A`
43
-
|
44
-
LL | trait B { fn f<T: A>(a: T) -> A; }
45
-
| ++++++ ~
46
-
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
36
+
help: use `dyn`
47
37
|
48
-
LL | trait B { fn f(a: impl A) -> A; }
49
-
| ++++
38
+
LL | trait A { fn g(b: dyn B) -> B; }
39
+
| +++
50
40
51
41
warning: trait objects without an explicit `dyn` are deprecated
52
-
--> $DIR/avoid-ice-on-warning-3.rs:1:25
42
+
--> $DIR/avoid-ice-on-warning-3.rs:12:25
53
43
|
54
-
LL | trait B { fn f(a: A) -> A; }
44
+
LL | trait A { fn g(b: B) -> B; }
55
45
| ^
56
46
|
57
47
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
58
48
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
59
-
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
49
+
help: use `dyn`
60
50
|
61
-
LL | trait B { fn f(a: A) -> impl A; }
62
-
| ++++
51
+
LL | trait A { fn g(b: B) -> dyn B; }
52
+
| +++
63
53
64
54
warning: trait objects without an explicit `dyn` are deprecated
65
-
--> $DIR/avoid-ice-on-warning-3.rs:1:19
55
+
--> $DIR/avoid-ice-on-warning-3.rs:4:19
66
56
|
67
57
LL | trait B { fn f(a: A) -> A; }
68
58
| ^
69
59
|
70
60
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
71
61
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
72
-
= note: `A` it is not object safe, so it can't be `dyn`
73
62
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
74
-
help: use a new generic type parameter, constrained by `A`
75
-
|
76
-
LL | trait B { fn f<T: A>(a: T) -> A; }
77
-
| ++++++ ~
78
-
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
63
+
help: use `dyn`
79
64
|
80
-
LL | trait B { fn f(a: impl A) -> A; }
81
-
| ++++
65
+
LL | trait B { fn f(a: dyn A) -> A; }
66
+
| +++
82
67
83
68
error[E0038]: the trait `A` cannot be made into an object
84
-
--> $DIR/avoid-ice-on-warning-3.rs:1:19
69
+
--> $DIR/avoid-ice-on-warning-3.rs:4:19
85
70
|
86
71
LL | trait B { fn f(a: A) -> A; }
87
72
| ^ `A` cannot be made into an object
88
73
|
89
74
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>
90
-
--> $DIR/avoid-ice-on-warning-3.rs:9:14
75
+
--> $DIR/avoid-ice-on-warning-3.rs:12:14
91
76
|
92
77
LL | trait A { fn g(b: B) -> B; }
93
78
| - ^ ...because associated function `g` has no `self` parameter
@@ -103,32 +88,27 @@ LL | trait A { fn g(b: B) -> B where Self: Sized; }
103
88
| +++++++++++++++++
104
89
105
90
warning: trait objects without an explicit `dyn` are deprecated
106
-
--> $DIR/avoid-ice-on-warning-3.rs:9:19
91
+
--> $DIR/avoid-ice-on-warning-3.rs:12:19
107
92
|
108
93
LL | trait A { fn g(b: B) -> B; }
109
94
| ^
110
95
|
111
96
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
112
97
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
113
-
= note: `B` it is not object safe, so it can't be `dyn`
114
98
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
115
-
help: use a new generic type parameter, constrained by `B`
116
-
|
117
-
LL | trait A { fn g<T: B>(b: T) -> B; }
118
-
| ++++++ ~
119
-
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
99
+
help: use `dyn`
120
100
|
121
-
LL | trait A { fn g(b: impl B) -> B; }
122
-
| ++++
101
+
LL | trait A { fn g(b: dyn B) -> B; }
102
+
| +++
123
103
124
104
error[E0038]: the trait `B` cannot be made into an object
125
-
--> $DIR/avoid-ice-on-warning-3.rs:9:19
105
+
--> $DIR/avoid-ice-on-warning-3.rs:12:19
126
106
|
127
107
LL | trait A { fn g(b: B) -> B; }
128
108
| ^ `B` cannot be made into an object
129
109
|
130
110
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>
131
-
--> $DIR/avoid-ice-on-warning-3.rs:1:14
111
+
--> $DIR/avoid-ice-on-warning-3.rs:4:14
132
112
|
133
113
LL | trait B { fn f(a: A) -> A; }
134
114
| - ^ ...because associated function `f` has no `self` parameter
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
20
20
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
21
21
= note: `#[warn(bare_trait_objects)]` on by default
22
-
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
error: trait objects without an explicit `dyn` are deprecated
2
+
--> $DIR/bare-trait-dont-suggest-dyn.rs:8:33
3
+
|
4
+
LL | fn ord_prefer_dot(s: String) -> Ord {
5
+
| ^^^
6
+
|
7
+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
8
+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
9
+
note: the lint level is defined here
10
+
--> $DIR/bare-trait-dont-suggest-dyn.rs:7:9
11
+
|
12
+
LL | #![deny(bare_trait_objects)]
13
+
| ^^^^^^^^^^^^^^^^^^
14
+
help: use `dyn`
15
+
|
16
+
LL | fn ord_prefer_dot(s: String) -> dyn Ord {
17
+
| +++
18
+
19
+
error[E0038]: the trait `Ord` cannot be made into an object
20
+
--> $DIR/bare-trait-dont-suggest-dyn.rs:8:33
21
+
|
22
+
LL | fn ord_prefer_dot(s: String) -> Ord {
23
+
| ^^^ `Ord` cannot be made into an object
24
+
|
25
+
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>
26
+
--> $SRC_DIR/core/src/cmp.rs:LL:COL
27
+
|
28
+
= note: the trait cannot be made into an object because it uses `Self` as a type parameter
29
+
::: $SRC_DIR/core/src/cmp.rs:LL:COL
30
+
|
31
+
= note: the trait cannot be made into an object because it uses `Self` as a type parameter
32
+
help: consider using an opaque type instead
33
+
|
34
+
LL | fn ord_prefer_dot(s: String) -> impl Ord {
35
+
| ++++
36
+
37
+
error: aborting due to 2 previous errors
38
+
39
+
For more information about this error, try `rustc --explain E0038`.
Copy file name to clipboardexpand all lines: tests/ui/traits/bound/not-on-bare-trait.stderr
+3-11
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,10 @@ LL | fn foo(_x: Foo + Send) {
7
7
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
8
8
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
9
9
= note: `#[warn(bare_trait_objects)]` on by default
10
-
help: use a new generic type parameter, constrained by `Foo + Send`
10
+
help: use `dyn`
11
11
|
12
-
LL | fn foo<T: Foo + Send>(_x: T) {
13
-
| +++++++++++++++ ~
14
-
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
15
-
|
16
-
LL | fn foo(_x: impl Foo + Send) {
17
-
| ++++
18
-
help: alternatively, use a trait object to accept any type that implements `Foo + Send`, accessing its methods at runtime using dynamic dispatch
19
-
|
20
-
LL | fn foo(_x: &(dyn Foo + Send)) {
21
-
| +++++ +
12
+
LL | fn foo(_x: dyn Foo + Send) {
13
+
| +++
22
14
23
15
error[E0277]: the size for values of type `(dyn Foo + Send + 'static)` cannot be known at compilation time
0 commit comments