1
Fork 0

Tweak E0271 wording

This commit is contained in:
Esteban Küber 2023-01-06 20:28:46 +00:00
parent 5ae8e23816
commit 6c2c8edac3
9 changed files with 18 additions and 14 deletions

View file

@ -1866,10 +1866,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
with_forced_trimmed_paths! { with_forced_trimmed_paths! {
if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() { if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() {
let fn_kind = self_ty.prefix_string(self.tcx);
let item = match self_ty.kind() {
ty::FnDef(def, _) => self.tcx.item_name(*def).to_string(),
_ => self_ty.to_string(),
};
Some(format!( Some(format!(
"expected `{self_ty}` to be a {fn_kind} that returns `{expected_ty}`, but it \ "expected `{item}` to be a {fn_kind} that returns `{expected_ty}`, but it \
returns `{normalized_ty}`", returns `{normalized_ty}`",
fn_kind = self_ty.prefix_string(self.tcx)
)) ))
} else if Some(trait_def_id) == self.tcx.lang_items().future_trait() { } else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
Some(format!( Some(format!(

View file

@ -43,8 +43,8 @@ impl Runtime {
fn main() { fn main() {
Runtime.block_on(async { Runtime.block_on(async {
StructAsync { callback }.await; StructAsync { callback }.await;
//~^ ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` //~^ ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` //~| ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` //~| ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
}); });
} }

View file

@ -1,4 +1,4 @@
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` error[E0271]: expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
--> $DIR/issue-98634.rs:45:23 --> $DIR/issue-98634.rs:45:23
| |
LL | StructAsync { callback }.await; LL | StructAsync { callback }.await;
@ -17,7 +17,7 @@ note: required by a bound in `StructAsync`
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` error[E0271]: expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
--> $DIR/issue-98634.rs:45:9 --> $DIR/issue-98634.rs:45:9
| |
LL | StructAsync { callback }.await; LL | StructAsync { callback }.await;
@ -36,7 +36,7 @@ note: required by a bound in `StructAsync`
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` error[E0271]: expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
--> $DIR/issue-98634.rs:45:33 --> $DIR/issue-98634.rs:45:33
| |
LL | StructAsync { callback }.await; LL | StructAsync { callback }.await;

View file

@ -30,7 +30,7 @@ fn baz(n: bool) -> i32 {
const fn return_ty_mismatch() { const fn return_ty_mismatch() {
const_eval_select((1,), foo, bar); const_eval_select((1,), foo, bar);
//~^ ERROR expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool` //~^ ERROR expected `bar` to be a fn item that returns `i32`, but it returns `bool`
} }
const fn args_ty_mismatch() { const fn args_ty_mismatch() {

View file

@ -60,7 +60,7 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
note: required by a bound in `const_eval_select` note: required by a bound in `const_eval_select`
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL --> $SRC_DIR/core/src/intrinsics.rs:LL:COL
error[E0271]: expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool` error[E0271]: expected `bar` to be a fn item that returns `i32`, but it returns `bool`
--> $DIR/const-eval-select-bad.rs:32:34 --> $DIR/const-eval-select-bad.rs:32:34
| |
LL | const_eval_select((1,), foo, bar); LL | const_eval_select((1,), foo, bar);

View file

@ -7,5 +7,5 @@ async fn test() {}
#[allow(unused_must_use)] #[allow(unused_must_use)]
fn main() { fn main() {
Box::new(test) as AsyncFnPtr; Box::new(test) as AsyncFnPtr;
//~^ ERROR expected `fn() -> impl Future<Output = ()> {test}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()> //~^ ERROR expected `test` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>
} }

View file

@ -1,4 +1,4 @@
error[E0271]: expected `fn() -> impl Future<Output = ()> {test}` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>` error[E0271]: expected `test` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
--> $DIR/issue-98604.rs:9:5 --> $DIR/issue-98604.rs:9:5
| |
LL | Box::new(test) as AsyncFnPtr; LL | Box::new(test) as AsyncFnPtr;

View file

@ -4,7 +4,7 @@ fn hi() -> impl Sized {
fn main() { fn main() {
let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi); let b: Box<dyn Fn() -> Box<u8>> = Box::new(hi);
//~^ ERROR expected `fn() -> impl Sized {hi}` to be a fn item that returns `Box<u8>`, but it returns `impl Sized` //~^ ERROR expected `hi` to be a fn item that returns `Box<u8>`, but it returns `impl Sized`
let boxed = b(); let boxed = b();
let null = *boxed; let null = *boxed;
println!("{null:?}"); println!("{null:?}");

View file

@ -1,4 +1,4 @@
error[E0271]: expected `fn() -> impl Sized {hi}` to be a fn item that returns `Box<u8>`, but it returns `impl Sized` error[E0271]: expected `hi` to be a fn item that returns `Box<u8>`, but it returns `impl Sized`
--> $DIR/issue-98608.rs:6:39 --> $DIR/issue-98608.rs:6:39
| |
LL | fn hi() -> impl Sized { LL | fn hi() -> impl Sized {