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 {
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

View 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 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
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 }

View File

@ -1546,10 +1546,10 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
/// 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 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
// 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
}
}

View File

@ -1546,7 +1546,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}
}
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);
}
}

View File

@ -330,7 +330,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
func: fun,
args,
cleanup: Some(cleanup),
destination: if expr.ty.conservative_is_uninhabited(this.hir.tcx()) {
destination:
if expr.ty.conservative_is_privately_uninhabited(this.hir.tcx()) {
None
} else {
Some((destination.clone(), success))
@ -419,8 +420,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
});
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()
}
};

View File

@ -230,7 +230,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
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