libstd: Remove "dual impls" from the language and enforce coherence rules. r=brson
"Dual impls" are impls that are both type implementations and trait implementations. They can lead to ambiguity and so this patch removes them from the language. This also enforces coherence rules. Without this patch, records can implement traits not defined in the current crate. This patch fixes this, and updates all of rustc to adhere to the new enforcement. Most of this patch is fixing rustc to obey the coherence rules, which involves converting a bunch of records to structs.
This commit is contained in:
parent
f1e78c6dd7
commit
eb4d39e1fe
77 changed files with 699 additions and 832 deletions
|
|
@ -1,19 +0,0 @@
|
|||
// 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.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#[link(name = "b", vers = "0.1")];
|
||||
#[crate_type = "lib"];
|
||||
|
||||
extern mod a;
|
||||
use a::to_strz;
|
||||
|
||||
impl int: to_strz {
|
||||
fn to_strz() -> ~str { fmt!("%?", self) }
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
type Foo = @[u8];
|
||||
|
||||
impl Foo : Drop { //~ ERROR the Drop trait may only be implemented
|
||||
//~^ ERROR cannot provide an extension implementation
|
||||
fn finalize(&self) {
|
||||
io::println("kaboom");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@
|
|||
extern mod std;
|
||||
use std::map;
|
||||
use std::map::HashMap;
|
||||
use std::map::Map;
|
||||
use std::map::StdMap;
|
||||
|
||||
// Test that trait types printed in error msgs include the type arguments.
|
||||
|
||||
fn main() {
|
||||
let x: Map<~str,~str> = map::HashMap::<~str,~str>() as Map::<~str,~str>;
|
||||
let y: Map<uint,~str> = x;
|
||||
//~^ ERROR mismatched types: expected `@std::map::Map<uint,~str>`
|
||||
let x: StdMap<~str,~str> = map::HashMap::<~str,~str>() as
|
||||
StdMap::<~str,~str>;
|
||||
let y: StdMap<uint,~str> = x;
|
||||
//~^ ERROR mismatched types: expected `@std::map::StdMap<uint,~str>`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,19 +128,16 @@ impl CLike : cmp::Eq {
|
|||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
#[deriving_eq]
|
||||
struct Spanned<T> {
|
||||
lo: uint,
|
||||
hi: uint,
|
||||
node: T,
|
||||
}
|
||||
|
||||
impl<T:cmp::Eq> Spanned<T> : cmp::Eq {
|
||||
pure fn eq(&self, other: &Spanned<T>) -> bool {
|
||||
self.lo == other.lo &&
|
||||
self.hi == other.hi &&
|
||||
self.node == other.node
|
||||
}
|
||||
pure fn ne(&self, other: &Spanned<T>) -> bool { !self.eq(other) }
|
||||
enum AnEnum {
|
||||
AVariant,
|
||||
AnotherVariant
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl<T: Copy> cat<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Copy> cat<T> : Map<int, T> {
|
||||
impl<T: Copy> cat<T> : StdMap<int, T> {
|
||||
pure fn size() -> uint { self.meows as uint }
|
||||
fn insert(+k: int, +_v: T) -> bool {
|
||||
self.meows += k;
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
// 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.
|
||||
//
|
||||
// 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.
|
||||
|
||||
// xfail-fast (aux-build)
|
||||
// aux-build:issue_2242_a.rs
|
||||
// aux-build:issue_2242_b.rs
|
||||
// aux-build:issue_2242_c.rs
|
||||
|
||||
extern mod a;
|
||||
extern mod b;
|
||||
extern mod c;
|
||||
|
||||
use a::to_strz;
|
||||
|
||||
fn main() {
|
||||
io::println((~"foo").to_strz());
|
||||
io::println(1.to_strz());
|
||||
io::println(true.to_strz());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue