Skip to content

Commit ab0bb26

Browse files
Point to where missing return type should go
1 parent 05c6221 commit ab0bb26

36 files changed

+58
-58
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ fn report_trait_method_mismatch<'tcx>(
11881188
let ap = Applicability::MachineApplicable;
11891189
match sig.decl.output {
11901190
hir::FnRetTy::DefaultReturn(sp) => {
1191-
let sugg = format!("-> {} ", trait_sig.output());
1191+
let sugg = format!(" -> {}", trait_sig.output());
11921192
diag.span_suggestion_verbose(sp, msg, sugg, ap);
11931193
}
11941194
hir::FnRetTy::Return(hir_ty) => {

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct AddressOfTemporaryTaken {
110110
pub enum AddReturnTypeSuggestion {
111111
#[suggestion(
112112
hir_typeck_add_return_type_add,
113-
code = "-> {found} ",
113+
code = " -> {found}",
114114
applicability = "machine-applicable"
115115
)]
116116
Add {
@@ -120,7 +120,7 @@ pub enum AddReturnTypeSuggestion {
120120
},
121121
#[suggestion(
122122
hir_typeck_add_return_type_missing_here,
123-
code = "-> _ ",
123+
code = " -> _",
124124
applicability = "has-placeholders"
125125
)]
126126
MissingHere {

compiler/rustc_infer/src/errors/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ impl<'a> SourceKindMultiSuggestion<'a> {
194194
data: &'a FnRetTy<'a>,
195195
should_wrap_expr: Option<Span>,
196196
) -> Self {
197-
let (arrow, post) = match data {
198-
FnRetTy::DefaultReturn(_) => ("-> ", " "),
199-
_ => ("", ""),
197+
let arrow = match data {
198+
FnRetTy::DefaultReturn(_) => " -> ",
199+
_ => "",
200200
};
201201
let (start_span, start_span_code, end_span) = match should_wrap_expr {
202-
Some(end_span) => (data.span(), format!("{arrow}{ty_info}{post}{{ "), Some(end_span)),
203-
None => (data.span(), format!("{arrow}{ty_info}{post}"), None),
202+
Some(end_span) => (data.span(), format!("{arrow}{ty_info} {{"), Some(end_span)),
203+
None => (data.span(), format!("{arrow}{ty_info}"), None),
204204
};
205205
Self::ClosureReturn { start_span, start_span_code, end_span }
206206
}

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
247247
)?;
248248
FnRetTy::Ty(ty)
249249
} else {
250-
FnRetTy::Default(self.token.span.shrink_to_lo())
250+
FnRetTy::Default(self.prev_token.span.shrink_to_hi())
251251
})
252252
}
253253

