Add warn(unreachable_pub)
to rustc_builtin_macros
.
This commit is contained in:
parent
0685c97843
commit
0544d3a952
6 changed files with 51 additions and 50 deletions
|
@ -351,15 +351,15 @@ struct TypeParameter {
|
||||||
pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
|
pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
|
||||||
|
|
||||||
impl BlockOrExpr {
|
impl BlockOrExpr {
|
||||||
pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
|
pub(crate) fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
|
||||||
BlockOrExpr(stmts, None)
|
BlockOrExpr(stmts, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_expr(expr: P<Expr>) -> BlockOrExpr {
|
pub(crate) fn new_expr(expr: P<Expr>) -> BlockOrExpr {
|
||||||
BlockOrExpr(ThinVec::new(), Some(expr))
|
BlockOrExpr(ThinVec::new(), Some(expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
|
pub(crate) fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
|
||||||
BlockOrExpr(stmts, expr)
|
BlockOrExpr(stmts, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ fn find_type_parameters(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TraitDef<'a> {
|
impl<'a> TraitDef<'a> {
|
||||||
pub fn expand(
|
pub(crate) fn expand(
|
||||||
self,
|
self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
mitem: &ast::MetaItem,
|
mitem: &ast::MetaItem,
|
||||||
|
@ -471,7 +471,7 @@ impl<'a> TraitDef<'a> {
|
||||||
self.expand_ext(cx, mitem, item, push, false);
|
self.expand_ext(cx, mitem, item, push, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_ext(
|
pub(crate) fn expand_ext(
|
||||||
self,
|
self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
mitem: &ast::MetaItem,
|
mitem: &ast::MetaItem,
|
||||||
|
|
|
@ -27,17 +27,17 @@ pub(crate) enum PathKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
pub fn new(path: Vec<Symbol>) -> Path {
|
pub(crate) fn new(path: Vec<Symbol>) -> Path {
|
||||||
Path::new_(path, Vec::new(), PathKind::Std)
|
Path::new_(path, Vec::new(), PathKind::Std)
|
||||||
}
|
}
|
||||||
pub fn new_local(path: Symbol) -> Path {
|
pub(crate) fn new_local(path: Symbol) -> Path {
|
||||||
Path::new_(vec![path], Vec::new(), PathKind::Local)
|
Path::new_(vec![path], Vec::new(), PathKind::Local)
|
||||||
}
|
}
|
||||||
pub fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
|
pub(crate) fn new_(path: Vec<Symbol>, params: Vec<Box<Ty>>, kind: PathKind) -> Path {
|
||||||
Path { path, params, kind }
|
Path { path, params, kind }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_ty(
|
pub(crate) fn to_ty(
|
||||||
&self,
|
&self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -46,7 +46,7 @@ impl Path {
|
||||||
) -> P<ast::Ty> {
|
) -> P<ast::Ty> {
|
||||||
cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
|
cx.ty_path(self.to_path(cx, span, self_ty, self_generics))
|
||||||
}
|
}
|
||||||
pub fn to_path(
|
pub(crate) fn to_path(
|
||||||
&self,
|
&self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -87,7 +87,7 @@ pub(crate) fn self_ref() -> Ty {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ty {
|
impl Ty {
|
||||||
pub fn to_ty(
|
pub(crate) fn to_ty(
|
||||||
&self,
|
&self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -108,7 +108,7 @@ impl Ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_path(
|
pub(crate) fn to_path(
|
||||||
&self,
|
&self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -167,10 +167,10 @@ pub(crate) struct Bounds {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bounds {
|
impl Bounds {
|
||||||
pub fn empty() -> Bounds {
|
pub(crate) fn empty() -> Bounds {
|
||||||
Bounds { bounds: Vec::new() }
|
Bounds { bounds: Vec::new() }
|
||||||
}
|
}
|
||||||
pub fn to_generics(
|
pub(crate) fn to_generics(
|
||||||
&self,
|
&self,
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
|
|
@ -18,7 +18,7 @@ macro_rules! path {
|
||||||
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
|
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expand_deriving_smart_ptr(
|
pub(crate) fn expand_deriving_smart_ptr(
|
||||||
cx: &ExtCtxt<'_>,
|
cx: &ExtCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
_mitem: &MetaItem,
|
_mitem: &MetaItem,
|
||||||
|
|
|
@ -930,7 +930,7 @@ pub(crate) struct ExpectedItem<'a> {
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)]
|
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)]
|
||||||
pub struct NakedFunctionTestingAttribute {
|
pub(crate) struct NakedFunctionTestingAttribute {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label(builtin_macros_naked_attribute)]
|
#[label(builtin_macros_naked_attribute)]
|
||||||
pub naked_span: Span,
|
pub naked_span: Span,
|
||||||
|
|
|
@ -5,7 +5,7 @@ pub(crate) mod printf {
|
||||||
|
|
||||||
/// Represents a single `printf`-style substitution.
|
/// Represents a single `printf`-style substitution.
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum Substitution<'a> {
|
pub(crate) enum Substitution<'a> {
|
||||||
/// A formatted output substitution with its internal byte offset.
|
/// A formatted output substitution with its internal byte offset.
|
||||||
Format(Format<'a>),
|
Format(Format<'a>),
|
||||||
/// A literal `%%` escape, with its start and end indices.
|
/// A literal `%%` escape, with its start and end indices.
|
||||||
|
@ -13,21 +13,21 @@ pub(crate) mod printf {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Substitution<'a> {
|
impl<'a> Substitution<'a> {
|
||||||
pub fn as_str(&self) -> &str {
|
pub(crate) fn as_str(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Format(fmt) => fmt.span,
|
Substitution::Format(fmt) => fmt.span,
|
||||||
Substitution::Escape(_) => "%%",
|
Substitution::Escape(_) => "%%",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> InnerSpan {
|
pub(crate) fn position(&self) -> InnerSpan {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Format(fmt) => fmt.position,
|
Substitution::Format(fmt) => fmt.position,
|
||||||
&Substitution::Escape((start, end)) => InnerSpan::new(start, end),
|
&Substitution::Escape((start, end)) => InnerSpan::new(start, end),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&mut self, start: usize, end: usize) {
|
pub(crate) fn set_position(&mut self, start: usize, end: usize) {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Format(fmt) => fmt.position = InnerSpan::new(start, end),
|
Substitution::Format(fmt) => fmt.position = InnerSpan::new(start, end),
|
||||||
Substitution::Escape(pos) => *pos = (start, end),
|
Substitution::Escape(pos) => *pos = (start, end),
|
||||||
|
@ -38,7 +38,7 @@ pub(crate) mod printf {
|
||||||
///
|
///
|
||||||
/// This ignores cases where the substitution does not have an exact equivalent, or where
|
/// This ignores cases where the substitution does not have an exact equivalent, or where
|
||||||
/// the substitution would be unnecessary.
|
/// the substitution would be unnecessary.
|
||||||
pub fn translate(&self) -> Result<String, Option<String>> {
|
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Format(fmt) => fmt.translate(),
|
Substitution::Format(fmt) => fmt.translate(),
|
||||||
Substitution::Escape(_) => Err(None),
|
Substitution::Escape(_) => Err(None),
|
||||||
|
@ -48,23 +48,23 @@ pub(crate) mod printf {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
/// A single `printf`-style formatting directive.
|
/// A single `printf`-style formatting directive.
|
||||||
pub struct Format<'a> {
|
pub(crate) struct Format<'a> {
|
||||||
/// The entire original formatting directive.
|
/// The entire original formatting directive.
|
||||||
pub span: &'a str,
|
span: &'a str,
|
||||||
/// The (1-based) parameter to be converted.
|
/// The (1-based) parameter to be converted.
|
||||||
pub parameter: Option<u16>,
|
parameter: Option<u16>,
|
||||||
/// Formatting flags.
|
/// Formatting flags.
|
||||||
pub flags: &'a str,
|
flags: &'a str,
|
||||||
/// Minimum width of the output.
|
/// Minimum width of the output.
|
||||||
pub width: Option<Num>,
|
width: Option<Num>,
|
||||||
/// Precision of the conversion.
|
/// Precision of the conversion.
|
||||||
pub precision: Option<Num>,
|
precision: Option<Num>,
|
||||||
/// Length modifier for the conversion.
|
/// Length modifier for the conversion.
|
||||||
pub length: Option<&'a str>,
|
length: Option<&'a str>,
|
||||||
/// Type of parameter being converted.
|
/// Type of parameter being converted.
|
||||||
pub type_: &'a str,
|
type_: &'a str,
|
||||||
/// Byte offset for the start and end of this formatting directive.
|
/// Byte offset for the start and end of this formatting directive.
|
||||||
pub position: InnerSpan,
|
position: InnerSpan,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Format<'_> {
|
impl Format<'_> {
|
||||||
|
@ -72,7 +72,7 @@ pub(crate) mod printf {
|
||||||
///
|
///
|
||||||
/// Returns `Err` in cases where the `printf` directive does not have an exact Rust
|
/// Returns `Err` in cases where the `printf` directive does not have an exact Rust
|
||||||
/// equivalent, rather than guessing.
|
/// equivalent, rather than guessing.
|
||||||
pub fn translate(&self) -> Result<String, Option<String>> {
|
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
let (c_alt, c_zero, c_left, c_plus) = {
|
let (c_alt, c_zero, c_left, c_plus) = {
|
||||||
|
@ -249,7 +249,7 @@ pub(crate) mod printf {
|
||||||
|
|
||||||
/// A general number used in a `printf` formatting directive.
|
/// A general number used in a `printf` formatting directive.
|
||||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||||
pub enum Num {
|
enum Num {
|
||||||
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
|
// The range of these values is technically bounded by `NL_ARGMAX`... but, at least for GNU
|
||||||
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
|
// libc, it apparently has no real fixed limit. A `u16` is used here on the basis that it
|
||||||
// is *vanishingly* unlikely that *anyone* is going to try formatting something wider, or
|
// is *vanishingly* unlikely that *anyone* is going to try formatting something wider, or
|
||||||
|
@ -288,12 +288,12 @@ pub(crate) mod printf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all substitutions in a given string.
|
/// Returns an iterator over all substitutions in a given string.
|
||||||
pub fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
|
pub(crate) fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
|
||||||
Substitutions { s, pos: start_pos }
|
Substitutions { s, pos: start_pos }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator over substitutions in a string.
|
/// Iterator over substitutions in a string.
|
||||||
pub struct Substitutions<'a> {
|
pub(crate) struct Substitutions<'a> {
|
||||||
s: &'a str,
|
s: &'a str,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,7 @@ pub(crate) mod printf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse the next substitution from the input string.
|
/// Parse the next substitution from the input string.
|
||||||
pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
|
fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
|
||||||
use self::State::*;
|
use self::State::*;
|
||||||
|
|
||||||
let at = {
|
let at = {
|
||||||
|
@ -615,20 +615,20 @@ pub(crate) mod printf {
|
||||||
mod tests;
|
mod tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod shell {
|
pub(crate) mod shell {
|
||||||
use rustc_span::InnerSpan;
|
use rustc_span::InnerSpan;
|
||||||
|
|
||||||
use super::strcursor::StrCursor as Cur;
|
use super::strcursor::StrCursor as Cur;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum Substitution<'a> {
|
pub(crate) enum Substitution<'a> {
|
||||||
Ordinal(u8, (usize, usize)),
|
Ordinal(u8, (usize, usize)),
|
||||||
Name(&'a str, (usize, usize)),
|
Name(&'a str, (usize, usize)),
|
||||||
Escape((usize, usize)),
|
Escape((usize, usize)),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Substitution<'_> {
|
impl Substitution<'_> {
|
||||||
pub fn as_str(&self) -> String {
|
pub(crate) fn as_str(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Ordinal(n, _) => format!("${n}"),
|
Substitution::Ordinal(n, _) => format!("${n}"),
|
||||||
Substitution::Name(n, _) => format!("${n}"),
|
Substitution::Name(n, _) => format!("${n}"),
|
||||||
|
@ -636,17 +636,17 @@ pub mod shell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&self) -> InnerSpan {
|
pub(crate) fn position(&self) -> InnerSpan {
|
||||||
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
||||||
InnerSpan::new(pos.0, pos.1)
|
InnerSpan::new(pos.0, pos.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&mut self, start: usize, end: usize) {
|
fn set_position(&mut self, start: usize, end: usize) {
|
||||||
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
||||||
*pos = (start, end);
|
*pos = (start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate(&self) -> Result<String, Option<String>> {
|
pub(crate) fn translate(&self) -> Result<String, Option<String>> {
|
||||||
match self {
|
match self {
|
||||||
Substitution::Ordinal(n, _) => Ok(format!("{{{}}}", n)),
|
Substitution::Ordinal(n, _) => Ok(format!("{{{}}}", n)),
|
||||||
Substitution::Name(n, _) => Ok(format!("{{{}}}", n)),
|
Substitution::Name(n, _) => Ok(format!("{{{}}}", n)),
|
||||||
|
@ -656,12 +656,12 @@ pub mod shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all substitutions in a given string.
|
/// Returns an iterator over all substitutions in a given string.
|
||||||
pub fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
|
pub(crate) fn iter_subs(s: &str, start_pos: usize) -> Substitutions<'_> {
|
||||||
Substitutions { s, pos: start_pos }
|
Substitutions { s, pos: start_pos }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator over substitutions in a string.
|
/// Iterator over substitutions in a string.
|
||||||
pub struct Substitutions<'a> {
|
pub(crate) struct Substitutions<'a> {
|
||||||
s: &'a str,
|
s: &'a str,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
}
|
}
|
||||||
|
@ -683,7 +683,7 @@ pub mod shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse the next substitution from the input string.
|
/// Parse the next substitution from the input string.
|
||||||
pub fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
|
fn parse_next_substitution(s: &str) -> Option<(Substitution<'_>, &str)> {
|
||||||
let at = {
|
let at = {
|
||||||
let start = s.find('$')?;
|
let start = s.find('$')?;
|
||||||
match s[start + 1..].chars().next()? {
|
match s[start + 1..].chars().next()? {
|
||||||
|
@ -743,24 +743,24 @@ pub mod shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod strcursor {
|
mod strcursor {
|
||||||
pub struct StrCursor<'a> {
|
pub(crate) struct StrCursor<'a> {
|
||||||
s: &'a str,
|
s: &'a str,
|
||||||
pub at: usize,
|
pub at: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StrCursor<'a> {
|
impl<'a> StrCursor<'a> {
|
||||||
pub fn new_at(s: &'a str, at: usize) -> StrCursor<'a> {
|
pub(crate) fn new_at(s: &'a str, at: usize) -> StrCursor<'a> {
|
||||||
StrCursor { s, at }
|
StrCursor { s, at }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn at_next_cp(mut self) -> Option<StrCursor<'a>> {
|
pub(crate) fn at_next_cp(mut self) -> Option<StrCursor<'a>> {
|
||||||
match self.try_seek_right_cp() {
|
match self.try_seek_right_cp() {
|
||||||
true => Some(self),
|
true => Some(self),
|
||||||
false => None,
|
false => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
|
pub(crate) fn next_cp(mut self) -> Option<(char, StrCursor<'a>)> {
|
||||||
let cp = self.cp_after()?;
|
let cp = self.cp_after()?;
|
||||||
self.seek_right(cp.len_utf8());
|
self.seek_right(cp.len_utf8());
|
||||||
Some((cp, self))
|
Some((cp, self))
|
||||||
|
@ -770,11 +770,11 @@ mod strcursor {
|
||||||
&self.s[0..self.at]
|
&self.s[0..self.at]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slice_after(&self) -> &'a str {
|
pub(crate) fn slice_after(&self) -> &'a str {
|
||||||
&self.s[self.at..]
|
&self.s[self.at..]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn slice_between(&self, until: StrCursor<'a>) -> Option<&'a str> {
|
pub(crate) fn slice_between(&self, until: StrCursor<'a>) -> Option<&'a str> {
|
||||||
if !str_eq_literal(self.s, until.s) {
|
if !str_eq_literal(self.s, until.s) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#![feature(proc_macro_quote)]
|
#![feature(proc_macro_quote)]
|
||||||
#![feature(rustdoc_internals)]
|
#![feature(rustdoc_internals)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
|
#![warn(unreachable_pub)]
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue