Add warn(unreachable_pub) to rustc_ast_pretty.

This commit is contained in:
Nicholas Nethercote 2024-07-06 21:27:29 +10:00
parent a6b2880d5a
commit f2fc87db44
4 changed files with 20 additions and 19 deletions

View File

@ -3,6 +3,7 @@
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(rustdoc_internals)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
mod helpers;

View File

@ -89,7 +89,7 @@ impl Printer {
}
impl Token {
pub fn is_hardbreak_tok(&self) -> bool {
pub(crate) fn is_hardbreak_tok(&self) -> bool {
*self == Printer::hardbreak_tok_offset(0)
}
}

View File

@ -11,54 +11,54 @@ use std::ops::{Index, IndexMut};
/// Holding a RingBuffer whose view is elements left..right gives the ability to
/// use Index and IndexMut to access elements i in the infinitely long queue for
/// which left <= i < right.
pub struct RingBuffer<T> {
pub(super) struct RingBuffer<T> {
data: VecDeque<T>,
// Abstract index of data[0] in the infinitely sized queue.
offset: usize,
}
impl<T> RingBuffer<T> {
pub fn new() -> Self {
pub(super) fn new() -> Self {
RingBuffer { data: VecDeque::new(), offset: 0 }
}
pub fn is_empty(&self) -> bool {
pub(super) fn is_empty(&self) -> bool {
self.data.is_empty()
}
pub fn push(&mut self, value: T) -> usize {
pub(super) fn push(&mut self, value: T) -> usize {
let index = self.offset + self.data.len();
self.data.push_back(value);
index
}
pub fn clear(&mut self) {
pub(super) fn clear(&mut self) {
self.data.clear();
}
pub fn index_of_first(&self) -> usize {
pub(super) fn index_of_first(&self) -> usize {
self.offset
}
pub fn first(&self) -> Option<&T> {
pub(super) fn first(&self) -> Option<&T> {
self.data.front()
}
pub fn first_mut(&mut self) -> Option<&mut T> {
pub(super) fn first_mut(&mut self) -> Option<&mut T> {
self.data.front_mut()
}
pub fn pop_first(&mut self) -> Option<T> {
pub(super) fn pop_first(&mut self) -> Option<T> {
let first = self.data.pop_front()?;
self.offset += 1;
Some(first)
}
pub fn last(&self) -> Option<&T> {
pub(super) fn last(&self) -> Option<&T> {
self.data.back()
}
pub fn last_mut(&mut self) -> Option<&mut T> {
pub(super) fn last_mut(&mut self) -> Option<&mut T> {
self.data.back_mut()
}
}

View File

@ -110,13 +110,13 @@ impl Default for FixupContext {
impl FixupContext {
/// Create the initial fixup for printing an expression in statement
/// position.
pub fn new_stmt() -> Self {
pub(crate) fn new_stmt() -> Self {
FixupContext { stmt: true, ..FixupContext::default() }
}
/// Create the initial fixup for printing an expression as the right-hand
/// side of a match arm.
pub fn new_match_arm() -> Self {
pub(crate) fn new_match_arm() -> Self {
FixupContext { match_arm: true, ..FixupContext::default() }
}
@ -124,7 +124,7 @@ impl FixupContext {
/// of an `if` or `while`. There are a few other positions which are
/// grammatically equivalent and also use this, such as the iterator
/// expression in `for` and the scrutinee in `match`.
pub fn new_cond() -> Self {
pub(crate) fn new_cond() -> Self {
FixupContext { parenthesize_exterior_struct_lit: true, ..FixupContext::default() }
}
@ -139,7 +139,7 @@ impl FixupContext {
///
/// Not every expression has a leftmost subexpression. For example neither
/// `-$a` nor `[$a]` have one.
pub fn leftmost_subexpression(self) -> Self {
pub(crate) fn leftmost_subexpression(self) -> Self {
FixupContext {
stmt: false,
leftmost_subexpression_in_stmt: self.stmt || self.leftmost_subexpression_in_stmt,
@ -158,7 +158,7 @@ impl FixupContext {
/// current expression, and is not surrounded by a paren/bracket/brace. For
/// example the `$b` in `$a + $b` and `-$b`, but not the one in `[$b]` or
/// `$a.f($b)`.
pub fn subsequent_subexpression(self) -> Self {
pub(crate) fn subsequent_subexpression(self) -> Self {
FixupContext {
stmt: false,
leftmost_subexpression_in_stmt: false,
@ -173,7 +173,7 @@ impl FixupContext {
///
/// The documentation on `FixupContext::leftmost_subexpression_in_stmt` has
/// examples.
pub fn would_cause_statement_boundary(self, expr: &Expr) -> bool {
pub(crate) fn would_cause_statement_boundary(self, expr: &Expr) -> bool {
(self.leftmost_subexpression_in_stmt && !classify::expr_requires_semi_to_be_stmt(expr))
|| (self.leftmost_subexpression_in_match_arm && classify::expr_is_complete(expr))
}
@ -189,7 +189,7 @@ impl FixupContext {
///
/// - `true && false`, because otherwise this would be misinterpreted as a
/// "let chain".
pub fn needs_par_as_let_scrutinee(self, expr: &Expr) -> bool {
pub(crate) fn needs_par_as_let_scrutinee(self, expr: &Expr) -> bool {
self.parenthesize_exterior_struct_lit && parser::contains_exterior_struct_lit(expr)
|| parser::needs_par_as_let_scrutinee(expr.precedence().order())
}