Skip to content

Commit 9292173

Browse files
Rollup merge of #129777 - nnethercote:unreachable_pub-4, r=Urgau
Add `unreachable_pub`, round 4 A follow-up to #129732. r? `@Urgau`
2 parents 6dccab5 + 772207e commit 9292173

File tree

362 files changed

+502
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+502
-485
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
4646
/// Returns `true` if `local` is `NeedsDrop` at the given `Location`.
4747
///
4848
/// Only updates the cursor if absolutely necessary
49-
pub fn needs_drop(
49+
fn needs_drop(
5050
&mut self,
5151
ccx: &'mir ConstCx<'mir, 'tcx>,
5252
local: Local,
@@ -76,7 +76,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
7676
/// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`.
7777
///
7878
/// Only updates the cursor if absolutely necessary
79-
pub fn needs_non_const_drop(
79+
pub(crate) fn needs_non_const_drop(
8080
&mut self,
8181
ccx: &'mir ConstCx<'mir, 'tcx>,
8282
local: Local,
@@ -106,7 +106,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
106106
/// Returns `true` if `local` is `HasMutInterior` at the given `Location`.
107107
///
108108
/// Only updates the cursor if absolutely necessary.
109-
pub fn has_mut_interior(
109+
fn has_mut_interior(
110110
&mut self,
111111
ccx: &'mir ConstCx<'mir, 'tcx>,
112112
local: Local,

compiler/rustc_const_eval/src/check_consts/ops.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
5757

5858
/// A function call where the callee is a pointer.
5959
#[derive(Debug)]
60-
pub struct FnCallIndirect;
60+
pub(crate) struct FnCallIndirect;
6161
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
6262
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
6363
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
@@ -66,7 +66,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
6666

6767
/// A function call where the callee is not marked as `const`.
6868
#[derive(Debug, Clone, Copy)]
69-
pub struct FnCallNonConst<'tcx> {
69+
pub(crate) struct FnCallNonConst<'tcx> {
7070
pub caller: LocalDefId,
7171
pub callee: DefId,
7272
pub args: GenericArgsRef<'tcx>,
@@ -299,7 +299,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
299299
///
300300
/// Contains the name of the feature that would allow the use of this function.
301301
#[derive(Debug)]
302-
pub struct FnCallUnstable(pub DefId, pub Option<Symbol>);
302+
pub(crate) struct FnCallUnstable(pub DefId, pub Option<Symbol>);
303303

304304
impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
305305
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
@@ -324,7 +324,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
324324
}
325325

326326
#[derive(Debug)]
327-
pub struct Coroutine(pub hir::CoroutineKind);
327+
pub(crate) struct Coroutine(pub hir::CoroutineKind);
328328
impl<'tcx> NonConstOp<'tcx> for Coroutine {
329329
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
330330
if let hir::CoroutineKind::Desugared(
@@ -356,7 +356,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
356356
}
357357

358358
#[derive(Debug)]
359-
pub struct HeapAllocation;
359+
pub(crate) struct HeapAllocation;
360360
impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
361361
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
362362
ccx.dcx().create_err(errors::UnallowedHeapAllocations {
@@ -368,15 +368,15 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
368368
}
369369

370370
#[derive(Debug)]
371-
pub struct InlineAsm;
371+
pub(crate) struct InlineAsm;
372372
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
373373
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
374374
ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
375375
}
376376
}
377377

378378
#[derive(Debug)]
379-
pub struct LiveDrop<'tcx> {
379+
pub(crate) struct LiveDrop<'tcx> {
380380
pub dropped_at: Option<Span>,
381381
pub dropped_ty: Ty<'tcx>,
382382
}
@@ -394,7 +394,7 @@ impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
394394
#[derive(Debug)]
395395
/// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow never escapes to
396396
/// the final value of the constant.
397-
pub struct TransientCellBorrow;
397+
pub(crate) struct TransientCellBorrow;
398398
impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
399399
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
400400
Status::Unstable(sym::const_refs_to_cell)
@@ -410,7 +410,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
410410
/// A borrow of a type that contains an `UnsafeCell` somewhere. The borrow might escape to
411411
/// the final value of the constant, and thus we cannot allow this (for now). We may allow
412412
/// it in the future for static items.
413-
pub struct CellBorrow;
413+
pub(crate) struct CellBorrow;
414414
impl<'tcx> NonConstOp<'tcx> for CellBorrow {
415415
fn importance(&self) -> DiagImportance {
416416
// Most likely the code will try to do mutation with these borrows, which
@@ -431,7 +431,7 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
431431
/// This op is for `&mut` borrows in the trailing expression of a constant
432432
/// which uses the "enclosing scopes rule" to leak its locals into anonymous
433433
/// static or const items.
434-
pub struct MutBorrow(pub hir::BorrowKind);
434+
pub(crate) struct MutBorrow(pub hir::BorrowKind);
435435

436436
impl<'tcx> NonConstOp<'tcx> for MutBorrow {
437437
fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
@@ -461,7 +461,7 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
461461
}
462462

463463
#[derive(Debug)]
464-
pub struct TransientMutBorrow(pub hir::BorrowKind);
464+
pub(crate) struct TransientMutBorrow(pub hir::BorrowKind);
465465

466466
impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
467467
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
@@ -484,7 +484,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
484484
}
485485

486486
#[derive(Debug)]
487-
pub struct MutDeref;
487+
pub(crate) struct MutDeref;
488488
impl<'tcx> NonConstOp<'tcx> for MutDeref {
489489
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
490490
Status::Unstable(sym::const_mut_refs)
@@ -505,7 +505,7 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
505505

506506
/// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
507507
#[derive(Debug)]
508-
pub struct PanicNonStr;
508+
pub(crate) struct PanicNonStr;
509509
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
510510
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
511511
ccx.dcx().create_err(errors::PanicNonStrErr { span })
@@ -516,7 +516,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
516516
/// Not currently intended to ever be allowed, even behind a feature gate: operation depends on
517517
/// allocation base addresses that are not known at compile-time.
518518
#[derive(Debug)]
519-
pub struct RawPtrComparison;
519+
pub(crate) struct RawPtrComparison;
520520
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
521521
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
522522
// FIXME(const_trait_impl): revert to span_bug?
@@ -525,7 +525,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
525525
}
526526

527527
#[derive(Debug)]
528-
pub struct RawMutPtrDeref;
528+
pub(crate) struct RawMutPtrDeref;
529529
impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
530530
fn status_in_item(&self, _: &ConstCx<'_, '_>) -> Status {
531531
Status::Unstable(sym::const_mut_refs)
@@ -546,7 +546,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
546546
/// Not currently intended to ever be allowed, even behind a feature gate: operation depends on
547547
/// allocation base addresses that are not known at compile-time.
548548
#[derive(Debug)]
549-
pub struct RawPtrToIntCast;
549+
pub(crate) struct RawPtrToIntCast;
550550
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
551551
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
552552
ccx.dcx().create_err(errors::RawPtrToIntErr { span })
@@ -555,7 +555,7 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
555555

556556
/// An access to a (non-thread-local) `static`.
557557
#[derive(Debug)]
558-
pub struct StaticAccess;
558+
pub(crate) struct StaticAccess;
559559
impl<'tcx> NonConstOp<'tcx> for StaticAccess {
560560
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
561561
if let hir::ConstContext::Static(_) = ccx.const_kind() {
@@ -582,19 +582,19 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
582582

583583
/// An access to a thread-local `static`.
584584
#[derive(Debug)]
585-
pub struct ThreadLocalAccess;
585+
pub(crate) struct ThreadLocalAccess;
586586
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
587587
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
588588
ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
589589
}
590590
}
591591

592592
/// Types that cannot appear in the signature or locals of a `const fn`.
593-
pub mod mut_ref {
593+
pub(crate) mod mut_ref {
594594
use super::*;
595595

596596
#[derive(Debug)]
597-
pub struct MutRef(pub mir::LocalKind);
597+
pub(crate) struct MutRef(pub mir::LocalKind);
598598
impl<'tcx> NonConstOp<'tcx> for MutRef {
599599
fn status_in_item(&self, _ccx: &ConstCx<'_, 'tcx>) -> Status {
600600
Status::Unstable(sym::const_mut_refs)

compiler/rustc_const_eval/src/interpret/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ pub(super) struct MemPlace<Prov: Provenance = CtfeProvenance> {
6161

6262
impl<Prov: Provenance> MemPlace<Prov> {
6363
/// Adjust the provenance of the main pointer (metadata is unaffected).
64-
pub fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self {
64+
fn map_provenance(self, f: impl FnOnce(Prov) -> Prov) -> Self {
6565
MemPlace { ptr: self.ptr.map_provenance(|p| p.map(f)), ..self }
6666
}
6767

6868
/// Turn a mplace into a (thin or wide) pointer, as a reference, pointing to the same space.
6969
#[inline]
70-
pub fn to_ref(self, cx: &impl HasDataLayout) -> Immediate<Prov> {
70+
fn to_ref(self, cx: &impl HasDataLayout) -> Immediate<Prov> {
7171
Immediate::new_pointer_with_meta(self.ptr, self.meta, cx)
7272
}
7373

compiler/rustc_const_eval/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(trait_alias)]
1515
#![feature(try_blocks)]
1616
#![feature(yeet_expr)]
17+
#![warn(unreachable_pub)]
1718
// tidy-alphabetical-end
1819

1920
pub mod check_consts;

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use crate::cfi::typeid::itanium_cxx_abi::transform::{TransformTy, TransformTyOpt
2626
use crate::cfi::typeid::TypeIdOptions;
2727

2828
/// Options for encode_ty.
29-
pub type EncodeTyOptions = TypeIdOptions;
29+
pub(crate) type EncodeTyOptions = TypeIdOptions;
3030

3131
/// Substitution dictionary key.
3232
#[derive(Eq, Hash, PartialEq)]
33-
pub enum DictKey<'tcx> {
33+
pub(crate) enum DictKey<'tcx> {
3434
Ty(Ty<'tcx>, TyQ),
3535
Region(Region<'tcx>),
3636
Const(Const<'tcx>),
@@ -39,7 +39,7 @@ pub enum DictKey<'tcx> {
3939

4040
/// Type and extended type qualifiers.
4141
#[derive(Eq, Hash, PartialEq)]
42-
pub enum TyQ {
42+
pub(crate) enum TyQ {
4343
None,
4444
Const,
4545
Mut,

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ use crate::cfi::typeid::itanium_cxx_abi::encode::EncodeTyOptions;
2323
use crate::cfi::typeid::TypeIdOptions;
2424

2525
/// Options for transform_ty.
26-
pub type TransformTyOptions = TypeIdOptions;
26+
pub(crate) type TransformTyOptions = TypeIdOptions;
2727

28-
pub struct TransformTy<'tcx> {
28+
pub(crate) struct TransformTy<'tcx> {
2929
tcx: TyCtxt<'tcx>,
3030
options: TransformTyOptions,
3131
parents: Vec<Ty<'tcx>>,
3232
}
3333

3434
impl<'tcx> TransformTy<'tcx> {
35-
pub fn new(tcx: TyCtxt<'tcx>, options: TransformTyOptions) -> Self {
35+
pub(crate) fn new(tcx: TyCtxt<'tcx>, options: TransformTyOptions) -> Self {
3636
TransformTy { tcx, options, parents: Vec::new() }
3737
}
3838
}

compiler/rustc_sanitizers/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
// tidy-alphabetical-start
77
#![feature(let_chains)]
8+
#![warn(unreachable_pub)]
89
// tidy-alphabetical-end
910

1011
pub mod cfi;

compiler/rustc_serialize/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(never_type)]
1717
#![feature(ptr_sub_ptr)]
1818
#![feature(rustdoc_internals)]
19+
#![warn(unreachable_pub)]
1920
// tidy-alphabetical-end
2021

2122
pub use self::serialize::{Decodable, Decoder, Encodable, Encoder};

compiler/rustc_session/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(map_many_mut)]
66
#![feature(option_get_or_insert_default)]
77
#![feature(rustc_attrs)]
8+
#![warn(unreachable_pub)]
89
// tidy-alphabetical-end
910

1011
pub mod errors;

0 commit comments

Comments
 (0)