From 6561732f887e9e379293821d4d802a6fa1c44fd6 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 20 Nov 2018 19:07:17 +0000 Subject: [PATCH] Consider privacy in more locations --- src/librustc/cfg/construct.rs | 3 ++- src/librustc/ty/layout.rs | 4 ++-- src/librustc/ty/sty.rs | 10 +++++----- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/build/expr/into.rs | 14 +++++++------- src/librustc_mir/hair/pattern/check_match.rs | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 1521b7a69ab..a33dca0ac04 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -415,7 +415,8 @@ fn call<'b, I: Iterator>(&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 diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 3ebdd44aba9..f4506c8e819 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -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 } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index ceb423f3092..2189267cb0b 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -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 } } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index aea48ead428..c01502e44d9 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -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); } } diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index e344d845869..8660bbadf3d 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -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() } }; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 5a83fe76d7c..66de4e6b37f 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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 -- 2.44.0