Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support issue = "none" in unstable attributes #66299

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
use crate::ty::{self, TyCtxt};
use crate::util::nodemap::{FxHashSet, FxHashMap};

use std::mem::replace;
use std::cmp::Ordering;
use std::mem::replace;
use std::num::NonZeroU32;

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum StabilityLevel {
Expand Down Expand Up @@ -441,7 +442,7 @@ impl<'tcx> Index<'tcx> {
let stability = tcx.intern_stability(Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
issue: 27812,
issue: NonZeroU32::new(27812),
is_soft: false,
},
feature: sym::rustc_private,
Expand Down Expand Up @@ -488,7 +489,7 @@ pub fn report_unstable(
sess: &Session,
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
issue: Option<NonZeroU32>,
is_soft: bool,
span: Span,
soft_handler: impl FnOnce(&'static lint::Lint, Span, &str),
Expand Down Expand Up @@ -520,7 +521,7 @@ pub fn report_unstable(
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
} else {
emit_feature_err(
&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg
&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg
);
}
}
Expand Down Expand Up @@ -637,7 +638,7 @@ pub enum EvalResult {
Deny {
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
issue: Option<NonZeroU32>,
is_soft: bool,
},
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
Expand Down Expand Up @@ -758,7 +759,7 @@ impl<'tcx> TyCtxt<'tcx> {
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
if feature == sym::rustc_private && issue == 27812 {
if feature == sym::rustc_private && issue == NonZeroU32::new(27812) {
if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
return EvalResult::Allow;
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use std::cell::{self, RefCell};
use std::env;
use std::fmt;
use std::io::Write;
use std::num::NonZeroU32;
use std::path::PathBuf;
use std::time::Duration;
use std::sync::Arc;
Expand Down Expand Up @@ -183,7 +184,7 @@ enum DiagnosticBuilderMethod {
pub enum DiagnosticMessageId {
ErrorId(u16), // EXXXX error code as integer
LintId(lint::LintId),
StabilityId(u32), // issue number
StabilityId(Option<NonZeroU32>), // issue number
}

impl From<&'static lint::Lint> for DiagnosticMessageId {
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::default::Default;
use std::{mem, slice, vec};
use std::num::NonZeroU32;
use std::iter::FromIterator;
use std::rc::Rc;
use std::cell::RefCell;
Expand Down Expand Up @@ -4399,7 +4400,7 @@ pub struct Stability {
pub since: String,
pub deprecation: Option<Deprecation>,
pub unstable_reason: Option<String>,
pub issue: Option<u32>,
pub issue: Option<NonZeroU32>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -4428,7 +4429,7 @@ impl Clean<Stability> for attr::Stability {
_ => None,
},
issue: match self.level {
attr::Unstable {issue, ..} => Some(issue),
attr::Unstable {issue, ..} => issue,
_ => None,
}
}
Expand Down
31 changes: 21 additions & 10 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::print::pprust;
use crate::sess::ParseSess;

use errors::{Applicability, Handler};
use std::num::NonZeroU32;
use syntax_pos::hygiene::Transparency;
use syntax_pos::{symbol::Symbol, symbol::sym, Span};

Expand Down Expand Up @@ -157,7 +158,7 @@ pub struct Stability {
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
pub enum StabilityLevel {
// Reason for the current stability level and the relevant rust-lang issue
Unstable { reason: Option<Symbol>, issue: u32, is_soft: bool },
Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
Stable { since: Symbol },
}

Expand Down Expand Up @@ -394,18 +395,28 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,

match (feature, reason, issue) {
(Some(feature), reason, Some(issue)) => {
let issue = match &*issue.as_str() {
// FIXME(rossmacarthur): remove "0" because "none" should be used
// See #41260
"none" | "0" => None,
issue => {
if let Ok(num) = issue.parse() {
NonZeroU32::new(num)
} else {
span_err!(
diagnostic,
attr.span,
E0545,
"incorrect 'issue'"
);
continue
}
}
};
stab = Some(Stability {
level: Unstable {
reason,
issue: {
if let Ok(issue) = issue.as_str().parse() {
issue
} else {
span_err!(diagnostic, attr.span, E0545,
"incorrect 'issue'");
continue
}
},
issue,
is_soft,
},
feature,
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/feature_gate/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ declare_features! (
/// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`.
(active, allocator_internals, "1.20.0", None, None),

// no-tracking-issue-end

/// Added for testing E0705; perma-unstable.
(active, test_2018_feature, "1.31.0", Some(0), Some(Edition::Edition2018)),
(active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),

// no-tracking-issue-end

// -------------------------------------------------------------------------
// feature-group-end: internal feature gates
Expand Down
31 changes: 16 additions & 15 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use log::debug;

use std::env;
use std::num::NonZeroU32;

#[derive(Copy, Clone, Debug)]
pub enum Stability {
Expand Down Expand Up @@ -55,25 +56,28 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features:
PostExpansionVisitor { parse_sess, features }.visit_attribute(attr)
}

fn find_lang_feature_issue(feature: Symbol) -> Option<u32> {
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.iter().chain(REMOVED_FEATURES).chain(STABLE_REMOVED_FEATURES)
let found = ACCEPTED_FEATURES
.iter()
.chain(REMOVED_FEATURES)
.chain(STABLE_REMOVED_FEATURES)
.find(|t| t.name == feature);
match found {
Some(&Feature { issue, .. }) => issue,
None => panic!("Feature `{}` is not declared anywhere", feature),
Some(found) => found.issue(),
None => panic!("feature `{}` is not declared anywhere", feature),
}
}
}

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

#[derive(Debug, Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -126,14 +130,11 @@ fn leveled_feature_err<'a, S: Into<MultiSpan>>(
GateStrength::Soft => diag.struct_span_warn(span, explain),
};

match issue {
None | Some(0) => {} // We still accept `0` as a stand-in for backwards compatibility
Some(n) => {
err.note(&format!(
"for more information, see https://github.com/rust-lang/rust/issues/{}",
n,
));
}
if let Some(n) = issue {
err.note(&format!(
"for more information, see https://github.com/rust-lang/rust/issues/{}",
n,
));
}

// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
Expand Down
11 changes: 9 additions & 2 deletions src/libsyntax/feature_gate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ mod active;
mod builtin_attrs;
mod check;

use std::fmt;
use crate::{edition::Edition, symbol::Symbol};
use std::fmt;
use std::num::NonZeroU32;
use syntax_pos::Span;

#[derive(Clone, Copy)]
Expand All @@ -46,11 +47,17 @@ pub struct Feature {
state: State,
name: Symbol,
since: &'static str,
issue: Option<u32>,
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
edition: Option<Edition>,
description: &'static str,
}

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

pub use active::{Features, INCOMPLETE_FEATURES};
pub use builtin_attrs::{
AttributeGate, AttributeType, GatedCfg,
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/feature-gate/unstable-attribute-allow-issue-none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Check that an issue value can be explicitly set to "none" instead of "0"
#![crate_type = "lib"]
#![feature(staged_api)]
#![stable(feature = "stable_test_feature", since = "1.0.0")]

#[unstable(feature = "unstable_test_feature", issue = "0")]
fn unstable_issue_0() {}

#[unstable(feature = "unstable_test_feature", issue = "none")]
fn unstable_issue_none() {}

#[unstable(feature = "unstable_test_feature", issue = "something")] //~ ERROR incorrect 'issue'
fn unstable_issue_not_allowed() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error[E0545]: incorrect 'issue'
--> $DIR/unstable-attribute-allow-issue-none.rs:12:1
|
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error