Skip to content

Commit 426dbcd

Browse files
authored
Rollup merge of #111533 - clubby789:drop-tracking-error, r=oli-obk
Handle error body in generator layout Fixes #111468 I feel like making this query return `Option<GeneratorLayout>` might be better but had some issues with that approach
2 parents c78a67b + f77971e commit 426dbcd

File tree

8 files changed

+49
-11
lines changed

8 files changed

+49
-11
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,8 @@ fn opaque_type_cycle_error(
15141514
}
15151515
if tcx.sess.opts.unstable_opts.drop_tracking_mir
15161516
&& let DefKind::Generator = tcx.def_kind(closure_def_id)
1517+
&& let Some(generator_layout) = tcx.mir_generator_witnesses(closure_def_id)
15171518
{
1518-
let generator_layout = tcx.mir_generator_witnesses(closure_def_id);
15191519
for interior_ty in &generator_layout.field_tys {
15201520
label_match(interior_ty.ty, interior_ty.source_info.span);
15211521
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15161516
if encode_opt {
15171517
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
15181518

1519-
if tcx.sess.opts.unstable_opts.drop_tracking_mir && let DefKind::Generator = self.tcx.def_kind(def_id) {
1520-
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- tcx.mir_generator_witnesses(def_id));
1519+
if tcx.sess.opts.unstable_opts.drop_tracking_mir
1520+
&& let DefKind::Generator = self.tcx.def_kind(def_id)
1521+
&& let Some(witnesses) = tcx.mir_generator_witnesses(def_id)
1522+
{
1523+
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses);
15211524
}
15221525
}
15231526
if encode_const {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ rustc_queries! {
527527
}
528528
}
529529

530-
query mir_generator_witnesses(key: DefId) -> &'tcx mir::GeneratorLayout<'tcx> {
530+
query mir_generator_witnesses(key: DefId) -> &'tcx Option<mir::GeneratorLayout<'tcx>> {
531531
arena_cache
532532
desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
533533
cache_on_disk_if { key.is_local() }

compiler/rustc_middle/src/ty/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ impl<'tcx> TyCtxt<'tcx> {
668668
self,
669669
def_id: DefId,
670670
) -> impl Iterator<Item = ty::EarlyBinder<Ty<'tcx>>> {
671-
let generator_layout = &self.mir_generator_witnesses(def_id);
671+
let generator_layout = self.mir_generator_witnesses(def_id);
672672
generator_layout
673-
.field_tys
674-
.iter()
673+
.as_ref()
674+
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
675675
.filter(|decl| !decl.ignore_for_traits)
676676
.map(|decl| ty::EarlyBinder(decl.ty))
677677
}

compiler/rustc_mir_transform/src/generator.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ fn create_cases<'tcx>(
13971397
pub(crate) fn mir_generator_witnesses<'tcx>(
13981398
tcx: TyCtxt<'tcx>,
13991399
def_id: LocalDefId,
1400-
) -> GeneratorLayout<'tcx> {
1400+
) -> Option<GeneratorLayout<'tcx>> {
14011401
assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
14021402

14031403
let (body, _) = tcx.mir_promoted(def_id);
@@ -1410,6 +1410,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14101410
// Get the interior types and substs which typeck computed
14111411
let movable = match *gen_ty.kind() {
14121412
ty::Generator(_, _, movability) => movability == hir::Movability::Movable,
1413+
ty::Error(_) => return None,
14131414
_ => span_bug!(body.span, "unexpected generator type {}", gen_ty),
14141415
};
14151416

@@ -1425,7 +1426,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14251426

14261427
check_suspend_tys(tcx, &generator_layout, &body);
14271428

1428-
generator_layout
1429+
Some(generator_layout)
14291430
}
14301431

14311432
impl<'tcx> MirPass<'tcx> for StateTransform {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2447,10 +2447,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24472447
&& generator_did.is_local()
24482448
// Try to avoid cycles.
24492449
&& !generator_within_in_progress_typeck
2450+
&& let Some(generator_info) = self.tcx.mir_generator_witnesses(generator_did)
24502451
{
2451-
let generator_info = &self.tcx.mir_generator_witnesses(generator_did);
24522452
debug!(?generator_info);
2453-
24542453
'find_source: for (variant, source_info) in
24552454
generator_info.variant_fields.iter().zip(&generator_info.variant_source_info)
24562455
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// compile-flags: -Zdrop-tracking-mir --edition=2021
2+
3+
#![feature(generators)]
4+
5+
pub async fn async_bad_body() {
6+
match true {} //~ ERROR non-exhaustive patterns: type `bool` is non-empty
7+
}
8+
9+
pub fn generator_bad_body() {
10+
|| {
11+
// 'non-exhaustive pattern' only seems to be reported once, so this annotation doesn't work
12+
// keep the function around so we can make sure it doesn't ICE
13+
match true {}; // ERROR non-exhaustive patterns: type `bool` is non-empty
14+
yield ();
15+
};
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0004]: non-exhaustive patterns: type `bool` is non-empty
2+
--> $DIR/drop-tracking-error-body.rs:6:11
3+
|
4+
LL | match true {}
5+
| ^^^^
6+
|
7+
= note: the matched value is of type `bool`
8+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
9+
|
10+
LL ~ match true {
11+
LL + _ => todo!(),
12+
LL ~ }
13+
|
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0004`.

0 commit comments

Comments
 (0)