Skip to content

Commit

Permalink
Format librustc_feature
Browse files Browse the repository at this point in the history
Use #[rustfmt::skip] on the tidy-parsed macro invocations
  • Loading branch information
Mark-Simulacrum committed Dec 24, 2019
1 parent 6891388 commit 8d6d0e7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
4 changes: 0 additions & 4 deletions rustfmt.toml
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion 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 {
Expand All @@ -23,6 +23,7 @@ macro_rules! declare_features {
}
}

#[rustfmt::skip]
declare_features! (
// -------------------------------------------------------------------------
// feature-group-start: for testing purposes
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_feature/active.rs
@@ -1,18 +1,18 @@
//! 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) => {{
fn f(features: &mut Features, _: Span) {
features.$field = true;
}
f as fn(&mut Features, Span)
}}
}};
}

macro_rules! declare_features {
Expand Down Expand Up @@ -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),
}
}
}
Expand All @@ -91,6 +91,7 @@ impl Feature {
// 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
Expand Down
37 changes: 24 additions & 13 deletions 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);
Expand Down Expand Up @@ -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"),
}
}
}
Expand Down Expand Up @@ -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";
Expand All @@ -159,6 +169,7 @@ const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never b
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:
Expand Down
21 changes: 10 additions & 11 deletions src/librustc_feature/lib.rs
Expand Up @@ -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 {
Expand All @@ -43,7 +43,7 @@ pub struct Feature {
pub state: State,
pub name: Symbol,
pub since: &'static str,
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
pub edition: Option<Edition>,
description: &'static str,
}
Expand Down Expand Up @@ -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 {
Expand All @@ -84,7 +84,7 @@ impl UnstableFeatures {
match (disable_unstable_features, bootstrap) {
(_, true) => UnstableFeatures::Cheat,
(true, _) => UnstableFeatures::Disallow,
(false, _) => UnstableFeatures::Allow
(false, _) => UnstableFeatures::Allow,
}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {

pub enum GateIssue {
Language,
Library(Option<NonZeroU32>)
Library(Option<NonZeroU32>),
}

pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU32> {
Expand All @@ -128,10 +128,9 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU3
}

pub use accepted::ACCEPTED_FEATURES;
pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES};
pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
pub use active::{Features, ACTIVE_FEATURES, INCOMPLETE_FEATURES};
pub use builtin_attrs::{
AttributeGate, AttributeTemplate, AttributeType, find_gated_cfg, GatedCfg,
BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
deprecated_attributes, is_builtin_attr_name,
deprecated_attributes, find_gated_cfg, is_builtin_attr_name, AttributeGate, AttributeTemplate,
AttributeType, BuiltinAttribute, GatedCfg, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
};
pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
4 changes: 3 additions & 1 deletion src/librustc_feature/removed.rs
@@ -1,6 +1,6 @@
//! List of the removed feature gates.

use super::{State, Feature};
use super::{Feature, State};
use syntax_pos::symbol::sym;

macro_rules! declare_features {
Expand Down Expand Up @@ -41,6 +41,7 @@ macro_rules! declare_features {
};
}

#[rustfmt::skip]
declare_features! (
// -------------------------------------------------------------------------
// feature-group-start: removed features
Expand Down Expand Up @@ -111,6 +112,7 @@ declare_features! (
// -------------------------------------------------------------------------
);

#[rustfmt::skip]
declare_features! (
(stable_removed, no_stack_check, "1.0.0", None, None),
);

0 comments on commit 8d6d0e7

Please sign in to comment.