Skip to content

Commit 26f340a

Browse files
committedOct 21, 2023
Auto merge of rust-lang#117020 - matthiaskrgr:rollup-cg62m4h, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#106601 (Suggest `;` after bare `match` expression E0308) - rust-lang#116975 (Move `invalid-llvm-passes` test to `invalid-compile-flags` folder) - rust-lang#117019 (fix spans for removing `.await` on `for` expressions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 786c94a + bd1046d commit 26f340a

File tree

10 files changed

+50
-6
lines changed

10 files changed

+50
-6
lines changed
 

‎compiler/rustc_hir_typeck/src/_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
121121
prior_arm_ty,
122122
prior_arm_span,
123123
scrut_span: scrut.span,
124+
scrut_hir_id: scrut.hir_id,
124125
source: match_src,
125126
prior_arms: other_arms.clone(),
126127
opt_suggest_box_span,

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

+13
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
776776
ref prior_arms,
777777
opt_suggest_box_span,
778778
scrut_span,
779+
scrut_hir_id,
779780
..
780781
}) => match source {
781782
hir::MatchSource::TryDesugar(scrut_hir_id) => {
@@ -843,6 +844,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
843844
) {
844845
err.subdiagnostic(subdiag);
845846
}
847+
if let Some(hir::Node::Expr(m)) = self.tcx.hir().find_parent(scrut_hir_id)
848+
&& let Some(hir::Node::Stmt(stmt)) = self.tcx.hir().find_parent(m.hir_id)
849+
&& let hir::StmtKind::Expr(_) = stmt.kind
850+
{
851+
err.span_suggestion_verbose(
852+
stmt.span.shrink_to_hi(),
853+
"consider using a semicolon here, but this will discard any values \
854+
in the match arms",
855+
";",
856+
Applicability::MaybeIncorrect,
857+
);
858+
}
846859
if let Some(ret_sp) = opt_suggest_box_span {
847860
// Get return type span and point to it.
848861
self.suggest_boxing_for_return_impl_trait(

‎compiler/rustc_middle/src/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ pub struct MatchExpressionArmCause<'tcx> {
541541
pub prior_arm_ty: Ty<'tcx>,
542542
pub prior_arm_span: Span,
543543
pub scrut_span: Span,
544+
pub scrut_hir_id: hir::HirId,
544545
pub source: hir::MatchSource,
545546
pub prior_arms: Vec<Span>,
546547
pub opt_suggest_box_span: Option<Span>,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16441644

16451645
// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
16461646
if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1)
1647-
&& let Some(expr_span) = expr.span.find_ancestor_inside(await_expr.span)
1647+
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
16481648
{
16491649
let removal_span = self
16501650
.tcx

‎tests/ui/async-await/unnecessary-await.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ async fn with_macros() {
3131
f!(());
3232
}
3333

34+
// Regression test for issue #117014.
35+
async fn desugaring_span_ctxt() {
36+
for x in [] {}.await //~ ERROR `()` is not a future
37+
}
38+
3439
fn main() {}

‎tests/ui/async-await/unnecessary-await.stderr

+14-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ LL | f!(());
4949
= note: required for `()` to implement `IntoFuture`
5050
= note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
5151

52-
error: aborting due to 3 previous errors
52+
error[E0277]: `()` is not a future
53+
--> $DIR/unnecessary-await.rs:36:20
54+
|
55+
LL | for x in [] {}.await
56+
| -^^^^^
57+
| ||
58+
| |`()` is not a future
59+
| help: remove the `.await`
60+
|
61+
= help: the trait `Future` is not implemented for `()`
62+
= note: () must be a future or must implement `IntoFuture` to be awaited
63+
= note: required for `()` to implement `IntoFuture`
64+
65+
error: aborting due to 4 previous errors
5366

5467
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/suggestions/issue-81839.stderr

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ error[E0308]: `match` arms have incompatible types
44
LL | / match num {
55
LL | | 1 => {
66
LL | | cx.answer_str("hi");
7-
| | --------------------
8-
| | | |
9-
| | | help: consider removing this semicolon
10-
| | this is found to be of type `()`
7+
| | -------------------- this is found to be of type `()`
118
LL | | }
129
LL | | _ => cx.answer_str("hi"),
1310
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found future
1411
LL | | }
1512
| |_____- `match` arms have incompatible types
13+
|
14+
help: consider removing this semicolon
15+
|
16+
LL - cx.answer_str("hi");
17+
LL + cx.answer_str("hi")
18+
|
19+
help: consider using a semicolon here, but this will discard any values in the match arms
20+
|
21+
LL | };
22+
| +
1623

1724
error: aborting due to previous error
1825

‎tests/ui/wf/wf-unsafe-trait-obj-match.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ LL | | }
1111
|
1212
= note: expected reference `&S`
1313
found reference `&R`
14+
help: consider using a semicolon here, but this will discard any values in the match arms
15+
|
16+
LL | };
17+
| +
1418

1519
error[E0038]: the trait `Trait` cannot be made into an object
1620
--> $DIR/wf-unsafe-trait-obj-match.rs:26:21

0 commit comments

Comments
 (0)
Please sign in to comment.