Skip to content

Commit 6561732

Browse files
committed
Consider privacy in more locations
1 parent 4d8a6ea commit 6561732

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

src/librustc/cfg/construct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
415415
args: I) -> CFGIndex {
416416
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
417417
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
418-
if self.tables.expr_ty(call_expr).conservative_is_uninhabited(self.tcx) {
418+
let m = self.tcx.hir.get_module_parent(call_expr.id);
419+
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
419420
self.add_unreachable_node()
420421
} else {
421422
ret

src/librustc/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ fn layout_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
194194
let layout = cx.layout_raw_uncached(ty);
195195
// Type-level uninhabitedness should always imply ABI uninhabitedness.
196196
if let Ok(layout) = layout {
197-
if ty.conservative_is_uninhabited(tcx) {
197+
if ty.conservative_is_privately_uninhabited(tcx) {
198198
assert!(layout.abi.is_uninhabited());
199199
}
200200
}
@@ -557,7 +557,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
557557
let size = element.size.checked_mul(count, dl)
558558
.ok_or(LayoutError::SizeOverflow(ty))?;
559559

560-
let abi = if count != 0 && ty.conservative_is_uninhabited(tcx) {
560+
let abi = if count != 0 && ty.conservative_is_privately_uninhabited(tcx) {
561561
Abi::Uninhabited
562562
} else {
563563
Abi::Aggregate { sized: true }

src/librustc/ty/sty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,10 +1546,10 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
15461546
/// Checks whether a type is definitely uninhabited. This is
15471547
/// conservative: for some types that are uninhabited we return `false`,
15481548
/// but we only return `true` for types that are definitely uninhabited.
1549-
/// `ty.conservative_is_uninhabited` implies that any value of type `ty`
1549+
/// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty`
15501550
/// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero
15511551
/// size, to account for partial initialisation. See #49298 for details.)
1552-
pub fn conservative_is_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
1552+
pub fn conservative_is_privately_uninhabited(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
15531553
// FIXME(varkor): we can make this less conversative by substituting concrete
15541554
// type arguments.
15551555
match self.sty {
@@ -1565,16 +1565,16 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
15651565
// one uninhabited field.
15661566
def.variants.iter().all(|var| {
15671567
var.fields.iter().any(|field| {
1568-
tcx.type_of(field.did).conservative_is_uninhabited(tcx)
1568+
tcx.type_of(field.did).conservative_is_privately_uninhabited(tcx)
15691569
})
15701570
})
15711571
}
1572-
ty::Tuple(tys) => tys.iter().any(|ty| ty.conservative_is_uninhabited(tcx)),
1572+
ty::Tuple(tys) => tys.iter().any(|ty| ty.conservative_is_privately_uninhabited(tcx)),
15731573
ty::Array(ty, len) => {
15741574
match len.assert_usize(tcx) {
15751575
// If the array is definitely non-empty, it's uninhabited if
15761576
// the type of its elements is uninhabited.
1577-
Some(n) if n != 0 => ty.conservative_is_uninhabited(tcx),
1577+
Some(n) if n != 0 => ty.conservative_is_privately_uninhabited(tcx),
15781578
_ => false
15791579
}
15801580
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15461546
}
15471547
}
15481548
None => {
1549-
if !sig.output().conservative_is_uninhabited(self.tcx()) {
1549+
if !sig.output().conservative_is_privately_uninhabited(self.tcx()) {
15501550
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
15511551
}
15521552
}

src/librustc_mir/build/expr/into.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
330330
func: fun,
331331
args,
332332
cleanup: Some(cleanup),
333-
destination: if expr.ty.conservative_is_uninhabited(this.hir.tcx()) {
334-
None
335-
} else {
336-
Some((destination.clone(), success))
337-
},
333+
destination:
334+
if expr.ty.conservative_is_privately_uninhabited(this.hir.tcx()) {
335+
None
336+
} else {
337+
Some((destination.clone(), success))
338+
},
338339
from_hir_call,
339340
},
340341
);
@@ -419,8 +420,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
419420
});
420421

421422
let rvalue = unpack!(block = this.as_local_rvalue(block, expr));
422-
this.cfg
423-
.push_assign(block, source_info, destination, rvalue);
423+
this.cfg.push_assign(block, source_info, destination, rvalue);
424424
block.unit()
425425
}
426426
};

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
230230
let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns {
231231
self.tcx.is_ty_uninhabited_from(module, pat_ty)
232232
} else {
233-
pat_ty.conservative_is_uninhabited(self.tcx)
233+
pat_ty.is_never()
234234
};
235235
if !scrutinee_is_uninhabited {
236236
// We know the type is inhabited, so this must be wrong

0 commit comments

Comments
 (0)