When elaborating predicates, purge duplicates from the initial vector.

Fixes #21965.
This commit is contained in:
Niko Matsakis 2015-02-05 11:48:20 -05:00
parent 2bd8ec2d19
commit be8d9bb98a
2 changed files with 32 additions and 8 deletions

View file

@ -11,12 +11,12 @@
use middle::subst::{Substs, VecPerParamSpace};
use middle::infer::InferCtxt;
use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef};
use std::collections::HashSet;
use std::fmt;
use std::rc::Rc;
use syntax::ast;
use syntax::codemap::Span;
use util::common::ErrorReported;
use util::nodemap::FnvHashSet;
use util::ppaux::Repr;
use super::{Obligation, ObligationCause, PredicateObligation,
@ -36,7 +36,7 @@ use super::{Obligation, ObligationCause, PredicateObligation,
pub struct Elaborator<'cx, 'tcx:'cx> {
tcx: &'cx ty::ctxt<'tcx>,
stack: Vec<StackEntry<'tcx>>,
visited: HashSet<ty::Predicate<'tcx>>,
visited: FnvHashSet<ty::Predicate<'tcx>>,
}
struct StackEntry<'tcx> {
@ -65,14 +65,11 @@ pub fn elaborate_trait_refs<'cx, 'tcx>(
pub fn elaborate_predicates<'cx, 'tcx>(
tcx: &'cx ty::ctxt<'tcx>,
predicates: Vec<ty::Predicate<'tcx>>)
mut predicates: Vec<ty::Predicate<'tcx>>)
-> Elaborator<'cx, 'tcx>
{
let visited: HashSet<ty::Predicate<'tcx>> =
predicates.iter()
.map(|b| (*b).clone())
.collect();
let mut visited = FnvHashSet();
predicates.retain(|pred| visited.insert(pred.clone()));
let entry = StackEntry { position: 0, predicates: predicates };
Elaborator { tcx: tcx, stack: vec![entry], visited: visited }
}

View file

@ -0,0 +1,27 @@
// Copyright 2015 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Check that we do not report ambiguities when the same predicate
// appears in the environment twice. Issue #21965.
trait Foo {
type B;
fn get() -> Self::B;
}
fn foo<T>() -> ()
where T : Foo<B=()>, T : Foo<B=()>
{
<T as Foo>::get()
}
fn main() {
}