Skip to content

Commit 5d53921

Browse files
committed
Auto merge of #26747 - huonw:stability-issue, r=alexcrichton
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.
2 parents ed14593 + 69d340a commit 5d53921

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
@@ -378,6 +378,8 @@ pub struct Stability {
378378
// The reason for the current stability level. If deprecated, the
379379
// reason for deprecation.
380380
pub reason: Option<InternedString>,
381+
// The relevant rust-lang issue
382+
pub issue: Option<u32>
381383
}
382384

383385
/// The available stability levels.
@@ -412,41 +414,54 @@ fn find_stability_generic<'a,
412414

413415
used_attrs.push(attr);
414416

415-
let (feature, since, reason) = match attr.meta_item_list() {
417+
let (feature, since, reason, issue) = match attr.meta_item_list() {
416418
Some(metas) => {
417419
let mut feature = None;
418420
let mut since = None;
419421
let mut reason = None;
422+
let mut issue = None;
420423
for meta in metas {
421-
if meta.name() == "feature" {
422-
match meta.value_str() {
423-
Some(v) => feature = Some(v),
424-
None => {
425-
diagnostic.span_err(meta.span, "incorrect meta item");
426-
continue 'outer;
424+
match &*meta.name() {
425+
"feature" => {
426+
match meta.value_str() {
427+
Some(v) => feature = Some(v),
428+
None => {
429+
diagnostic.span_err(meta.span, "incorrect meta item");
430+
continue 'outer;
431+
}
427432
}
428433
}
429-
}
430-
if &meta.name()[..] == "since" {
431-
match meta.value_str() {
432-
Some(v) => since = Some(v),
433-
None => {
434-
diagnostic.span_err(meta.span, "incorrect meta item");
435-
continue 'outer;
434+
"since" => {
435+
match meta.value_str() {
436+
Some(v) => since = Some(v),
437+
None => {
438+
diagnostic.span_err(meta.span, "incorrect meta item");
439+
continue 'outer;
440+
}
436441
}
437442
}
438-
}
439-
if &meta.name()[..] == "reason" {
440-
match meta.value_str() {
441-
Some(v) => reason = Some(v),
442-
None => {
443-
diagnostic.span_err(meta.span, "incorrect meta item");
444-
continue 'outer;
443+
"reason" => {
444+
match meta.value_str() {
445+
Some(v) => reason = Some(v),
446+
None => {
447+
diagnostic.span_err(meta.span, "incorrect meta item");
448+
continue 'outer;
449+
}
450+
}
451+
}
452+
"issue" => {
453+
match meta.value_str().and_then(|s| s.parse().ok()) {
454+
Some(v) => issue = Some(v),
455+
None => {
456+
diagnostic.span_err(meta.span, "incorrect meta item");
457+
continue 'outer;
458+
}
445459
}
446460
}
461+
_ => {}
447462
}
448463
}
449-
(feature, since, reason)
464+
(feature, since, reason, issue)
450465
}
451466
None => {
452467
diagnostic.span_err(attr.span(), "incorrect stability attribute type");
@@ -480,7 +495,8 @@ fn find_stability_generic<'a,
480495
feature: feature.unwrap_or(intern_and_get_ident("bogus")),
481496
since: since,
482497
deprecated_since: None,
483-
reason: reason
498+
reason: reason,
499+
issue: issue,
484500
});
485501
} else { // "deprecated"
486502
if deprecated.is_some() {
@@ -504,6 +520,12 @@ fn find_stability_generic<'a,
504520
either stable or unstable attribute");
505521
}
506522
}
523+
} else if stab.as_ref().map_or(false, |s| s.level == Unstable && s.issue.is_none()) {
524+
// non-deprecated unstable items need to point to issues.
525+
// FIXME: uncomment this error
526+
// diagnostic.span_err(item_sp,
527+
// "non-deprecated unstable items need to point \
528+
// to an issue with `issue = \"NNN\"`");
507529
}
508530

509531
(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)