Skip to content

Commit 6d5dc7c

Browse files
committed
---
yaml --- r: 113631 b: refs/heads/snap-stage3 c: ea87f12 h: refs/heads/master i: 113629: 4d4790d 113627: 77b130e 113623: 3997ec6 113615: da7626d 113599: 1899561 v: v3
1 parent 94c8b93 commit 6d5dc7c

File tree

12 files changed

+226
-70
lines changed

12 files changed

+226
-70
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: abdacecdf86b4b5a4f432560445a24e1c5f4751b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: bcabcf53cfe2a86ebf02aa762b8ab7278060ce10
4+
refs/heads/snap-stage3: ea87f126bdf8de4acc4f74c14ac0ae10d95a2472
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/fmt/mod.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,44 @@ pub mod rt;
4343

4444
pub type Result = result::Result<(), FormatError>;
4545

46-
/// dox
46+
/// The error type which is returned from formatting a message into a stream.
47+
///
48+
/// This type does not support transmission of an error other than that an error
49+
/// occurred. Any extra information must be arranged to be transmitted through
50+
/// some other means.
4751
pub enum FormatError {
48-
/// dox
52+
/// A generic write error occurred during formatting, no other information
53+
/// is transmitted via this variant.
4954
WriteError,
5055
}
5156

52-
/// dox
57+
/// A collection of methods that are required to format a message into a stream.
58+
///
59+
/// This trait is the type which this modules requires when formatting
60+
/// information. This is similar to the standard library's `io::Writer` trait,
61+
/// but it is only intended for use in libcore.
62+
///
63+
/// This trait should generally not be implemented by consumers of the standard
64+
/// library. The `write!` macro accepts an instance of `io::Writer`, and the
65+
/// `io::Writer` trait is favored over implementing this trait.
5366
pub trait FormatWriter {
54-
/// dox
67+
/// Writes a slice of bytes into this writer, returning whether the write
68+
/// succeeded.
69+
///
70+
/// This method can only succeed if the entire byte slice was successfully
71+
/// written, and this method will not return until all data has been
72+
/// written or an error occurs.
73+
///
74+
/// # Errors
75+
///
76+
/// This function will return an instance of `FormatError` on error.
5577
fn write(&mut self, bytes: &[u8]) -> Result;
78+
79+
/// Glue for usage of the `write!` macro with implementors of this trait.
80+
///
81+
/// This method should generally not be invoked manually, but rather through
82+
/// the `write!` macro itself.
83+
fn write_fmt(&mut self, args: &Arguments) -> Result { write(self, args) }
5684
}
5785

5886
/// A struct to represent both where to emit formatting strings to and how they

branches/snap-stage3/src/libcore/prelude.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@
1010

1111
//! The core prelude
1212
//!
13-
//! For more information, see std::prelude.
13+
//! This module is intended for users of libcore which do not link to libstd as
14+
//! well. This module is not imported by default, but using the entire contents
15+
//! of this module will provide all of the useful traits and types in libcore
16+
//! that one would expect from the standard library as well.
17+
//!
18+
//! There is no method to automatically inject this prelude, and this prelude is
19+
//! a subset of the standard library's prelude.
20+
//!
21+
//! # Example
22+
//!
23+
//! ```ignore
24+
//! # fn main() {
25+
//! #![feature(globs)]
26+
//!
27+
//! use core::prelude::*;
28+
//! # }
29+
//! ```
1430
1531
// Reexported core operators
1632
pub use kinds::{Copy, Send, Sized, Share};

branches/snap-stage3/src/librustc/middle/trans/adt.rs

Lines changed: 103 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ pub enum Repr {
8585
* all start with a field for the discriminant.
8686
*/
8787
General(IntType, Vec<Struct>),
88+
/**
89+
* Two cases distinguished by a nullable pointer: the case with discriminant
90+
* `nndiscr` must have single field which is known to be nonnull due to its type.
91+
* The other case is known to be zero sized. Hence we represent the enum
92+
* as simply a nullable pointer: if not null it indicates the `nndiscr` variant,
93+
* otherwise it indicates the other case.
94+
*/
95+
RawNullablePointer {
96+
pub nndiscr: Disr,
97+
pub nnty: ty::t,
98+
pub nullfields: Vec<ty::t>
99+
},
88100
/**
89101
* Two cases distinguished by a nullable pointer: the case with discriminant
90102
* `nndiscr` is represented by the struct `nonnull`, where the `ptrfield`th
@@ -96,7 +108,7 @@ pub enum Repr {
96108
* is represented such that `None` is a null pointer and `Some` is the
97109
* identity function.
98110
*/
99-
NullablePointer {
111+
StructWrappedNullablePointer {
100112
pub nonnull: Struct,
101113
pub nndiscr: Disr,
102114
pub ptrfield: uint,
@@ -200,17 +212,23 @@ fn represent_type_uncached(cx: &CrateContext, t: ty::t) -> Repr {
200212
if cases.get(1 - discr).is_zerolen(cx) {
201213
match cases.get(discr).find_ptr() {
202214
Some(ptrfield) => {
203-
return NullablePointer {
204-
nndiscr: discr as u64,
205-
nonnull: mk_struct(cx,
206-
cases.get(discr)
207-
.tys
208-
.as_slice(),
209-
false),
210-
ptrfield: ptrfield,
211-
nullfields: cases.get(1 - discr).tys
212-
.clone()
213-
}
215+
let st = mk_struct(cx, cases.get(discr).tys.as_slice(),
216+
false);
217+
218+
return if st.fields.len() == 1 {
219+
RawNullablePointer {
220+
nndiscr: discr as Disr,
221+
nnty: *st.fields.get(0),
222+
nullfields: cases.get(1 - discr).tys.clone()
223+
}
224+
} else {
225+
StructWrappedNullablePointer {
226+
nndiscr: discr as Disr,
227+
nonnull: st,
228+
ptrfield: ptrfield,
229+
nullfields: cases.get(1 - discr).tys.clone()
230+
}
231+
};
214232
}
215233
None => { }
216234
}
@@ -413,8 +431,8 @@ pub fn incomplete_type_of(cx: &CrateContext, r: &Repr, name: &str) -> Type {
413431
}
414432
pub fn finish_type_of(cx: &CrateContext, r: &Repr, llty: &mut Type) {
415433
match *r {
416-
CEnum(..) | General(..) => { }
417-
Univariant(ref st, _) | NullablePointer{ nonnull: ref st, .. } =>
434+
CEnum(..) | General(..) | RawNullablePointer { .. } => { }
435+
Univariant(ref st, _) | StructWrappedNullablePointer { nonnull: ref st, .. } =>
418436
llty.set_struct_body(struct_llfields(cx, st, false).as_slice(),
419437
st.packed)
420438
}
@@ -423,7 +441,8 @@ pub fn finish_type_of(cx: &CrateContext, r: &Repr, llty: &mut Type) {
423441
fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool) -> Type {
424442
match *r {
425443
CEnum(ity, _, _) => ll_inttype(cx, ity),
426-
Univariant(ref st, _) | NullablePointer{ nonnull: ref st, .. } => {
444+
RawNullablePointer { nnty, .. } => type_of::sizing_type_of(cx, nnty),
445+
Univariant(ref st, _) | StructWrappedNullablePointer { nonnull: ref st, .. } => {
427446
match name {
428447
None => {
429448
Type::struct_(cx, struct_llfields(cx, st, sizing).as_slice(),
@@ -495,12 +514,10 @@ fn struct_llfields(cx: &CrateContext, st: &Struct, sizing: bool) -> Vec<Type> {
495514
pub fn trans_switch(bcx: &Block, r: &Repr, scrutinee: ValueRef)
496515
-> (_match::branch_kind, Option<ValueRef>) {
497516
match *r {
498-
CEnum(..) | General(..) => {
517+
CEnum(..) | General(..) |
518+
RawNullablePointer { .. } | StructWrappedNullablePointer { .. } => {
499519
(_match::switch, Some(trans_get_discr(bcx, r, scrutinee, None)))
500520
}
501-
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
502-
(_match::switch, Some(nullable_bitdiscr(bcx, nonnull, nndiscr, ptrfield, scrutinee)))
503-
}
504521
Univariant(..) => {
505522
(_match::single, None)
506523
}
@@ -528,8 +545,14 @@ pub fn trans_get_discr(bcx: &Block, r: &Repr, scrutinee: ValueRef, cast_to: Opti
528545
val = C_u8(bcx.ccx(), 0);
529546
signed = false;
530547
}
531-
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
532-
val = nullable_bitdiscr(bcx, nonnull, nndiscr, ptrfield, scrutinee);
548+
RawNullablePointer { nndiscr, nnty, .. } => {
549+
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
550+
let llptrty = type_of::sizing_type_of(bcx.ccx(), nnty);
551+
val = ICmp(bcx, cmp, Load(bcx, scrutinee), C_null(llptrty));
552+
signed = false;
553+
}
554+
StructWrappedNullablePointer { nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
555+
val = struct_wrapped_nullable_bitdiscr(bcx, nonnull, nndiscr, ptrfield, scrutinee);
533556
signed = false;
534557
}
535558
}
@@ -539,10 +562,10 @@ pub fn trans_get_discr(bcx: &Block, r: &Repr, scrutinee: ValueRef, cast_to: Opti
539562
}
540563
}
541564

542-
fn nullable_bitdiscr(bcx: &Block, nonnull: &Struct, nndiscr: Disr, ptrfield: uint,
543-
scrutinee: ValueRef) -> ValueRef {
544-
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
565+
fn struct_wrapped_nullable_bitdiscr(bcx: &Block, nonnull: &Struct, nndiscr: Disr, ptrfield: uint,
566+
scrutinee: ValueRef) -> ValueRef {
545567
let llptr = Load(bcx, GEPi(bcx, scrutinee, [0, ptrfield]));
568+
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
546569
let llptrty = type_of::type_of(bcx.ccx(), *nonnull.fields.get(ptrfield));
547570
ICmp(bcx, cmp, llptr, C_null(llptrty))
548571
}
@@ -590,7 +613,8 @@ pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr)
590613
Univariant(..) => {
591614
bcx.ccx().sess().bug("no cases for univariants or structs")
592615
}
593-
NullablePointer{ .. } => {
616+
RawNullablePointer { .. } |
617+
StructWrappedNullablePointer { .. } => {
594618
assert!(discr == 0 || discr == 1);
595619
_match::single_result(Result::new(bcx, C_i1(bcx.ccx(), discr != 0)))
596620
}
@@ -621,7 +645,13 @@ pub fn trans_start_init(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr) {
621645
Univariant(..) => {
622646
assert_eq!(discr, 0);
623647
}
624-
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
648+
RawNullablePointer { nndiscr, nnty, ..} => {
649+
if discr != nndiscr {
650+
let llptrty = type_of::sizing_type_of(bcx.ccx(), nnty);
651+
Store(bcx, C_null(llptrty), val)
652+
}
653+
}
654+
StructWrappedNullablePointer { nonnull: ref nonnull, nndiscr, ptrfield, .. } => {
625655
if discr != nndiscr {
626656
let llptrptr = GEPi(bcx, val, [0, ptrfield]);
627657
let llptrty = type_of::type_of(bcx.ccx(),
@@ -651,8 +681,11 @@ pub fn num_args(r: &Repr, discr: Disr) -> uint {
651681
st.fields.len() - (if dtor { 1 } else { 0 })
652682
}
653683
General(_, ref cases) => cases.get(discr as uint).fields.len() - 1,
654-
NullablePointer{ nonnull: ref nonnull, nndiscr,
655-
nullfields: ref nullfields, .. } => {
684+
RawNullablePointer { nndiscr, ref nullfields, .. } => {
685+
if discr == nndiscr { 1 } else { nullfields.len() }
686+
}
687+
StructWrappedNullablePointer { nonnull: ref nonnull, nndiscr,
688+
nullfields: ref nullfields, .. } => {
656689
if discr == nndiscr { nonnull.fields.len() } else { nullfields.len() }
657690
}
658691
}
@@ -675,19 +708,25 @@ pub fn trans_field_ptr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr,
675708
General(_, ref cases) => {
676709
struct_field_ptr(bcx, cases.get(discr as uint), val, ix + 1, true)
677710
}
678-
NullablePointer{ nonnull: ref nonnull, nullfields: ref nullfields,
679-
nndiscr, .. } => {
680-
if discr == nndiscr {
681-
struct_field_ptr(bcx, nonnull, val, ix, false)
682-
} else {
683-
// The unit-like case might have a nonzero number of unit-like fields.
684-
// (e.g., Result or Either with () as one side.)
685-
let ty = type_of::type_of(bcx.ccx(), *nullfields.get(ix));
686-
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
687-
// The contents of memory at this pointer can't matter, but use
688-
// the value that's "reasonable" in case of pointer comparison.
689-
PointerCast(bcx, val, ty.ptr_to())
690-
}
711+
RawNullablePointer { nndiscr, ref nullfields, .. } |
712+
StructWrappedNullablePointer { nndiscr, ref nullfields, .. } if discr != nndiscr => {
713+
// The unit-like case might have a nonzero number of unit-like fields.
714+
// (e.d., Result of Either with (), as one side.)
715+
let ty = type_of::type_of(bcx.ccx(), *nullfields.get(ix));
716+
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
717+
// The contents of memory at this pointer can't matter, but use
718+
// the value that's "reasonable" in case of pointer comparision.
719+
PointerCast(bcx, val, ty.ptr_to())
720+
}
721+
RawNullablePointer { nndiscr, nnty, .. } => {
722+
assert_eq!(ix, 0);
723+
assert_eq!(discr, nndiscr);
724+
let ty = type_of::type_of(bcx.ccx(), nnty);
725+
PointerCast(bcx, val, ty.ptr_to())
726+
}
727+
StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
728+
assert_eq!(discr, nndiscr);
729+
struct_field_ptr(bcx, nonnull, val, ix, false)
691730
}
692731
}
693732
}
@@ -759,7 +798,15 @@ pub fn trans_const(ccx: &CrateContext, r: &Repr, discr: Disr,
759798
let contents = build_const_struct(ccx, st, vals);
760799
C_struct(ccx, contents.as_slice(), st.packed)
761800
}
762-
NullablePointer{ nonnull: ref nonnull, nndiscr, .. } => {
801+
RawNullablePointer { nndiscr, nnty, .. } => {
802+
if discr == nndiscr {
803+
assert_eq!(vals.len(), 1);
804+
vals[0]
805+
} else {
806+
C_null(type_of::sizing_type_of(ccx, nnty))
807+
}
808+
}
809+
StructWrappedNullablePointer { nonnull: ref nonnull, nndiscr, .. } => {
763810
if discr == nndiscr {
764811
C_struct(ccx, build_const_struct(ccx,
765812
nonnull,
@@ -867,7 +914,15 @@ pub fn const_get_discrim(ccx: &CrateContext, r: &Repr, val: ValueRef)
867914
}
868915
}
869916
Univariant(..) => 0,
870-
NullablePointer{ nndiscr, ptrfield, .. } => {
917+
RawNullablePointer { nndiscr, .. } => {
918+
if is_null(val) {
919+
/* subtraction as uint is ok because nndiscr is either 0 or 1 */
920+
(1 - nndiscr) as Disr
921+
} else {
922+
nndiscr
923+
}
924+
}
925+
StructWrappedNullablePointer { nndiscr, ptrfield, .. } => {
871926
if is_null(const_struct_field(ccx, val, ptrfield)) {
872927
/* subtraction as uint is ok because nndiscr is either 0 or 1 */
873928
(1 - nndiscr) as Disr
@@ -891,7 +946,11 @@ pub fn const_get_field(ccx: &CrateContext, r: &Repr, val: ValueRef,
891946
CEnum(..) => ccx.sess().bug("element access in C-like enum const"),
892947
Univariant(..) => const_struct_field(ccx, val, ix),
893948
General(..) => const_struct_field(ccx, val, ix + 1),
894-
NullablePointer{ .. } => const_struct_field(ccx, val, ix)
949+
RawNullablePointer { .. } => {
950+
assert_eq!(ix, 0);
951+
val
952+
}
953+
StructWrappedNullablePointer{ .. } => const_struct_field(ccx, val, ix)
895954
}
896955
}
897956

branches/snap-stage3/src/librustc/middle/trans/debuginfo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,10 @@ fn prepare_enum_metadata(cx: &CrateContext,
16751675
}),
16761676
}
16771677
}
1678-
adt::NullablePointer { nonnull: ref struct_def, nndiscr, .. } => {
1678+
adt::RawNullablePointer { nnty, .. } => {
1679+
FinalMetadata(type_metadata(cx, nnty, span))
1680+
}
1681+
adt::StructWrappedNullablePointer { nonnull: ref struct_def, nndiscr, .. } => {
16791682
let (metadata_stub,
16801683
variant_llvm_type,
16811684
member_description_factory) =

branches/snap-stage3/src/librustc/middle/typeck/astconv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
653653
tcx.sess.span_err(
654654
ast_ty.span,
655655
format!("reference to trait `{name}` where a type is expected; \
656-
try `~{name}` or `&{name}`", name=path_str));
656+
try `Box<{name}>` or `&{name}`", name=path_str));
657657
ty::mk_err()
658658
}
659659
ast::DefTy(did) | ast::DefStruct(did) => {

branches/snap-stage3/src/test/compile-fail/issue-5883.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
trait A {}
1212

1313
struct Struct {
14-
r: A //~ ERROR reference to trait `A` where a type is expected; try `~A` or `&A`
14+
r: A //~ ERROR reference to trait `A` where a type is expected; try `Box<A>` or `&A`
1515
}
1616

1717
fn new_struct(r: A) -> Struct {
18-
//~^ ERROR reference to trait `A` where a type is expected; try `~A` or `&A`
18+
//~^ ERROR reference to trait `A` where a type is expected; try `Box<A>` or `&A`
1919
Struct { r: r }
2020
}
2121

2222
trait Curve {}
2323
enum E {X(Curve)}
24-
//~^ ERROR reference to trait `Curve` where a type is expected; try `~Curve` or `&Curve`
24+
//~^ ERROR reference to trait `Curve` where a type is expected; try `Box<Curve>` or `&Curve`
2525
fn main() {}

branches/snap-stage3/src/test/compile-fail/trait-bounds-not-on-bare-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Foo {
1414
// This should emit the less confusing error, not the more confusing one.
1515

1616
fn foo(_x: Foo:Send) {
17-
//~^ERROR reference to trait `Foo` where a type is expected; try `~Foo` or `&Foo`
17+
//~^ERROR reference to trait `Foo` where a type is expected; try `Box<Foo>` or `&Foo`
1818
}
1919

2020
fn main() { }

0 commit comments

Comments
 (0)