]> git.lizzy.rs Git - rust.git/commitdiff
Consider privacy in more locations
authorvarkor <github@varkor.com>
Tue, 20 Nov 2018 19:07:17 +0000 (19:07 +0000)
committervarkor <github@varkor.com>
Tue, 11 Dec 2018 11:18:55 +0000 (11:18 +0000)
src/librustc/cfg/construct.rs
src/librustc/ty/layout.rs
src/librustc/ty/sty.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/build/expr/into.rs
src/librustc_mir/hair/pattern/check_match.rs

index 1521b7a69ab0386572a485bc0ed05c1f0044ea5a..a33dca0ac046e5c7dcb58b62e473bbcf35dc229a 100644 (file)
@@ -415,7 +415,8 @@ fn call<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
             args: I) -> CFGIndex {
         let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
         let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
-        if self.tables.expr_ty(call_expr).conservative_is_uninhabited(self.tcx) {
+        let m = self.tcx.hir.get_module_parent(call_expr.id);
+        if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
             self.add_unreachable_node()
         } else {
             ret
index 3ebdd44aba9f8e1039e15d3cf2c0c12ec7975032..f4506c8e8197661a3377f9400b5909c12a046586 100644 (file)
@@ -194,7 +194,7 @@ fn layout_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
             let layout = cx.layout_raw_uncached(ty);
             // Type-level uninhabitedness should always imply ABI uninhabitedness.
             if let Ok(layout) = layout {
-                if ty.conservative_is_uninhabited(tcx) {
+                if ty.conservative_is_privately_uninhabited(tcx) {
                     assert!(layout.abi.is_uninhabited());
                 }
             }
@@ -557,7 +557,7 @@ enum StructKind {
                 let size = element.size.checked_mul(count, dl)
                     .ok_or(LayoutError::SizeOverflow(ty))?;
 
-                let abi = if count != 0 && ty.conservative_is_uninhabited(tcx) {
+                let abi = if count != 0 && ty.conservative_is_privately_uninhabited(tcx) {
                     Abi::Uninhabited
                 } else {
                     Abi::Aggregate { sized: true }
index ceb423f309229210bf57b033ac49eac441e3d835..2189267cb0b05e130438fb1feaa9ce2e8febe713 100644 (file)
@@ -1546,10 +1546,10 @@ pub fn is_never(&self) -> bool {
     /// Checks whether a type is definitely uninhabited. This is
     /// conservative: for some types that are uninhabited we return `false`,
     /// but we only return `true` for types that are definitely uninhabited.
-    /// `ty.conservative_is_uninhabited` implies that any value of type `ty`
+    /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
     /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
     /// size, to account for partial initialisation. See #49298 for details.)
-    pub fn conservative_is_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
+    pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
         // FIXME(varkor): we can make this less conversative by substituting concrete
         // type arguments.
         match self.sty {
@@ -1565,16 +1565,16 @@ pub fn conservative_is_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
                 //     one uninhabited field.
                 def.variants.iter().all(|var| {
                     var.fields.iter().any(|field| {
-                        tcx.type_of(field.did).conservative_is_uninhabited(tcx)
+                        tcx.type_of(field.did).conservative_is_privately_uninhabited(tcx)
                     })
                 })
             }
-            ty::Tuple(tys) => tys.iter().any(|ty| ty.conservative_is_uninhabited(tcx)),
+            ty::Tuple(tys) => tys.iter().any(|ty| ty.conservative_is_privately_uninhabited(tcx)),
             ty::Array(ty, len) => {
                 match len.assert_usize(tcx) {
                     // If the array is definitely non-empty, it's uninhabited if
                     // the type of its elements is uninhabited.
-                    Some(n) if n != 0 => ty.conservative_is_uninhabited(tcx),
+                    Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
                     _ => false
                 }
             }
index aea48ead428a4aa8235425919cbe626910bf6631..c01502e44d944d671825dbde06b0cf21b983b90f 100644 (file)
@@ -1546,7 +1546,7 @@ fn check_call_dest(
                 }
             }
             None => {
-                if !sig.output().conservative_is_uninhabited(self.tcx()) {
+                if !sig.output().conservative_is_privately_uninhabited(self.tcx()) {
                     span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
                 }
             }
index e344d845869808e6a36c1a5fe99e5944218b4600..8660bbadf3dc2e07d48209155a32b8740e72accc 100644 (file)
@@ -330,11 +330,12 @@ pub fn into_expr(
                             func: fun,
                             args,
                             cleanup: Some(cleanup),
-                            destination: if expr.ty.conservative_is_uninhabited(this.hir.tcx()) {
-                                None
-                            } else {
-                                Some((destination.clone(), success))
-                            },
+                            destination:
+                                if expr.ty.conservative_is_privately_uninhabited(this.hir.tcx()) {
+                                    None
+                                } else {
+                                    Some((destination.clone(), success))
+                                },
                             from_hir_call,
                         },
                     );
@@ -419,8 +420,7 @@ pub fn into_expr(
                 });
 
                 let rvalue = unpack!(block = this.as_local_rvalue(block, expr));
-                this.cfg
-                    .push_assign(block, source_info, destination, rvalue);
+                this.cfg.push_assign(block, source_info, destination, rvalue);
                 block.unit()
             }
         };
index 5a83fe76d7c537c8a720a51656f1dc6bd2dbc352..66de4e6b37f11b10452829f8685441bd87add9c1 100644 (file)
@@ -230,7 +230,7 @@ fn check_match(
                 let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
                     self.tcx.is_ty_uninhabited_from(module, pat_ty)
                 } else {
-                    pat_ty.conservative_is_uninhabited(self.tcx)
+                    pat_ty.is_never()
                 };
                 if !scrutinee_is_uninhabited {
                     // We know the type is inhabited, so this must be wrong