about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-02-02 14:58:12 +0000
committerMichael Goulet <michael@errs.io>2025-02-03 19:00:22 +0000
commit0d907c17a8258b012f6b1e327709ef5789128167 (patch)
tree1dbeb630375e6dc84e3e96db428dcad0dde59309
parent23ab0f2cdc1f2563e258f29c37741154a2f084d6 (diff)
downloadrust-0d907c17a8258b012f6b1e327709ef5789128167.tar.gz
rust-0d907c17a8258b012f6b1e327709ef5789128167.zip
Make error message less awkward
-rw-r--r--compiler/rustc_hir_typeck/src/check.rs12
-rw-r--r--compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs2
-rw-r--r--tests/ui/error-codes/E0746.stderr4
-rw-r--r--tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs2
-rw-r--r--tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr2
-rw-r--r--tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr14
-rw-r--r--tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs6
-rw-r--r--tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr6
-rw-r--r--tests/ui/issues/issue-18107.rs2
-rw-r--r--tests/ui/issues/issue-18107.stderr2
-rw-r--r--tests/ui/unsized/box-instead-of-dyn-fn.rs2
-rw-r--r--tests/ui/unsized/box-instead-of-dyn-fn.stderr2
-rw-r--r--tests/ui/unsized/issue-91801.rs2
-rw-r--r--tests/ui/unsized/issue-91801.stderr2
-rw-r--r--tests/ui/unsized/issue-91803.rs2
-rw-r--r--tests/ui/unsized/issue-91803.stderr2
16 files changed, 32 insertions, 32 deletions
diff --git a/compiler/rustc_hir_typeck/src/check.rs b/compiler/rustc_hir_typeck/src/check.rs
index 97386cc7793..9fdc5a0ae4e 100644
--- a/compiler/rustc_hir_typeck/src/check.rs
+++ b/compiler/rustc_hir_typeck/src/check.rs
@@ -117,17 +117,17 @@ pub(super) fn check_fn<'a, 'tcx>(
 
     fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
 
-    let return_or_body_span = match decl.output {
-        hir::FnRetTy::DefaultReturn(_) => body.value.span,
-        hir::FnRetTy::Return(ty) => ty.span,
-    };
-
     // We checked the root's ret ty during wfcheck, but not the child.
     if fcx.tcx.is_typeck_child(fn_def_id.to_def_id()) {
+        let return_or_body_span = match decl.output {
+            hir::FnRetTy::DefaultReturn(_) => body.value.span,
+            hir::FnRetTy::Return(ty) => ty.span,
+        };
+
         fcx.require_type_is_sized(
             declared_ret_ty,
             return_or_body_span,
-            ObligationCauseCode::WellFormed(None),
+            ObligationCauseCode::SizedReturnType,
         );
     }
 
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
index eb6d3ea59bb..c194cc11727 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
@@ -1765,7 +1765,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
         };
 
         err.code(E0746);
-        err.primary_message("return type cannot have an unboxed trait object");
+        err.primary_message("return type cannot be a trait object without pointer indirection");
         err.children.clear();
 
         let span = obligation.cause.span;
diff --git a/tests/ui/error-codes/E0746.stderr b/tests/ui/error-codes/E0746.stderr
index ce3e9736969..ec785561415 100644
--- a/tests/ui/error-codes/E0746.stderr
+++ b/tests/ui/error-codes/E0746.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/E0746.rs:8:13
    |
 LL | fn foo() -> dyn Trait { Struct }
