Skip to content

Commit 69d340a

Browse files
committed
rustc: implement unstable(issue = "nnn").
This takes an issue number and points people to it in the printed error message. This commit does not make it an error to have no `issue` field.
1 parent fe283b4 commit 69d340a

File tree

4 files changed

+92
-25
lines changed

4 files changed

+92
-25
lines changed

src/librustc/middle/stability.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,19 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
289289
if !cross_crate { return }
290290

291291
match *stab {
292-
Some(&Stability { level: attr::Unstable, ref feature, ref reason, .. }) => {
292+
Some(&Stability { level: attr::Unstable, ref feature, ref reason, issue, .. }) => {
293293
self.used_features.insert(feature.clone(), attr::Unstable);
294294

295295
if !self.active_features.contains(feature) {
296-
let msg = match *reason {
296+
let mut msg = match *reason {
297297
Some(ref r) => format!("use of unstable library feature '{}': {}",
298298
&feature, &r),
299299
None => format!("use of unstable library feature '{}'", &feature)
300300
};
301+
if let Some(n) = issue {
302+
use std::fmt::Write;
303+
write!(&mut msg, " (see issue #{})", n).unwrap();
304+
}
301305

302306
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic,
303307
&feature, span, &msg);

src/libsyntax/attr.rs

+45-23
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ pub struct Stability {
375375
// The reason for the current stability level. If deprecated, the
376376
// reason for deprecation.
377377
pub reason: Option<InternedString>,
378+
// The relevant rust-lang issue
379+
pub issue: Option<u32>
378380
}
379381

380382
/// The available stability levels.
@@ -409,41 +411,54 @@ fn find_stability_generic<'a,
409411

410412
used_attrs.push(attr);
411413

412-
let (feature, since, reason) = match attr.meta_item_list() {
414+
let (feature, since, reason, issue) = match attr.meta_item_list() {
413415
Some(metas) => {
414416
let mut feature = None;
415417
let mut since = None;
416418
let mut reason = None;
419+
let mut issue = None;
417420
for meta in metas {
418-
if meta.name() == "feature" {
419-
match meta.value_str() {
420-
Some(v) => feature = Some(v),
421-
None => {
422-
diagnostic.span_err(meta.span, "incorrect meta item");
423-
continue 'outer;
421+
match &*meta.name() {
422+
"feature" => {
423+
match meta.value_str() {
424+
Some(v) => feature = Some(v),
425+
None => {
426+
diagnostic.span_err(meta.span, "incorrect meta item");
427+
continue 'outer;
428+
}
424429
}
425430
}
426-
}
427-
if &meta.name()[..] == "since" {
428-
match meta.value_str() {
429-
Some(v) => since = Some(v),
430-
None => {
431-
diagnostic.span_err(meta.span, "incorrect meta item");
432-
continue 'outer;
431+
"since" => {
432+
match meta.value_str() {
433+
Some(v) => since = Some(v),
434+
None => {
435+
diagnostic.span_err(meta.span, "incorrect meta item");
436+
continue 'outer;
437+
}
433438
}
434439
}
435-
}
436-
if &meta.name()[..] == "reason" {
437-
match meta.value_str() {
438-
Some(v) => reason = Some(v),
439-
None => {
440-
diagnostic.span_err(meta.span, "incorrect meta item");
441-
continue 'outer;
440+
"reason" => {
441+
match meta.value_str() {
442+
Some(v) => reason = Some(v),
443+
None => {
444+
diagnostic.span_err(meta.span, "incorrect meta item");
445+
continue 'outer;
446+
}
447+
}
448+
}
449+
"issue" => {
450+
match meta.value_str().and_then(|s| s.parse().ok()) {
451+
Some(v) => issue = Some(v),
452+
None => {
453+
diagnostic.span_err(meta.span, "incorrect meta item");
454+
continue 'outer;
455+
}
442456
}
443457
}
458+
_ => {}
444459
}
445460
}
446-
(feature, since, reason)
461+
(feature, since, reason, issue)
447462
}
448463
None => {
449464
diagnostic.span_err(attr.span(), "incorrect stability attribute type");
@@ -477,7 +492,8 @@ fn find_stability_generic<'a,
477492
feature: feature.unwrap_or(intern_and_get_ident("bogus")),
478493
since: since,
479494
deprecated_since: None,
480-
reason: reason
495+
reason: reason,
496+
issue: issue,
481497
});
482498
} else { // "deprecated"
483499
if deprecated.is_some() {
@@ -501,6 +517,12 @@ fn find_stability_generic<'a,
501517
either stable or unstable attribute");
502518
}
503519
}
520+
} else if stab.as_ref().map_or(false, |s| s.level == Unstable && s.issue.is_none()) {
521+
// non-deprecated unstable items need to point to issues.
522+
// FIXME: uncomment this error
523+
// diagnostic.span_err(item_sp,
524+
// "non-deprecated unstable items need to point \
525+
// to an issue with `issue = \"NNN\"`");
504526
}
505527

506528
(stab, used_attrs)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(staged_api)]
12+
#![staged_api]
13+
#![stable(feature = "foo", since = "1.2.0")]
14+
15+
16+
#[unstable(feature = "foo", issue = "1")]
17+
pub fn unstable() {}
18+
19+
#[unstable(feature = "foo", reason = "message", issue = "2")]
20+
pub fn unstable_msg() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:stability_attribute_issue.rs
12+
13+
#![deny(deprecated)]
14+
15+
extern crate stability_attribute_issue;
16+
use stability_attribute_issue::*;
17+
18+
fn main() {
19+
unstable(); //~ ERROR use of unstable library feature 'foo' (see issue #1)
20+
unstable_msg(); //~ ERROR use of unstable library feature 'foo': message (see issue #2)
21+
}

0 commit comments

Comments
 (0)