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.
pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &'tcx [Ty<'tcx>] {
match queries::adt_sized_constraint::try_get(tcx, DUMMY_SP, self.did) {
Ok(tys) => tys,
- Err(_) => {
+ Err(mut bug) => {
debug!("adt_sized_constraint: {:?} is recursive", self);
// This should be reported as an error by `check_representable`.
//
// Consider the type as Sized in the meanwhile to avoid
- // further errors.
+ // further errors. Delay our `bug` diagnostic here to get
+ // emitted later as well in case we accidentally otherwise don't
+ // emit an error.
+ bug.delay_as_bug();
tcx.intern_type_list(&[tcx.types.err])
}
}
let needs_drop = |ty: Ty<'tcx>| -> bool {
match ty::queries::needs_drop_raw::try_get(tcx, DUMMY_SP, param_env.and(ty)) {
Ok(v) => v,
- Err(_) => {
+ Err(mut bug) => {
// Cycles should be reported as an error by `check_representable`.
//
- // Consider the type as not needing drop in the meanwhile to avoid
- // further errors.
+ // Consider the type as not needing drop in the meanwhile to
+ // avoid further errors.
+ //
+ // In case we forgot to emit a bug elsewhere, delay our
+ // diagnostic to get emitted as a compiler bug.
+ bug.delay_as_bug();
false
}
}