@@ -13,7 +13,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
 LL | fn foo() -> Box<dyn Trait> { Box::new(Struct) }
    |             ++++         +   +++++++++      +
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/E0746.rs:11:13
    |
 LL | fn bar() -> dyn Trait {
diff --git a/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs
index 046ced072ba..901d4b39cf3 100644
--- a/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs
+++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs
@@ -20,7 +20,7 @@ impl DynIncompatible for B {
 }
 
 fn car() -> dyn DynIncompatible { //~ ERROR the trait `DynIncompatible` is not dyn compatible
-//~^ ERROR return type cannot have an unboxed trait object
+//~^ ERROR return type cannot be a trait object without pointer indirection
     if true {
         return A;
     }
diff --git a/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr
index 3bfb0edd4c4..c2fd11fe23d 100644
--- a/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr
+++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr
@@ -26,7 +26,7 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o
 LL |     fn foo() -> Self where Self: Sized;
    |                      +++++++++++++++++
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13
    |
 LL | fn car() -> dyn DynIncompatible {
diff --git a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
index 86a752fb316..11491a55738 100644
--- a/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
+++ b/tests/ui/impl-trait/dyn-trait-return-should-be-impl-trait.stderr
@@ -18,7 +18,7 @@ LL | fn bar() -> (usize, dyn Trait) { (42, Struct) }
    = note: required because it appears within the type `(usize, (dyn Trait + 'static))`
    = note: the return type of a function must have a statically known size
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:15:13
    |
 LL | fn bap() -> Trait { Struct }
@@ -33,7 +33,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
 LL | fn bap() -> Box<dyn Trait> { Box::new(Struct) }
    |             +++++++      +   +++++++++      +
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:17:13
    |
 LL | fn ban() -> dyn Trait { Struct }
@@ -48,7 +48,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
 LL | fn ban() -> Box<dyn Trait> { Box::new(Struct) }
    |             ++++         +   +++++++++      +
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:19:13
    |
 LL | fn bak() -> dyn Trait { unimplemented!() }
@@ -63,7 +63,7 @@ help: alternatively, box the return type, and wrap all of the returned values in
 LL | fn bak() -> Box<dyn Trait> { Box::new(unimplemented!()) }
    |             ++++         +   +++++++++                +
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:21:13
    |
 LL | fn bal() -> dyn Trait {
@@ -82,7 +82,7 @@ LL |     }
 LL ~     Box::new(42)
    |
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:27:13
    |
 LL | fn bax() -> dyn Trait {
@@ -101,7 +101,7 @@ LL |     } else {
 LL ~         Box::new(42)
    |
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:62:13
    |
 LL | fn bat() -> dyn Trait {
@@ -120,7 +120,7 @@ LL |     }
 LL ~     Box::new(42)
    |
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/dyn-trait-return-should-be-impl-trait.rs:68:13
    |
 LL | fn bay() -> dyn Trait {
diff --git a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
index a8a6288eb56..719edd525de 100644
--- a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
+++ b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.rs
@@ -63,7 +63,7 @@ fn dog() -> impl std::fmt::Display {
     }
 }
 
-fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
+fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
     match 13 {
         0 => {
             return 0i32;
@@ -74,7 +74,7 @@ fn hat() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed
     }
 }
 
-fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
+fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
     match 13 {
         0 => 0i32,
         1 => 1u32,
@@ -82,7 +82,7 @@ fn pug() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed
     }
 }
 
-fn man() -> dyn std::fmt::Display { //~ ERROR return type cannot have an unboxed trait object
+fn man() -> dyn std::fmt::Display { //~ ERROR return type cannot be a trait object without pointer indirection
     if false {
         0i32
     } else {
diff --git a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
index bd2f0ab90a5..17eaed436df 100644
--- a/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
+++ b/tests/ui/impl-trait/point-to-type-err-cause-on-impl-trait-return.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:66:13
    |
 LL | fn hat() -> dyn std::fmt::Display {
@@ -19,7 +19,7 @@ LL |         _ => {
 LL ~             Box::new(1u32)
    |
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:77:13
    |
 LL | fn pug() -> dyn std::fmt::Display {
@@ -38,7 +38,7 @@ LL ~         1 => Box::new(1u32),
 LL ~         _ => Box::new(2u32),
    |
 
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:85:13
    |
 LL | fn man() -> dyn std::fmt::Display {
diff --git a/tests/ui/issues/issue-18107.rs b/tests/ui/issues/issue-18107.rs
index 4bf5b6c0f30..b1b6ff4f7ad 100644
--- a/tests/ui/issues/issue-18107.rs
+++ b/tests/ui/issues/issue-18107.rs
@@ -2,7 +2,7 @@ pub trait AbstractRenderer {}
 
 fn _create_render(_: &()) ->
     dyn AbstractRenderer
-//~^ ERROR return type cannot have an unboxed trait object
+//~^ ERROR return type cannot be a trait object without pointer indirection
 {
     match 0 {
         _ => unimplemented!()
diff --git a/tests/ui/issues/issue-18107.stderr b/tests/ui/issues/issue-18107.stderr
index 705f7d0df12..6956d6a34aa 100644
--- a/tests/ui/issues/issue-18107.stderr
+++ b/tests/ui/issues/issue-18107.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/issue-18107.rs:4:5
    |
 LL |     dyn AbstractRenderer
diff --git a/tests/ui/unsized/box-instead-of-dyn-fn.rs b/tests/ui/unsized/box-instead-of-dyn-fn.rs
index 321c2ebf5a1..720176081d6 100644
--- a/tests/ui/unsized/box-instead-of-dyn-fn.rs
+++ b/tests/ui/unsized/box-instead-of-dyn-fn.rs
@@ -3,7 +3,7 @@ use std::fmt::Debug;
 // Test to suggest boxing the return type, and the closure branch of the `if`
 
 fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> dyn Fn() + 'a {
-    //~^ ERROR return type cannot have an unboxed trait object
+    //~^ ERROR return type cannot be a trait object without pointer indirection
     if a % 2 == 0 {
         move || println!("{a}")
     } else {
diff --git a/tests/ui/unsized/box-instead-of-dyn-fn.stderr b/tests/ui/unsized/box-instead-of-dyn-fn.stderr
index 1f1845569ef..1836d5dfffe 100644
--- a/tests/ui/unsized/box-instead-of-dyn-fn.stderr
+++ b/tests/ui/unsized/box-instead-of-dyn-fn.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/box-instead-of-dyn-fn.rs:5:56
    |
 LL | fn print_on_or_the_other<'a>(a: i32, b: &'a String) -> dyn Fn() + 'a {
diff --git a/tests/ui/unsized/issue-91801.rs b/tests/ui/unsized/issue-91801.rs
index 096b1a93574..d906a08a55a 100644
--- a/tests/ui/unsized/issue-91801.rs
+++ b/tests/ui/unsized/issue-91801.rs
@@ -6,7 +6,7 @@ pub static ALL_VALIDATORS: &[(&'static str, &'static Validator)] =
     &[("validate that credits and debits balance", &validate_something)];
 
 fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Validator<'a> {
-    //~^ ERROR return type cannot have an unboxed trait object
+    //~^ ERROR return type cannot be a trait object without pointer indirection
     return Box::new(move |something: &'_ Something| -> Result<(), ()> {
         first(something).or_else(|_| second(something))
     });
diff --git a/tests/ui/unsized/issue-91801.stderr b/tests/ui/unsized/issue-91801.stderr
index e13cabbb81d..28e10f9caa4 100644
--- a/tests/ui/unsized/issue-91801.stderr
+++ b/tests/ui/unsized/issue-91801.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/issue-91801.rs:8:77
    |
 LL | fn or<'a>(first: &'static Validator<'a>, second: &'static Validator<'a>) -> Validator<'a> {
diff --git a/tests/ui/unsized/issue-91803.rs b/tests/ui/unsized/issue-91803.rs
index c74897cc4bc..8d35c7582b8 100644
--- a/tests/ui/unsized/issue-91803.rs
+++ b/tests/ui/unsized/issue-91803.rs
@@ -1,7 +1,7 @@
 trait Foo<'a> {}
 
 fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {
-    //~^ ERROR return type cannot have an unboxed trait object
+    //~^ ERROR return type cannot be a trait object without pointer indirection
     return Box::new(panic!());
 }
 
diff --git a/tests/ui/unsized/issue-91803.stderr b/tests/ui/unsized/issue-91803.stderr
index 3b89066499d..e0fde4b1c1b 100644
--- a/tests/ui/unsized/issue-91803.stderr
+++ b/tests/ui/unsized/issue-91803.stderr
@@ -1,4 +1,4 @@
-error[E0746]: return type cannot have an unboxed trait object
+error[E0746]: return type cannot be a trait object without pointer indirection
   --> $DIR/issue-91803.rs:3:43
    |
 LL | fn or<'a>(first: &'static dyn Foo<'a>) -> dyn Foo<'a> {