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.
This commit is contained in:
parent
97f2c37435
commit
ecb29c11bb
2 changed files with 12 additions and 5 deletions
|
|
@ -1684,12 +1684,15 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
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])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1069,11 +1069,15 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue