Skip to content

Commit fae0fc1

Browse files
committed
Add deny(unreachable_pub) to rustc_builtin_macros.
1 parent ccf6b1c commit fae0fc1

File tree

6 files changed

+51
-50
lines changed

6 files changed

+51
-50
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ struct TypeParameter {
351351
pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
352352

353353
impl BlockOrExpr {
354-
pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
354+
pub(crate) fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
355355
BlockOrExpr(stmts, None)
356356
}
357357

358-
pub fn new_expr(expr: P<Expr>) -> BlockOrExpr {
358+
pub(crate) fn new_expr(expr: P<Expr>) -> BlockOrExpr {
359359
BlockOrExpr(ThinVec::new(), Some(expr))
360360
}
361361

362-
pub fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
362+
pub(crate) fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
363363
BlockOrExpr(stmts, expr)
364364
}
365365

@@ -461,7 +461,7 @@ fn find_type_parameters(
461461
}
462462

463463
impl<'a> TraitDef<'a> {
464-
pub fn expand(
464+
pub(crate) fn expand(
465465
self,
466466
cx: &ExtCtxt<'_>,
467467
mitem: &ast::MetaItem,
@@ -471,7 +471,7 @@ impl<'a> TraitDef<'a> {
471471
self.expand_ext(cx, mitem, item, push, false);
472472
}
473473

474-
pub fn expand_ext(
474+
pub(crate) fn expand_ext(
475475
self,
476476
cx: &ExtCtxt<'_>,
477477
mitem: &ast::MetaItem,

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ pub(crate) enum PathKind {
2727
}
2828

2929
impl Path {
30-
pub fn new(path: Vec<Symbol>) -> Path {
30+
pub(crate) fn new(path: Vec<Symbol>) -> Path {
3131
Path::new_(path, Vec::new(), PathKind::Std)
3232
}
33-
pub fn new_local(path: Symbol) -> Path {
33+
pub(crate) fn new_local(path: Symbol) -> Path {
3434
Path::new_(vec![path], Vec::new(), PathKind::Local)
3535
}
36-
pub fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
36+
pub(crate) fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
3737
Path { path, params, kind }
3838
}
3939

40-
pub fn to_ty(
40+
pub(crate) fn to_ty(
4141
&self,
4242
cx: &ExtCtxt<'_>,
4343
span: Span,
@@ -46,7 +46,7 @@ impl Path {
4646
) -> P<ast::Ty> {
4747
cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
4848
}
49-
pub fn to_path(
49+
pub(crate) fn to_path(
5050
&self,
5151
cx: &ExtCtxt<'_>,
5252
span: Span,
@@ -87,7 +87,7 @@ pub(crate) fn self_ref() -> Ty {
8787
}
8888

8989
impl Ty {
90-
pub fn to_ty(
90+
pub(crate) fn to_ty(
9191
&self,
9292
cx: &ExtCtxt<'_>,
9393
span: Span,
@@ -108,7 +108,7 @@ impl Ty {
108108
}
109109
}
110110

111-
pub fn to_path(
111+
pub(crate) fn to_path(
112112
&self,
113113
cx: &ExtCtxt<'_>,
114114
span: Span,
@@ -167,10 +167,10 @@ pub(crate) struct Bounds {
167167
}
168168

169169
impl Bounds {
170-
pub fn empty() -> Bounds {
170+
pub(crate) fn empty() -> Bounds {
171171
Bounds { bounds: Vec::new() }
172172
}
173-
pub fn to_generics(
173+
pub(crate) fn to_generics(
174174
&self,
175175
cx: &ExtCtxt<'_>,
176176
span: Span,

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ macro_rules! path {
1818
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
1919
}
2020

21-
pub fn expand_deriving_smart_ptr(
21+
pub(crate) fn expand_deriving_smart_ptr(
2222
cx: &ExtCtxt<'_>,
2323
span: Span,
2424
_mitem: &MetaItem,

compiler/rustc_builtin_macros/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ pub(crate) struct ExpectedItem<'a> {
930930

931931
#[derive(Diagnostic)]
932932
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)]
933-
pub struct NakedFunctionTestingAttribute {
933+
pub(crate) struct NakedFunctionTestingAttribute {
934934
#[primary_span]
935935
#[label(builtin_macros_naked_attribute)]
936936
pub naked_span: Span,

compiler/rustc_builtin_macros/src/format_foreign.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@ pub(crate) mod printf {
55

66
/// Represents a single `printf`-style substitution.
77
#[derive(Clone, PartialEq, Debug)]
8-
pub enum Substitution<'a> {
8+
pub(crate) enum Substitution<'a> {
99
/// A formatted output substitution with its internal byte offset.
1010
Format(Format<'a>),
1111
/// A literal `%%` escape, with its start and end indices.
1212
Escape((usize, usize)),
1313
}
1414

1515
impl<'a> Substitution<'a> {
16-
pub fn as_str(&self) -> &str {
16+
pub(crate) fn as_str(&self) -> &str {
1717
match self {
1818
Substitution::Format(fmt) => fmt.span,
1919
Substitution::Escape(_) => "%%",
2020
}
2121
}
2222

23-
pub fn position(&self) -> InnerSpan {
23+
pub(crate) fn position(&self) -> InnerSpan {
2424
match self {
2525
Substitution::Format(fmt) => fmt.position,
2626
&Substitution::Escape((start, end)) => InnerSpan::new(start, end),
2727
}
2828
}
2929

30-
pub fn set_position(&mut self, start: usize, end: usize) {
30+
pub(crate) fn set_position(&mut self, start: usize, end: usize) {
3131
match self {
3232
Substitution::Format(fmt) => fmt.position = InnerSpan::new(start, end),
3333
Substitution::Escape(pos) => *pos = (start, end),
@@ -38,7 +38,7 @@ pub(crate) mod printf {
3838
///
3939
/// This ignores cases where the substitution does not have an exact equivalent, or where
4040
/// the substitution would be unnecessary.
41-
pub fn translate(&self) -> Result<String, Option<String>> {
41+
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
4242
match self {
4343
Substitution::Format(fmt) => fmt.translate(),
4444
Substitution::Escape(_) => Err(None),
@@ -48,31 +48,31 @@ pub(crate) mod printf {
4848

4949
#[derive(Clone, PartialEq, Debug)]
5050
/// A single `printf`-style formatting directive.
51-
pub struct Format<'a> {
51+
pub(crate) struct Format<'a> {
5252
/// The entire original formatting directive.
53-
pub span: &'a str,
53+
span: &'a str,
5454
/// The (1-based) parameter to be converted.
55-
pub parameter: Option<u16>,
55+
parameter: Option<u16>,
5656
/// Formatting flags.
57-
pub flags: &'a str,
57+
flags: &'a str,
5858
/// Minimum width of the output.
59-
pub width: Option<Num>,
59+
width: Option<Num>,
6060
/// Precision of the conversion.
61-
pub precision: Option<Num>,
61+
precision: Option<Num>,
6262
/// Length modifier for the conversion.
63-
pub length: Option<&'a str>,
63+
length: Option<&'a str>,
6464
/// Type of parameter being converted.
65-
pub type_: &'a str,
65+
type_: &'a str,
6666
/// Byte offset for the start and end of this formatting directive.
67-
pub position: InnerSpan,
67+
position: InnerSpan,
6868
}
6969

7070
impl Format<'_> {
7171
/// Translate this directive into an equivalent Rust formatting directive.
7272
///
7373
/// Returns `Err` in cases where the `printf` directive does not have an exact Rust
7474
/// equivalent, rather than guessing.
75-
pub fn translate(&self) -> Result<String, Option<String>> {
75+
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
7676
use std::fmt::Write;
7777

7878
let (c_alt, c_zero, c_left, c_plus) = {
@@ -249,7 +249,7 @@ pub(crate) mod printf {
249249

250250
/// A general number used in a `printf` formatting directive.
251251
#[derive(Copy, Clone, PartialEq, Debug)]
252-
pub enum Num {
252+
enum Num {
253253
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
254254
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
255255
// is *vanishingly* unlikely that *anyone* is going to try formatting something wider, or
@@ -288,12 +288,12 @@ pub(crate) mod printf {
288288
}
289289

290290
/// Returns an iterator over all substitutions in a given string.
291-
pub fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
291+
pub(crate) fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
292292
Substitutions { s, pos: start_pos }
293293
}
294294

295295
/// Iterator over substitutions in a string.
296-
pub struct Substitutions<'a> {
296+
pub(crate) struct Substitutions<'a> {
297297
s: &'a str,
298298
pos: usize,
299299
}
@@ -327,7 +327,7 @@ pub(crate) mod printf {
327327
}
328328

329329
/// Parse the next substitution from the input string.
330-
pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
330+
fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
331331
use self::State::*;
332332

333333
let at = {
@@ -615,38 +615,38 @@ pub(crate) mod printf {
615615
mod tests;
616616
}
617617

618-
pub mod shell {
618+
pub(crate) mod shell {
619619
use rustc_span::InnerSpan;
620620

621621
use super::strcursor::StrCursor as Cur;
622622

623623
#[derive(Clone, PartialEq, Debug)]
624-
pub enum Substitution<'a> {
624+
pub(crate) enum Substitution<'a> {
625625
Ordinal(u8, (usize, usize)),
626626
Name(&'a str, (usize, usize)),
627627
Escape((usize, usize)),
628628
}
629629

630630
impl Substitution<'_> {
631-
pub fn as_str(&self) -> String {
631+
pub(crate) fn as_str(&self) -> String {
632632
match self {
633633
Substitution::Ordinal(n, _) => format!("${n}"),
634634
Substitution::Name(n, _) => format!("${n}"),
635635
Substitution::Escape(_) => "$$".into(),
636636
}
637637
}
638638

639-
pub fn position(&self) -> InnerSpan {
639+
pub(crate) fn position(&self) -> InnerSpan {
640640
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
641641
InnerSpan::new(pos.0, pos.1)
642642
}
643643

644-
pub fn set_position(&mut self, start: usize, end: usize) {
644+
fn set_position(&mut self, start: usize, end: usize) {
645645
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
646646
*pos = (start, end);
647647
}
648648

649-
pub fn translate(&self) -> Result<String, Option<String>> {
649+
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
650650
match self {
651651
Substitution::Ordinal(n, _) => Ok(format!("{{{}}}", n)),
652652
Substitution::Name(n, _) => Ok(format!("{{{}}}", n)),
@@ -656,12 +656,12 @@ pub mod shell {
656656
}
657657

658658
/// Returns an iterator over all substitutions in a given string.
659-
pub fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
659+
pub(crate) fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
660660
Substitutions { s, pos: start_pos }
661661
}
662662

663663
/// Iterator over substitutions in a string.
664-
pub struct Substitutions<'a> {
664+
pub(crate) struct Substitutions<'a> {
665665
s: &'a str,
666666
pos: usize,
667667
}
@@ -683,7 +683,7 @@ pub mod shell {
683683
}
684684

685685
/// Parse the next substitution from the input string.
686-
pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
686+
fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
687687
let at = {
688688
let start = s.find('$')?;
689689
match s[start + 1..].chars().next()? {
@@ -743,24 +743,24 @@ pub mod shell {
743743
}
744744

745745
mod strcursor {
746-
pub struct StrCursor<'a> {
746+
pub(crate) struct StrCursor<'a> {
747747
s: &'a str,
748748
pub at: usize,
749749
}
750750

751751
impl<'a> StrCursor<'a> {
752-
pub fn new_at(s: &'a str, at: usize) -> StrCursor<'a> {
752+
pub(crate) fn new_at(s: &'a str, at: usize) -> StrCursor<'a> {
753753
StrCursor { s, at }
754754
}
755755

756-
pub fn at_next_cp(mut self) -> Option<StrCursor<'a>> {
756+
pub(crate) fn at_next_cp(mut self) -> Option<StrCursor<'a>> {
757757
match self.try_seek_right_cp() {
758758
true => Some(self),
759759
false => None,
760760
}
761761
}
762762

763-
pub fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
763+
pub(crate) fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
764764
let cp = self.cp_after()?;
765765
self.seek_right(cp.len_utf8());
766766
Some((cp, self))
@@ -770,11 +770,11 @@ mod strcursor {
770770
&self.s[0..self.at]
771771
}
772772

773-
pub fn slice_after(&self) -> &'a str {
773+
pub(crate) fn slice_after(&self) -> &'a str {
774774
&self.s[self.at..]
775775
}
776776

777-
pub fn slice_between(&self, until: StrCursor<'a>) -> Option<&'a str> {
777+
pub(crate) fn slice_between(&self, until: StrCursor<'a>) -> Option<&'a str> {
778778
if !str_eq_literal(self.s, until.s) {
779779
None
780780
} else {

compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![allow(internal_features)]
66
#![allow(rustc::diagnostic_outside_of_impl)]
77
#![allow(rustc::untranslatable_diagnostic)]
8+
#![deny(unreachable_pub)]
89
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
910
#![doc(rust_logo)]
1011
#![feature(assert_matches)]

0 commit comments

Comments
 (0)