diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index f374f1dc26795..2984ea086efc5 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -445,7 +445,8 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } } - (&ty::ty_param(ref a_p), &ty::ty_param(ref b_p)) if a_p.idx == b_p.idx => { + (&ty::ty_param(ref a_p), &ty::ty_param(ref b_p)) if + a_p.idx == b_p.idx && a_p.space == b_p.space => { Ok(a) } diff --git a/src/test/compile-fail/type-params-in-different-spaces-1.rs b/src/test/compile-fail/type-params-in-different-spaces-1.rs new file mode 100644 index 0000000000000..6e32e6e48354c --- /dev/null +++ b/src/test/compile-fail/type-params-in-different-spaces-1.rs @@ -0,0 +1,25 @@ +// Copyright 2014 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. + +use std::num::Num; + +trait BrokenAdd: Num { + fn broken_add(&self, rhs: T) -> Self { + *self + rhs //~ ERROR mismatched types + } +} + +impl BrokenAdd for T {} + +pub fn main() { + let foo: u8 = 0u8; + let x: u8 = foo.broken_add("hello darkness my old friend".to_string()); + println!("{}", x); +} diff --git a/src/test/compile-fail/type-params-in-different-spaces-2.rs b/src/test/compile-fail/type-params-in-different-spaces-2.rs new file mode 100644 index 0000000000000..955efeef30d79 --- /dev/null +++ b/src/test/compile-fail/type-params-in-different-spaces-2.rs @@ -0,0 +1,35 @@ +// Copyright 2014 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. + +trait Tr { + fn op(T) -> Self; +} + +// these compile as if Self: Tr, even tho only Self: Tr +trait A: Tr { + fn test(u: U) -> Self { + Tr::op(u) //~ ERROR expected Tr, but found Tr + } +} +trait B: Tr { + fn test(u: U) -> Self { + Tr::op(u) //~ ERROR expected Tr, but found Tr + } +} + +impl Tr for T { + fn op(t: T) -> T { t } +} +impl A for T {} + +fn main() { + std::io::println(A::test((&7306634593706211700, 8))); +} + diff --git a/src/test/compile-fail/type-params-in-different-spaces-3.rs b/src/test/compile-fail/type-params-in-different-spaces-3.rs new file mode 100644 index 0000000000000..a3d69d53ba9c0 --- /dev/null +++ b/src/test/compile-fail/type-params-in-different-spaces-3.rs @@ -0,0 +1,18 @@ +// Copyright 2014 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. + +trait Tr { + fn test(u: X) -> Self { + u //~ ERROR mismatched types + } +} + +fn main() {} +