From 3e215a3c87362d386206d8cca55710d2d5032e18 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 11 Jul 2018 16:01:48 +0200 Subject: [PATCH] Typeck existential types properly --- src/librustc_typeck/check/mod.rs | 1 + src/test/ui/impl-trait/auto-trait-leak.rs | 2 + src/test/ui/impl-trait/auto-trait-leak.stderr | 84 ++++++++++++++----- 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e74652ff9321..e4a93b09e98e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1309,6 +1309,7 @@ pub fn check_item_type<'a,'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Item hir::ItemKind::Union(..) => { check_union(tcx, it.id, it.span); } + hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => { let def_id = tcx.hir.local_def_id(it.id); let pty_ty = tcx.type_of(def_id); diff --git a/src/test/ui/impl-trait/auto-trait-leak.rs b/src/test/ui/impl-trait/auto-trait-leak.rs index a594ee8aab42..a241ba53461f 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.rs +++ b/src/test/ui/impl-trait/auto-trait-leak.rs @@ -23,7 +23,9 @@ fn main() { // return type, which can't depend on the obligation. fn cycle1() -> impl Clone { //~^ ERROR cycle detected + //~| ERROR cycle detected send(cycle2().clone()); + //~^ ERROR cannot be sent between threads safely Rc::new(Cell::new(5)) } diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index 6681116f0f39..10711d1cd8ce 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -1,29 +1,67 @@ -error[E0391]: cycle detected when processing `cycle1` - --> $DIR/auto-trait-leak.rs:24:1 - | -LL | fn cycle1() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... -note: ...which requires processing `cycle2::{{impl-Trait}}`... - --> $DIR/auto-trait-leak.rs:31:16 - | -LL | fn cycle2() -> impl Clone { - | ^^^^^^^^^^ -note: ...which requires processing `cycle2`... - --> $DIR/auto-trait-leak.rs:31:1 - | -LL | fn cycle2() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... -note: ...which requires processing `cycle1::{{impl-Trait}}`... +error[E0391]: cycle detected when processing `cycle1::{{impl-Trait}}` --> $DIR/auto-trait-leak.rs:24:16 | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^ - = note: ...which again requires processing `cycle1`, completing the cycle -note: cycle used when type-checking all item bodies + | +note: ...which requires processing `cycle1`... + --> $DIR/auto-trait-leak.rs:24:1 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... +note: ...which requires processing `cycle2::{{impl-Trait}}`... + --> $DIR/auto-trait-leak.rs:33:16 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^ +note: ...which requires processing `cycle2`... + --> $DIR/auto-trait-leak.rs:33:1 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... + = note: ...which again requires processing `cycle1::{{impl-Trait}}`, completing the cycle -error: aborting due to previous error +error[E0391]: cycle detected when processing `cycle1::{{impl-Trait}}` + --> $DIR/auto-trait-leak.rs:24:16 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^ + | +note: ...which requires processing `cycle1`... + --> $DIR/auto-trait-leak.rs:24:1 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`... +note: ...which requires processing `cycle2::{{impl-Trait}}`... + --> $DIR/auto-trait-leak.rs:33:16 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^ +note: ...which requires processing `cycle2`... + --> $DIR/auto-trait-leak.rs:33:1 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires processing `cycle1::{{impl-Trait}}`, completing the cycle -For more information about this error, try `rustc --explain E0391`. +error[E0277]: `std::rc::Rc` cannot be sent between threads safely + --> $DIR/auto-trait-leak.rs:27:5 + | +LL | send(cycle2().clone()); + | ^^^^ `std::rc::Rc` cannot be sent between threads safely + | + = help: within `impl std::clone::Clone`, the trait `std::marker::Send` is not implemented for `std::rc::Rc` + = note: required because it appears within the type `impl std::clone::Clone` +note: required by `send` + --> $DIR/auto-trait-leak.rs:16:1 + | +LL | fn send(_: T) {} + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors occurred: E0277, E0391. +For more information about an error, try `rustc --explain E0277`.