Skip to content

Commit 779fc37

Browse files
committed
Move E0562 to librustc from librustc_typeck
With the check for impl trait moving from type checking to HIR lowering the error needs to move too.
1 parent 88a28ff commit 779fc37

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

src/librustc/diagnostics.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,46 @@ If you want to get command-line arguments, use `std::env::args`. To exit with a
17701770
specified exit code, use `std::process::exit`.
17711771
"##,
17721772

1773+
E0562: r##"
1774+
Abstract return types (written `impl Trait` for some trait `Trait`) are only
1775+
allowed as function return types.
1776+
1777+
Erroneous code example:
1778+
1779+
```compile_fail,E0562
1780+
#![feature(conservative_impl_trait)]
1781+
1782+
fn main() {
1783+
let count_to_ten: impl Iterator<Item=usize> = 0..10;
1784+
// error: `impl Trait` not allowed outside of function and inherent method
1785+
// return types
1786+
for i in count_to_ten {
1787+
println!("{}", i);
1788+
}
1789+
}
1790+
```
1791+
1792+
Make sure `impl Trait` only appears in return-type position.
1793+
1794+
```
1795+
#![feature(conservative_impl_trait)]
1796+
1797+
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
1798+
0..n
1799+
}
1800+
1801+
fn main() {
1802+
for i in count_to_n(10) { // ok!
1803+
println!("{}", i);
1804+
}
1805+
}
1806+
```
1807+
1808+
See [RFC 1522] for more details.
1809+
1810+
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
1811+
"##,
1812+
17731813
E0591: r##"
17741814
Per [RFC 401][rfc401], if you have a function declaration `foo`:
17751815

src/librustc_typeck/diagnostics.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,46 +3818,6 @@ let s = Simba { mother: 1, father: 0 }; // ok!
38183818
```
38193819
"##,
38203820

3821-
E0562: r##"
3822-
Abstract return types (written `impl Trait` for some trait `Trait`) are only
3823-
allowed as function return types.
3824-
3825-
Erroneous code example:
3826-
3827-
```compile_fail,E0562
3828-
#![feature(conservative_impl_trait)]
3829-
3830-
fn main() {
3831-
let count_to_ten: impl Iterator<Item=usize> = 0..10;
3832-
// error: `impl Trait` not allowed outside of function and inherent method
3833-
// return types
3834-
for i in count_to_ten {
3835-
println!("{}", i);
3836-
}
3837-
}
3838-
```
3839-
3840-
Make sure `impl Trait` only appears in return-type position.
3841-
3842-
```
3843-
#![feature(conservative_impl_trait)]
3844-
3845-
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
3846-
0..n
3847-
}
3848-
3849-
fn main() {
3850-
for i in count_to_n(10) { // ok!
3851-
println!("{}", i);
3852-
}
3853-
}
3854-
```
3855-
3856-
See [RFC 1522] for more details.
3857-
3858-
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
3859-
"##,
3860-
38613821
E0569: r##"
38623822
If an impl has a generic parameter with the `#[may_dangle]` attribute, then
38633823
that impl must be declared as an `unsafe impl.

0 commit comments

Comments
 (0)