Skip to content

Commit

Permalink
Unrolled build for rust-lang#123834
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#123834 - compiler-errors:async-closure-with-tainted-body, r=oli-obk

Don't do coroutine-closure-specific upvar analysis if tainted by errors

See the comment

Fixes rust-lang#123821
Fixes rust-lang#123818
  • Loading branch information
rust-timer committed Apr 12, 2024
2 parents 22a2425 + 49e73c3 commit f640ce0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, Pro
use rustc_middle::mir::FakeReadCause;
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::{
self, ClosureSizeProfileData, Ty, TyCtxt, TypeckResults, UpvarArgs, UpvarCapture,
self, ClosureSizeProfileData, Ty, TyCtxt, TypeVisitableExt as _, TypeckResults, UpvarArgs,
UpvarCapture,
};
use rustc_session::lint;
use rustc_span::sym;
Expand Down Expand Up @@ -191,6 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}
};
let args = self.resolve_vars_if_possible(args);
let closure_def_id = closure_def_id.expect_local();

assert_eq!(self.tcx.hir().body_owner_def_id(body.id()), closure_def_id);
Expand Down Expand Up @@ -361,7 +363,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// For coroutine-closures, we additionally must compute the
// `coroutine_captures_by_ref_ty` type, which is used to generate the by-ref
// version of the coroutine-closure's output coroutine.
if let UpvarArgs::CoroutineClosure(args) = args {
if let UpvarArgs::CoroutineClosure(args) = args
&& !args.references_error()
{
let closure_env_region: ty::Region<'_> = ty::Region::new_bound(
self.tcx,
ty::INNERMOST,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
}
}

#[derive(Debug, Copy, Clone, HashStable)]
#[derive(Debug, Copy, Clone, HashStable, TypeFoldable, TypeVisitable)]
pub enum UpvarArgs<'tcx> {
Closure(GenericArgsRef<'tcx>),
Coroutine(GenericArgsRef<'tcx>),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ edition: 2021

#![feature(async_closure)]

struct DropMe;

trait Impossible {}
fn trait_error<T: Impossible>() {}

pub fn main() {
let b = DropMe;
let async_closure = async move || {
// Type error here taints the environment. This causes us to fallback all
// variables to `Error`. This means that when we compute the upvars for the
// *outer* coroutine-closure, we don't actually see any upvars since `MemCategorization`
// and `ExprUseVisitor`` will bail early when it sees error. This means
// that our underlying assumption that the parent and child captures are
// compatible ends up being broken, previously leading to an ICE.
trait_error::<()>();
//~^ ERROR the trait bound `(): Impossible` is not satisfied
let _b = b;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0277]: the trait bound `(): Impossible` is not satisfied
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:19:23
|
LL | trait_error::<()>();
| ^^ the trait `Impossible` is not implemented for `()`
|
help: this trait has no implementations, consider adding one
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:7:1
|
LL | trait Impossible {}
| ^^^^^^^^^^^^^^^^
note: required by a bound in `trait_error`
--> $DIR/dont-ice-when-body-tainted-by-errors.rs:8:19
|
LL | fn trait_error<T: Impossible>() {}
| ^^^^^^^^^^ required by this bound in `trait_error`

error: aborting due to 1 previous error

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

0 comments on commit f640ce0

Please sign in to comment.