Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 3 pull requests #117020

Merged
merged 6 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
prior_arm_ty,
prior_arm_span,
scrut_span: scrut.span,
scrut_hir_id: scrut.hir_id,
source: match_src,
prior_arms: other_arms.clone(),
opt_suggest_box_span,
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ref prior_arms,
opt_suggest_box_span,
scrut_span,
scrut_hir_id,
..
}) => match source {
hir::MatchSource::TryDesugar(scrut_hir_id) => {
Expand Down Expand Up @@ -843,6 +844,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) {
err.subdiagnostic(subdiag);
}
if let Some(hir::Node::Expr(m)) = self.tcx.hir().find_parent(scrut_hir_id)
&& let Some(hir::Node::Stmt(stmt)) = self.tcx.hir().find_parent(m.hir_id)
&& let hir::StmtKind::Expr(_) = stmt.kind
{
err.span_suggestion_verbose(
stmt.span.shrink_to_hi(),
"consider using a semicolon here, but this will discard any values \
in the match arms",
";",
Applicability::MaybeIncorrect,
);
}
if let Some(ret_sp) = opt_suggest_box_span {
// Get return type span and point to it.
self.suggest_boxing_for_return_impl_trait(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ pub struct MatchExpressionArmCause<'tcx> {
pub prior_arm_ty: Ty<'tcx>,
pub prior_arm_span: Span,
pub scrut_span: Span,
pub scrut_hir_id: hir::HirId,
pub source: hir::MatchSource,
pub prior_arms: Vec<Span>,
pub opt_suggest_box_span: Option<Span>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {

// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1)
&& let Some(expr_span) = expr.span.find_ancestor_inside(await_expr.span)
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
{
let removal_span = self
.tcx
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/async-await/unnecessary-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ async fn with_macros() {
f!(());
}

// Regression test for issue #117014.
async fn desugaring_span_ctxt() {
for x in [] {}.await //~ ERROR `()` is not a future
}

fn main() {}
15 changes: 14 additions & 1 deletion tests/ui/async-await/unnecessary-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ LL | f!(());
= note: required for `()` to implement `IntoFuture`
= note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors
error[E0277]: `()` is not a future
--> $DIR/unnecessary-await.rs:36:20
|
LL | for x in [] {}.await
| -^^^^^
| ||
| |`()` is not a future
| help: remove the `.await`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
15 changes: 11 additions & 4 deletions tests/ui/suggestions/issue-81839.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ error[E0308]: `match` arms have incompatible types
LL | / match num {
LL | | 1 => {
LL | | cx.answer_str("hi");
| | --------------------
| | | |
| | | help: consider removing this semicolon
| | this is found to be of type `()`
| | -------------------- this is found to be of type `()`
LL | | }
LL | | _ => cx.answer_str("hi"),
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found future
LL | | }
| |_____- `match` arms have incompatible types
|
help: consider removing this semicolon
|
LL - cx.answer_str("hi");
LL + cx.answer_str("hi")
|
help: consider using a semicolon here, but this will discard any values in the match arms
|
LL | };
| +

error: aborting due to previous error

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/wf/wf-unsafe-trait-obj-match.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ LL | | }
|
= note: expected reference `&S`
found reference `&R`
help: consider using a semicolon here, but this will discard any values in the match arms
|
LL | };
| +

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