From 779fc372c794057816951f2583985c512b0c6387 Mon Sep 17 00:00:00 2001 From: Christopher Vittal Date: Fri, 10 Nov 2017 12:09:40 -0500 Subject: [PATCH] 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. --- src/librustc/diagnostics.rs | 40 ++++++++++++++++++++++++++++++ src/librustc_typeck/diagnostics.rs | 40 ------------------------------ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 2b6e1d85568..bab3bded77b 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1770,6 +1770,46 @@ If you want to get command-line arguments, use `std::env::args`. To exit with a specified exit code, use `std::process::exit`. "##, +E0562: r##" +Abstract return types (written `impl Trait` for some trait `Trait`) are only +allowed as function return types. + +Erroneous code example: + +```compile_fail,E0562 +#![feature(conservative_impl_trait)] + +fn main() { + let count_to_ten: impl Iterator = 0..10; + // error: `impl Trait` not allowed outside of function and inherent method + // return types + for i in count_to_ten { + println!("{}", i); + } +} +``` + +Make sure `impl Trait` only appears in return-type position. + +``` +#![feature(conservative_impl_trait)] + +fn count_to_n(n: usize) -> impl Iterator { + 0..n +} + +fn main() { + for i in count_to_n(10) { // ok! + println!("{}", i); + } +} +``` + +See [RFC 1522] for more details. + +[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md +"##, + E0591: r##" Per [RFC 401][rfc401], if you have a function declaration `foo`: diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 73bec697d49..cdf70847c02 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3818,46 +3818,6 @@ let s = Simba { mother: 1, father: 0 }; // ok! ``` "##, -E0562: r##" -Abstract return types (written `impl Trait` for some trait `Trait`) are only -allowed as function return types. - -Erroneous code example: - -```compile_fail,E0562 -#![feature(conservative_impl_trait)] - -fn main() { - let count_to_ten: impl Iterator = 0..10; - // error: `impl Trait` not allowed outside of function and inherent method - // return types - for i in count_to_ten { - println!("{}", i); - } -} -``` - -Make sure `impl Trait` only appears in return-type position. - -``` -#![feature(conservative_impl_trait)] - -fn count_to_n(n: usize) -> impl Iterator { - 0..n -} - -fn main() { - for i in count_to_n(10) { // ok! - println!("{}", i); - } -} -``` - -See [RFC 1522] for more details. - -[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md -"##, - E0569: r##" If an impl has a generic parameter with the `#[may_dangle]` attribute, then that impl must be declared as an `unsafe impl.