Skip to content

Commit 031e085

Browse files
committed
Tweak output
1 parent 1fa6ada commit 031e085

File tree

4 files changed

+44
-66
lines changed

4 files changed

+44
-66
lines changed

compiler/rustc_hir_typeck/src/_match.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
224224
let mut ret_span: MultiSpan = semi_span.into();
225225
ret_span.push_span_label(
226226
expr.span,
227-
"this could be implicitly returned but it is a statement, not a \
228-
tail expression",
227+
"this could be implicitly returned but it is a statement, not a tail expression",
229228
);
230229
ret_span.push_span_label(ret, "the `match` arms can conform to this return type");
231230
ret_span.push_span_label(
232231
semi_span,
233-
"the `match` is a statement because of this semicolon, consider \
234-
removing it",
232+
"the `match` is a statement because of this semicolon, consider removing it",
235233
);
236234
diag.span_note(ret_span, "you might have meant to return the `match` expression");
237235
diag.tool_only_span_suggestion(

compiler/rustc_hir_typeck/src/demand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1699,20 +1699,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16991699
return;
17001700
}
17011701
let [.., stmt] = block.stmts else {
1702-
err.span_help(block.span, "this empty block is missing a tail expression");
1702+
err.span_label(block.span, "this empty block is missing a tail expression");
17031703
return;
17041704
};
17051705
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
17061706
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else { return; };
17071707
if self.can_eq(self.param_env, expected_ty, ty).is_ok() {
1708-
err.span_suggestion_verbose(
1708+
err.span_suggestion_short(
17091709
stmt.span.with_lo(tail_expr.span.hi()),
17101710
"remove this semicolon",
17111711
"",
17121712
Applicability::MachineApplicable,
17131713
);
17141714
} else {
1715-
err.span_help(block.span, "this block is missing a tail expression");
1715+
err.span_label(block.span, "this block is missing a tail expression");
17161716
}
17171717
}
17181718
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1077,12 +1077,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10771077
return;
10781078
}
10791079
let [.., stmt] = block.stmts else {
1080-
err.span_help(block.span, "this empty block is missing a tail expression");
1080+
err.span_label(block.span, "this empty block is missing a tail expression");
10811081
return;
10821082
};
10831083
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
10841084
let Some(ty) = typeck.expr_ty_opt(tail_expr) else {
1085-
err.span_help(block.span, "this block is missing a tail expression");
1085+
err.span_label(block.span, "this block is missing a tail expression");
10861086
return;
10871087
};
10881088
let ty = self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(ty));
@@ -1091,14 +1091,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10911091
let new_obligation =
10921092
self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_pred_and_self);
10931093
if self.predicate_must_hold_modulo_regions(&new_obligation) {
1094-
err.span_suggestion_verbose(
1094+
err.span_suggestion_short(
10951095
stmt.span.with_lo(tail_expr.span.hi()),
10961096
"remove this semicolon",
10971097
"",
10981098
Applicability::MachineApplicable,
10991099
);
11001100
} else {
1101-
err.span_help(block.span, "this block is missing a tail expression");
1101+
err.span_label(block.span, "this block is missing a tail expression");
11021102
}
11031103
}
11041104

src/test/ui/type/binding-assigned-block-without-tail-expression.stderr

+35-55
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,107 @@
11
error[E0277]: `()` doesn't implement `std::fmt::Display`
22
--> $DIR/binding-assigned-block-without-tail-expression.rs:14:20
33
|
4+
LL | 42;
5+
| - help: remove this semicolon
6+
...
47
LL | println!("{}", x);
58
| ^ `()` cannot be formatted with the default formatter
69
|
710
= help: the trait `std::fmt::Display` is not implemented for `()`
811
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
912
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
10-
help: remove this semicolon
11-
|
12-
LL - 42;
13-
LL + 42
14-
|
1513

1614
error[E0277]: `()` doesn't implement `std::fmt::Display`
1715
--> $DIR/binding-assigned-block-without-tail-expression.rs:15:20
1816
|
17+
LL | let y = {};
18+
| -- this empty block is missing a tail expression
19+
...
1920
LL | println!("{}", y);
2021
| ^ `()` cannot be formatted with the default formatter
2122
|
22-
help: this empty block is missing a tail expression
23-
--> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
24-
|
25-
LL | let y = {};
26-
| ^^
2723
= help: the trait `std::fmt::Display` is not implemented for `()`
2824
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
2925
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
3026

