Skip to content

Commit eb4d39e

Browse files
committed
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.
1 parent f1e78c6 commit eb4d39e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+704
-837
lines changed

src/libcore/gc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ with destructors.
4242
#[allow(structural_records)];
4343

4444
use cast;
45+
use container::{Container, Mutable, Map, Set};
4546
use io;
4647
use libc::{size_t, uintptr_t};
4748
use option::{None, Option, Some};

src/libcore/hashmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
use cmp::Eq;
1818
use hash::Hash;
19-
use prelude::*;
2019
use to_bytes::IterBytes;
2120

2221
/// Open addressing with linear probing.
@@ -464,6 +463,7 @@ pub mod linear {
464463

465464
#[test]
466465
pub mod test {
466+
use container::{Container, Mutable, Map, Set};
467467
use option::{None, Some};
468468
use hashmap::linear::LinearMap;
469469
use hashmap::linear;

src/libcore/num.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ pub trait Num {
2323
static pure fn from_int(n: int) -> self;
2424
}
2525

26+
pub trait IntConvertible {
27+
pure fn to_int(&self) -> int;
28+
static pure fn from_int(n: int) -> self;
29+
}
30+
2631
pub trait Zero {
2732
static pure fn zero() -> self;
2833
}

src/libcore/pipes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ use either::{Either, Left, Right};
9696
use kinds::Owned;
9797
use libc;
9898
use option;
99-
use option::unwrap;
99+
use option::{None, Option, Some, unwrap};
100100
use pipes;
101101
use ptr;
102-
use prelude::*;
103102
use private;
104103
use task;
105104
use vec;

src/libcore/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
3535
pub use vec::{OwnedVector, OwnedCopyableVector};
3636
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
3737
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
38+
pub use container::{Container, Mutable, Map, Set};
39+
pub use pipes::{GenericChan, GenericPort};
3840

3941
pub use num::Num;
4042
pub use ptr::Ptr;

src/libcore/private/weak_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use option::{Some, None, swap_unwrap};
2222
use private::at_exit::at_exit;
2323
use private::global::global_data_clone_create;
2424
use private::finally::Finally;
25-
use pipes::{Port, Chan, SharedChan, stream};
25+
use pipes::{Port, Chan, SharedChan, GenericSmartChan, stream};
2626
use task::{Task, task, spawn};
2727
use task::rt::{task_id, get_task_id};
2828
use hashmap::linear::LinearMap;

src/libcore/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use iter;
4545
use libc;
4646
use option;
4747
use result::Result;
48-
use pipes::{stream, Chan, Port, SharedChan};
48+
use pipes::{stream, Chan, GenericChan, GenericPort, Port, SharedChan};
4949
use pipes;
5050
use prelude::*;
5151
use ptr;

src/libcore/task/spawn.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@
7474
#[warn(deprecated_mode)];
7575

7676
use cast;
77+
use container::Map;
78+
use oldcomm;
7779
use option;
78-
use pipes::{stream, Chan, Port};
80+
use pipes::{Chan, GenericChan, GenericPort, Port};
7981
use pipes;
8082
use prelude::*;
8183
use private;

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use core::to_bytes::IterBytes;
3737
use core::uint;
3838
use core::vec;
3939
use std::map::HashMap;
40+
use std::serialize::Encodable;
4041
use std::{ebml, map};
4142
use std;
4243
use syntax::ast::*;

src/librustc/metadata/tydecode.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
use core::prelude::*;
1818

1919
use middle::ty;
20-
use middle::ty::{FnTyBase, FnMeta, FnSig};
20+
use middle::ty::{FnTyBase, FnMeta, FnSig, arg, creader_cache_key, field};
21+
use middle::ty::{substs};
2122

2223
use core::io;
2324
use core::str;
@@ -174,9 +175,11 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs {
174175
while peek(st) != ']' { params.push(parse_ty(st, conv)); }
175176
st.pos = st.pos + 1u;
176177

177-
return {self_r: self_r,
178-
self_ty: self_ty,
179-
tps: params};
178+
return substs {
179+
self_r: self_r,
180+
self_ty: self_ty,
181+
tps: params
182+
};
180183
}
181184

182185
fn parse_bound_region(st: @pstate) -> ty::bound_region {
@@ -308,7 +311,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
308311
let mut fields: ~[ty::field] = ~[];
309312
while peek(st) != ']' {
310313
let name = st.tcx.sess.ident_of(parse_str(st, '='));
311-
fields.push({ident: name, mt: parse_mt(st, conv)});
314+
fields.push(ty::field { ident: name, mt: parse_mt(st, conv) });
312315
}
313316
st.pos = st.pos + 1u;
314317
return ty::mk_rec(st.tcx, fields);
@@ -333,12 +336,13 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
333336
assert (next(st) == ':');
334337
let len = parse_hex(st);
335338
assert (next(st) == '#');
336-
match st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
339+
let key = creader_cache_key { cnum: st.crate, pos: pos, len: len };
340+
match st.tcx.rcache.find(key) {
337341
Some(tt) => return tt,
338342
None => {
339343
let ps = @{pos: pos ,.. copy *st};
340344
let tt = parse_ty(ps, conv);
341-
st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
345+
st.tcx.rcache.insert(key, tt);
342346
return tt;
343347
}
344348
}
@@ -421,8 +425,7 @@ fn parse_onceness(c: char) -> ast::Onceness {
421425
}
422426

423427
fn parse_arg(st: @pstate, conv: conv_did) -> ty::arg {
424-
{mode: parse_mode(st),
425-
ty: parse_ty(st, conv)}
428+
ty::arg { mode: parse_mode(st), ty: parse_ty(st, conv) }
426429
}
427430

428431
fn parse_mode(st: @pstate) -> ast::mode {
@@ -446,7 +449,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
446449
let mut inputs: ~[ty::arg] = ~[];
447450
while peek(st) != ']' {
448451
let mode = parse_mode(st);
449-
inputs.push({mode: mode, ty: parse_ty(st, conv)});
452+
inputs.push(ty::arg { mode: mode, ty: parse_ty(st, conv) });
450453
}
451454
st.pos += 1u; // eat the ']'
452455
let ret_ty = parse_ty(st, conv);

0 commit comments

Comments
 (0)