Fix 'FIXME' about using NonZeroU32 instead of u32.

It was blocked by #58732 (const fn NonZeroU32::new), which is fixed now.
This commit is contained in:
Mara Bos 2020-09-17 21:11:22 +02:00
parent 7bdb5dee7b
commit 84ef603c84
4 changed files with 18 additions and 17 deletions

View File

@ -1,6 +1,6 @@
//! List of the accepted feature gates. //! List of the accepted feature gates.
use super::{Feature, State}; use super::{to_nonzero, Feature, State};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
macro_rules! declare_features { macro_rules! declare_features {
@ -14,7 +14,7 @@ macro_rules! declare_features {
state: State::Accepted, state: State::Accepted,
name: sym::$feature, name: sym::$feature,
since: $ver, since: $ver,
issue: $issue, issue: to_nonzero($issue),
edition: None, edition: None,
description: concat!($($doc,)*), description: concat!($($doc,)*),
} }

View File

@ -1,6 +1,6 @@
//! List of the active feature gates. //! List of the active feature gates.
use super::{Feature, State}; use super::{to_nonzero, Feature, State};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
@ -29,7 +29,7 @@ macro_rules! declare_features {
state: State::Active { set: set!($feature) }, state: State::Active { set: set!($feature) },
name: sym::$feature, name: sym::$feature,
since: $ver, since: $ver,
issue: $issue, issue: to_nonzero($issue),
edition: $edition, edition: $edition,
description: concat!($($doc,)*), description: concat!($($doc,)*),
} }

View File

@ -46,17 +46,11 @@ pub struct Feature {
pub state: State, pub state: State,
pub name: Symbol, pub name: Symbol,
pub since: &'static str, pub since: &'static str,
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32> issue: Option<NonZeroU32>,
pub edition: Option<Edition>, pub edition: Option<Edition>,
description: &'static str, description: &'static str,
} }
impl Feature {
fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(NonZeroU32::new)
}
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Stability { pub enum Stability {
Unstable, Unstable,
@ -102,8 +96,8 @@ impl UnstableFeatures {
fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> { fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) { if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) {
// FIXME (#28244): enforce that active features have issue numbers // FIXME (#28244): enforce that active features have issue numbers
// assert!(info.issue().is_some()) // assert!(info.issue.is_some())
info.issue() info.issue
} else { } else {
// search in Accepted, Removed, or Stable Removed features // search in Accepted, Removed, or Stable Removed features
let found = ACCEPTED_FEATURES let found = ACCEPTED_FEATURES
@ -112,12 +106,19 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
.chain(STABLE_REMOVED_FEATURES) .chain(STABLE_REMOVED_FEATURES)
.find(|t| t.name == feature); .find(|t| t.name == feature);
match found { match found {
Some(found) => found.issue(), Some(found) => found.issue,
None => panic!("feature `{}` is not declared anywhere", feature), None => panic!("feature `{}` is not declared anywhere", feature),
} }
} }
} }
const fn to_nonzero(n: Option<u32>) -> Option<NonZeroU32> {
match n {
None => None,
Some(n) => NonZeroU32::new(n),
}
}
pub enum GateIssue { pub enum GateIssue {
Language, Language,
Library(Option<NonZeroU32>), Library(Option<NonZeroU32>),

View File

@ -1,6 +1,6 @@
//! List of the removed feature gates. //! List of the removed feature gates.
use super::{Feature, State}; use super::{to_nonzero, Feature, State};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
macro_rules! declare_features { macro_rules! declare_features {
@ -14,7 +14,7 @@ macro_rules! declare_features {
state: State::Removed { reason: $reason }, state: State::Removed { reason: $reason },
name: sym::$feature, name: sym::$feature,
since: $ver, since: $ver,
issue: $issue, issue: to_nonzero($issue),
edition: None, edition: None,
description: concat!($($doc,)*), description: concat!($($doc,)*),
} }
@ -32,7 +32,7 @@ macro_rules! declare_features {
state: State::Stabilized { reason: None }, state: State::Stabilized { reason: None },
name: sym::$feature, name: sym::$feature,
since: $ver, since: $ver,
issue: $issue, issue: to_nonzero($issue),
edition: None, edition: None,
description: concat!($($doc,)*), description: concat!($($doc,)*),
} }