1
Fork 0

Tweak output

This commit is contained in:
Esteban Küber 2023-01-06 02:49:15 +00:00
parent 1fa6ada9dd
commit 031e085450
4 changed files with 44 additions and 66 deletions

View file

@ -224,14 +224,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut ret_span: MultiSpan = semi_span.into(); let mut ret_span: MultiSpan = semi_span.into();
ret_span.push_span_label( ret_span.push_span_label(
expr.span, expr.span,
"this could be implicitly returned but it is a statement, not a \ "this could be implicitly returned but it is a statement, not a tail expression",
tail expression",
); );
ret_span.push_span_label(ret, "the `match` arms can conform to this return type"); ret_span.push_span_label(ret, "the `match` arms can conform to this return type");
ret_span.push_span_label( ret_span.push_span_label(
semi_span, semi_span,
"the `match` is a statement because of this semicolon, consider \ "the `match` is a statement because of this semicolon, consider removing it",
removing it",
); );
diag.span_note(ret_span, "you might have meant to return the `match` expression"); diag.span_note(ret_span, "you might have meant to return the `match` expression");
diag.tool_only_span_suggestion( diag.tool_only_span_suggestion(

View file

@ -1699,20 +1699,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return; return;
} }
let [.., stmt] = block.stmts else { let [.., stmt] = block.stmts else {
err.span_help(block.span, "this empty block is missing a tail expression"); err.span_label(block.span, "this empty block is missing a tail expression");
return; return;
}; };
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; }; let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else { return; }; let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else { return; };
if self.can_eq(self.param_env, expected_ty, ty).is_ok() { if self.can_eq(self.param_env, expected_ty, ty).is_ok() {
err.span_suggestion_verbose( err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()), stmt.span.with_lo(tail_expr.span.hi()),
"remove this semicolon", "remove this semicolon",
"", "",
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } else {
err.span_help(block.span, "this block is missing a tail expression"); err.span_label(block.span, "this block is missing a tail expression");
} }
} }
} }

View file

@ -1077,12 +1077,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
return; return;
} }
let [.., stmt] = block.stmts else { let [.., stmt] = block.stmts else {
err.span_help(block.span, "this empty block is missing a tail expression"); err.span_label(block.span, "this empty block is missing a tail expression");
return; return;
}; };
let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; }; let hir::StmtKind::Semi(tail_expr) = stmt.kind else { return; };
let Some(ty) = typeck.expr_ty_opt(tail_expr) else { let Some(ty) = typeck.expr_ty_opt(tail_expr) else {
err.span_help(block.span, "this block is missing a tail expression"); err.span_label(block.span, "this block is missing a tail expression");
return; return;
}; };
let ty = self.resolve_numeric_literals_with_default(self.resolve_vars_if_possible(ty)); 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> {
let new_obligation = let new_obligation =
self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_pred_and_self); self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_pred_and_self);
if self.predicate_must_hold_modulo_regions(&new_obligation) { if self.predicate_must_hold_modulo_regions(&new_obligation) {
err.span_suggestion_verbose( err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()), stmt.span.with_lo(tail_expr.span.hi()),
"remove this semicolon", "remove this semicolon",
"", "",
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } else {
err.span_help(block.span, "this block is missing a tail expression"); err.span_label(block.span, "this block is missing a tail expression");
} }
} }

View file

