Skip to content

Commit 13d165e

Browse files
committed
Add deny(unreachable_pub) to rustc_builtin_macros.
1 parent 38a6b67 commit 13d165e

File tree

5 files changed

+50
-49
lines changed

5 files changed

+50
-49
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ struct TypeParameter {
352352
pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
353353

354354
impl BlockOrExpr {
355-
pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
355+
pub(crate) fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
356356
BlockOrExpr(stmts, None)
357357
}
358358

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

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

@@ -462,7 +462,7 @@ fn find_type_parameters(
462462
}
463463

464464
impl<'a> TraitDef<'a> {
465-
pub fn expand(
465+
pub(crate) fn expand(
466466
self,
467467
cx: &ExtCtxt<'_>,
468468
mitem: &ast::MetaItem,
@@ -472,7 +472,7 @@ impl<'a> TraitDef<'a> {
472472
self.expand_ext(cx, mitem, item, push, false);
473473
}
474474

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

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ pub(crate) enum PathKind {
2828
}
2929

3030
impl Path {
31-
pub fn new(path: Vec<Symbol>) -> Path {
31+
pub(crate) fn new(path: Vec<Symbol>) -> Path {
3232
Path::new_(path, Vec::new(), PathKind::Std)
3333
}
34-
pub fn new_local(path: Symbol) -> Path {
34+
pub(crate) fn new_local(path: Symbol) -> Path {
3535
Path::new_(vec![path], Vec::new(), PathKind::Local)
3636
}
37-
pub fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
37+
pub(crate) fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
3838
Path { path, params, kind }
3939
}
4040

41-
pub fn to_ty(
41+
pub(crate) fn to_ty(
4242
&self,
4343
cx: &ExtCtxt<'_>,
4444
span: Span,
@@ -47,7 +47,7 @@ impl Path {
4747
) -> P<ast::Ty> {
4848
cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
4949
}
50-
pub fn to_path(
50+
pub(crate) fn to_path(
5151
&self,
5252
cx: &ExtCtxt<'_>,
5353
span: Span,
@@ -88,7 +88,7 @@ pub(crate) fn self_ref() -> Ty {
8888
}
8989

9090
impl Ty {
91-
pub fn to_ty(
91+
pub(crate) fn to_ty(
9292
&self,
9393
cx: &ExtCtxt<'_>,
9494
span: Span,
@@ -109,7 +109,7 @@ impl Ty {
109109
}
110110
}
111111

112-
pub fn to_path(
112+
pub(crate) fn to_path(
113113
&self,
114114
cx: &ExtCtxt<'_>,
115115
span: Span,
@@ -168,10 +168,10 @@ pub(crate) struct Bounds {
168168
}
169169

170170
impl Bounds {
171-
pub fn empty() -> Bounds {
171+
pub(crate) fn empty() -> Bounds {
172172
Bounds { bounds: Vec::new() }
173173
}
174-
pub fn to_generics(
174+
pub(crate) fn to_generics(
175175
&self,
176176
cx: &ExtCtxt<'_>,
177177
span: Span,

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! path {
1616
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
1717
}
1818

19-
pub fn expand_deriving_smart_ptr(
19+
pub(crate) fn expand_deriving_smart_ptr(
2020
cx: &ExtCtxt<'_>,
2121
span: Span,
2222
_mitem: &MetaItem,

compiler/rustc_builtin_macros/src/format_foreign.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ pub(crate) mod printf {
44

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

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

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

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

4848
#[derive(Clone, PartialEq, Debug)]
4949
/// A single `printf`-style formatting directive.
50-
pub struct Format<'a> {
50+
pub(crate) struct Format<'a> {
5151
/// The entire original formatting directive.
52-
pub span: &'a str,
52+
span: &'a str,
5353
/// The (1-based) parameter to be converted.
54-
pub parameter: Option<u16>,
54+
parameter: Option<u16>,
5555
/// Formatting flags.
56-
pub flags: &'a str,
56+
flags: &'a str,
5757
/// Minimum width of the output.
58-
pub width: Option<Num>,
58+
width: Option<Num>,
5959
/// Precision of the conversion.
60-
pub precision: Option<Num>,
60+
precision: Option<Num>,
6161
/// Length modifier for the conversion.
62-
pub length: Option<&'a str>,
62+
length: Option<&'a str>,
6363
/// Type of parameter being converted.
64-
pub type_: &'a str,
64+
type_: &'a str,
6565
/// Byte offset for the start and end of this formatting directive.
66-
pub position: InnerSpan,
66+
position: InnerSpan,
6767
}
6868

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

7777
let (c_alt, c_zero, c_left, c_plus) = {
@@ -248,7 +248,7 @@ pub(crate) mod printf {
248248

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

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

294294
/// Iterator over substitutions in a string.
295-
pub struct Substitutions<'a> {
295+
pub(crate) struct Substitutions<'a> {
296296
s: &'a str,
297297
pos: usize,
298298
}
@@ -326,7 +326,7 @@ pub(crate) mod printf {
326326
}
327327

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

332332
let at = {
@@ -614,37 +614,37 @@ pub(crate) mod printf {
614614
mod tests;
615615
}
616616

617-
pub mod shell {
617+
pub(crate) mod shell {
618618
use super::strcursor::StrCursor as Cur;
619619
use rustc_span::InnerSpan;
620620

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

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

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

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

647-
pub fn translate(&self) -> Result<String, Option<String>> {
647+
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
648648
match self {
649649
Substitution::Ordinal(n, _) => Ok(format!("{{{}}}", n)),
650650
Substitution::Name(n, _) => Ok(format!("{{{}}}", n)),
@@ -654,12 +654,12 @@ pub mod shell {
654654
}
655655

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

661661
/// Iterator over substitutions in a string.
662-
pub struct Substitutions<'a> {
662+
pub(crate) struct Substitutions<'a> {
663663
s: &'a str,
664664
pos: usize,
665665
}
@@ -681,7 +681,7 @@ pub mod shell {
681681
}
682682

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

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

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

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

761-
pub fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
761+
pub(crate) fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
762762
let cp = self.cp_after()?;
763763
self.seek_right(cp.len_utf8());
764764
Some((cp, self))
@@ -768,11 +768,11 @@ mod strcursor {
768768
&self.s[0..self.at]
769769
}
770770

771-
pub fn slice_after(&self) -> &'a str {
771+
pub(crate) fn slice_after(&self) -> &'a str {
772772
&self.s[self.at..]
773773
}
774774

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

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![allow(rustc::diagnostic_outside_of_impl)]
77
#![allow(rustc::untranslatable_diagnostic)]
88
#![cfg_attr(bootstrap, feature(lint_reasons))]
9+
#![deny(unreachable_pub)]
910
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1011
#![doc(rust_logo)]
1112
#![feature(assert_matches)]

0 commit comments

Comments
 (0)