Skip to content

Commit 82a2429

Browse files
committed
Auto merge of #27617 - AlisdairO:diagnostics193, r=Manishearth
As title :-) Part of #24407. r? @Manishearth
2 parents febdc3b + d07a094 commit 82a2429

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/librustc_typeck/diagnostics.rs

+37-2
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,43 @@ information see the [opt-in builtin traits RFC](https://github.com/rust-lang/
18031803
rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
18041804
"##,
18051805

1806+
E0193: r##"
1807+
`where` clauses must use generic type parameters: it does not make sense to use
1808+
them otherwise. An example causing this error:
1809+
1810+
```
1811+
trait Foo {
1812+
fn bar(&self);
1813+
}
1814+
1815+
#[derive(Copy,Clone)]
1816+
struct Wrapper<T> {
1817+
Wrapped: T
1818+
}
1819+
1820+
impl Foo for Wrapper<u32> where Wrapper<u32>: Clone {
1821+
fn bar(&self) { }
1822+
}
1823+
```
1824+
1825+
This use of a `where` clause is strange - a more common usage would look
1826+
something like the following:
1827+
1828+
```
1829+
impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone {
1830+
fn bar(&self) { }
1831+
}
1832+
```
1833+
1834+
Here, we're saying that the implementation exists on Wrapper only when the
1835+
wrapped type `T` implements `Clone`. The `where` clause is important because
1836+
some types will not implement `Clone`, and thus will not get this method.
1837+
1838+
In our erroneous example, however, we're referencing a single concrete type.
1839+
Since we know for certain that Wrapper<u32> implements Clone, there's no reason
1840+
to also specify it in a `where` clause.
1841+
"##,
1842+
18061843
E0195: r##"
18071844
Your method's lifetime parameters do not match the trait declaration.
18081845
Erroneous code example:
@@ -2558,8 +2595,6 @@ register_diagnostics! {
25582595
E0188, // can not cast a immutable reference to a mutable pointer
25592596
E0189, // deprecated: can only cast a boxed pointer to a boxed object
25602597
E0190, // deprecated: can only cast a &-pointer to an &-object
2561-
E0193, // cannot bound type where clause bounds may only be attached to types
2562-
// involving type parameters
25632598
E0194,
25642599
E0196, // cannot determine a type for this closure
25652600
E0203, // type parameter has more than one relaxed default bound,

0 commit comments

Comments
 (0)