@ -1,29 +1,25 @@
error[E0277]: `()` doesn't implement `std::fmt::Display` error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/binding-assigned-block-without-tail-expression.rs:14:20 --> $DIR/binding-assigned-block-without-tail-expression.rs:14:20
| |
LL | 42;
| - help: remove this semicolon
...
LL | println!("{}", x); LL | println!("{}", x);
| ^ `()` cannot be formatted with the default formatter | ^ `()` cannot be formatted with the default formatter
| |
= help: the trait `std::fmt::Display` is not implemented for `()` = help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= 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) = 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)
help: remove this semicolon
|
LL - 42;
LL + 42
|
error[E0277]: `()` doesn't implement `std::fmt::Display` error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/binding-assigned-block-without-tail-expression.rs:15:20 --> $DIR/binding-assigned-block-without-tail-expression.rs:15:20
| |
LL | let y = {};
| -- this empty block is missing a tail expression
...
LL | println!("{}", y); LL | println!("{}", y);
| ^ `()` cannot be formatted with the default formatter | ^ `()` cannot be formatted with the default formatter
| |
help: this empty block is missing a tail expression
--> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
|
LL | let y = {};
| ^^
= help: the trait `std::fmt::Display` is not implemented for `()` = help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= 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) = 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)
@ -31,32 +27,28 @@ LL | let y = {};
error[E0277]: `()` doesn't implement `std::fmt::Display` error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/binding-assigned-block-without-tail-expression.rs:16:20 --> $DIR/binding-assigned-block-without-tail-expression.rs:16:20
| |
LL | "hi";
| - help: remove this semicolon
...
LL | println!("{}", z); LL | println!("{}", z);
| ^ `()` cannot be formatted with the default formatter | ^ `()` cannot be formatted with the default formatter
| |
= help: the trait `std::fmt::Display` is not implemented for `()` = help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= 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) = 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)
help: remove this semicolon
|
LL - "hi";
LL + "hi"
|
error[E0277]: `()` doesn't implement `std::fmt::Display` error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/binding-assigned-block-without-tail-expression.rs:17:20 --> $DIR/binding-assigned-block-without-tail-expression.rs:17:20
| |
LL | println!("{}", s);
| ^ `()` cannot be formatted with the default formatter
|
help: this block is missing a tail expression
--> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
|
LL | let s = { LL | let s = {
| _____________^ | _____________-
LL | | S; LL | | S;
LL | | }; LL | | };
| |_____^ | |_____- this block is missing a tail expression
...
LL | println!("{}", s);
| ^ `()` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `()` = help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= 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) = 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)
@ -64,64 +56,52 @@ LL | | };
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/binding-assigned-block-without-tail-expression.rs:18:18 --> $DIR/binding-assigned-block-without-tail-expression.rs:18:18
| |
LL | 42;
| - help: remove this semicolon
...
LL | let _: i32 = x; LL | let _: i32 = x;
| --- ^ expected `i32`, found `()` | --- ^ expected `i32`, found `()`
| | | |
| expected due to this | expected due to this
|
help: remove this semicolon
|
LL - 42;
LL + 42
|
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/binding-assigned-block-without-tail-expression.rs:19:18 --> $DIR/binding-assigned-block-without-tail-expression.rs:19:18
| |
LL | let y = {};
| -- this empty block is missing a tail expression
...
LL | let _: i32 = y; LL | let _: i32 = y;
| --- ^ expected `i32`, found `()` | --- ^ expected `i32`, found `()`
| | | |
| expected due to this | expected due to this
|
help: this empty block is missing a tail expression
--> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
|
LL | let y = {};
| ^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/binding-assigned-block-without-tail-expression.rs:20:18 --> $DIR/binding-assigned-block-without-tail-expression.rs:20:18
| |
LL | let _: i32 = z;
| --- ^ expected `i32`, found `()`
| |
| expected due to this
|
help: this block is missing a tail expression
--> $DIR/binding-assigned-block-without-tail-expression.rs:8:13
|
LL | let z = { LL | let z = {
| _____________^ | _____________-
LL | | "hi"; LL | | "hi";
LL | | }; LL | | };
| |_____^ | |_____- this block is missing a tail expression
...
LL | let _: i32 = z;
| --- ^ expected `i32`, found `()`
| |
| expected due to this
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/binding-assigned-block-without-tail-expression.rs:21:18 --> $DIR/binding-assigned-block-without-tail-expression.rs:21:18
| |
LL | let _: i32 = s;
| --- ^ expected `i32`, found `()`
| |
| expected due to this
|
help: this block is missing a tail expression
--> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
|
LL | let s = { LL | let s = {
| _____________^ | _____________-
LL | | S; LL | | S;
LL | | }; LL | | };
| |_____^ | |_____- this block is missing a tail expression
...
LL | let _: i32 = s;
| --- ^ expected `i32`, found `()`
| |
| expected due to this
error: aborting due to 8 previous errors error: aborting due to 8 previous errors