From 94ab344537f0c0cc77a44b7a1265041ac296d7c1 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Sat, 14 Apr 2018 18:11:31 -0500 Subject: [PATCH] chalkify: Fix lowering of traits with supertraits --- src/librustc_traits/lowering.rs | 12 +++++++++-- .../ui/chalkify/lower_trait_supertrait.rs | 21 +++++++++++++++++++ .../ui/chalkify/lower_trait_supertrait.stderr | 14 +++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/chalkify/lower_trait_supertrait.rs create mode 100644 src/test/ui/chalkify/lower_trait_supertrait.stderr diff --git a/src/librustc_traits/lowering.rs b/src/librustc_traits/lowering.rs index df6793e8a604c..afa999f10f321 100644 --- a/src/librustc_traits/lowering.rs +++ b/src/librustc_traits/lowering.rs @@ -172,11 +172,19 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI // ``` // `FromEnv(WC) :- FromEnv(Self: Trait)`, for each where clause WC - // FIXME: Remove the [1..] slice; this is a hack because the query + // FIXME: Remove the filter; this is a hack because the query // predicates_of currently includes the trait itself (`Self: Trait`). let where_clauses = &tcx.predicates_of(def_id).predicates; let implied_bound_clauses = - where_clauses[1..].into_iter() + where_clauses.into_iter() + .filter(|wc| { + if let ty::Predicate::Trait(pred) = wc { + if pred.skip_binder().def_id() == def_id { + return false; + } + } + true + }) .map(|wc| implied_bound_from_trait(tcx, trait_pred, wc)); Lrc::new(tcx.mk_clauses(clauses.chain(implied_bound_clauses))) diff --git a/src/test/ui/chalkify/lower_trait_supertrait.rs b/src/test/ui/chalkify/lower_trait_supertrait.rs new file mode 100644 index 0000000000000..6a885b5f9a983 --- /dev/null +++ b/src/test/ui/chalkify/lower_trait_supertrait.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +trait Bar {} + +#[rustc_dump_program_clauses] //~ ERROR Implemented + //~^ ERROR FromEnv +trait Foo: Bar {} + +fn main() { + println!("hello"); +} diff --git a/src/test/ui/chalkify/lower_trait_supertrait.stderr b/src/test/ui/chalkify/lower_trait_supertrait.stderr new file mode 100644 index 0000000000000..8ea1dd6ee1614 --- /dev/null +++ b/src/test/ui/chalkify/lower_trait_supertrait.stderr @@ -0,0 +1,14 @@ +error: Implemented(Self: Foo) :- FromEnv(Self: Foo). + --> $DIR/lower_trait_supertrait.rs:15:1 + | +LL | #[rustc_dump_program_clauses] //~ ERROR Implemented + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: FromEnv(Self: Bar) :- FromEnv(Self: Foo). + --> $DIR/lower_trait_supertrait.rs:15:1 + | +LL | #[rustc_dump_program_clauses] //~ ERROR Implemented + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +