Skip to content

Commit be8d9bb

Browse files
committed
When elaborating predicates, purge duplicates from the initial vector.
Fixes #21965.
1 parent 2bd8ec2 commit be8d9bb

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/librustc/middle/traits/util.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
use middle::subst::{Substs, VecPerParamSpace};
1212
use middle::infer::InferCtxt;
1313
use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef};
14-
use std::collections::HashSet;
1514
use std::fmt;
1615
use std::rc::Rc;
1716
use syntax::ast;
1817
use syntax::codemap::Span;
1918
use util::common::ErrorReported;
19+
use util::nodemap::FnvHashSet;
2020
use util::ppaux::Repr;
2121

2222
use super::{Obligation, ObligationCause, PredicateObligation,
@@ -36,7 +36,7 @@ use super::{Obligation, ObligationCause, PredicateObligation,
3636
pub struct Elaborator<'cx, 'tcx:'cx> {
3737
tcx: &'cx ty::ctxt<'tcx>,
3838
stack: Vec<StackEntry<'tcx>>,
39-
visited: HashSet<ty::Predicate<'tcx>>,
39+
visited: FnvHashSet<ty::Predicate<'tcx>>,
4040
}
4141

4242
struct StackEntry<'tcx> {
@@ -65,14 +65,11 @@ pub fn elaborate_trait_refs<'cx, 'tcx>(
6565

6666
pub fn elaborate_predicates<'cx, 'tcx>(
6767
tcx: &'cx ty::ctxt<'tcx>,
68-
predicates: Vec<ty::Predicate<'tcx>>)
68+
mut predicates: Vec<ty::Predicate<'tcx>>)
6969
-> Elaborator<'cx, 'tcx>
7070
{
71-
let visited: HashSet<ty::Predicate<'tcx>> =
72-
predicates.iter()
73-
.map(|b| (*b).clone())
74-
.collect();
75-
71+
let mut visited = FnvHashSet();
72+
predicates.retain(|pred| visited.insert(pred.clone()));
7673
let entry = StackEntry { position: 0, predicates: predicates };
7774
Elaborator { tcx: tcx, stack: vec![entry], visited: visited }
7875
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that we do not report ambiguities when the same predicate
12+
// appears in the environment twice. Issue #21965.
13+
14+
trait Foo {
15+
type B;
16+
17+
fn get() -> Self::B;
18+
}
19+
20+
fn foo<T>() -> ()
21+
where T : Foo<B=()>, T : Foo<B=()>
22+
{
23+
<T as Foo>::get()
24+
}
25+
26+
fn main() {
27+
}

0 commit comments

Comments
 (0)