Skip to content

Commit 98b53cb

Browse files
committed
Rollup merge of rust-lang#27127 - AlisdairO:diagnostics172, r=Manishearth
As title :-) Part of rust-lang#24407. r? @Manishearth
2 parents d12130b + 686d326 commit 98b53cb

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/librustc/middle/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
165165
if from_tc.interior_param() || to_tc.interior_param() {
166166
span_err!(self.tcx.sess, span, E0139,
167167
"cannot transmute to or from a type that contains \
168-
type parameters in its interior");
168+
unsubstituted type parameters");
169169
return;
170170
}
171171

src/librustc_typeck/diagnostics.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,33 @@ return, for example with a `loop` that never breaks or a call to another
14761476
diverging function (such as `panic!()`).
14771477
"##,
14781478

1479+
E0172: r##"
1480+
This error means that an attempt was made to specify the type of a variable with
1481+
a combination of a concrete type and a trait. Consider the following example:
1482+
1483+
```
1484+
fn foo(bar: i32+std::fmt::Display) {}
1485+
```
1486+
1487+
The code is trying to specify that we want to receive a signed 32-bit integer
1488+
which also implements `Display`. This doesn't make sense: when we pass `i32`, a
1489+
concrete type, it implicitly includes all of the traits that it implements.
1490+
This includes `Display`, `Debug`, `Clone`, and a host of others.
1491+
1492+
If `i32` implements the trait we desire, there's no need to specify the trait
1493+
separately. If it does not, then we need to `impl` the trait for `i32` before
1494+
passing it into `foo`. Either way, a fixed definition for `foo` will look like
1495+
the following:
1496+
1497+
```
1498+
fn foo(bar: i32) {}
1499+
```
1500+
1501+
To learn more about traits, take a look at the Book:
1502+
1503+
https://doc.rust-lang.org/book/traits.html
1504+
"##,
1505+
14791506
E0178: r##"
14801507
In types, the `+` type operator has low precedence, so it is often necessary
14811508
to use parentheses.
@@ -2196,7 +2223,6 @@ register_diagnostics! {
21962223
E0164,
21972224
E0167,
21982225
E0168,
2199-
E0172,
22002226
E0173, // manual implementations of unboxed closure traits are experimental
22012227
E0174, // explicit use of unboxed closure methods are experimental
22022228
E0182,

0 commit comments

Comments
 (0)