Skip to content

Commit 052dfa7

Browse files
Make error message less awkward
1 parent 7bc0b3c commit 052dfa7

16 files changed

+32
-32
lines changed

compiler/rustc_hir_typeck/src/check.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,17 @@ pub(super) fn check_fn<'a, 'tcx>(
117117

118118
fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
119119

120-
let return_or_body_span = match decl.output {
121-
hir::FnRetTy::DefaultReturn(_) => body.value.span,
122-
hir::FnRetTy::Return(ty) => ty.span,
123-
};
124-
125120
// We checked the root's ret ty during wfcheck, but not the child.
126121
if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
122+
let return_or_body_span = match decl.output {
123+
hir::FnRetTy::DefaultReturn(_) => body.value.span,
124+
hir::FnRetTy::Return(ty) => ty.span,
125+
};
126+
127127
fcx.require_type_is_sized(
128128
declared_ret_ty,
129129
return_or_body_span,
130-
ObligationCauseCode::WellFormed(None),
130+
ObligationCauseCode::SizedReturnType,
131131
);
132132
}
133133

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17651765
};
17661766

17671767
err.code(E0746);
1768-
err.primary_message("return type cannot have an unboxed trait object");
1768+
err.primary_message("return type cannot be a trait object without pointer indirection");
17691769
err.children.clear();
17701770

17711771
let span = obligation.cause.span;

tests/ui/error-codes/E0746.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/E0746.rs:8:13
33
|
44
LL | fn foo() -> dyn Trait { Struct }
@@ -13,7 +13,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
1313
LL | fn foo() -> Box<dyn Trait> { Box::new(Struct) }
1414
| ++++ + +++++++++ +
1515

