diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-01-31 01:21:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-31 01:21:30 +0100 |
| commit | f60b95aaa151e14380f76264dfd92ae78c05ca6c (patch) | |
| tree | 6773aa0bf1e1ceb846bbfb0a934a75941e5641a3 /src/libsyntax | |
| parent | b3e63f28b31ce753192bb99273c09a0c6d25a4b6 (diff) | |
| parent | 7632ade65bde6160c46f31495532f5beadcaa3d8 (diff) | |
| download | rust-f60b95aaa151e14380f76264dfd92ae78c05ca6c.tar.gz rust-f60b95aaa151e14380f76264dfd92ae78c05ca6c.zip | |
Rollup merge of #68670 - euclio:invalid-issue, r=estebank
clarify "incorrect issue" error Changes the message to be more precise, shrinks the span and adds a label specifying why the `issue` field is incorrect.
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 { |