tests/ui/associated-type-bounds/issue-71443-1.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-71443-1.rs:6:5
33
|
44
LL | fn hello<F: for<'a> Iterator<Item: 'a>>() {
5-
| - help: try adding a return type: `-> Incorrect`
5+
| - help: try adding a return type: `-> Incorrect`
66
LL | Incorrect
77
| ^^^^^^^^^ expected `()`, found `Incorrect`
88

tests/ui/async-await/async-await-let-else.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error[E0277]: `Rc<()>` cannot be sent between threads safely
2222
--> $DIR/async-await-let-else.rs:47:13
2323
|
2424
LL | async fn foo2(x: Option<bool>) {
25-
| - within this `impl Future<Output = ()>`
25+
| - within this `impl Future<Output = ()>`
2626
...
2727
LL | is_send(foo2(Some(true)));
2828
| ------- ^^^^^^^^^^^^^^^^ `Rc<()>` cannot be sent between threads safely

tests/ui/async-await/issue-64130-3-other.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future<Output
22
--> $DIR/issue-64130-3-other.rs:25:12
33
|
44
LL | async fn bar() {
5-
| - within this `impl Future<Output = ()>`
5+
| - within this `impl Future<Output = ()>`
66
...
77
LL | is_qux(bar());
88
| ^^^^^ within `impl Future<Output = ()>`, the trait `Qux` is not implemented for `Foo`

tests/ui/async-await/issues/issue-67893.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | g(issue_67893::run())
66
| |
77
| required by a bound introduced by this call
88
|
9-
::: $DIR/auxiliary/issue_67893.rs:9:20
9+
::: $DIR/auxiliary/issue_67893.rs:9:19
1010
|
1111
LL | pub async fn run() {
12-
| - within this `impl Future<Output = ()>`
12+
| - within this `impl Future<Output = ()>`
1313
|
1414
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
1515
= note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>`

tests/ui/async-await/mutually-recursive-async-impl-trait-type.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0733]: recursion in an `async fn` requires boxing
2-
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:18
2+
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:17
33
|
44
LL | async fn rec_1() {
5-
| ^ recursive `async fn`
5+
| ^ recursive `async fn`
66
|
77
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
88
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
99

1010
error[E0733]: recursion in an `async fn` requires boxing
11-
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18
11+
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:17
1212
|
1313
LL | async fn rec_2() {
14-
| ^ recursive `async fn`
14+
| ^ recursive `async fn`
1515
|
1616
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
1717
= note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

tests/ui/async-await/partial-drop-partial-reinit.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | gimme_send(foo());
77
| required by a bound introduced by this call
88
...
99
LL | async fn foo() {
10-
| - within this `impl Future<Output = ()>`
10+
| - within this `impl Future<Output = ()>`
1111
|
1212
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`
1313
= note: required because it appears within the type `(NotSend,)`

tests/ui/block-result/block-must-not-have-result-res.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/block-must-not-have-result-res.rs:5:9
33
|
44
LL | fn drop(&mut self) {
5-
| - expected `()` because of default return type
5+
| - expected `()` because of default return type
66
LL | true
77
| ^^^^ expected `()`, found `bool`
88

tests/ui/block-result/issue-20862.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-20862.rs:2:5
33
|
44
LL | fn foo(x: i32) {
5-
| - help: a return type might be missing here: `-> _`
5+
| - help: a return type might be missing here: `-> _`
66
LL | |y| x + y
77
| ^^^^^^^^^ expected `()`, found closure
88
|

tests/ui/block-result/issue-22645.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error[E0308]: mismatched types
1717
--> $DIR/issue-22645.rs:15:3
1818
|
1919
LL | fn main() {
20-
| - expected `()` because of default return type
20+
| - expected `()` because of default return type
2121
LL | let b = Bob + 3.5;
2222
LL | b + 3
2323
| ^^^^^ expected `()`, found `Bob`

tests/ui/block-result/issue-5500.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-5500.rs:2:5
33
|
44
LL | fn main() {
5-
| - expected `()` because of default return type
5+
| - expected `()` because of default return type
66
LL | &panic!()
77
| ^^^^^^^^^ expected `()`, found `&_`
88
|

tests/ui/closures/add_semicolon_non_block_closure.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/add_semicolon_non_block_closure.rs:8:12
33
|
44
LL | fn main() {
5-
| - expected `()` because of default return type
5+
| - expected `()` because of default return type
66
LL | foo(|| bar())
77
| ^^^^^ expected `()`, found `i32`
88
|

tests/ui/closures/binder/implicit-return.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: implicit types in closure signatures are forbidden when `for<...>` is present
2-
--> $DIR/implicit-return.rs:4:34
2+
--> $DIR/implicit-return.rs:4:33
33
|
44
LL | let _f = for<'a> |_: &'a ()| {};
5-
| ------- ^
5+
| ------- ^
66
| |
77
| `for<...>` is here
88

tests/ui/closures/binder/implicit-stuff.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ LL | let _ = for<'a> |x: &'a ()| -> &() { x };
4141
| ^ explicit lifetime name needed here
4242

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

tests/ui/codemap_tests/tab.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0308]: mismatched types
88
--> $DIR/tab.rs:8:2
99
|
1010
LL | fn foo() {
11-
| - help: try adding a return type: `-> &'static str`
11+
| - help: try adding a return type: `-> &'static str`
1212
LL | "bar boo"
1313
| ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&str`
1414

tests/ui/compare-method/bad-self-type.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ LL | fn foo(self);
2828
found signature `fn(Box<MyFuture>)`
2929

3030
error[E0053]: method `bar` has an incompatible type for trait
31-
--> $DIR/bad-self-type.rs:24:18
31+
--> $DIR/bad-self-type.rs:24:17
3232
|
3333
LL | fn bar(self) {}
34-
| ^ expected `Option<()>`, found `()`
34+
| ^ expected `Option<()>`, found `()`
3535
|
3636
note: type in trait
3737
--> $DIR/bad-self-type.rs:18:21

tests/ui/impl-trait/in-trait/refine.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ LL | fn bar() {}
3030
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
3131
help: replace the return type so that it matches the trait
3232
|
33-
LL | fn bar() -> impl Sized {}
34-
| +++++++++++++
33+
LL | fn bar()-> impl Sized {}
34+
| +++++++++++++
3535

3636
error: impl trait in impl method signature does not match trait method signature
3737
--> $DIR/refine.rs:22:17

tests/ui/issues/issue-66667-function-cmp-cycle.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ error[E0308]: mismatched types
1919
--> $DIR/issue-66667-function-cmp-cycle.rs:2:5
2020
|
2121
LL | fn first() {
22-
| - help: try adding a return type: `-> bool`
22+
| - help: try adding a return type: `-> bool`
2323
LL | second == 1
2424
| ^^^^^^^^^^^ expected `()`, found `bool`
2525

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

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

tests/ui/lang-items/start_lang_item_args.missing_ret.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0308]: lang item `start` function has wrong type
2-
--> $DIR/start_lang_item_args.rs:29:84
2+
--> $DIR/start_lang_item_args.rs:29:83
33
|
44
LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) {}
5-
| ^ expected `isize`, found `()`
5+
| ^ expected `isize`, found `()`
66
|
77
= note: expected signature `fn(fn() -> _, _, _, _) -> isize`
88
found signature `fn(fn() -> _, _, _, _)`

tests/ui/loops/loop-break-value.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ error[E0308]: mismatched types
319319
--> $DIR/loop-break-value.rs:159:15
320320
|
321321
LL | fn main() {
322-
| - expected `()` because of this return type
322+
| - expected `()` because of this return type
323323
...
324324
LL | loop { // point at the return type
325325
| ---- this loop is expected to be of type `()`

tests/ui/mismatched_types/issue-19109.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-19109.rs:4:5
33
|
44
LL | fn function(t: &mut dyn Trait) {
5-
| - help: try adding a return type: `-> *mut dyn Trait`
5+
| - help: try adding a return type: `-> *mut dyn Trait`
66
LL | t as *mut dyn Trait
77
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `*mut dyn Trait`
88
|

tests/ui/offset-of/offset-of-output-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ error[E0308]: mismatched types
4242
--> $DIR/offset-of-output-type.rs:19:5
4343
|
4444
LL | fn main() {
45-
| - expected `()` because of default return type
45+
| - expected `()` because of default return type
4646
...
4747
LL | offset_of!(S, v)
4848
| ^^^^^^^^^^^^^^^^ expected `()`, found `usize`

tests/ui/parser/recover-quantified-closure.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ LL | for <Foo>::Bar in x {}
2525
= help: consider removing `for<...>`
2626

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

tests/ui/proc-macro/issue-37788.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-37788.rs:8:5
33
|
44
LL | fn main() {
5-
| - expected `()` because of default return type
5+
| - expected `()` because of default return type
66
LL | // Test that constructing the `visible_parent_map` (in `cstore_impl.rs`) does not ICE.
77
LL | std::cell::Cell::new(0)
88
| ^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`

tests/ui/proc-macro/resolved-located-at.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0308]: mismatched types
1010
--> $DIR/resolved-located-at.rs:7:27
1111
|
1212
LL | fn main() {
13-
| - expected `()` because of default return type
13+
| - expected `()` because of default return type
1414
LL | resolve_located_at!(a b)
1515
| ^ expected `()`, found `S`
1616
|

tests/ui/proc-macro/span-preservation.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ error[E0308]: mismatched types
3838
--> $DIR/span-preservation.rs:39:5
3939
|
4040
LL | extern "C" fn bar() {
41-
| - help: try adding a return type: `-> i32`
41+
| - help: try adding a return type: `-> i32`
4242
LL | 0
4343
| ^ expected `()`, found integer
4444

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

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

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

tests/ui/return/return-struct.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error[E0308]: mismatched types
1717
--> $DIR/return-struct.rs:15:5
1818
|
1919
LL | fn bar() {
20-
| - help: try adding a return type: `-> Age`
20+
| - help: try adding a return type: `-> Age`
2121
LL | let mut age = 29;
2222
LL | Age::Years(age, 55)
2323
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `Age`
@@ -26,7 +26,7 @@ error[E0308]: mismatched types
2626
--> $DIR/return-struct.rs:20:5
2727
|
2828
LL | fn baz() {
29-
| - help: try adding a return type: `-> S`
29+
| - help: try adding a return type: `-> S`
3030
LL | S
3131
| ^ expected `()`, found `S`
3232

tests/ui/suggestions/issue-83892.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-83892.rs:9:15
33
|
44
LL | fn main() {
5-
| - expected `()` because of default return type
5+
| - expected `()` because of default return type
66
LL | match () {
77
LL | () => func()
88
| ^^^^^^ expected `()`, found `u8`

0 commit comments

Comments
 (0)