Skip to content

Commit a1bedb7

Browse files
committed
Use mk_sub_trait_refs
1 parent e7d98d5 commit a1bedb7

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

src/librustc/middle/typeck/check/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use middle::lang_items::TypeIdLangItem;
112112
use util::common::{block_query, indenter, loop_query};
113113
use util::ppaux;
114114
use util::ppaux::{UserString, Repr};
115-
use util::nodemap::NodeMap;
115+
use util::nodemap::{NodeMap, FnvHashMap};
116116
use collections::{HashMap, HashSet};
117117

118118
use std::cell::{Cell, RefCell};
@@ -871,19 +871,17 @@ fn compare_impl_method(tcx: ty::ctxt,
871871
for impl_bound in impl_param_def.bounds.trait_bounds.iter() {
872872
let mut specified = false;
873873
for trait_bound in trait_param_def.bounds.trait_bounds.iter() {
874-
if !enforced_bounds.contains(&trait_bound.def_id) &&
875-
impl_bound.def_id == trait_bound.def_id {
876-
enforced_bounds.insert(trait_bound.def_id);
877-
specified = true;
878-
break
879-
} else {
880-
for s_trait_bound in ty::trait_supertraits(tcx, trait_bound.def_id).iter() {
881-
if !enforced_bounds.contains(&trait_bound.def_id) &&
882-
impl_bound.def_id == s_trait_bound.def_id {
874+
if !enforced_bounds.contains(&trait_bound.def_id) {
875+
match infer::mk_sub_trait_refs(&infcx,
876+
false,
877+
infer::RelateTraitRefs(impl_m_span),
878+
*impl_bound,
879+
*trait_bound) {
880+
result::Ok(()) => {
883881
enforced_bounds.insert(trait_bound.def_id);
884882
specified = true;
885-
break
886-
}
883+
} // Ok.
884+
result::Err(_) => {}
887885
}
888886
}
889887
}

src/test/compile-fail/typeck-trait-bounds-impl-comparison.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ impl Foo for int {
6565
fn test_error8_fn<T: C>(&self) {}
6666
//~^ ERROR implementation bound `C` was not specified in trait definition
6767
//~^^ ERROR bound `B` not enforced by this implementation
68+
}
69+
6870

71+
trait Getter<T> { }
72+
73+
trait Trait {
74+
fn method<G:Getter<int>>();
6975
}
7076

77+
impl Trait for uint {
78+
fn method<G: Getter<uint>>() {}
79+
//~^ ERROR requires Getter<uint> but Trait provides Getter<int>
80+
}
7181
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 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+
// Make sure rustc checks the type parameter bounds in implementations of traits,
12+
// see #2687
13+
trait Getter<T> { }
14+
15+
trait Trait {
16+
fn method<G:Getter<int>>();
17+
}
18+
19+
impl Trait for uint {
20+
fn method<G: Getter<uint>>() {}
21+
//~^ ERROR requires Getter<uint> but Trait provides Getter<int>
22+
}
23+
fn main() {}

0 commit comments

Comments
 (0)