3127
error[E0277]: `()` doesn't implement `std::fmt::Display`
3228
--> $DIR/binding-assigned-block-without-tail-expression.rs:16:20
3329
|
30+
LL | "hi";
31+
| - help: remove this semicolon
32+
...
3433
LL | println!("{}", z);
3534
| ^ `()` cannot be formatted with the default formatter
3635
|
3736
= help: the trait `std::fmt::Display` is not implemented for `()`
3837
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
3938
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
40-
help: remove this semicolon
41-
|
42-
LL - "hi";
43-
LL + "hi"
44-
|
4539

4640
error[E0277]: `()` doesn't implement `std::fmt::Display`
4741
--> $DIR/binding-assigned-block-without-tail-expression.rs:17:20
4842
|
49-
LL | println!("{}", s);
50-
| ^ `()` cannot be formatted with the default formatter
51-
|
52-
help: this block is missing a tail expression
53-
--> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
54-
|
5543
LL | let s = {
56-
| _____________^
44+
| _____________-
5745
LL | | S;
5846
LL | | };
59-
| |_____^
47+
| |_____- this block is missing a tail expression
48+
...
49+
LL | println!("{}", s);
50+
| ^ `()` cannot be formatted with the default formatter
51+
|
6052
= help: the trait `std::fmt::Display` is not implemented for `()`
6153
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
6254
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
6355

6456
error[E0308]: mismatched types
6557
--> $DIR/binding-assigned-block-without-tail-expression.rs:18:18
6658
|
59+
LL | 42;
60+
| - help: remove this semicolon
61+
...
6762
LL | let _: i32 = x;
6863
| --- ^ expected `i32`, found `()`
6964
| |
7065
| expected due to this
71-
|
72-
help: remove this semicolon
73-
|
74-
LL - 42;
75-
LL + 42
76-
|
7766

7867
error[E0308]: mismatched types
7968
--> $DIR/binding-assigned-block-without-tail-expression.rs:19:18
8069
|
70+
LL | let y = {};
71+
| -- this empty block is missing a tail expression
72+
...
8173
LL | let _: i32 = y;
8274
| --- ^ expected `i32`, found `()`
8375
| |
8476
| expected due to this
85-
|
86-
help: this empty block is missing a tail expression
87-
--> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
88-
|
89-
LL | let y = {};
90-
| ^^
9177

9278
error[E0308]: mismatched types
9379
--> $DIR/binding-assigned-block-without-tail-expression.rs:20:18
9480
|
95-
LL | let _: i32 = z;
96-
| --- ^ expected `i32`, found `()`
97-
| |
98-
| expected due to this
99-
|
100-
help: this block is missing a tail expression
101-
--> $DIR/binding-assigned-block-without-tail-expression.rs:8:13
102-
|
10381
LL | let z = {
104-
| _____________^
82+
| _____________-
10583
LL | | "hi";
10684
LL | | };
107-
| |_____^
85+
| |_____- this block is missing a tail expression
86+
...
87+
LL | let _: i32 = z;
88+
| --- ^ expected `i32`, found `()`
89+
| |
90+
| expected due to this
10891

10992
error[E0308]: mismatched types
11093
--> $DIR/binding-assigned-block-without-tail-expression.rs:21:18
11194
|
112-
LL | let _: i32 = s;
113-
| --- ^ expected `i32`, found `()`
114-
| |
115-
| expected due to this
116-
|
117-
help: this block is missing a tail expression
118-
--> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
119-
|
12095
LL | let s = {
121-
| _____________^
96+
| _____________-
12297
LL | | S;
12398
LL | | };
124-
| |_____^
99+
| |_____- this block is missing a tail expression
100+
...
101+
LL | let _: i32 = s;
102+
| --- ^ expected `i32`, found `()`
103+
| |
104+
| expected due to this
125105

126106
error: aborting due to 8 previous errors
127107

0 commit comments

Comments
 (0)