]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Fix two instances of `try_get`
authorAlex Crichton <alex@alexcrichton.com>
Wed, 23 Aug 2017 19:54:36 +0000 (12:54 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 25 Aug 2017 23:08:35 +0000 (16:08 -0700)
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.

src/librustc/ty/mod.rs
src/librustc/ty/util.rs

index f9bbcc1bbe086cb1a22dae090e12ec224dd858de..852bd48a5eeed871fe5bd30eb7e8b5295d842aa2 100644 (file)
@@ -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])
             }
         }
index 9cd6aa2111873a69f9becbb6b011e205b25f2978..bbbb8611f98a5f104b11b96b2d93954d3826bda3 100644 (file)
@@ -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
             }
         }