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

Make issue field optional in #[unstable] to avoid issue = "0" #60860

8 changes: 4 additions & 4 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl<'a, 'tcx> Index<'tcx> {
let stability = tcx.intern_stability(Stability {
level: attr::StabilityLevel::Unstable {
reason: Some(Symbol::intern(reason)),
issue: 27812,
issue: Some(27812),
},
feature: Symbol::intern("rustc_private"),
rustc_depr: None,
Expand Down Expand Up @@ -515,7 +515,7 @@ pub enum EvalResult {
Deny {
feature: Symbol,
reason: Option<Symbol>,
issue: u32,
issue: Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a Option<NonZeroU32>> instead? There's no valid issue #0, which means that we can try to save some space here.

Copy link
Contributor Author

@Julian-Wollersberger Julian-Wollersberger May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be done in this PR though, because the stage 0 compiler expects the old syntax and therefore the issue = "0" in stdlib and stdcore must remain until the changes made here get into stage 0.
(To be precise, x.py check emits errors and AFAIK Travis checks that.)
Also, there are other places where issues are represented as Option<u32> and even Some(0)

},
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
Unmarked,
Expand Down Expand Up @@ -686,7 +686,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, '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 == Some(27812) {
if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
return EvalResult::Allow;
}
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
emit_feature_err(&self.sess.parse_sess, feature, span,
GateIssue::Library(Some(issue)), &msg);
GateIssue::Library(issue), &msg);
}
}
EvalResult::Unmarked => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ enum DiagnosticBuilderMethod {
pub enum DiagnosticMessageId {
ErrorId(u16), // EXXXX error code as integer
LintId(lint::LintId),
StabilityId(u32), // issue number
StabilityId(Option<u32>), // issue number
Julian-Wollersberger marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<&'static lint::Lint> for DiagnosticMessageId {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4314,7 +4314,7 @@ impl Clean<Stability> for attr::Stability {
_ => None,
},
issue: match self.level {
attr::Unstable {issue, ..} => Some(issue),
attr::Unstable {issue, ..} => issue,
_ => None,
}
}
Expand Down
75 changes: 46 additions & 29 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub struct Stability {
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, 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 },
Unstable { reason: Option<Symbol>, issue: Option<u32> },
Julian-Wollersberger marked this conversation as resolved.
Show resolved Hide resolved
Stable { since: Symbol },
}

Expand Down Expand Up @@ -307,6 +307,7 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
break
}

// Expansion of `get_meta!`
let mut feature = None;
let mut reason = None;
let mut issue = None;
Expand Down Expand Up @@ -341,36 +342,52 @@ fn find_stability_generic<'a, I>(sess: &ParseSess,
}
}

match (feature, reason, issue) {
(Some(feature), reason, Some(issue)) => {
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
}
}
},
feature,
rustc_depr: None,
const_stability: None,
promotable: false,
allow_const_fn_ptr: false,
})
}
(None, _, _) => {
handle_errors(sess, attr.span, AttrError::MissingFeature);
continue
}
_ => {
span_err!(diagnostic, attr.span, E0547, "missing 'issue'");
// Parse the optional symbol to an optional integer.
let issue: Option<u32> = if let Some(issue_sym) = issue {
if let Ok(issue_num) = issue_sym.as_str().parse() {
//TODO Some ui tests fail because they directly use `thread_local!`
// internals ($SRC_DIR/libstd/thread/local.rs). That emits this warning.
// Removing the `issue = "0"` there isn't possible in libstd because the
// stage 0 compiler gives a syntax error for the missing issue.
//
// How can I fix this?
// + Don't include the warning is this PR and wait for the next
// master to beta promotion, because then I could remove the
// `issue = "0"`s in libstd and libcore
// + With a #[cfg(not(stage0))] somehow?
// + Just --bless the warnings?
/*if issue_num == 0 {
//TODO How do I choose an error number?
struct_span_warn!(diagnostic, attr.span, E0547,
"Issue #0 should not be used"
).help("Consider omitting the `issue` attribute")
.emit();
}*/
Some(issue_num)
} else {
span_err!(diagnostic, attr.span, E0545, "incorrect 'issue'");
continue
}
} else {
None
};

// `feature` is required, `reason` and `issue` are optional.
if let Some(feature) = feature {
stab = Some(Stability {
level: Unstable {
reason,
issue,
},
feature,
rustc_depr: None,
const_stability: None,
promotable: false,
allow_const_fn_ptr: false,
})
} else {
handle_errors(sess, attr.span, AttrError::MissingFeature);
continue
}
}
sym::stable => {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ register_diagnostics! {
E0544, // multiple stability levels
E0545, // incorrect 'issue'
E0546, // missing 'feature'
E0547, // missing 'issue'
E0547, // missing 'issue' //TODO I reused this one for the warning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a good idea? :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not, but I don't know how to properly do it. Can someone help me here?

// E0548, // replaced with a generic attribute input check
E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute
E0550, // multiple deprecated attributes
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ pub enum SyntaxExtension {
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
/// for a given macro.
local_inner_macros: bool,
/// The macro's feature name if it is unstable, and the stability feature
unstable_feature: Option<(Symbol, u32)>,
/// The macro's feature name if it is unstable, and the tracking issue
unstable_feature: Option<(Symbol, Option<u32>)>,
Julian-Wollersberger marked this conversation as resolved.
Show resolved Hide resolved
/// Edition of the crate in which the macro is defined
edition: Edition,
},
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
allow_internal_unsafe,
local_inner_macros,
// can't infer this type
unstable_feature: Option<(Symbol, u32)>,
unstable_feature: Option<(Symbol, Option<u32>)>,
edition| {

// feature-gate the macro invocation
Expand All @@ -731,7 +731,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}) {
let explain = format!("macro {}! is unstable", path);
emit_feature_err(this.cx.parse_sess, feature, span,
GateIssue::Library(Some(issue)), &explain);
GateIssue::Library(issue), &explain);
this.cx.trace_macros_diag();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "0")]
we're apparently really bad at it")]

#![feature(rustc_const_unstable, const_fn)]
#![feature(staged_api)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: `foo` is not yet stable as a const fn
--> $DIR/dont_promote_unstable_const_fn.rs:15:25
--> $DIR/dont_promote_unstable_const_fn.rs:14:25
|
LL | const fn bar() -> u32 { foo() }
| ^^^^^
|
= help: add `#![feature(foo)]` to the crate attributes to enable

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:18:28
--> $DIR/dont_promote_unstable_const_fn.rs:17:28
|
LL | let _: &'static u32 = &foo();
| ------------ ^^^^^ creates a temporary which is freed while still in use
Expand All @@ -17,7 +17,7 @@ LL | }
| - temporary value is freed at the end of this statement

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:22:28
--> $DIR/dont_promote_unstable_const_fn.rs:21:28
|
LL | let _: &'static u32 = &meh();
| ------------ ^^^^^ creates a temporary which is freed while still in use
Expand All @@ -28,7 +28,7 @@ LL | }
| - temporary value is freed at the end of this statement

error[E0716]: temporary value dropped while borrowed
--> $DIR/dont_promote_unstable_const_fn.rs:23:26
--> $DIR/dont_promote_unstable_const_fn.rs:22:26
|
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary which is freed while still in use
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "0")]
we're apparently really bad at it")]

#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(staged_api)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn`
--> $DIR/min_const_fn_libstd_stability.rs:15:25
--> $DIR/min_const_fn_libstd_stability.rs:14:25
|
LL | const fn bar() -> u32 { foo() }
| ^^^^^
Expand All @@ -8,7 +8,7 @@ LL | const fn bar() -> u32 { foo() }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn`
--> $DIR/min_const_fn_libstd_stability.rs:22:26
--> $DIR/min_const_fn_libstd_stability.rs:21:26
|
LL | const fn bar2() -> u32 { foo2() }
| ^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | const fn bar2() -> u32 { foo2() }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn_libstd_stability.rs:26:26
--> $DIR/min_const_fn_libstd_stability.rs:25:26
|
LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
| ^^^^^^^^^^^^^
Expand All @@ -26,7 +26,7 @@ LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn`
--> $DIR/min_const_fn_libstd_stability.rs:34:32
--> $DIR/min_const_fn_libstd_stability.rs:33:32
|
LL | const fn bar2_gated() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "0")]
we're apparently really bad at it")]

#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(staged_api)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:15:41
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:14:41
|
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
| ^^^^^
Expand All @@ -8,7 +8,7 @@ LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:22:42
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:21:42
|
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
| ^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:26:33
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:25:33
|
LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
| ^^^^^^^^^^^^^
Expand All @@ -26,7 +26,7 @@ LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:34:48
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:33:48
|
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "0")]
we're apparently really bad at it")]

#![feature(rustc_const_unstable, const_fn, foo, foo2)]
#![feature(staged_api)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0723]: can only call other `const fn` within a `const fn`, but `const foo` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:15:32
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:14:32
|
LL | const unsafe fn bar() -> u32 { foo() }
| ^^^^^
Expand All @@ -8,7 +8,7 @@ LL | const unsafe fn bar() -> u32 { foo() }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:22:33
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:21:33
|
LL | const unsafe fn bar2() -> u32 { foo2() }
| ^^^^^^
Expand All @@ -17,7 +17,7 @@ LL | const unsafe fn bar2() -> u32 { foo2() }
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `const fn` within a `const fn`, but `const foo2_gated` is not stable as `const fn`
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:30:39
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:29:39
|
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
| ^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn foo_stable_1_0_0() {}
//~^ ERROR feature `foo` is declared stable since 1.29.0
fn foo_stable_1_29_0() {}

#[unstable(feature = "foo", issue = "0")]
#[unstable(feature = "foo")]
//~^ ERROR feature `foo` is declared unstable
fn foo_unstable() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ LL | #[stable(feature = "foo", since = "1.29.0")]
error[E0711]: feature `foo` is declared unstable, but was previously declared stable
--> $DIR/stability-attribute-consistency.rs:12:1
|
LL | #[unstable(feature = "foo", issue = "0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #[unstable(feature = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-17337.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![feature(staged_api)]
#![deny(deprecated)]

#![unstable(feature = "unstable_test_feature", issue = "0")]
#![unstable(feature = "unstable_test_feature")]

struct Foo;

impl Foo {
#[unstable(feature = "unstable_test_feature", issue = "0")]
#[unstable(feature = "unstable_test_feature")]
#[rustc_deprecated(since = "1.0.0", reason = "text")]
fn foo(self) {}
}
Expand Down
Loading