mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
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:
@@ -1684,12 +1684,15 @@ pub fn destructor(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Destructor> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user