Skip to content

Commit

Permalink
Rollup merge of rust-lang#76851 - fusion-engineering-forks:fixme-nonz…
Browse files Browse the repository at this point in the history
…ero, r=petrochenkov

Fix 'FIXME' about using NonZeroU32 instead of u32.

It was blocked by rust-lang#58732 (const fn NonZeroU32::new), which is fixed now.
  • Loading branch information
Dylan-DPC authored Oct 1, 2020
2 parents edf43ea + 2140d80 commit 3f868d2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! List of the accepted feature gates.
use super::{Feature, State};
use super::{to_nonzero, Feature, State};
use rustc_span::symbol::sym;

macro_rules! declare_features {
Expand All @@ -14,7 +14,7 @@ macro_rules! declare_features {
state: State::Accepted,
name: sym::$feature,
since: $ver,
issue: $issue,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! List of the active feature gates.
use super::{Feature, State};
use super::{to_nonzero, Feature, State};

use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Symbol};
Expand Down Expand Up @@ -29,7 +29,7 @@ macro_rules! declare_features {
state: State::Active { set: set!($feature) },
name: sym::$feature,
since: $ver,
issue: $issue,
issue: to_nonzero($issue),
edition: $edition,
description: concat!($($doc,)*),
}
Expand Down
23 changes: 13 additions & 10 deletions compiler/rustc_feature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@ 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<NonZeroU32>,
pub edition: Option<Edition>,
description: &'static str,
}

impl Feature {
fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(NonZeroU32::new)
}
}

#[derive(Copy, Clone, Debug)]
pub enum Stability {
Unstable,
Expand Down Expand Up @@ -102,8 +96,8 @@ impl UnstableFeatures {
fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) {
// FIXME (#28244): enforce that active features have issue numbers
// assert!(info.issue().is_some())
info.issue()
// assert!(info.issue.is_some())
info.issue
} else {
// search in Accepted, Removed, or Stable Removed features
let found = ACCEPTED_FEATURES
Expand All @@ -112,12 +106,21 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
.chain(STABLE_REMOVED_FEATURES)
.find(|t| t.name == feature);
match found {
Some(found) => found.issue(),
Some(found) => found.issue,
None => panic!("feature `{}` is not declared anywhere", feature),
}
}
}

const fn to_nonzero(n: Option<u32>) -> Option<NonZeroU32> {
// Can be replaced with `n.and_then(NonZeroU32::new)` if that is ever usable
// in const context. Requires https://github.com/rust-lang/rfcs/pull/2632.
match n {
None => None,
Some(n) => NonZeroU32::new(n),
}
}

pub enum GateIssue {
Language,
Library(Option<NonZeroU32>),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! List of the removed feature gates.
use super::{Feature, State};
use super::{to_nonzero, Feature, State};
use rustc_span::symbol::sym;

macro_rules! declare_features {
Expand All @@ -14,7 +14,7 @@ macro_rules! declare_features {
state: State::Removed { reason: $reason },
name: sym::$feature,
since: $ver,
issue: $issue,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
Expand All @@ -32,7 +32,7 @@ macro_rules! declare_features {
state: State::Stabilized { reason: None },
name: sym::$feature,
since: $ver,
issue: $issue,
issue: to_nonzero($issue),
edition: None,
description: concat!($($doc,)*),
}
Expand Down

0 comments on commit 3f868d2

Please sign in to comment.