16-
error[E0746]: return type cannot have an unboxed trait object
16+
error[E0746]: return type cannot be a trait object without pointer indirection
1717
--> $DIR/E0746.rs:11:13
1818
|
1919
LL | fn bar() -> dyn Trait {

tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl DynIncompatible for B {
2020
}
2121

2222
fn car() -> dyn DynIncompatible { //~ ERROR the trait `DynIncompatible` is not dyn compatible
23-
//~^ ERROR return type cannot have an unboxed trait object
23+
//~^ ERROR return type cannot be a trait object without pointer indirection
2424
if true {
2525
return A;
2626
}

tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o
2626
LL | fn foo() -> Self where Self: Sized;
2727
| +++++++++++++++++
2828

29-
error[E0746]: return type cannot have an unboxed trait object
29+
error[E0746]: return type cannot be a trait object without pointer indirection
3030
--> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
3131
|
3232
LL | fn car() -> dyn DynIncompatible {

tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
1818
= note: required because it appears within the type `(usize, (dyn Trait + 'static))`
1919
= note: the return type of a function must have a statically known size
2020

21-
error[E0746]: return type cannot have an unboxed trait object
21+
error[E0746]: return type cannot be a trait object without pointer indirection
2222
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
2323
|
2424
LL | fn bap() -> Trait { Struct }
@@ -33,7 +33,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
3333
LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) }
3434
| +++++++ + +++++++++ +
3535

36-
error[E0746]: return type cannot have an unboxed trait object
36+
error[E0746]: return type cannot be a trait object without pointer indirection
3737
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
3838
|
3939
LL | fn ban() -> dyn Trait { Struct }
@@ -48,7 +48,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
4848
LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
4949
| ++++ + +++++++++ +
5050

51-
error[E0746]: return type cannot have an unboxed trait object
51+
error[E0746]: return type cannot be a trait object without pointer indirection
5252
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
5353
|
5454
LL | fn bak() -> dyn Trait { unimplemented!() }
@@ -63,7 +63,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
6363
LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
6464
| ++++ + +++++++++ +
6565

66-
error[E0746]: return type cannot have an unboxed trait object
66+
error[E0746]: return type cannot be a trait object without pointer indirection
6767
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:21:13
6868
|
6969
LL | fn bal() -> dyn Trait {
@@ -82,7 +82,7 @@ LL | }
8282
LL ~ Box::new(42)
8383
|
8484

85-
error[E0746]: return type cannot have an unboxed trait object
85+
error[E0746]: return type cannot be a trait object without pointer indirection
8686
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:27:13
8787
|
8888
LL | fn bax() -> dyn Trait {
@@ -101,7 +101,7 @@ LL | } else {
101101
LL ~ Box::new(42)
102102
|
103103

104-
error[E0746]: return type cannot have an unboxed trait object
104+
error[E0746]: return type cannot be a trait object without pointer indirection
105105
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:62:13
106106
|
107107
LL | fn bat() -> dyn Trait {
@@ -120,7 +120,7 @@ LL | }
120120
LL ~ Box::new(42)
121121
|
122122

123-
error[E0746]: return type cannot have an unboxed trait object
123+
error[E0746]: return type cannot be a trait object without pointer indirection
124124
--> $DIR/dyn-trait-return-should-be-impl-trait.rs:68:13
125125
|
126126
LL | fn bay() -> dyn Trait {

tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn dog() -> impl std::fmt::Display {
6363
}
6464
}
6565

66-
fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
66+
fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
6767
match 13 {
6868
0 => {
6969
return 0i32;
@@ -74,15 +74,15 @@ fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed
7474
}
7575
}
7676

77-
fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
77+
fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
7878
match 13 {
7979
0 => 0i32,
8080
1 => 1u32,
8181
_ => 2u32,
8282
}
8383
}
8484

85-
fn man() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
85+
fn man() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
8686
if false {
8787
0i32
8888
} else {

tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:66:13
33
|
44
LL | fn hat() -> dyn std::fmt::Display {
@@ -19,7 +19,7 @@ LL | _ => {
1919
LL ~ Box::new(1u32)
2020
|
2121

22-
error[E0746]: return type cannot have an unboxed trait object
22+
error[E0746]: return type cannot be a trait object without pointer indirection
2323
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:77:13
2424
|
2525
LL | fn pug() -> dyn std::fmt::Display {
@@ -38,7 +38,7 @@ LL ~ 1 => Box::new(1u32),
3838
LL ~ _ => Box::new(2u32),
3939
|
4040

41-
error[E0746]: return type cannot have an unboxed trait object
41+
error[E0746]: return type cannot be a trait object without pointer indirection
4242
--> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:85:13
4343
|
4444
LL | fn man() -> dyn std::fmt::Display {

tests/ui/issues/issue-18107.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub trait AbstractRenderer {}
22

33
fn _create_render(_: &()) ->
44
dyn AbstractRenderer
5-
//~^ ERROR return type cannot have an unboxed trait object
5+
//~^ ERROR return type cannot be a trait object without pointer indirection
66
{
77
match 0 {
88
_ => unimplemented!()

tests/ui/issues/issue-18107.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/issue-18107.rs:4:5
33
|
44
LL | dyn AbstractRenderer

tests/ui/unsized/box-instead-of-dyn-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Debug;
33
// Test to suggest boxing the return type, and the closure branch of the `if`
44

55
fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> dyn Fn() + 'a {
6-
//~^ ERROR return type cannot have an unboxed trait object
6+
//~^ ERROR return type cannot be a trait object without pointer indirection
77
if a % 2 == 0 {
88
move || println!("{a}")
99
} else {

tests/ui/unsized/box-instead-of-dyn-fn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/box-instead-of-dyn-fn.rs:5:56
33
|
44
LL | fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> dyn Fn() + 'a {

tests/ui/unsized/issue-91801.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub static ALL_VALIDATORS: &[(&'static str, &'static Validator)] =
66
&[("validate that credits and debits balance", &validate_something)];
77

88
fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Validator<'a> {
9-
//~^ ERROR return type cannot have an unboxed trait object
9+
//~^ ERROR return type cannot be a trait object without pointer indirection
1010
return Box::new(move |something: &'_ Something| -> Result<(), ()> {
1111
first(something).or_else(|_| second(something))
1212
});

tests/ui/unsized/issue-91801.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/issue-91801.rs:8:77
33
|
44
LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Validator<'a> {

tests/ui/unsized/issue-91803.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
trait Foo<'a> {}
22

33
fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {
4-
//~^ ERROR return type cannot have an unboxed trait object
4+
//~^ ERROR return type cannot be a trait object without pointer indirection
55
return Box::new(panic!());
66
}
77

tests/ui/unsized/issue-91803.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0746]: return type cannot have an unboxed trait object
1+
error[E0746]: return type cannot be a trait object without pointer indirection
22
--> $DIR/issue-91803.rs:3:43
33
|
44
LL | fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {

0 commit comments

Comments
 (0)