Skip to content

Commit ecb29c1

Browse files
committed
rustc: Fix two instances of try_get
The `sized_constraint` and `needs_drop_raw` queries both use `try_get` to detect cycles, but in both of these cases the cycle indicates an error has happened elsewhere in compilation. In these cases we can just delay the diagnostic to get emitted as a bug later if we ended up forgetting to emit the error diagnostic.
1 parent 97f2c37 commit ecb29c1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/librustc/ty/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,12 +1684,15 @@ impl<'a, 'gcx, 'tcx> AdtDef {
16841684
pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &'tcx [Ty<'tcx>] {
16851685
match queries::adt_sized_constraint::try_get(tcx, DUMMY_SP, self.did) {
16861686
Ok(tys) => tys,
1687-
Err(_) => {
1687+
Err(mut bug) => {
16881688
debug!("adt_sized_constraint: {:?} is recursive", self);
16891689
// This should be reported as an error by `check_representable`.
16901690
//
16911691
// Consider the type as Sized in the meanwhile to avoid
1692-
// further errors.
1692+
// further errors. Delay our `bug` diagnostic here to get
1693+
// emitted later as well in case we accidentally otherwise don't
1694+
// emit an error.
1695+
bug.delay_as_bug();
16931696
tcx.intern_type_list(&[tcx.types.err])
16941697
}
16951698
}

src/librustc/ty/util.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,15 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10691069
let needs_drop = |ty: Ty<'tcx>| -> bool {
10701070
match ty::queries::needs_drop_raw::try_get(tcx, DUMMY_SP, param_env.and(ty)) {
10711071
Ok(v) => v,
1072-
Err(_) => {
1072+
Err(mut bug) => {
10731073
// Cycles should be reported as an error by `check_representable`.
10741074
//
1075-
// Consider the type as not needing drop in the meanwhile to avoid
1076-
// further errors.
1075+
// Consider the type as not needing drop in the meanwhile to
1076+
// avoid further errors.
1077+
//
1078+
// In case we forgot to emit a bug elsewhere, delay our
1079+
// diagnostic to get emitted as a compiler bug.
1080+
bug.delay_as_bug();
10771081
false
10781082
}
10791083
}

0 commit comments

Comments
 (0)