Commit 26cfeb1
committed
Silence errors in experssions caused by bare traits in paths
Address #51077 in editions>=2021 by treating `<Trait>` as a `<{type error}>` instead of `<dyn Trait>`, silencing subsequent errors. We new emit a single error ("missing `dyn`").
```
error[E0782]: trait objects must include the `dyn` keyword
--> f800.rs:2:15
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^
|
help: add `dyn` keyword before this trait
|
2 | let x: u32 = <dyn Default>::default();
| +++
```
instead of 6
```
error[E0782]: trait objects must include the `dyn` keyword
--> f800.rs:2:15
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^
|
help: add `dyn` keyword before this trait
|
2 | let x: u32 = <dyn Default>::default();
| +++
error[E0038]: the trait `Default` cannot be made into an object
--> f800.rs:2:15
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^ `Default` cannot be made into an object
|
= note: the trait cannot be made into an object because it requires `Self: Sized`
= 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>
error[E0277]: the size for values of type `dyn Default` cannot be known at compilation time
--> f800.rs:2:15
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Default`
note: required by a bound in `default`
--> /home/gh-estebank/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/default.rs:104:20
|
104 | pub trait Default: Sized {
| ^^^^^ required by this bound in `Default::default`
...
136 | fn default() -> Self;
| ------- required by a bound in this associated function
error[E0308]: mismatched types
--> f800.rs:2:14
|
2 | let x: u32 = <Default>::default();
| --- ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `dyn Default`
| |
| expected due to this
|
= note: expected type `u32`
found trait object `dyn Default`
= help: `u32` implements `Default` so you could change the expected type to `Box<dyn Default>`
error[E0038]: the trait `Default` cannot be made into an object
--> f800.rs:2:14
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^^^^^^^^^^^^^^ `Default` cannot be made into an object
|
= note: the trait cannot be made into an object because it requires `Self: Sized`
= 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>
error[E0277]: the size for values of type `dyn Default` cannot be known at compilation time
--> f800.rs:2:14
|
2 | let x: u32 = <Default>::default();
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Default`
= note: the return type of a function must have a statically known size
```1 parent f21554f commit 26cfeb1
File tree
15 files changed
+131
-114
lines changed- compiler/rustc_hir_analysis/src/hir_ty_lowering
- tests/ui
- associated-type-bounds
- const-generics/generic_const_exprs
- dyn-keyword
- impl-trait
- resolve
15 files changed
+131
-114
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2069 | 2069 | | |
2070 | 2070 | | |
2071 | 2071 | | |
2072 | | - | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
2073 | 2084 | | |
2074 | 2085 | | |
2075 | 2086 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 13 | | |
18 | 14 | | |
19 | 15 | | |
| |||
Lines changed: 5 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 1 | | |
33 | 2 | | |
34 | 3 | | |
| |||
45 | 14 | | |
46 | 15 | | |
47 | 16 | | |
48 | | - | |
| 17 | + | |
49 | 18 | | |
50 | 19 | | |
51 | 20 | | |
| |||
60 | 29 | | |
61 | 30 | | |
62 | 31 | | |
63 | | - | |
| 32 | + | |
64 | 33 | | |
65 | 34 | | |
66 | 35 | | |
| |||
75 | 44 | | |
76 | 45 | | |
77 | 46 | | |
78 | | - | |
| 47 | + | |
79 | 48 | | |
80 | 49 | | |
81 | 50 | | |
| |||
85 | 54 | | |
86 | 55 | | |
87 | 56 | | |
88 | | - | |
| 57 | + | |
89 | 58 | | |
90 | | - | |
91 | | - | |
| 59 | + | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
Lines changed: 2 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 19 | | |
43 | 20 | | |
44 | 21 | | |
| |||
62 | 39 | | |
63 | 40 | | |
64 | 41 | | |
65 | | - | |
| 42 | + | |
66 | 43 | | |
67 | | - | |
| 44 | + | |
68 | 45 | | |
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Lines changed: 2 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | 1 | | |
8 | 2 | | |
9 | 3 | | |
| |||
15 | 9 | | |
16 | 10 | | |
17 | 11 | | |
18 | | - | |
| 12 | + | |
19 | 13 | | |
20 | | - | |
21 | | - | |
| 14 | + | |
0 commit comments