Skip to content

Commit e2ce5d7

Browse files
committed
renaming test cases
1 parent e6f48fa commit e2ce5d7

File tree

5 files changed

+15
-54
lines changed

5 files changed

+15
-54
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

-39
Original file line numberDiff line numberDiff line change
@@ -1791,45 +1791,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17911791
}
17921792
}
17931793

1794-
/// A common error is to add an extra semicolon:
1795-
///
1796-
/// ```compile_fail,E0308
1797-
/// fn foo() -> usize {
1798-
/// 22;
1799-
/// }
1800-
/// ```
1801-
///
1802-
/// This routine checks if the final statement in a block is an
1803-
/// expression with an explicit semicolon whose type is compatible
1804-
/// with `expected_ty`. If so, it suggests removing the semicolon.
1805-
pub(crate) fn consider_removing_semicolon(
1806-
&self,
1807-
blk: &'tcx hir::Block<'tcx>,
1808-
expected_ty: Ty<'tcx>,
1809-
err: &mut Diag<'_>,
1810-
) -> bool {
1811-
if let Some((span_semi, boxed)) = self.err_ctxt().could_remove_semicolon(blk, expected_ty) {
1812-
if let StatementAsExpression::NeedsBoxing = boxed {
1813-
err.span_suggestion_verbose(
1814-
span_semi,
1815-
"consider removing this semicolon and boxing the expression",
1816-
"",
1817-
Applicability::HasPlaceholders,
1818-
);
1819-
} else {
1820-
err.span_suggestion_short(
1821-
span_semi,
1822-
"remove this semicolon to return this value",
1823-
"",
1824-
Applicability::MachineApplicable,
1825-
);
1826-
}
1827-
true
1828-
} else {
1829-
false
1830-
}
1831-
}
1832-
18331794
pub(crate) fn is_field_suggestable(
18341795
&self,
18351796
field: &ty::FieldDef,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19761976
self.suggest_accessing_field_where_appropriate(cause, &exp_found, diag);
19771977
self.suggest_await_on_expect_found(cause, span, &exp_found, diag);
19781978
self.suggest_function_pointers(cause, span, &exp_found, diag);
1979-
self.suggest_for_statments_as_exp(cause, &exp_found, diag);
1979+
self.suggest_turning_stmt_into_expr(cause, &exp_found, diag);
19801980
}
19811981
}
19821982

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
298298
}
299299
}
300300

301-
pub(super) fn suggest_for_statments_as_exp(
301+
pub(super) fn suggest_turning_stmt_into_expr(
302302
&self,
303303
cause: &ObligationCause<'tcx>,
304304
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
305-
diag: &mut Diagnostic,
305+
diag: &mut Diag<'_>,
306306
) {
307307
let ty::error::ExpectedFound { expected, found } = exp_found;
308308
if !found.peel_refs().is_unit() {
@@ -365,18 +365,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
365365
&self,
366366
blk: &'tcx hir::Block<'tcx>,
367367
expected_ty: Ty<'tcx>,
368-
err: &mut Diagnostic,
368+
diag: &mut Diag<'_>,
369369
) -> bool {
370370
if let Some((span_semi, boxed)) = self.could_remove_semicolon(blk, expected_ty) {
371371
if let StatementAsExpression::NeedsBoxing = boxed {
372-
err.span_suggestion_verbose(
372+
diag.span_suggestion_verbose(
373373
span_semi,
374374
"consider removing this semicolon and boxing the expression",
375375
"",
376376
Applicability::HasPlaceholders,
377377
);
378378
} else {
379-
err.span_suggestion_short(
379+
diag.span_suggestion_short(
380380
span_semi,
381381
"remove this semicolon to return this value",
382382
"",

tests/ui/inference/issue-105431-stmts-as-exp.stderr tests/ui/inference/stmts-as-exp-105431.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/issue-105431-stmts-as-exp.rs:11:5
2+
--> $DIR/stmts-as-exp-105431.rs:11:5
33
|
44
LL | fn test_if() -> i32 {
55
| --- expected `i32` because of return type
@@ -19,7 +19,7 @@ LL + 4
1919
|
2020

2121
error[E0308]: mismatched types
22-
--> $DIR/issue-105431-stmts-as-exp.rs:15:13
22+
--> $DIR/stmts-as-exp-105431.rs:15:13
2323
|
2424
LL | if true {
2525
| _____________^
@@ -30,7 +30,7 @@ LL | | }
3030
| |_____^ expected `i32`, found `()`
3131

3232
error[E0308]: mismatched types
33-
--> $DIR/issue-105431-stmts-as-exp.rs:19:10
33+
--> $DIR/stmts-as-exp-105431.rs:19:10
3434
|
3535
LL | else {
3636
| __________^
@@ -40,7 +40,7 @@ LL | | }
4040
| |_____^ expected `i32`, found `()`
4141

4242
error[E0308]: mismatched types
43-
--> $DIR/issue-105431-stmts-as-exp.rs:30:5
43+
--> $DIR/stmts-as-exp-105431.rs:30:5
4444
|
4545
LL | fn test_match() -> i32 {
4646
| --- expected `i32` because of return type
@@ -60,7 +60,7 @@ LL + _ => { 2 }
6060
|
6161

6262
error[E0308]: mismatched types
63-
--> $DIR/issue-105431-stmts-as-exp.rs:36:14
63+
--> $DIR/stmts-as-exp-105431.rs:36:14
6464
|
6565
LL | 1 => { 1; }
6666
| ^^^-^^
@@ -69,7 +69,7 @@ LL | 1 => { 1; }
6969
| expected `i32`, found `()`
7070

7171
error[E0308]: mismatched types
72-
--> $DIR/issue-105431-stmts-as-exp.rs:37:14
72+
--> $DIR/stmts-as-exp-105431.rs:37:14
7373
|
7474
LL | _ => { 2; }
7575
| ^^^-^^
@@ -78,7 +78,7 @@ LL | _ => { 2; }
7878
| expected `i32`, found `()`
7979

8080
error[E0308]: `match` arms have incompatible types
81-
--> $DIR/issue-105431-stmts-as-exp.rs:45:16
81+
--> $DIR/stmts-as-exp-105431.rs:45:16
8282
|
8383
LL | let res = match v {
8484
| _______________-
@@ -93,7 +93,7 @@ LL | | };
9393
| |_____- `match` arms have incompatible types
9494

9595
error[E0308]: mismatched types
96-
--> $DIR/issue-105431-stmts-as-exp.rs:59:5
96+
--> $DIR/stmts-as-exp-105431.rs:59:5
9797
|
9898
LL | fn test_if_match_mixed() -> i32 {
9999
| --- expected `i32` because of return type
@@ -113,7 +113,7 @@ LL + }
113113
|
114114

115115
error[E0308]: mismatched types
116-
--> $DIR/issue-105431-stmts-as-exp.rs:72:5
116+
--> $DIR/stmts-as-exp-105431.rs:72:5
117117
|
118118
LL | fn test_if_match_mixed_failed() -> i32 {
119119
| --- expected `i32` because of return type

0 commit comments

Comments
 (0)