Skip to content

Commit 26e22b8

Browse files
authored
Rollup merge of rust-lang#35080 - jonathandturner:fix_numeric_expected_found, r=nikomatsakis
Rename _ to {integer} and {float} for unknown numeric types This PR renames _ to {integer} or {float} for unknown numeric types, to help people parse error messages that have numeric types that haven't been nailed down. Example: ```rust fn main() { let x: String = 4; } ``` Before: ``` error[E0308]: mismatched types --> quicktest.rs:2:21 | 2 | let x: String = 4; | ^ expected struct `std::string::String`, found integral variable | = note: expected type `std::string::String` = note: found type `_` error: aborting due to previous error ``` after: ``` error[E0308]: mismatched types --> quicktest.rs:2:21 | 2 | let x: String = 4; | ^ expected struct `std::string::String`, found integral variable | = note: expected type `std::string::String` = note: found type `{integer}` error: aborting due to previous error ``` ```
2 parents 8c6421f + ea77049 commit 26e22b8

35 files changed

+43
-41
lines changed

src/librustc/util/ppaux.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,9 @@ impl fmt::Display for ty::InferTy {
974974
ty::TyVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
975975
ty::IntVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
976976
ty::FloatVar(ref vid) if print_var_ids => write!(f, "{:?}", vid),
977-
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => write!(f, "_"),
977+
ty::TyVar(_) => write!(f, "_"),
978+
ty::IntVar(_) => write!(f, "{}", "{integer}"),
979+
ty::FloatVar(_) => write!(f, "{}", "{float}"),
978980
ty::FreshTy(v) => write!(f, "FreshTy({})", v),
979981
ty::FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
980982
ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v)

src/test/compile-fail/array-not-vector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let _x: i32 = [1, 2, 3];
1313
//~^ ERROR mismatched types
1414
//~| expected type `i32`
15-
//~| found type `[_; 3]`
15+
//~| found type `[{integer}; 3]`
1616
//~| expected i32, found array of 3 elements
1717

1818
let x: &[i32] = &[1, 2, 3];

src/test/compile-fail/bad-const-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
static i: String = 10;
1212
//~^ ERROR mismatched types
1313
//~| expected type `std::string::String`
14-
//~| found type `_`
14+
//~| found type `{integer}`
1515
//~| expected struct `std::string::String`, found integral variable
1616
fn main() { println!("{}", i); }

src/test/compile-fail/coerce-mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
f(&x);
1616
//~^ ERROR mismatched types
1717
//~| expected type `&mut i32`
18-
//~| found type `&_`
18+
//~| found type `&{integer}`
1919
//~| values differ in mutability
2020
}

src/test/compile-fail/coercion-slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ fn main() {
1414
let _: &[i32] = [0];
1515
//~^ ERROR mismatched types
1616
//~| expected type `&[i32]`
17-
//~| found type `[_; 1]`
17+
//~| found type `[{integer}; 1]`
1818
//~| expected &-ptr, found array of 1 elements
1919
}

src/test/compile-fail/fully-qualified-type-name1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
x = 5;
1616
//~^ ERROR mismatched types
1717
//~| expected type `std::option::Option<usize>`
18-
//~| found type `_`
18+
//~| found type `{integer}`
1919
//~| expected enum `std::option::Option`, found integral variable
2020
}

