@@ -573,8 +573,8 @@ implementation if the function is called with unparametrized substitutions
573
573
(i.e., substitutions where none of the substituted types are themselves
574
574
parametrized).
575
575
576
- However, with trait objects we have to make a table containing _every object
577
- that implements the trait_ . Now, if it has type parameters, we need to add
576
+ However, with trait objects we have to make a table containing _every_ object
577
+ that implements the trait . Now, if it has type parameters, we need to add
578
578
implementations for every type that implements the trait, and there could
579
579
theoretically be an infinite number of types.
580
580
@@ -609,9 +609,9 @@ fn call_foo(thing: Box<Trait>) {
609
609
```
610
610
611
611
we don't just need to create a table of all implementations of all methods of
612
- `Trait`, we need to create a table of all implementations of `foo()`, _for each
613
- different type fed to `foo()`_ . In this case this turns out to be (10 types
614
- implementing `Trait`)*(3 types being fed to `foo()`) = 30 implementations!
612
+ `Trait`, we need to create such a table, for each different type fed to
613
+ `foo()`. In this case this turns out to be (10 types implementing `Trait`)*(3
614
+ types being fed to `foo()`) = 30 implementations!
615
615
616
616
With real world traits these numbers can grow drastically.
617
617
@@ -684,19 +684,19 @@ If the trait `Foo` was deriving from something like `Super<String>` or
684
684
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
685
685
`get_a()` will definitely return an object of that type.
686
686
687
- However, if it derives from `Super<Self>`, the method `get_a()` would return an
688
- object of unknown type when called on the function, _even though `Super` is
689
- object safe_ . `Self` type parameters let us make object safe traits no longer
690
- safe, so they are forbidden when specifying supertraits.
687
+ However, if it derives from `Super<Self>`, even though `Super` is object safe,
688
+ the method `get_a()` would return an object of unknown type when called on the
689
+ function . `Self` type parameters let us make object safe traits no longer safe,
690
+ so they are forbidden when specifying supertraits.
691
691
692
692
There's no easy fix for this, generally code will need to be refactored so that
693
693
you no longer need to derive from `Super<Self>`.
694
694
"#### ,
695
695
696
696
E0079 : r##"
697
697
Enum variants which contain no data can be given a custom integer
698
- representation. This error indicates that the value provided is not an
699
- integer literal and is therefore invalid.
698
+ representation. This error indicates that the value provided is not an integer
699
+ literal and is therefore invalid.
700
700
701
701
For example, in the following code,
702
702
@@ -708,18 +708,17 @@ enum Foo {
708
708
709
709
we try to set the representation to a string.
710
710
711
- There's no general fix for this; if you can work with an integer
712
- then just set it to one:
711
+ There's no general fix for this; if you can work with an integer then just set
712
+ it to one:
713
713
714
714
```
715
715
enum Foo {
716
716
Q = 32
717
717
}
718
718
```
719
719
720
- however if you actually wanted a mapping between variants
721
- and non-integer objects, it may be preferable to use a method with
722
- a match instead:
720
+ however if you actually wanted a mapping between variants and non-integer
721
+ objects, it may be preferable to use a method with a match instead:
723
722
724
723
```
725
724
enum Foo { Q }
@@ -1156,6 +1155,73 @@ It is advisable to find out what the unhandled cases are and check for them,
1156
1155
returning an appropriate value or panicking if necessary.
1157
1156
"## ,
1158
1157
1158
+ E0270 : r##"
1159
+ Rust lets you define functions which are known to never return, i.e. are
1160
+ "diverging", by marking its return type as `!`.
1161
+
1162
+ For example, the following functions never return:
1163
+
1164
+ ```
1165
+ fn foo() -> ! {
1166
+ loop {}
1167
+ }
1168
+
1169
+ fn bar() -> ! {
1170
+ foo() // foo() is diverging, so this will diverge too
1171
+ }
1172
+
1173
+ fn baz() -> ! {
1174
+ panic!(); // this macro internally expands to a call to a diverging function
1175
+ }
1176
+
1177
+ ```
1178
+
1179
+ Such functions can be used in a place where a value is expected without
1180
+ returning a value of that type, for instance:
1181
+
1182
+ ```
1183
+ let y = match x {
1184
+ 1 => 1,
1185
+ 2 => 4,
1186
+ _ => foo() // diverging function called here
1187
+ };
1188
+ println!("{}", y)
1189
+ ```
1190
+
1191
+ If the third arm of the match block is reached, since `foo()` doesn't ever
1192
+ return control to the match block, it is fine to use it in a place where an
1193
+ integer was expected. The `match` block will never finish executing, and any
1194
+ point where `y` (like the print statement) is needed will not be reached.
1195
+
1196
+ However, if we had a diverging function that actually does finish execution
1197
+
1198
+ ```
1199
+ fn foo() -> {
1200
+ loop {break;}
1201
+ }
1202
+ ```
1203
+
1204
+ then we would have an unknown value for `y` in the following code:
1205
+
1206
+ ```
1207
+ let y = match x {
1208
+ 1 => 1,
1209
+ 2 => 4,
1210
+ _ => foo()
1211
+ };
1212
+ println!("{}", y);
1213
+ ```
1214
+
1215
+ In the previous example, the print statement was never reached when the wildcard
1216
+ match arm was hit, so we were okay with `foo()` not returning an integer that we
1217
+ could set to `y`. But in this example, `foo()` actually does return control, so
1218
+ the print statement will be executed with an uninitialized value.
1219
+
1220
+ Obviously we cannot have functions which are allowed to be used in such
1221
+ positions and yet can return control. So, if you are defining a function that
1222
+ returns `!`, make sure that there is no way for it to actually finish executing.
1223
+ "## ,
1224
+
1159
1225
E0271 : r##"
1160
1226
This is because of a type mismatch between the associated type of some
1161
1227
trait (e.g. `T::Bar`, where `T` implements `trait Quux { type Bar; }`)
@@ -1292,6 +1358,11 @@ for v in &vs {
1292
1358
```
1293
1359
"## ,
1294
1360
1361
+ E0272 : r##"
1362
+
1363
+ The `#[rustc_on_unimplemented]` attribute lets you specify
1364
+ "## ,
1365
+
1295
1366
E0277 : r##"
1296
1367
You tried to use a type which doesn't implement some trait in a place which
1297
1368
expected that trait. Erroneous code example:
@@ -1716,7 +1787,6 @@ register_diagnostics! {
1716
1787
// E0134,
1717
1788
// E0135,
1718
1789
E0264 , // unknown external lang item
1719
- E0270 , // computation may converge in a function marked as diverging
1720
1790
E0272 , // rustc_on_unimplemented attribute refers to non-existent type parameter
1721
1791
E0273 , // rustc_on_unimplemented must have named format arguments
1722
1792
E0274 , // rustc_on_unimplemented must have a value
0 commit comments