diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-03-20 17:15:27 +1300 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-03-25 10:03:57 +1300 |
| commit | 95602a759d9190cad92279aa5929d30166f2255c (patch) | |
| tree | a3f7026e046eda5326c70ba47c3c91c5b1e54a35 /src/libterm | |
| parent | ed810385045ab0db90303574ba3ea47dfa2a36d5 (diff) | |
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases. Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference. [breaking change] * Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed. * The unused casts lint has gone. * Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are: - You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_` - Casts do not influence inference of integer types. E.g., the following used to type check: ``` let x = 42; let y = &x as *const u32; ``` Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information: ``` let x: u32 = 42; let y = &x as *const u32; ```
Diffstat (limited to 'src/libterm')
| -rw-r--r-- | src/libterm/lib.rs | 12 | ||||
| -rw-r--r-- | src/libterm/terminfo/mod.rs | 4 | ||||
| -rw-r--r-- | src/libterm/terminfo/parser/compiled.rs | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c907b87bc3c..41e066cc94a 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -103,7 +103,7 @@ impl Write for WriterWrapper { /// opened. pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stdout() as Box<Write + Send>, + wrapped: box std::io::stdout(), }) } @@ -112,14 +112,14 @@ pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { /// opened. pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { let ti = TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stdout() as Box<Write + Send>, + wrapped: box std::io::stdout(), }); match ti { Some(t) => Some(t), None => { WinConsole::new(WriterWrapper { - wrapped: box std::io::stdout() as Box<Write + Send>, + wrapped: box std::io::stdout(), }) } } @@ -130,7 +130,7 @@ pub fn stdout() -> Option<Box<Terminal<WriterWrapper> + Send>> { /// opened. pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> { TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stderr() as Box<Write + Send>, + wrapped: box std::io::stderr(), }) } @@ -139,14 +139,14 @@ pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> { /// opened. pub fn stderr() -> Option<Box<Terminal<WriterWrapper> + Send>> { let ti = TerminfoTerminal::new(WriterWrapper { - wrapped: box std::io::stderr() as Box<Write + Send>, + wrapped: box std::io::stderr(), }); match ti { Some(t) => Some(t), None => { WinConsole::new(WriterWrapper { - wrapped: box std::io::stderr() as Box<Write + Send>, + wrapped: box std::io::stderr(), }) } } diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index 309320b52ff..1d6657d5932 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -190,7 +190,7 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> { out: out, ti: msys_terminfo(), num_colors: 8, - } as Box<Terminal<T>+Send>) + }) }, _ => { debug!("error finding terminfo entry: {:?}", err); @@ -213,7 +213,7 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> { return Some(box TerminfoTerminal {out: out, ti: inf, - num_colors: nc} as Box<Terminal<T>+Send>); + num_colors: nc}); } fn dim_if_necessary(&self, color: color::Color) -> color::Color { diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index cc9a2880b5d..8d0a9e6e971 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -186,7 +186,7 @@ pub fn parse(file: &mut Read, longnames: bool) let magic = try!(read_le_u16(file)); if magic != 0x011A { return Err(format!("invalid magic number: expected {:x}, found {:x}", - 0x011A as usize, magic as usize)); + 0x011A_usize, magic as usize)); } let names_bytes = try!(read_le_u16(file)) as int; |
