Add warn(unreachable_pub) to rustc_const_eval.

This commit is contained in:
Nicholas Nethercote 2024-08-30 16:36:04 +10:00
parent d7caea129d
commit 88b6a78d0b
4 changed files with 26 additions and 25 deletions

View File

@ -46,7 +46,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
/// Returns `true` if `local` is `NeedsDrop` at the given `Location`. /// Returns `true` if `local` is `NeedsDrop` at the given `Location`.
/// ///
/// Only updates the cursor if absolutely necessary /// Only updates the cursor if absolutely necessary
pub fn needs_drop( fn needs_drop(
&mut self, &mut self,
ccx: &'mir ConstCx<'mir, 'tcx>, ccx: &'mir ConstCx<'mir, 'tcx>,
local: Local, local: Local,
@ -76,7 +76,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
/// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`. /// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`.
/// ///
/// Only updates the cursor if absolutely necessary /// Only updates the cursor if absolutely necessary
pub fn needs_non_const_drop( pub(crate) fn needs_non_const_drop(
&mut self, &mut self,
ccx: &'mir ConstCx<'mir, 'tcx>, ccx: &'mir ConstCx<'mir, 'tcx>,
local: Local, local: Local,
@ -106,7 +106,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
/// Returns `true` if `local` is `HasMutInterior` at the given `Location`. /// Returns `true` if `local` is `HasMutInterior` at the given `Location`.
/// ///
/// Only updates the cursor if absolutely necessary. /// Only updates the cursor if absolutely necessary.
pub fn has_mut_interior( fn has_mut_interior(
&mut self, &mut self,
ccx: &'mir ConstCx<'mir, 'tcx>, ccx: &'mir ConstCx<'mir, 'tcx>,
local: Local, local: Local,

View File

@ -57,7 +57,7 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
/// A function call where the callee is a pointer. /// A function call where the callee is a pointer.
#[derive(Debug)] #[derive(Debug)]
pub struct FnCallIndirect; pub(crate) struct FnCallIndirect;
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect { impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() }) ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
@ -66,7 +66,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
/// A function call where the callee is not marked as `const`. /// A function call where the callee is not marked as `const`.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct FnCallNonConst<'tcx> { pub(crate) struct FnCallNonConst<'tcx> {
pub caller: LocalDefId, pub caller: LocalDefId,
pub callee: DefId, pub callee: DefId,
pub args: GenericArgsRef<'tcx>, pub args: GenericArgsRef<'tcx>,
@ -299,7 +299,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
/// ///
/// Contains the name of the feature that would allow the use of this function. /// Contains the name of the feature that would allow the use of this function.
#[derive(Debug)] #[derive(Debug)]
pub struct FnCallUnstable(pub DefId, pub Option<Symbol>); pub(crate) struct FnCallUnstable(pub DefId, pub Option<Symbol>);
impl<'tcx> NonConstOp<'tcx> for FnCallUnstable { impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
@ -324,7 +324,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Coroutine(pub hir::CoroutineKind); pub(crate) struct Coroutine(pub hir::CoroutineKind);
impl<'tcx> NonConstOp<'tcx> for Coroutine { impl<'tcx> NonConstOp<'tcx> for Coroutine {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
if let hir::CoroutineKind::Desugared( if let hir::CoroutineKind::Desugared(
@ -356,7 +356,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct HeapAllocation; pub(crate) struct HeapAllocation;
impl<'tcx> NonConstOp<'tcx> for HeapAllocation { impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedHeapAllocations { ccx.dcx().create_err(errors::UnallowedHeapAllocations {
@ -368,7 +368,7 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct InlineAsm; pub(crate) struct InlineAsm;
impl<'tcx> NonConstOp<'tcx> for InlineAsm { impl<'tcx> NonConstOp<'tcx> for InlineAsm {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() }) ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
@ -376,7 +376,7 @@ impl<'tcx> NonConstOp<'tcx> for InlineAsm {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LiveDrop<'tcx> { pub(crate) struct LiveDrop<'tcx> {
pub dropped_at: Option<Span>, pub dropped_at: Option<Span>,
pub dropped_ty: Ty<'tcx>, pub dropped_ty: Ty<'tcx>,
} }
@ -394,7 +394,7 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
#[derive(Debug)] #[derive(Debug)]
/// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow never escapes to /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow never escapes to
/// the final value of the constant. /// the final value of the constant.
pub struct TransientCellBorrow; pub(crate) struct TransientCellBorrow;
impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow { impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
Status::Unstable(sym::const_refs_to_cell) Status::Unstable(sym::const_refs_to_cell)
@ -410,7 +410,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
/// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow might escape to /// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow might escape to
/// the final value of the constant, and thus we cannot allow this (for now). We may allow /// the final value of the constant, and thus we cannot allow this (for now). We may allow
/// it in the future for static items. /// it in the future for static items.
pub struct CellBorrow; pub(crate) struct CellBorrow;
impl<'tcx> NonConstOp<'tcx> for CellBorrow { impl<'tcx> NonConstOp<'tcx> for CellBorrow {
fn importance(&self) -> DiagImportance { fn importance(&self) -> DiagImportance {
// Most likely the code will try to do mutation with these borrows, which // Most likely the code will try to do mutation with these borrows, which
@ -431,7 +431,7 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
/// This op is for `&mut` borrows in the trailing expression of a constant /// This op is for `&mut` borrows in the trailing expression of a constant
/// which uses the "enclosing scopes rule" to leak its locals into anonymous /// which uses the "enclosing scopes rule" to leak its locals into anonymous
/// static or const items. /// static or const items.
pub struct MutBorrow(pub hir::BorrowKind); pub(crate) struct MutBorrow(pub hir::BorrowKind);
impl<'tcx> NonConstOp<'tcx> for MutBorrow { impl<'tcx> NonConstOp<'tcx> for MutBorrow {
fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
@ -461,7 +461,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct TransientMutBorrow(pub hir::BorrowKind); pub(crate) struct TransientMutBorrow(pub hir::BorrowKind);
impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow { impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
@ -484,7 +484,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct MutDeref; pub(crate) struct MutDeref;
impl<'tcx> NonConstOp<'tcx> for MutDeref { impl<'tcx> NonConstOp<'tcx> for MutDeref {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
Status::Unstable(sym::const_mut_refs) Status::Unstable(sym::const_mut_refs)
@ -505,7 +505,7 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
/// A call to a `panic()` lang item where the first argument is _not_ a `&str`. /// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
#[derive(Debug)] #[derive(Debug)]
pub struct PanicNonStr; pub(crate) struct PanicNonStr;
impl<'tcx> NonConstOp<'tcx> for PanicNonStr { impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::PanicNonStrErr { span }) ccx.dcx().create_err(errors::PanicNonStrErr { span })
@ -516,7 +516,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
/// Not currently intended to ever be allowed, even behind a feature gate: operation depends on /// Not currently intended to ever be allowed, even behind a feature gate: operation depends on
/// allocation base addresses that are not known at compile-time. /// allocation base addresses that are not known at compile-time.
#[derive(Debug)] #[derive(Debug)]
pub struct RawPtrComparison; pub(crate) struct RawPtrComparison;
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison { impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
// FIXME(const_trait_impl): revert to span_bug? // FIXME(const_trait_impl): revert to span_bug?
@ -525,7 +525,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RawMutPtrDeref; pub(crate) struct RawMutPtrDeref;
impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref { impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
Status::Unstable(sym::const_mut_refs) Status::Unstable(sym::const_mut_refs)
@ -546,7 +546,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
/// Not currently intended to ever be allowed, even behind a feature gate: operation depends on /// Not currently intended to ever be allowed, even behind a feature gate: operation depends on
/// allocation base addresses that are not known at compile-time. /// allocation base addresses that are not known at compile-time.
#[derive(Debug)] #[derive(Debug)]
pub struct RawPtrToIntCast; pub(crate) struct RawPtrToIntCast;
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast { impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::RawPtrToIntErr { span }) ccx.dcx().create_err(errors::RawPtrToIntErr { span })
@ -555,7 +555,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
/// An access to a (non-thread-local) `static`. /// An access to a (non-thread-local) `static`.
#[derive(Debug)] #[derive(Debug)]
pub struct StaticAccess; pub(crate) struct StaticAccess;
impl<'tcx> NonConstOp<'tcx> for StaticAccess { impl<'tcx> NonConstOp<'tcx> for StaticAccess {
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
if let hir::ConstContext::Static(_) = ccx.const_kind() { if let hir::ConstContext::Static(_) = ccx.const_kind() {
@ -582,7 +582,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
/// An access to a thread-local `static`. /// An access to a thread-local `static`.
#[derive(Debug)] #[derive(Debug)]
pub struct ThreadLocalAccess; pub(crate) struct ThreadLocalAccess;
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess { impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
ccx.dcx().create_err(errors::ThreadLocalAccessErr { span }) ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
@ -590,11 +590,11 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
} }
/// Types that cannot appear in the signature or locals of a `const fn`. /// Types that cannot appear in the signature or locals of a `const fn`.
pub mod mut_ref { pub(crate) mod mut_ref {
use super::*; use super::*;
#[derive(Debug)] #[derive(Debug)]
pub struct MutRef(pub mir::LocalKind); pub(crate) struct MutRef(pub mir::LocalKind);
impl<'tcx> NonConstOp<'tcx> for MutRef { impl<'tcx> NonConstOp<'tcx> for MutRef {
fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
Status::Unstable(sym::const_mut_refs) Status::Unstable(sym::const_mut_refs)

View File

@ -61,13 +61,13 @@ pub(super) struct MemPlace<Prov: Provenance = CtfeProvenance> {
impl<Prov: Provenance> MemPlace<Prov> { impl<Prov: Provenance> MemPlace<Prov> {
/// Adjust the provenance of the main pointer (metadata is unaffected). /// Adjust the provenance of the main pointer (metadata is unaffected).
pub fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self { fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self {
MemPlace { ptr: self.ptr.map_provenance(|p| p.map(f)), ..self } MemPlace { ptr: self.ptr.map_provenance(|p| p.map(f)), ..self }
} }
/// Turn a mplace into a (thin or wide) pointer, as a reference, pointing to the same space. /// Turn a mplace into a (thin or wide) pointer, as a reference, pointing to the same space.
#[inline] #[inline]
pub fn to_ref(self, cx: &impl HasDataLayout) -> Immediate<Prov> { fn to_ref(self, cx: &impl HasDataLayout) -> Immediate<Prov> {
Immediate::new_pointer_with_meta(self.ptr, self.meta, cx) Immediate::new_pointer_with_meta(self.ptr, self.meta, cx)
} }

View File

@ -14,6 +14,7 @@
#![feature(trait_alias)] #![feature(trait_alias)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(yeet_expr)] #![feature(yeet_expr)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end // tidy-alphabetical-end
pub mod check_consts; pub mod check_consts;