src/test/compile-fail/if-let-arm-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
if let Some(b) = None { //~ ERROR: `if let` arms have incompatible types
1313
//~^ expected (), found integral variable
1414
//~| expected type `()`
15-
//~| found type `_`
15+
//~| found type `{integer}`
1616
()
1717
} else { //~ NOTE: `if let` arm with an incompatible type
1818
1

src/test/compile-fail/indexing-requires-a-uint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
fn main() {
1515
fn bar<T>(_: T) {}
16-
[0][0u8]; //~ ERROR: `[_]: std::ops::Index<u8>` is not satisfied
16+
[0][0u8]; //~ ERROR: `[{integer}]: std::ops::Index<u8>` is not satisfied
1717

1818
[0][0]; // should infer to be a usize
1919

src/test/compile-fail/integral-variable-unification-error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let mut x = 2;
1313
x = 5.0;
1414
//~^ ERROR mismatched types
15-
//~| expected type `_`
16-
//~| found type `_`
15+
//~| expected type `{integer}`
16+
//~| found type `{float}`
1717
//~| expected integral variable, found floating-point variable
1818
}

src/test/compile-fail/issue-13466.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ pub fn main() {
1717
let _x: usize = match Some(1) {
1818
Ok(u) => u,
1919
//~^ ERROR mismatched types
20-
//~| expected type `std::option::Option<_>`
20+
//~| expected type `std::option::Option<{integer}>`
2121
//~| found type `std::result::Result<_, _>`
2222
//~| expected enum `std::option::Option`, found enum `std::result::Result`
2323

2424
Err(e) => panic!(e)
2525
//~^ ERROR mismatched types
26-
//~| expected type `std::option::Option<_>`
26+
//~| expected type `std::option::Option<{integer}>`
2727
//~| found type `std::result::Result<_, _>`
2828
//~| expected enum `std::option::Option`, found enum `std::result::Result`
2929
};

src/test/compile-fail/issue-17651.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
fn main() {
1515
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
1616
(|| Box::new(*(&[0][..])))();
17-
//~^ ERROR `[_]: std::marker::Sized` is not satisfied
17+
//~^ ERROR `[{integer}]: std::marker::Sized` is not satisfied
1818
}

src/test/compile-fail/issue-19991.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
fn main() {
1515
if let Some(homura) = Some("madoka") { //~ ERROR missing an else clause
1616
//~| expected type `()`
17-
//~| found type `_`
17+
//~| found type `{integer}`
1818
//~| expected (), found integral variable
1919
765
2020
};

src/test/compile-fail/issue-26237.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
macro_rules! macro_panic {
1212
($not_a_function:expr, $some_argument:ident) => {
1313
$not_a_function($some_argument)
14-
//~^ ERROR expected function, found `_`
14+
//~^ ERROR expected function, found `{integer}`
1515
}
1616
}
1717

src/test/compile-fail/issue-4201.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
} else if false {
1515
//~^ ERROR if may be missing an else clause
1616
//~| expected type `()`
17-
//~| found type `_`
17+
//~| found type `{integer}`
1818
//~| expected (), found integral variable
1919
1
2020
};

src/test/compile-fail/issue-4968.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const A: (isize,isize) = (4,2);
1414
fn main() {
1515
match 42 { A => () }
1616
//~^ ERROR mismatched types
17-
//~| expected type `_`
17+
//~| expected type `{integer}`
1818
//~| found type `(isize, isize)`
1919
//~| expected integral variable, found tuple
2020
}

src/test/compile-fail/issue-7867.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ fn main() {
2525
match &Some(42) {
2626
Some(x) => (),
2727
//~^ ERROR mismatched types
28-
//~| expected type `&std::option::Option<_>`
28+
//~| expected type `&std::option::Option<{integer}>`
2929
//~| found type `std::option::Option<_>`
3030
//~| expected &-ptr, found enum `std::option::Option`
3131
None => ()
3232
//~^ ERROR mismatched types
33-
//~| expected type `&std::option::Option<_>`
33+
//~| expected type `&std::option::Option<{integer}>`
3434
//~| found type `std::option::Option<_>`
3535
//~| expected &-ptr, found enum `std::option::Option`
3636
}

src/test/compile-fail/kindck-impl-type-params-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ fn take_param<T:Foo>(foo: &T) { }
2121
fn main() {
2222
let x: Box<_> = box 3;
2323
take_param(&x);
24-
//~^ ERROR `Box<_>: std::marker::Copy` is not satisfied
24+
//~^ ERROR `Box<{integer}>: std::marker::Copy` is not satisfied
2525
}

src/test/compile-fail/match-range-fail.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ fn main() {
2020
10 ... "what" => ()
2121
};
2222
//~^^ ERROR only char and numeric types are allowed in range
23-
//~| start type: _
23+
//~| start type: {integer}
2424
//~| end type: &'static str
2525

2626
match 5 {
2727
'c' ... 100 => { }
2828
_ => { }
2929
};
3030
//~^^^ ERROR mismatched types
31-
//~| expected type `_`
31+
//~| expected type `{integer}`
3232
//~| found type `char`
3333
}

src/test/compile-fail/match-vec-mismatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
};
1919

2020
match &[0, 1, 2] {
21-
[..] => {} //~ ERROR expected an array or slice, found `&[_; 3]`
21+
[..] => {} //~ ERROR expected an array or slice, found `&[{integer}; 3]`
2222
};
2323

2424
match &[0, 1, 2] {

src/test/compile-fail/method-self-arg-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ fn main() {
2424
//~| expected &-ptr, found struct `Foo`
2525
Foo::bar(&42); //~ ERROR mismatched types
2626
//~| expected type `&Foo`
27-
//~| found type `&_`
27+
//~| found type `&{integer}`
2828
//~| expected struct `Foo`, found integral variable
2929
}

src/test/compile-fail/mut-pattern-mismatched.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
// (separate lines to ensure the spans are accurate)
1515

1616
let &_ //~ ERROR mismatched types
17-
//~| expected type `&mut _`
17+
//~| expected type `&mut {integer}`
1818
//~| found type `&_`
1919
//~| values differ in mutability
2020
= foo;
@@ -23,7 +23,7 @@ fn main() {
2323
let bar = &1;
2424
let &_ = bar;
2525
let &mut _ //~ ERROR mismatched types
26-
//~| expected type `&_`
26+
//~| expected type `&{integer}`
2727
//~| found type `&mut _`
2828
//~| values differ in mutability
2929
= bar;

src/test/compile-fail/no_send-rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn bar<T: Send>(_: T) {}
1515
fn main() {
1616
let x = Rc::new(5);
1717
bar(x);
18-
//~^ ERROR `std::rc::Rc<_>: std::marker::Send` is not satisfied
18+
//~^ ERROR `std::rc::Rc<{integer}>: std::marker::Send` is not satisfied
1919
}

src/test/compile-fail/range-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ pub fn main() {
2323
// Unsized type.
2424
let arr: &[_] = &[1, 2, 3];
2525
let range = *arr..;
26-
//~^ ERROR `[_]: std::marker::Sized` is not satisfied
26+
//~^ ERROR `[{integer}]: std::marker::Sized` is not satisfied
2727
}

src/test/compile-fail/repeat_count.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
let d = [0; 0.5];
2929
//~^ ERROR mismatched types
3030
//~| expected type `usize`
31-
//~| found type `_`
31+
//~| found type `{float}`
3232
//~| expected usize, found floating-point variable
3333
//~| ERROR expected usize for repeat count, found float [E0306]
3434
let e = [0; "foo"];

src/test/compile-fail/slightly-nice-generic-literal-messages.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fn main() {
1616
match Foo(1.1, marker::PhantomData) {
1717
1 => {}
1818
//~^ ERROR mismatched types
19-
//~| expected type `Foo<_, _>`
20-
//~| found type `_`
19+
//~| expected type `Foo<{float}, _>`
20+
//~| found type `{integer}`
2121
//~| expected struct `Foo`, found integral variable
2222
}
2323

src/test/compile-fail/str-idx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
pub fn main() {
1212
let s: &str = "hello";
13-
let c: u8 = s[4]; //~ ERROR `str: std::ops::Index<_>` is not satisfied
13+
let c: u8 = s[4]; //~ ERROR `str: std::ops::Index<{integer}>` is not satisfied
1414
}

src/test/compile-fail/struct-base-wrong-type-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ fn main() {
2424
//~| expected struct `Foo`, found struct `Bar`
2525
let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types
2626
//~| expected type `Foo`
27-
//~| found type `_`
27+
//~| found type `{integer}`
2828
//~| expected struct `Foo`, found integral variable
2929
}

src/test/compile-fail/struct-base-wrong-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types
2323
//~| expected struct `Foo`, found struct `Bar`
2424
static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types
2525
//~| expected type `Foo`
26-
//~| found type `_`
26+
//~| found type `{integer}`
2727
//~| expected struct `Foo`, found integral variable
2828

2929
fn main() {

src/test/compile-fail/traits-inductive-overflow-simultaneous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ fn is_ee<T: Combo>(t: T) {
2626

2727
fn main() {
2828
is_ee(4);
29-
//~^ ERROR overflow evaluating the requirement `_: Tweedle
29+
//~^ ERROR overflow evaluating the requirement `{integer}: Tweedle
3030
}

src/test/compile-fail/tuple-arity-mismatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
let y = first ((1,2.0,3));
1717
//~^ ERROR mismatched types
1818
//~| expected type `(isize, f64)`
19-
//~| found type `(isize, f64, _)`
19+
//~| found type `(isize, f64, {integer})`
2020
//~| expected a tuple with 2 elements, found one with 3 elements
2121

2222
let y = first ((1,));

src/test/compile-fail/tuple-index-out-of-bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ fn main() {
2020
tuple.0;
2121
tuple.1;
2222
tuple.2;
23-
//~^ ERROR attempted out-of-bounds tuple index `2` on type `(_, _)`
23+
//~^ ERROR attempted out-of-bounds tuple index `2` on type `({integer}, {integer})`
2424
}

src/test/compile-fail/type-mismatch-multiple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
fn main() { let a: bool = 1; let b: i32 = true; }
1414
//~^ ERROR mismatched types
1515
//~| expected type `bool`
16-
//~| found type `_`
16+
//~| found type `{integer}`
1717
//~| expected bool, found integral variable
1818
//~| ERROR mismatched types
1919
//~| expected i32, found bool

src/test/compile-fail/typeck-unsafe-always-share.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn test<T: Sync>(s: T) {}
2727
fn main() {
2828
let us = UnsafeCell::new(MySync{u: UnsafeCell::new(0)});
2929
test(us);
30-
//~^ ERROR `std::cell::UnsafeCell<MySync<_>>: std::marker::Sync` is not satisfied
30+
//~^ ERROR `std::cell::UnsafeCell<MySync<{integer}>>: std::marker::Sync` is not satisfied
3131

3232
let uns = UnsafeCell::new(NoSync);
3333
test(uns);

src/test/compile-fail/vtable-res-trait-param.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl TraitB for isize {
2424

2525
fn call_it<B:TraitB>(b: B) -> isize {
2626
let y = 4;
27-
b.gimme_an_a(y) //~ ERROR `_: TraitA` is not satisfied
27+
b.gimme_an_a(y) //~ ERROR `{integer}: TraitA` is not satisfied
2828
}
2929

3030
fn main() {

src/test/ui/mismatched_types/issue-26480.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0308]: mismatched types
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize
66
$DIR/issue-26480.rs:38:5: 38:19 note: in this expansion of write! (defined in $DIR/issue-26480.rs)
77

8-
error: non-scalar cast: `_` as `()`
8+
error: non-scalar cast: `{integer}` as `()`
99
--> $DIR/issue-26480.rs:33:19
1010
|
1111
33 | ($x:expr) => ($x as ())

0 commit comments

Comments
 (0)