Skip to content

Commit

Permalink
Point to where missing return type should go
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 30, 2023
1 parent 05c6221 commit ab0bb26
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ fn report_trait_method_mismatch<'tcx>(
let ap = Applicability::MachineApplicable;
match sig.decl.output {
hir::FnRetTy::DefaultReturn(sp) => {
let sugg = format!("-> {} ", trait_sig.output());
let sugg = format!(" -> {}", trait_sig.output());
diag.span_suggestion_verbose(sp, msg, sugg, ap);
}
hir::FnRetTy::Return(hir_ty) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub struct AddressOfTemporaryTaken {
pub enum AddReturnTypeSuggestion {
#[suggestion(
hir_typeck_add_return_type_add,
code = "-> {found} ",
code = " -> {found}",
applicability = "machine-applicable"
)]
Add {
Expand All @@ -120,7 +120,7 @@ pub enum AddReturnTypeSuggestion {
},
#[suggestion(
hir_typeck_add_return_type_missing_here,
code = "-> _ ",
code = " -> _",
applicability = "has-placeholders"
)]
MissingHere {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_infer/src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ impl<'a> SourceKindMultiSuggestion<'a> {
data: &'a FnRetTy<'a>,
should_wrap_expr: Option<Span>,
) -> Self {
let (arrow, post) = match data {
FnRetTy::DefaultReturn(_) => ("-> ", " "),
_ => ("", ""),
let arrow = match data {
FnRetTy::DefaultReturn(_) => " -> ",
_ => "",
};
let (start_span, start_span_code, end_span) = match should_wrap_expr {
Some(end_span) => (data.span(), format!("{arrow}{ty_info}{post}{{ "), Some(end_span)),
None => (data.span(), format!("{arrow}{ty_info}{post}"), None),
Some(end_span) => (data.span(), format!("{arrow}{ty_info} {{"), Some(end_span)),
None => (data.span(), format!("{arrow}{ty_info}"), None),
};
Self::ClosureReturn { start_span, start_span_code, end_span }
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
)?;
FnRetTy::Ty(ty)
} else {
FnRetTy::Default(self.token.span.shrink_to_lo())
FnRetTy::Default(self.prev_token.span.shrink_to_hi())
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-type-bounds/issue-71443-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-71443-1.rs:6:5
|
LL | fn hello<F: for<'a> Iterator<Item: 'a>>() {
| - help: try adding a return type: `-> Incorrect`
| - help: try adding a return type: `-> Incorrect`
LL | Incorrect
| ^^^^^^^^^ expected `()`, found `Incorrect`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/async-await-let-else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error[E0277]: `Rc<()>` cannot be sent between threads safely
--> $DIR/async-await-let-else.rs:47:13
|
LL | async fn foo2(x: Option<bool>) {
| - within this `impl Future<Output = ()>`
| - within this `impl Future<Output = ()>`
...
LL | is_send(foo2(Some(true)));
| ------- ^^^^^^^^^^^^^^^^ `Rc<()>` cannot be sent between threads safely
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/issue-64130-3-other.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future<Output
--> $DIR/issue-64130-3-other.rs:25:12
|
LL | async fn bar() {
| - within this `impl Future<Output = ()>`
| - within this `impl Future<Output = ()>`
...
LL | is_qux(bar());
| ^^^^^ within `impl Future<Output = ()>`, the trait `Qux` is not implemented for `Foo`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/issues/issue-67893.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | g(issue_67893::run())
| |
| required by a bound introduced by this call
|
::: $DIR/auxiliary/issue_67893.rs:9:20
::: $DIR/auxiliary/issue_67893.rs:9:19
|
LL | pub async fn run() {
| - within this `impl Future<Output = ()>`
| - within this `impl Future<Output = ()>`
|
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
= note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:18
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:17
|
LL | async fn rec_1() {
| ^ recursive `async fn`
| ^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:17
|
LL | async fn rec_2() {
| ^ recursive `async fn`
| ^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/partial-drop-partial-reinit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | gimme_send(foo());
| required by a bound introduced by this call
...
LL | async fn foo() {
| - within this `impl Future<Output = ()>`
| - within this `impl Future<Output = ()>`
|
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
= note: required because it appears within the type `(NotSend,)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-res.rs:5:9
|
LL | fn drop(&mut self) {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | true
| ^^^^ expected `()`, found `bool`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/block-result/issue-20862.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-20862.rs:2:5
|
LL | fn foo(x: i32) {
| - help: a return type might be missing here: `-> _`
| - help: a return type might be missing here: `-> _`
LL | |y| x + y
| ^^^^^^^^^ expected `()`, found closure
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/block-result/issue-22645.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ error[E0308]: mismatched types
--> $DIR/issue-22645.rs:15:3
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | let b = Bob + 3.5;
LL | b + 3
| ^^^^^ expected `()`, found `Bob`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/block-result/issue-5500.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-5500.rs:2:5
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | &panic!()
| ^^^^^^^^^ expected `()`, found `&_`
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/add_semicolon_non_block_closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/add_semicolon_non_block_closure.rs:8:12
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | foo(|| bar())
| ^^^^^ expected `()`, found `i32`
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/closures/binder/implicit-return.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/implicit-return.rs:4:34
--> $DIR/implicit-return.rs:4:33
|
LL | let _f = for<'a> |_: &'a ()| {};
| ------- ^
| ------- ^
| |
| `for<...>` is here

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/closures/binder/implicit-stuff.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ LL | let _ = for<'a> |x: &'a ()| -> &() { x };
| ^ explicit lifetime name needed here

error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/implicit-stuff.rs:5:22
--> $DIR/implicit-stuff.rs:5:21
|
LL | let _ = for<> || {};
| ----- ^
| ----- ^
| |
| `for<...>` is here

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/codemap_tests/tab.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/tab.rs:8:2
|
LL | fn foo() {
| - help: try adding a return type: `-> &'static str`
| - help: try adding a return type: `-> &'static str`
LL | "bar boo"
| ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&str`

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/compare-method/bad-self-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ LL | fn foo(self);
found signature `fn(Box<MyFuture>)`

error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/bad-self-type.rs:24:18
--> $DIR/bad-self-type.rs:24:17
|
LL | fn bar(self) {}
| ^ expected `Option<()>`, found `()`
| ^ expected `Option<()>`, found `()`
|
note: type in trait
--> $DIR/bad-self-type.rs:18:21
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/in-trait/refine.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ LL | fn bar() {}
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
help: replace the return type so that it matches the trait
|
LL | fn bar() -> impl Sized {}
| +++++++++++++
LL | fn bar()-> impl Sized {}
| +++++++++++++

error: impl trait in impl method signature does not match trait method signature
--> $DIR/refine.rs:22:17
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/issues/issue-66667-function-cmp-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:2:5
|
LL | fn first() {
| - help: try adding a return type: `-> bool`
| - help: try adding a return type: `-> bool`
LL | second == 1
| ^^^^^^^^^^^ expected `()`, found `bool`

Expand All @@ -44,7 +44,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:8:5
|
LL | fn second() {
| - help: try adding a return type: `-> bool`
| - help: try adding a return type: `-> bool`
LL | first == 1
| ^^^^^^^^^^ expected `()`, found `bool`

Expand All @@ -69,7 +69,7 @@ error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:14:5
|
LL | fn bar() {
| - help: try adding a return type: `-> bool`
| - help: try adding a return type: `-> bool`
LL | bar == 1
| ^^^^^^^^ expected `()`, found `bool`

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/lang-items/start_lang_item_args.missing_ret.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0308]: lang item `start` function has wrong type
--> $DIR/start_lang_item_args.rs:29:84
--> $DIR/start_lang_item_args.rs:29:83
|
LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) {}
| ^ expected `isize`, found `()`
| ^ expected `isize`, found `()`
|
= note: expected signature `fn(fn() -> _, _, _, _) -> isize`
found signature `fn(fn() -> _, _, _, _)`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/loops/loop-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ error[E0308]: mismatched types
--> $DIR/loop-break-value.rs:159:15
|
LL | fn main() {
| - expected `()` because of this return type
| - expected `()` because of this return type
...
LL | loop { // point at the return type
| ---- this loop is expected to be of type `()`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/mismatched_types/issue-19109.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-19109.rs:4:5
|
LL | fn function(t: &mut dyn Trait) {
| - help: try adding a return type: `-> *mut dyn Trait`
| - help: try adding a return type: `-> *mut dyn Trait`
LL | t as *mut dyn Trait
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `*mut dyn Trait`
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/offset-of/offset-of-output-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ error[E0308]: mismatched types
--> $DIR/offset-of-output-type.rs:19:5
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
...
LL | offset_of!(S, v)
| ^^^^^^^^^^^^^^^^ expected `()`, found `usize`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/recover-quantified-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ LL | for <Foo>::Bar in x {}
= help: consider removing `for<...>`

error: implicit types in closure signatures are forbidden when `for<...>` is present
--> $DIR/recover-quantified-closure.rs:2:25
--> $DIR/recover-quantified-closure.rs:2:24
|
LL | for<'a> |x: &'a u8| *x + 1;
| ------- ^
| ------- ^
| |
| `for<...>` is here

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/issue-37788.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-37788.rs:8:5
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE.
LL | std::cell::Cell::new(0)
| ^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/resolved-located-at.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0308]: mismatched types
--> $DIR/resolved-located-at.rs:7:27
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | resolve_located_at!(a b)
| ^ expected `()`, found `S`
|
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/proc-macro/span-preservation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ error[E0308]: mismatched types
--> $DIR/span-preservation.rs:39:5
|
LL | extern "C" fn bar() {
| - help: try adding a return type: `-> i32`
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/span-preservation.rs:44:5
|
LL | extern "C" fn baz() {
| - help: try adding a return type: `-> i32`
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/span-preservation.rs:49:5
|
LL | extern "Rust" fn rust_abi() {
| - help: try adding a return type: `-> i32`
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/span-preservation.rs:54:5
|
LL | extern "\x43" fn c_abi_escaped() {
| - help: try adding a return type: `-> i32`
| - help: try adding a return type: `-> i32`
LL | 0
| ^ expected `()`, found integer

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/return/return-struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ error[E0308]: mismatched types
--> $DIR/return-struct.rs:15:5
|
LL | fn bar() {
| - help: try adding a return type: `-> Age`
| - help: try adding a return type: `-> Age`
LL | let mut age = 29;
LL | Age::Years(age, 55)
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `Age`
Expand All @@ -26,7 +26,7 @@ error[E0308]: mismatched types
--> $DIR/return-struct.rs:20:5
|
LL | fn baz() {
| - help: try adding a return type: `-> S`
| - help: try adding a return type: `-> S`
LL | S
| ^ expected `()`, found `S`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/issue-83892.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-83892.rs:9:15
|
LL | fn main() {
| - expected `()` because of default return type
| - expected `()` because of default return type
LL | match () {
LL | () => func()
| ^^^^^^ expected `()`, found `u8`
Expand Down
Loading

0 comments on commit ab0bb26

Please sign in to comment.