Skip to content

Commit 6c2c8ed

Browse files
committed
Tweak E0271 wording
1 parent 5ae8e23 commit 6c2c8ed

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1866,10 +1866,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18661866

18671867
with_forced_trimmed_paths! {
18681868
if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() {
1869+
let fn_kind = self_ty.prefix_string(self.tcx);
1870+
let item = match self_ty.kind() {
1871+
ty::FnDef(def, _) => self.tcx.item_name(*def).to_string(),
1872+
_ => self_ty.to_string(),
1873+
};
18691874
Some(format!(
1870-
"expected `{self_ty}` to be a {fn_kind} that returns `{expected_ty}`, but it \
1875+
"expected `{item}` to be a {fn_kind} that returns `{expected_ty}`, but it \
18711876
returns `{normalized_ty}`",
1872-
fn_kind = self_ty.prefix_string(self.tcx)
18731877
))
18741878
} else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
18751879
Some(format!(

tests/ui/async-await/issue-98634.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl Runtime {
4343
fn main() {
4444
Runtime.block_on(async {
4545
StructAsync { callback }.await;
46-
//~^ 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 = ()>`
47-
//~| 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 = ()>`
48-
//~| 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 = ()>`
46+
//~^ ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
47+
//~| ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
48+
//~| ERROR expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
4949
});
5050
}

tests/ui/async-await/issue-98634.stderr

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

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

39-
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 = ()>`
39+
error[E0271]: expected `callback` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
4040
--> $DIR/issue-98634.rs:45:33
4141
|
4242
LL | StructAsync { callback }.await;

tests/ui/intrinsics/const-eval-select-bad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn baz(n: bool) -> i32 {
3030

3131
const fn return_ty_mismatch() {
3232
const_eval_select((1,), foo, bar);
33-
//~^ ERROR expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool`
33+
//~^ ERROR expected `bar` to be a fn item that returns `i32`, but it returns `bool`
3434
}
3535

3636
const fn args_ty_mismatch() {

tests/ui/intrinsics/const-eval-select-bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
6060
note: required by a bound in `const_eval_select`
6161
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
6262

63-
error[E0271]: expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool`
63+
error[E0271]: expected `bar` to be a fn item that returns `i32`, but it returns `bool`
6464
--> $DIR/const-eval-select-bad.rs:32:34
6565
|
6666
LL | const_eval_select((1,), foo, bar);

tests/ui/type-alias-impl-trait/issue-98604.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ async fn test() {}
77
#[allow(unused_must_use)]
88
fn main() {
99
Box::new(test) as AsyncFnPtr;
10-
//~^ 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 = ()>
10+
//~^ ERROR expected `test` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>
1111
}

tests/ui/type-alias-impl-trait/issue-98604.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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 = ()>`
1+
error[E0271]: expected `test` to be a fn item that returns `Pin<Box<dyn Future<Output = ()>>>`, but it returns `impl Future<Output = ()>`
22
--> $DIR/issue-98604.rs:9:5
33
|
44
LL | Box::new(test) as AsyncFnPtr;

tests/ui/type-alias-impl-trait/issue-98608.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn hi() -> impl Sized {
44

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

tests/ui/type-alias-impl-trait/issue-98608.stderr

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

0 commit comments

Comments
 (0)