Consider privacy in more locations

This commit is contained in:
varkor 2018-11-20 19:07:17 +00:00
parent 4d8a6eac39
commit 6561732f88
6 changed files with 18 additions and 17 deletions

View File

@ -415,7 +415,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
args: I) -> CFGIndex { args: I) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args); 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() self.add_unreachable_node()
} else { } else {
ret ret

View File

@ -194,7 +194,7 @@ fn layout_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let layout = cx.layout_raw_uncached(ty); let layout = cx.layout_raw_uncached(ty);
// Type-level uninhabitedness should always imply ABI uninhabitedness. // Type-level uninhabitedness should always imply ABI uninhabitedness.
if let Ok(layout) = layout { if let Ok(layout) = layout {
if ty.conservative_is_uninhabited(tcx) { if ty.conservative_is_privately_uninhabited(tcx) {
assert!(layout.abi.is_uninhabited()); assert!(layout.abi.is_uninhabited());
} }
} }
@ -557,7 +557,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
let size = element.size.checked_mul(count, dl) let size = element.size.checked_mul(count, dl)
.ok_or(LayoutError::SizeOverflow(ty))?; .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 Abi::Uninhabited
} else { } else {
Abi::Aggregate { sized: true } Abi::Aggregate { sized: true }

View File

@ -1546,10 +1546,10 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
/// Checks whether a type is definitely uninhabited. This is /// Checks whether a type is definitely uninhabited. This is
/// conservative: for some types that are uninhabited we return `false`, /// conservative: for some types that are uninhabited we return `false`,
/// but we only return `true` for types that are definitely uninhabited. /// 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 /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
/// size, to account for partial initialisation. See #49298 for details.) /// 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 // FIXME(varkor): we can make this less conversative by substituting concrete
// type arguments. // type arguments.
match self.sty { match self.sty {
@ -1565,16 +1565,16 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
// one uninhabited field. // one uninhabited field.
def.variants.iter().all(|var| { def.variants.iter().all(|var| {
var.fields.iter().any(|field| { 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) => { ty::Array(ty, len) => {
match len.assert_usize(tcx) { match len.assert_usize(tcx) {
// If the array is definitely non-empty, it's uninhabited if // If the array is definitely non-empty, it's uninhabited if
// the type of its elements is uninhabited. // 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 _ => false
} }
} }

View File

@ -1546,7 +1546,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
} }
} }
None => { 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); span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
} }
} }

View File

@ -330,11 +330,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
func: fun, func: fun,
args, args,
cleanup: Some(cleanup), cleanup: Some(cleanup),
destination: if expr.ty.conservative_is_uninhabited(this.hir.tcx()) { destination:
None if expr.ty.conservative_is_privately_uninhabited(this.hir.tcx()) {
} else { None
Some((destination.clone(), success)) } else {
}, Some((destination.clone(), success))
},
from_hir_call, from_hir_call,
}, },
); );
@ -419,8 +420,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
}); });
let rvalue = unpack!(block = this.as_local_rvalue(block, expr)); let rvalue = unpack!(block = this.as_local_rvalue(block, expr));
this.cfg this.cfg.push_assign(block, source_info, destination, rvalue);
.push_assign(block, source_info, destination, rvalue);
block.unit() block.unit()
} }
}; };

View File

@ -230,7 +230,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns { let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
self.tcx.is_ty_uninhabited_from(module, pat_ty) self.tcx.is_ty_uninhabited_from(module, pat_ty)
} else { } else {
pat_ty.conservative_is_uninhabited(self.tcx) pat_ty.is_never()
}; };
if !scrutinee_is_uninhabited { if !scrutinee_is_uninhabited {
// We know the type is inhabited, so this must be wrong // We know the type is inhabited, so this must be wrong