Point at argument when evaluating Path's bounds

When evaluating an `ExprKind::Call`, we first have to `check_expr` on it's
callee. When this one is a `ExprKind::Path`, we had to evaluate the bounds
introduced for its arguments, but by the time we evaluated them we no
longer had access to the argument spans. Now we special case this so
that we can point at the right place on unsatisfied bounds. This also
allows the E0277 deduplication to kick in correctly, so we now emit
fewer errors.
This commit is contained in:
Esteban Kuber 2021-09-14 10:52:36 +00:00
parent 1d82905685
commit 4951e3ad9e
10 changed files with 43 additions and 52 deletions

View file

@ -28,13 +28,11 @@ pub fn f1_int_uint() {
pub fn f1_uint_uint() {
f1(2u32, 4u32);
//~^ ERROR `u32: Foo` is not satisfied
//~| ERROR `u32: Foo` is not satisfied
}
pub fn f1_uint_int() {
f1(2u32, 4i32);
//~^ ERROR `u32: Foo` is not satisfied
//~| ERROR `u32: Foo` is not satisfied
}
pub fn f2_int() {

View file

@ -24,13 +24,7 @@ LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| ^^^ required by this bound in `f1`
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:29:5
|
LL | f1(2u32, 4u32);
| ^^ the trait `Foo` is not implemented for `u32`
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:35:14
--> $DIR/associated-types-path-2.rs:34:14
|
LL | f1(2u32, 4i32);
| -- ^^^^ the trait `Foo` is not implemented for `u32`
@ -43,14 +37,8 @@ note: required by a bound in `f1`
LL | pub fn f1<T: Foo>(a: T, x: T::A) {}
| ^^^ required by this bound in `f1`
error[E0277]: the trait bound `u32: Foo` is not satisfied
--> $DIR/associated-types-path-2.rs:35:5
|
LL | f1(2u32, 4i32);
| ^^ the trait `Foo` is not implemented for `u32`
error[E0308]: mismatched types
--> $DIR/associated-types-path-2.rs:41:18
--> $DIR/associated-types-path-2.rs:39:18
|
LL | let _: i32 = f2(2i32);
| --- ^^^^^^^^ expected `i32`, found `u32`
@ -62,7 +50,7 @@ help: you can convert a `u32` to an `i32` and panic if the converted value doesn
LL | let _: i32 = f2(2i32).try_into().unwrap();
| ++++++++++++++++++++
error: aborting due to 6 previous errors
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View file

@ -12,10 +12,10 @@ LL | fn foo(x: &dyn Foo) {
| +
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
--> $DIR/feature-gate-unsized_fn_params.rs:24:5
--> $DIR/feature-gate-unsized_fn_params.rs:24:9
|
LL | foo(*x);
| ^^^ doesn't have a size known at compile-time
| ^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Foo + 'static)`
= note: all function arguments must have a statically known size

View file

@ -4,5 +4,4 @@
fn main() {
(|| Box::new(*(&[0][..])))();
//~^ ERROR the size for values of type
//~| ERROR the size for values of type
}

View file

@ -13,16 +13,6 @@ note: required by `Box::<T>::new`
LL | pub fn new(x: T) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
--> $DIR/issue-17651.rs:5:9
|
LL | (|| Box::new(*(&[0][..])))();
| ^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[{integer}]`
= note: all function arguments must have a statically known size
= help: unsized fn params are gated as an unstable feature
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,8 +1,8 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/issue-30355.rs:5:6
--> $DIR/issue-30355.rs:5:8
|
LL | &X(*Y)
| ^ doesn't have a size known at compile-time
| ^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: all function arguments must have a statically known size

View file

@ -21,7 +21,6 @@ fn main() {
let ref_cl: &dyn Fn() -> () = &cl;
f_sized(*ref_cl);
//~^ ERROR: the size for values of type `dyn Fn()` cannot be known at compilation time [E0277]
//~| ERROR: the size for values of type `dyn Fn()` cannot be known at compilation time [E0277]
use std::rc::Rc;
let rc = Rc::new(0);

View file

@ -55,7 +55,7 @@ LL | fn f_sized<T: Sized>(t: T) {}
| ^ required by this bound in `f_sized`
error[E0277]: `Rc<{integer}>` cannot be sent between threads safely
--> $DIR/issue-84973-blacklist.rs:28:12
--> $DIR/issue-84973-blacklist.rs:27:12
|
LL | f_send(rc);
| ------ ^^ `Rc<{integer}>` cannot be sent between threads safely
@ -69,16 +69,6 @@ note: required by a bound in `f_send`
LL | fn f_send<T: Send>(t: T) {}
| ^^^^ required by this bound in `f_send`
error[E0277]: the size for values of type `dyn Fn()` cannot be known at compilation time
--> $DIR/issue-84973-blacklist.rs:22:5
|
LL | f_sized(*ref_cl);
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `dyn Fn()`
= note: all function arguments must have a statically known size
= help: unsized fn params are gated as an unstable feature
error: aborting due to 6 previous errors
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0277`.