auto merge of #20189 : cmr/rust/i32-fallback, r=nikomatsakis
Doesn't yet converge on a fixed point, but generally works. A better algorithm will come with the implementation of default type parameter fallback. If inference fails to determine an exact integral or floating point type, it will set the type to i32 or f64, respectively. Closes #16968
This commit is contained in:
commit
ee3c5957ea
14 changed files with 57 additions and 54 deletions
|
|
@ -8,8 +8,9 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:type annotations required
|
||||
fn main() {
|
||||
panic!(
|
||||
1.2 //~ ERROR cannot determine a type for this expression
|
||||
std::default::Default::default()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ where T : Convert<U>
|
|||
}
|
||||
|
||||
fn a() {
|
||||
test(22_i32, 44); //~ ERROR type annotations required
|
||||
test(22_i32, std::default::Default::default()); //~ ERROR type annotations required
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:explicit panic
|
||||
|
||||
fn foo<T>(t: T) {}
|
||||
fn main() { foo(panic!()) }
|
||||
//~^ ERROR type annotations required
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
fn foo(_: *const ()) {}
|
||||
|
||||
fn main() {
|
||||
let a = 3; //~ ERROR cannot determine a type for this local variable
|
||||
let a = 3;
|
||||
foo(&a as *const _ as *const ());
|
||||
}
|
||||
|
||||
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
fn main() {
|
||||
println!("{}", std::mem::size_of_val(&1));
|
||||
//~^ ERROR cannot determine a type for this expression
|
||||
}
|
||||
|
||||
|
|
@ -9,8 +9,5 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
panic!(
|
||||
1.2
|
||||
//~^ ERROR cannot determine the type of this number; add a suffix to specify the type explicitly
|
||||
);
|
||||
println!("{}", 1.2);
|
||||
}
|
||||
|
|
@ -12,6 +12,5 @@
|
|||
|
||||
fn main() {
|
||||
let mut array = [1, 2, 3];
|
||||
//~^ ERROR cannot determine a type for this local variable: cannot determine the type of this integ
|
||||
let pie_slice = array[1..2];
|
||||
}
|
||||
|
|
@ -10,6 +10,5 @@
|
|||
|
||||
pub fn main() {
|
||||
let x = [1, 2, 3];
|
||||
//~^ ERROR cannot determine a type for this local variable: cannot determine the type of this
|
||||
let y = x.as_slice();
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
// Test that if there is one impl we can infer everything.
|
||||
|
||||
use std::mem;
|
||||
|
||||
trait Convert<Target> {
|
||||
fn convert(&self) -> Target;
|
||||
}
|
||||
|
||||
impl Convert<u32> for i16 {
|
||||
fn convert(&self) -> u32 {
|
||||
*self as u32
|
||||
}
|
||||
}
|
||||
|
||||
fn test<T,U>(_: T, _: U, t_size: uint, u_size: uint)
|
||||
where T : Convert<U>
|
||||
{
|
||||
assert_eq!(mem::size_of::<T>(), t_size);
|
||||
assert_eq!(mem::size_of::<U>(), u_size);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// T = i16, U = u32
|
||||
test(22, 44, 2, 4);
|
||||
}
|
||||
|
|
@ -36,11 +36,10 @@ where T : Convert<U>
|
|||
}
|
||||
|
||||
fn main() {
|
||||
use std::default::Default;
|
||||
// T = i16, U = u32
|
||||
test(22_i16, 44, 2, 4);
|
||||
test(22, 44_u32, 2, 4);
|
||||
test(22_i16, Default::default(), 2, 4);
|
||||
|
||||
// T = u32, U = i16
|
||||
test(22_u32, 44, 4, 2);
|
||||
test(22, 44_i16, 4, 2);
|
||||
test(22_u32, Default::default(), 4, 2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue