From e6d5f251f11f4ac74f23748b665a29f0ceddfdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Wed, 30 Jan 2019 00:50:27 +0100 Subject: [PATCH 1/3] Fix #57730 --- src/librustc_passes/ast_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 3deb2ff8d8a0b..bad1367a89af4 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -519,7 +519,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let Some(ref type_) = data.output { // `-> Foo` syntax is essentially an associated type binding, // so it is also allowed to contain nested `impl Trait`. - self.with_impl_trait(None, |this| visit::walk_ty(this, type_)); + self.with_impl_trait(None, |this| this.visit_ty(type_)); } } } From 9d2a0b9e82d2e0581ba73e193d73a4b8103f0792 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 1 Feb 2019 12:08:50 -0500 Subject: [PATCH 2/3] add regression test for #57979 --- src/test/ui/issues/issue-57979.rs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/ui/issues/issue-57979.rs diff --git a/src/test/ui/issues/issue-57979.rs b/src/test/ui/issues/issue-57979.rs new file mode 100644 index 0000000000000..abd46b60ab194 --- /dev/null +++ b/src/test/ui/issues/issue-57979.rs @@ -0,0 +1,42 @@ +// Regression test for #57979. This situation is meant to be an error. +// As noted in the issue thread, we decided to forbid nested impl +// trait of this kind: +// +// ```rust +// fn foo() -> impl Foo { .. } +// ``` +// +// Basically there are two hidden variables here, let's call them `X` +// and `Y`, and we must prove that: +// +// ``` +// X: Foo +// Y: Bar +// ``` +// +// However, the user is only giving us the return type `X`. It's true +// that in some cases, we can infer `Y` from `X`, because `X` only +// implements `Foo` for one type (and indeed the compiler does +// inference of this kind), but I do recall that we intended to forbid +// this -- in part because such inference is fragile, and there is not +// necessarily a way for the user to be more explicit should the +// inference fail (so you could get stuck with no way to port your +// code forward if, for example, more impls are added to an existing +// type). +// +// The same seems to apply in this situation. Here there are three impl traits, so we have +// +// ``` +// X: IntoIterator +// Y: Borrow> +// Z: AsRef<[u8]> +// ``` + +use std::borrow::Borrow; + +pub struct Data(TBody); + +pub fn collect(_: impl IntoIterator>>>) { + //~^ ERROR + unimplemented!() +} From cce2c89e3bb7cb91610ea6891290491bf763bee3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 14 Feb 2019 10:26:02 -0500 Subject: [PATCH 3/3] add .stderr file --- src/test/ui/issues/issue-57979.stderr | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/ui/issues/issue-57979.stderr diff --git a/src/test/ui/issues/issue-57979.stderr b/src/test/ui/issues/issue-57979.stderr new file mode 100644 index 0000000000000..488f30ab7c5a7 --- /dev/null +++ b/src/test/ui/issues/issue-57979.stderr @@ -0,0 +1,17 @@ +error[E0666]: nested `impl Trait` is not allowed + --> $DIR/issue-57979.rs:39:61 + | +LL | pub fn collect(_: impl IntoIterator>>>) { + | -----------------^^^^^^^^^^^^^^^^-- + | | | + | | nested `impl Trait` here + | outer `impl Trait` + +error[E0601]: `main` function not found in crate `issue_57979` + | + = note: consider adding a `main` function to `$DIR/issue-57979.rs` + +error: aborting due to 2 previous errors + +Some errors occurred: E0601, E0666. +For more information about an error, try `rustc --explain E0601`.