From 8d6d0e71a66355a9e2da366d22c7a4e355718fdf Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 24 Dec 2019 17:44:51 -0500 Subject: [PATCH] Format librustc_feature Use #[rustfmt::skip] on the tidy-parsed macro invocations --- rustfmt.toml | 4 --- src/librustc_feature/accepted.rs | 3 ++- src/librustc_feature/active.rs | 9 ++++--- src/librustc_feature/builtin_attrs.rs | 37 +++++++++++++++++---------- src/librustc_feature/lib.rs | 21 ++++++++------- src/librustc_feature/removed.rs | 4 ++- 6 files changed, 44 insertions(+), 34 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 5eab1944645..73f8cc1ff68 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -10,10 +10,6 @@ ignore = [ # (and generally rustfmt can move around comments in UI-testing incompatible ways) "src/test", - # tidy issues (line length, etc.) - # to be fixed shortly - "src/librustc_feature", - # do not format submodules "src/doc/book", "src/doc/edition-guide", diff --git a/src/librustc_feature/accepted.rs b/src/librustc_feature/accepted.rs index 3f294dc02ed..144a3faaba5 100644 --- a/src/librustc_feature/accepted.rs +++ b/src/librustc_feature/accepted.rs @@ -1,6 +1,6 @@ //! List of the accepted feature gates. -use super::{State, Feature}; +use super::{Feature, State}; use syntax_pos::symbol::sym; macro_rules! declare_features { @@ -23,6 +23,7 @@ macro_rules! declare_features { } } +#[rustfmt::skip] declare_features! ( // ------------------------------------------------------------------------- // feature-group-start: for testing purposes diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index 36664af8782..708e48fe6ad 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -1,10 +1,10 @@ //! List of the active feature gates. -use super::{State, Feature}; +use super::{Feature, State}; use syntax_pos::edition::Edition; +use syntax_pos::symbol::{sym, Symbol}; use syntax_pos::Span; -use syntax_pos::symbol::{Symbol, sym}; macro_rules! set { ($field: ident) => {{ @@ -12,7 +12,7 @@ fn f(features: &mut Features, _: Span) { features.$field = true; } f as fn(&mut Features, Span) - }} + }}; } macro_rules! declare_features { @@ -72,7 +72,7 @@ impl Feature { pub fn set(&self, features: &mut Features, span: Span) { match self.state { State::Active { set } => set(features, span), - _ => panic!("called `set` on feature `{}` which is not `active`", self.name) + _ => panic!("called `set` on feature `{}` which is not `active`", self.name), } } } @@ -91,6 +91,7 @@ pub fn set(&self, features: &mut Features, span: Span) { // N.B., `tools/tidy/src/features.rs` parses this information directly out of the // source, so take care when modifying it. +#[rustfmt::skip] declare_features! ( // ------------------------------------------------------------------------- // feature-group-start: internal feature gates diff --git a/src/librustc_feature/builtin_attrs.rs b/src/librustc_feature/builtin_attrs.rs index 0a4fb8a224e..5ae87d9712d 100644 --- a/src/librustc_feature/builtin_attrs.rs +++ b/src/librustc_feature/builtin_attrs.rs @@ -1,20 +1,20 @@ //! Built-in attributes and `cfg` flag gating. -use AttributeType::*; use AttributeGate::*; +use AttributeType::*; use crate::{Features, Stability}; -use rustc_data_structures::fx::FxHashMap; -use syntax_pos::symbol::{Symbol, sym}; use lazy_static::lazy_static; +use rustc_data_structures::fx::FxHashMap; +use syntax_pos::symbol::{sym, Symbol}; type GateFn = fn(&Features) -> bool; macro_rules! cfg_fn { ($field: ident) => { - (|features| { features.$field }) as GateFn - } + (|features| features.$field) as GateFn + }; } pub type GatedCfg = (Symbol, Symbol, GateFn); @@ -66,9 +66,10 @@ pub enum AttributeGate { impl std::fmt::Debug for AttributeGate { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - Self::Gated(ref stab, name, expl, _) => - write!(fmt, "Gated({:?}, {}, {})", stab, name, expl), - Self::Ungated => write!(fmt, "Ungated") + Self::Gated(ref stab, name, expl, _) => { + write!(fmt, "Gated({:?}, {}, {})", stab, name, expl) + } + Self::Ungated => write!(fmt, "Ungated"), } } } @@ -135,22 +136,31 @@ macro_rules! gated { macro_rules! rustc_attr { (TEST, $attr:ident, $typ:expr, $tpl:expr $(,)?) => { rustc_attr!( - $attr, $typ, $tpl, - concat!("the `#[", stringify!($attr), "]` attribute is just used for rustc unit tests \ + $attr, + $typ, + $tpl, + concat!( + "the `#[", + stringify!($attr), + "]` attribute is just used for rustc unit tests \ and will never be stable", ), ) }; ($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => { - (sym::$attr, $typ, $tpl, - Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs))) + ( + sym::$attr, + $typ, + $tpl, + Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)), + ) }; } macro_rules! experimental { ($attr:ident) => { concat!("the `#[", stringify!($attr), "]` attribute is an experimental feature") - } + }; } const IMPL_DETAIL: &str = "internal implementation detail"; @@ -159,6 +169,7 @@ macro_rules! experimental { pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate); /// Attributes that have a special meaning to rustc or rustdoc. +#[rustfmt::skip] pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== // Stable attributes: diff --git a/src/librustc_feature/lib.rs b/src/librustc_feature/lib.rs index c38bb3740af..b85feee040c 100644 --- a/src/librustc_feature/lib.rs +++ b/src/librustc_feature/lib.rs @@ -11,13 +11,13 @@ //! symbol to the `accepted` or `removed` modules respectively. mod accepted; -mod removed; mod active; mod builtin_attrs; +mod removed; use std::fmt; use std::num::NonZeroU32; -use syntax_pos::{Span, edition::Edition, symbol::Symbol}; +use syntax_pos::{edition::Edition, symbol::Symbol, Span}; #[derive(Clone, Copy)] pub enum State { @@ -43,7 +43,7 @@ pub struct Feature { pub state: State, pub name: Symbol, pub since: &'static str, - issue: Option, // FIXME: once #58732 is done make this an Option + issue: Option, // FIXME: once #58732 is done make this an Option pub edition: Option, description: &'static str, } @@ -72,7 +72,7 @@ pub enum UnstableFeatures { /// during the build that feature-related lints are set to warn or above /// because the build turns on warnings-as-errors and uses lots of unstable /// features. As a result, this is always required for building Rust itself. - Cheat + Cheat, } impl UnstableFeatures { @@ -84,7 +84,7 @@ pub fn from_environment() -> UnstableFeatures { match (disable_unstable_features, bootstrap) { (_, true) => UnstableFeatures::Cheat, (true, _) => UnstableFeatures::Disallow, - (false, _) => UnstableFeatures::Allow + (false, _) => UnstableFeatures::Allow, } } @@ -117,7 +117,7 @@ fn find_lang_feature_issue(feature: Symbol) -> Option { pub enum GateIssue { Language, - Library(Option) + Library(Option), } pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option { @@ -128,10 +128,9 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option