librustc: Ensure that type parameters are in the right positions in paths.
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
This commit is contained in:
parent
3b6314c39b
commit
8693943676
70 changed files with 1130 additions and 528 deletions
37
src/test/compile-fail/bad-mid-path-type-params.rs
Normal file
37
src/test/compile-fail/bad-mid-path-type-params.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#[no_std];
|
||||
|
||||
struct S<T> {
|
||||
contents: T,
|
||||
}
|
||||
|
||||
impl<T> S<T> {
|
||||
fn new<U>(x: T, _: U) -> S<T> {
|
||||
S {
|
||||
contents: x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait Trait<T> {
|
||||
fn new<U>(x: T, y: U) -> Self;
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
contents: int,
|
||||
}
|
||||
|
||||
impl Trait<int> for S2 {
|
||||
fn new<U>(x: int, _: U) -> S2 {
|
||||
S2 {
|
||||
contents: x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = S::new::<int,float>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
|
||||
let _ = S::<'self,int>::new::<float>(1, 1.0); //~ ERROR this impl has no lifetime parameter
|
||||
let _: S2 = Trait::new::<int,float>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
|
||||
let _: S2 = Trait::<'self,int>::new::<float>(1, 1.0); //~ ERROR this trait has no lifetime parameter
|
||||
}
|
||||
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright 2013 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.
|
||||
|
||||
pub trait Nummy {
|
||||
fn from_inty<T>() -> Self;
|
||||
}
|
||||
|
||||
impl Nummy for float {
|
||||
fn from_inty<T>() -> float { 0.0 }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _1:float = Nummy::from_inty::<int>(); //~ ERROR not enough type
|
||||
//~^ NOTE Static methods have an extra implicit type parameter
|
||||
}
|
||||
|
|
@ -23,17 +23,17 @@ let x: u64<int>; //~ ERROR type parameters are not allowed on this type
|
|||
let x: float<int>; //~ ERROR type parameters are not allowed on this type
|
||||
let x: char<int>; //~ ERROR type parameters are not allowed on this type
|
||||
|
||||
let x: int<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: i8<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: i16<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: i32<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: i64<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: uint<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: u8<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: u16<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: u32<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: u64<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: float<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: char<'static>; //~ ERROR region parameters are not allowed on this type
|
||||
let x: int<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: i64<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: uint<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: u64<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: float<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
let x: char<'static>; //~ ERROR lifetime parameters are not allowed on this type
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,4 @@ fn a_fn3<'a,'b>(e: a_class<'a>) -> a_class<'b> {
|
|||
//~^ ERROR cannot infer an appropriate lifetime
|
||||
}
|
||||
|
||||
fn a_fn4<'a,'b>() {
|
||||
let _: int<'a> = 1; //~ ERROR region parameters are not allowed on this type
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ mod a {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let _ = a::S::new(); //~ ERROR function `new` is private
|
||||
let _ = a::S::new(); //~ ERROR method `new` is private
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
// xfail-pretty
|
||||
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
|
|
|
|||
|
|
@ -36,5 +36,6 @@ struct Lots {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
assert!(Zero::zero::<Lots>().is_zero());
|
||||
let lots: Lots = Zero::zero();
|
||||
assert!(lots.is_zero());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,12 @@ extern mod extra;
|
|||
use std::num::Float;
|
||||
|
||||
pub fn main() {
|
||||
let nan = Float::NaN::<float>();
|
||||
let nan: float = Float::NaN();
|
||||
assert!((nan).is_NaN());
|
||||
|
||||
let inf = Float::infinity::<float>();
|
||||
assert_eq!(-inf, Float::neg_infinity::<float>());
|
||||
let inf: float = Float::infinity();
|
||||
let neg_inf: float = Float::neg_infinity();
|
||||
assert_eq!(-inf, neg_inf);
|
||||
|
||||
assert!( nan != nan);
|
||||
assert!( nan != -nan);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,24 @@ impl<T> S<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = S::<int>::new::<float>(1, 1.0);
|
||||
trait Trait<T> {
|
||||
fn new<U>(x: T, y: U) -> Self;
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
contents: int,
|
||||
}
|
||||
|
||||
impl Trait<int> for S2 {
|
||||
fn new<U>(x: int, _: U) -> S2 {
|
||||
S2 {
|
||||
contents: x,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = S::<int>::new::<float>(1, 1.0);
|
||||
let _: S2 = Trait::<int>::new::<float>(1, 1.0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ fn main () {
|
|||
|
||||
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
|
||||
assert_eq!(B::staticthing(&0i, 3.14, 1), (3.14, 1));
|
||||
assert_eq!(B::staticthing::<float, int, int>(&0i, 3.14, 1), (3.14, 1));
|
||||
assert_eq!(B::<float>::staticthing::<int>(&0i, 3.14, 1), (3.14, 1));
|
||||
|
||||
assert_eq!(g(0i, 3.14, 1), (3.14, 1));
|
||||
assert_eq!(g(false, 3.14, 1), (3.14, 1));
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ mod base {
|
|||
use std::io;
|
||||
|
||||
pub trait HasNew<T> {
|
||||
fn new() -> T;
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
pub struct Foo {
|
||||
|
|
@ -41,6 +41,6 @@ mod base {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let _f: base::Foo = base::HasNew::new::<base::Foo, base::Foo>();
|
||||
let _b: base::Bar = base::HasNew::new::<base::Bar, base::Bar>();
|
||||
let _f: base::Foo = base::HasNew::<base::Foo>::new();
|
||||
let _b: base::Bar = base::HasNew::<base::Bar>::new();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue