Skip to content

Commit 083497c

Browse files
committed
---
yaml --- r: 175787 b: refs/heads/auto c: f72b164 h: refs/heads/master i: 175785: 74d12ed 175783: 3238e7e v: v3
1 parent 4eca2ee commit 083497c

29 files changed

+403
-411
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: a637365b10c175e23af40171af1724d5474cb303
13+
refs/heads/auto: f72b1645103e12b581f7022b893c37b5fe41aef7
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,7 @@ pub fn type_is_scalar(ty: Ty) -> bool {
31263126
ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
31273127
ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
31283128
ty_bare_fn(..) | ty_ptr(_) => true,
3129+
ty_tup(ref tys) if tys.is_empty() => true,
31293130
_ => false
31303131
}
31313132
}

branches/auto/src/librustc_typeck/check/mod.rs

Lines changed: 86 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -990,65 +990,86 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
990990
}
991991
}
992992

993-
fn report_cast_to_unsized_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
994-
span: Span,
995-
t_span: Span,
996-
e_span: Span,
997-
t_1: Ty<'tcx>,
998-
t_e: Ty<'tcx>,
999-
id: ast::NodeId) {
1000-
let tstr = fcx.infcx().ty_to_string(t_1);
1001-
fcx.type_error_message(span, |actual| {
1002-
format!("cast to unsized type: `{}` as `{}`", actual, tstr)
1003-
}, t_e, None);
1004-
match t_e.sty {
1005-
ty::ty_rptr(_, ty::mt { mutbl: mt, .. }) => {
1006-
let mtstr = match mt {
1007-
ast::MutMutable => "mut ",
1008-
ast::MutImmutable => ""
1009-
};
1010-
if ty::type_is_trait(t_1) {
1011-
span_help!(fcx.tcx().sess, t_span, "did you mean `&{}{}`?", mtstr, tstr);
1012-
} else {
1013-
span_help!(fcx.tcx().sess, span,
1014-
"consider using an implicit coercion to `&{}{}` instead",
1015-
mtstr, tstr);
993+
fn check_cast(fcx: &FnCtxt,
994+
cast_expr: &ast::Expr,
995+
e: &ast::Expr,
996+
t: &ast::Ty) {
997+
let id = cast_expr.id;
998+
let span = cast_expr.span;
999+
1000+
// Find the type of `e`. Supply hints based on the type we are casting to,
1001+
// if appropriate.
1002+
let t_1 = fcx.to_ty(t);
1003+
let t_1 = structurally_resolved_type(fcx, span, t_1);
1004+
1005+
check_expr_with_expectation(fcx, e, ExpectCastableToType(t_1));
1006+
1007+
let t_e = fcx.expr_ty(e);
1008+
1009+
debug!("t_1={}", fcx.infcx().ty_to_string(t_1));
1010+
debug!("t_e={}", fcx.infcx().ty_to_string(t_e));
1011+
1012+
if ty::type_is_error(t_e) {
1013+
fcx.write_error(id);
1014+
return
1015+
}
1016+
1017+
if !fcx.type_is_known_to_be_sized(t_1, cast_expr.span) {
1018+
let tstr = fcx.infcx().ty_to_string(t_1);
1019+
fcx.type_error_message(span, |actual| {
1020+
format!("cast to unsized type: `{}` as `{}`", actual, tstr)
1021+
}, t_e, None);
1022+
match t_e.sty {
1023+
ty::ty_rptr(_, ty::mt { mutbl: mt, .. }) => {
1024+
let mtstr = match mt {
1025+
ast::MutMutable => "mut ",
1026+
ast::MutImmutable => ""
1027+
};
1028+
if ty::type_is_trait(t_1) {
1029+
span_help!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr);
1030+
} else {
1031+
span_help!(fcx.tcx().sess, span,
1032+
"consider using an implicit coercion to `&{}{}` instead",
1033+
mtstr, tstr);
1034+
}
1035+
}
1036+
ty::ty_uniq(..) => {
1037+
span_help!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr);
1038+
}
1039+
_ => {
1040+
span_help!(fcx.tcx().sess, e.span,
1041+
"consider using a box or reference as appropriate");
10161042
}
10171043
}
1018-
ty::ty_uniq(..) => {
1019-
span_help!(fcx.tcx().sess, t_span, "did you mean `Box<{}>`?", tstr);
1020-
}
1021-
_ => {
1022-
span_help!(fcx.tcx().sess, e_span,
1023-
"consider using a box or reference as appropriate");
1024-
}
1044+
fcx.write_error(id);
1045+
return
10251046
}
1026-
fcx.write_error(id);
1027-
}
10281047

1048+
if ty::type_is_trait(t_1) {
1049+
// This will be looked up later on.
1050+
vtable::check_object_cast(fcx, cast_expr, e, t_1);
1051+
fcx.write_ty(id, t_1);
1052+
return
1053+
}
10291054

1030-
fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
1031-
span: Span,
1032-
t_1: Ty<'tcx>,
1033-
t_e: Ty<'tcx>,
1034-
e: &ast::Expr) {
1035-
fn cast_through_integer_err<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
1036-
span: Span,
1037-
t_1: Ty<'tcx>,
1038-
t_e: Ty<'tcx>) {
1055+
let t_1 = structurally_resolved_type(fcx, span, t_1);
1056+
let t_e = structurally_resolved_type(fcx, span, t_e);
1057+
1058+
if ty::type_is_nil(t_e) {
10391059
fcx.type_error_message(span, |actual| {
1040-
format!("illegal cast; cast through an \
1041-
integer first: `{}` as `{}`",
1060+
format!("cast from nil: `{}` as `{}`",
1061+
actual,
1062+
fcx.infcx().ty_to_string(t_1))
1063+
}, t_e, None);
1064+
} else if ty::type_is_nil(t_1) {
1065+
fcx.type_error_message(span, |actual| {
1066+
format!("cast to nil: `{}` as `{}`",
10421067
actual,
10431068
fcx.infcx().ty_to_string(t_1))
10441069
}, t_e, None);
10451070
}
10461071

10471072
let t_e_is_bare_fn_item = ty::type_is_bare_fn_item(t_e);
1048-
let t_e_is_scalar = ty::type_is_scalar(t_e);
1049-
let t_e_is_integral = ty::type_is_integral(t_e);
1050-
let t_e_is_float = ty::type_is_floating_point(t_e);
1051-
let t_e_is_c_enum = ty::type_is_c_like_enum(fcx.tcx(), t_e);
10521073

10531074
let t_1_is_scalar = ty::type_is_scalar(t_1);
10541075
let t_1_is_char = ty::type_is_char(t_1);
@@ -1057,9 +1078,18 @@ fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
10571078

10581079
// casts to scalars other than `char` and `bare fn` are trivial
10591080
let t_1_is_trivial = t_1_is_scalar && !t_1_is_char && !t_1_is_bare_fn;
1060-
10611081
if t_e_is_bare_fn_item && t_1_is_bare_fn {
10621082
demand::coerce(fcx, e.span, t_1, &*e);
1083+
} else if ty::type_is_c_like_enum(fcx.tcx(), t_e) && t_1_is_trivial {
1084+
if t_1_is_float || ty::type_is_unsafe_ptr(t_1) {
1085+
fcx.type_error_message(span, |actual| {
1086+
format!("illegal cast; cast through an \
1087+
integer first: `{}` as `{}`",
1088+
actual,
1089+
fcx.infcx().ty_to_string(t_1))
1090+
}, t_e, None);
1091+
}
1092+
// casts from C-like enums are allowed
10631093
} else if t_1_is_char {
10641094
let t_e = fcx.infcx().shallow_resolve(t_e);
10651095
if t_e.sty != ty::ty_uint(ast::TyU8) {
@@ -1071,16 +1101,6 @@ fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
10711101
} else if t_1.sty == ty::ty_bool {
10721102
span_err!(fcx.tcx().sess, span, E0054,
10731103
"cannot cast as `bool`, compare with zero instead");
1074-
} else if t_1_is_float && (t_e_is_scalar || t_e_is_c_enum) && !(
1075-
t_e_is_integral || t_e_is_float || t_e.sty == ty::ty_bool) {
1076-
// Casts to float must go through an integer or boolean
1077-
cast_through_integer_err(fcx, span, t_1, t_e)
1078-
} else if t_e_is_c_enum && t_1_is_trivial {
1079-
if ty::type_is_unsafe_ptr(t_1) {
1080-
// ... and likewise with C enum -> *T
1081-
cast_through_integer_err(fcx, span, t_1, t_e)
1082-
}
1083-
// casts from C-like enums are allowed
10841104
} else if ty::type_is_region_ptr(t_e) && ty::type_is_unsafe_ptr(t_1) {
10851105
fn types_compatible<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
10861106
t1: Ty<'tcx>, t2: Ty<'tcx>) -> bool {
@@ -1122,7 +1142,7 @@ fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
11221142
demand::coerce(fcx, e.span, t_1, &*e);
11231143
}
11241144
}
1125-
} else if !(t_e_is_scalar && t_1_is_trivial) {
1145+
} else if !(ty::type_is_scalar(t_e) && t_1_is_trivial) {
11261146
/*
11271147
If more type combinations should be supported than are
11281148
supported here, then file an enhancement issue and
@@ -1133,49 +1153,15 @@ fn check_cast_inner<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
11331153
actual,
11341154
fcx.infcx().ty_to_string(t_1))
11351155
}, t_e, None);
1156+
} else if ty::type_is_unsafe_ptr(t_e) && t_1_is_float {
1157+
fcx.type_error_message(span, |actual| {
1158+
format!("cannot cast from pointer to float directly: `{}` as `{}`; cast through an \
1159+
integer first",
1160+
actual,
1161+
fcx.infcx().ty_to_string(t_1))
1162+
}, t_e, None);
11361163
}
1137-
}
1138-
1139-
fn check_cast(fcx: &FnCtxt,
1140-
cast_expr: &ast::Expr,
1141-
e: &ast::Expr,
1142-
t: &ast::Ty) {
1143-
let id = cast_expr.id;
1144-
let span = cast_expr.span;
1145-
1146-
// Find the type of `e`. Supply hints based on the type we are casting to,
1147-
// if appropriate.
1148-
let t_1 = fcx.to_ty(t);
1149-
let t_1 = structurally_resolved_type(fcx, span, t_1);
1150-
1151-
check_expr_with_expectation(fcx, e, ExpectCastableToType(t_1));
1152-
1153-
let t_e = fcx.expr_ty(e);
1154-
1155-
debug!("t_1={}", fcx.infcx().ty_to_string(t_1));
1156-
debug!("t_e={}", fcx.infcx().ty_to_string(t_e));
1157-
1158-
if ty::type_is_error(t_e) {
1159-
fcx.write_error(id);
1160-
return
1161-
}
1162-
1163-
if !fcx.type_is_known_to_be_sized(t_1, cast_expr.span) {
1164-
report_cast_to_unsized_type(fcx, span, t.span, e.span, t_1, t_e, id);
1165-
return
1166-
}
1167-
1168-
if ty::type_is_trait(t_1) {
1169-
// This will be looked up later on.
1170-
vtable::check_object_cast(fcx, cast_expr, e, t_1);
1171-
fcx.write_ty(id, t_1);
1172-
return
1173-
}
1174-
1175-
let t_1 = structurally_resolved_type(fcx, span, t_1);
1176-
let t_e = structurally_resolved_type(fcx, span, t_e);
11771164

1178-
check_cast_inner(fcx, span, t_1, t_e, e);
11791165
fcx.write_ty(id, t_1);
11801166
}
11811167

branches/auto/src/libstd/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
//! memory types, including [`atomic`](sync/atomic/index.html).
8080
//!
8181
//! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets,
82-
//! timers, and process spawning, are defined in the [`io`](io/index.html) module.
82+
//! timers, and process spawning, are defined in the
83+
//! [`old_io`](old_io/index.html) module.
8384
//!
8485
//! Rust's I/O and concurrency depends on a small runtime interface
8586
//! that lives, along with its support code, in mod [`rt`](rt/index.html).
@@ -239,7 +240,7 @@ pub mod thread_local;
239240
pub mod dynamic_lib;
240241
pub mod ffi;
241242
pub mod fmt;
242-
pub mod io;
243+
pub mod old_io;
243244
pub mod os;
244245
pub mod path;
245246
pub mod rand;
@@ -284,7 +285,7 @@ mod std {
284285
pub use sync; // used for select!()
285286
pub use error; // used for try!()
286287
pub use fmt; // used for any formatting strings
287-
pub use io; // used for println!()
288+
pub use old_io; // used for println!()
288289
pub use option; // used for bitflags!{}
289290
pub use rt; // used for panic!()
290291
pub use vec; // used for vec![]

branches/auto/src/libstd/io/buffered.rs renamed to branches/auto/src/libstd/old_io/buffered.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use cmp;
1616
use fmt;
17-
use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
17+
use old_io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
1818
use iter::{IteratorExt, ExactSizeIterator, repeat};
1919
use ops::Drop;
2020
use option::Option;
@@ -34,7 +34,7 @@ use vec::Vec;
3434
/// # Example
3535
///
3636
/// ```rust
37-
/// use std::io::{BufferedReader, File};
37+
/// use std::old_io::{BufferedReader, File};
3838
///
3939
/// let file = File::open(&Path::new("message.txt"));
4040
/// let mut reader = BufferedReader::new(file);
@@ -137,7 +137,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
137137
/// # Example
138138
///
139139
/// ```rust
140-
/// use std::io::{BufferedWriter, File};
140+
/// use std::old_io::{BufferedWriter, File};
141141
///
142142
/// let file = File::create(&Path::new("message.txt")).unwrap();
143143
/// let mut writer = BufferedWriter::new(file);
@@ -324,7 +324,7 @@ impl<W: Reader> Reader for InternalBufferedWriter<W> {
324324
///
325325
/// ```rust
326326
/// # #![allow(unused_must_use)]
327-
/// use std::io::{BufferedStream, File};
327+
/// use std::old_io::{BufferedStream, File};
328328
///
329329
/// let file = File::open(&Path::new("message.txt"));
330330
/// let mut stream = BufferedStream::new(file);
@@ -437,13 +437,13 @@ mod test {
437437
pub struct NullStream;
438438

439439
impl Reader for NullStream {
440-
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
441-
Err(io::standard_error(io::EndOfFile))
440+
fn read(&mut self, _: &mut [u8]) -> old_io::IoResult<uint> {
441+
Err(old_io::standard_error(old_io::EndOfFile))
442442
}
443443
}
444444

445445
impl Writer for NullStream {
446-
fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) }
446+
fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) }
447447
}
448448

449449
/// A dummy reader intended at testing short-reads propagation.
@@ -452,9 +452,9 @@ mod test {
452452
}
453453

454454
impl Reader for ShortReader {
455-
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
455+
fn read(&mut self, _: &mut [u8]) -> old_io::IoResult<uint> {
456456
if self.lengths.is_empty() {
457-
Err(io::standard_error(io::EndOfFile))
457+
Err(old_io::standard_error(old_io::EndOfFile))
458458
} else {
459459
Ok(self.lengths.remove(0))
460460
}
@@ -555,13 +555,13 @@ mod test {
555555
fn test_buffered_stream() {
556556
struct S;
557557

558-
impl io::Writer for S {
559-
fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) }
558+
impl old_io::Writer for S {
559+
fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) }
560560
}
561561

562-
impl io::Reader for S {
563-
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
564-
Err(io::standard_error(io::EndOfFile))
562+
impl old_io::Reader for S {
563+
fn read(&mut self, _: &mut [u8]) -> old_io::IoResult<uint> {
564+
Err(old_io::standard_error(old_io::EndOfFile))
565565
}
566566
}
567567

@@ -664,7 +664,7 @@ mod test {
664664

665665
impl Writer for FailFlushWriter {
666666
fn write(&mut self, _buf: &[u8]) -> IoResult<()> { Ok(()) }
667-
fn flush(&mut self) -> IoResult<()> { Err(io::standard_error(EndOfFile)) }
667+
fn flush(&mut self) -> IoResult<()> { Err(old_io::standard_error(EndOfFile)) }
668668
}
669669

670670
let writer = FailFlushWriter;

0 commit comments

Comments
 (0)