rust/src/test
Manish Goregaokar b285d68f36
Rollup merge of #73334 - ayazhafiz:err/num-type-cannot-fit, r=estebank
Note numeric literals that can never fit in an expected type

re https://github.com/rust-lang/rust/pull/72380#discussion_r438289385

Given the toy code

```rust
fn is_positive(n: usize) {
  n > -1_isize;
}
```

We currently get a type mismatch error like the following:

```
error[E0308]: mismatched types
 --> src/main.rs:2:9
  |
2 |     n > -1_isize;
  |         ^^^^^^^^ expected `usize`, found `isize`
  |
help: you can convert an `isize` to `usize` and panic if the converted value wouldn't fit
  |
2 |     n > (-1_isize).try_into().unwrap();
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

But clearly, `-1` can never fit into a `usize`, so the suggestion will
always panic. A more useful message would tell the user that the value
can never fit in the expected type:

```
error[E0308]: mismatched types
 --> test.rs:2:9
  |
2 |     n > -1_isize;
  |         ^^^^^^^^ expected `usize`, found `isize`
  |
note: `-1_isize` can never fit into `usize`
 --> test.rs:2:9
  |
2 |     n > -1_isize;
  |         ^^^^^^^^
```

Which is what this commit implements.

I only added this check for negative literals because

- Currently we can only perform such a check for literals (constant
  value propagation is outside the scope of the typechecker at this
  point)
- A lint error for out-of-range numeric literals is already emitted

IMO it makes more sense to put this check in librustc_lint, but as far
as I can tell the typecheck pass happens before the lint pass, so I've
added it here.

r? @estebank
2020-06-19 09:15:10 -07:00
..
assembly Add initial asm!() support for hexagon 2020-06-16 08:58:13 -05:00
auxiliary test: Fix warnings in rust_test_helpers.c 2020-05-06 23:54:05 +03:00
codegen Rollup merge of #73054 - RalfJung:dont-panic, r=Mark-Simulacrum 2020-06-19 14:29:24 +02:00
codegen-units Change how compiler-builtins gets many CGUs 2020-06-15 07:38:00 -07:00
compile-fail Add Option to Force Unwind Tables 2020-05-04 12:08:35 +01:00
debuginfo Implement new gdb/lldb pretty-printers 2020-06-09 16:13:11 +03:00
incremental Auto merge of #72520 - jonas-schievink:cleanup-userty, r=matthewjasper 2020-05-25 06:17:15 +00:00
mir-opt Rollup merge of #73011 - richkadel:llvm-count-from-mir-pass, r=tmandry 2020-06-19 14:29:20 +02:00
pretty pretty/asm.rs should only be tested for x86_64 and not AArch64 2020-06-13 00:41:39 -07:00
run-make Enable static-pie for the x86_64-unknown-linux-musl target 2020-06-15 14:04:48 +02:00
run-make-fulldeps compiletest: Add directives to detect sanitizer support 2020-06-13 14:24:30 +02:00
run-pass-valgrind
rustdoc Rollup merge of #73044 - tmiasko:compiletest-san, r=nikomatsakis 2020-06-19 14:29:22 +02:00
rustdoc-js Make current crate aliases go first 2020-05-14 11:36:02 +02:00
rustdoc-js-std Make current crate aliases go first 2020-05-14 11:36:02 +02:00
rustdoc-ui remove extra space from crate-level doctest names 2020-05-15 23:56:23 -04:00
rustfix
ui Rollup merge of #73334 - ayazhafiz:err/num-type-cannot-fit, r=estebank 2020-06-19 09:15:10 -07:00
ui-fulldeps make all uses of ty::Error or ConstKind::Error delay a span bug 2020-06-15 18:25:58 -05:00
COMPILER_TESTS.md