]> git.lizzy.rs Git - rust.git/commitdiff
Tweak E0271 wording
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 6 Jan 2023 20:28:46 +0000 (20:28 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 30 Jan 2023 21:51:35 +0000 (21:51 +0000)
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
tests/ui/async-await/issue-98634.rs
tests/ui/async-await/issue-98634.stderr
tests/ui/intrinsics/const-eval-select-bad.rs
tests/ui/intrinsics/const-eval-select-bad.stderr
tests/ui/type-alias-impl-trait/issue-98604.rs
tests/ui/type-alias-impl-trait/issue-98604.stderr
tests/ui/type-alias-impl-trait/issue-98608.rs
tests/ui/type-alias-impl-trait/issue-98608.stderr

index e9842b2cba516a6d692f71765f86b1b2e0a366d9..df6ce2777cfa4805e82adbd0d12e4f22f0e97c87 100644 (file)
@@ -1866,10 +1866,14 @@ fn maybe_detailed_projection_msg(
 
         with_forced_trimmed_paths! {
             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!(
-                    "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}`",
-                    fn_kind = self_ty.prefix_string(self.tcx)
                 ))
             } else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
                 Some(format!(
index 104b85baa63f6cafd5f659dadfe9645be819fa8a..169cc7f9b21ea8265878c7cd06ab7ca3bbf65feb 100644 (file)
@@ -43,8 +43,8 @@ pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
 fn main() {
     Runtime.block_on(async {
         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 `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 `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 `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 = ()>`
     });
 }
index 17e598508e57f0e8994a717c955516aedeec9f28..08ea5bdc574fa8551ef2837986f14d9545b98f0d 100644 (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
    |
 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 = ()>>>> {
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
    |
 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 = ()>>>> {
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
    |
 LL |         StructAsync { callback }.await;
index fa14efad7b4a473ebd2f8744a2d9b7b154f2a7ce..991d1450aff994c2204799b0938fb464ab0eee0b 100644 (file)
@@ -30,7 +30,7 @@ fn baz(n: bool) -> i32 {
 
 const fn return_ty_mismatch() {
     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() {
index fd7d061b6b2e5627459e5ea11968c9539c345ff8..d4507a27aeaa1286e7cd6ce2e810ee45984d962a 100644 (file)
@@ -60,7 +60,7 @@ LL |     const_eval_select((), 42, 0xDEADBEEF);
 note: required by a bound in `const_eval_select`
   --> $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
    |
 LL |     const_eval_select((1,), foo, bar);
index 35f0bbfac93f6b0f59bd1f57eda603ee75676231..d07fc9822a02d9254f1bf5bd736472796220c7c1 100644 (file)
@@ -7,5 +7,5 @@ async fn test() {}
 #[allow(unused_must_use)]
 fn main() {
     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 = ()>
 }
index 650376f8c6b43acb52bcc094dd397e318a0fe7dd..c5a4b5217d7a0aaddfb240ceb422f3fbceb180d3 100644 (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
    |
 LL |     Box::new(test) as AsyncFnPtr;
index 1f89af0457653b066d09f2c0455f9cdf915329ff..5e026ea4096c30429a47ea531ca73e8ad19b3c49 100644 (file)
@@ -4,7 +4,7 @@ fn hi() -> impl Sized {
 
 fn main() {
     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 null = *boxed;
     println!("{null:?}");
index 3a3db42c42d3859d733b9de10ee0f90c2b7381aa..506d40cb7768f7426de7198330bd6e5e589800d9 100644 (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
    |
 LL | fn hi() -> impl Sized {