diff options
| author | Andy Russell <arussell123@gmail.com> | 2020-01-22 10:33:46 -0500 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2020-01-30 09:01:56 -0500 |
| commit | 7632ade65bde6160c46f31495532f5beadcaa3d8 (patch) | |
| tree | 63a8d391519257cfd3807a7c286264a0bcc3b942 /src/libsyntax | |
| parent | c4071d09197e22d2fab8334aa8d30659961bb977 (diff) | |
| download | rust-7632ade65bde6160c46f31495532f5beadcaa3d8.tar.gz rust-7632ade65bde6160c46f31495532f5beadcaa3d8.zip | |
clarify "incorrect issue" error
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr/builtin.rs | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 6cfe4f2de1e..1da005d70d4 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -371,6 +371,7 @@ where let mut feature = None; let mut reason = None; let mut issue = None; + let mut issue_num = None; let mut is_soft = false; for meta in metas { if let Some(mi) = meta.meta_item() { @@ -389,6 +390,37 @@ where if !get(mi, &mut issue) { continue 'outer; } + + // These unwraps are safe because `get` ensures the meta item + // is a name/value pair string literal. + issue_num = match &*issue.unwrap().as_str() { + "none" => None, + issue => { + match issue.parse() { + Ok(num) => { + // FIXME(rossmacarthur): disallow 0 + // Disallowing this requires updates to + // some submodules + NonZeroU32::new(num) + } + Err(err) => { + struct_span_err!( + diagnostic, + mi.span, + E0545, + "`issue` must be a numeric string \ + or \"none\"", + ) + .span_label( + mi.name_value_literal().unwrap().span, + &err.to_string(), + ) + .emit(); + continue 'outer; + } + } + } + }; } sym::soft => { if !mi.is_word() { @@ -420,27 +452,8 @@ where } match (feature, reason, issue) { - (Some(feature), reason, Some(issue)) => { - let issue = match &*issue.as_str() { - "none" => None, - issue => { - if let Ok(num) = issue.parse() { - // FIXME(rossmacarthur): disallow 0 - // Disallowing this requires updates to some submodules - NonZeroU32::new(num) - } else { - struct_span_err!( - diagnostic, - attr.span, - E0545, - "incorrect 'issue'" - ) - .emit(); - continue; - } - } - }; - let level = Unstable { reason, issue, is_soft }; + (Some(feature), reason, Some(_)) => { + let level = Unstable { reason, issue: issue_num, is_soft }; if sym::unstable == meta_name { stab = Some(Stability { level, feature, rustc_depr: None }); } else { |
