Skip to content

Commit 3f868d2

Browse files
authored
Rollup merge of rust-lang#76851 - fusion-engineering-forks:fixme-nonzero, 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.
2 parents edf43ea + 2140d80 commit 3f868d2

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

compiler/rustc_feature/src/accepted.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the accepted feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44
use rustc_span::symbol::sym;
55

66
macro_rules! declare_features {
@@ -14,7 +14,7 @@ macro_rules! declare_features {
1414
state: State::Accepted,
1515
name: sym::$feature,
1616
since: $ver,
17-
issue: $issue,
17+
issue: to_nonzero($issue),
1818
edition: None,
1919
description: concat!($($doc,)*),
2020
}

compiler/rustc_feature/src/active.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the active feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44

55
use rustc_span::edition::Edition;
66
use rustc_span::symbol::{sym, Symbol};
@@ -29,7 +29,7 @@ macro_rules! declare_features {
2929
state: State::Active { set: set!($feature) },
3030
name: sym::$feature,
3131
since: $ver,
32-
issue: $issue,
32+
issue: to_nonzero($issue),
3333
edition: $edition,
3434
description: concat!($($doc,)*),
3535
}

compiler/rustc_feature/src/lib.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,11 @@ pub struct Feature {
4646
pub state: State,
4747
pub name: Symbol,
4848
pub since: &'static str,
49-
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
49+
issue: Option<NonZeroU32>,
5050
pub edition: Option<Edition>,
5151
description: &'static str,
5252
}
5353

54-
impl Feature {
55-
fn issue(&self) -> Option<NonZeroU32> {
56-
self.issue.and_then(NonZeroU32::new)
57-
}
58-
}
59-
6054
#[derive(Copy, Clone, Debug)]
6155
pub enum Stability {
6256
Unstable,
@@ -102,8 +96,8 @@ impl UnstableFeatures {
10296
fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
10397
if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) {
10498
// FIXME (#28244): enforce that active features have issue numbers
105-
// assert!(info.issue().is_some())
106-
info.issue()
99+
// assert!(info.issue.is_some())
100+
info.issue
107101
} else {
108102
// search in Accepted, Removed, or Stable Removed features
109103
let found = ACCEPTED_FEATURES
@@ -112,12 +106,21 @@ fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
112106
.chain(STABLE_REMOVED_FEATURES)
113107
.find(|t| t.name == feature);
114108
match found {
115-
Some(found) => found.issue(),
109+
Some(found) => found.issue,
116110
None => panic!("feature `{}` is not declared anywhere", feature),
117111
}
118112
}
119113
}
120114

115+
const fn to_nonzero(n: Option<u32>) -> Option<NonZeroU32> {
116+
// Can be replaced with `n.and_then(NonZeroU32::new)` if that is ever usable
117+
// in const context. Requires https://github.com/rust-lang/rfcs/pull/2632.
118+
match n {
119+
None => None,
120+
Some(n) => NonZeroU32::new(n),
121+
}
122+
}
123+
121124
pub enum GateIssue {
122125
Language,
123126
Library(Option<NonZeroU32>),

compiler/rustc_feature/src/removed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! List of the removed feature gates.
22
3-
use super::{Feature, State};
3+
use super::{to_nonzero, Feature, State};
44
use rustc_span::symbol::sym;
55

66
macro_rules! declare_features {
@@ -14,7 +14,7 @@ macro_rules! declare_features {
1414
state: State::Removed { reason: $reason },
1515
name: sym::$feature,
1616
since: $ver,
17-
issue: $issue,
17+
issue: to_nonzero($issue),
1818
edition: None,
1919
description: concat!($($doc,)*),
2020
}
@@ -32,7 +32,7 @@ macro_rules! declare_features {
3232
state: State::Stabilized { reason: None },
3333
name: sym::$feature,
3434
since: $ver,
35-
issue: $issue,
35+
issue: to_nonzero($issue),
3636
edition: None,
3737
description: concat!($($doc,)*),
3838
}

0 commit comments

Comments
 (0)