diff options
| author | est31 <MTest31@outlook.com> | 2022-02-02 12:45:20 +0100 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2022-02-02 17:11:01 +0100 |
| commit | 670f5c6ef385f251df5cd7bcba9e8039a80bdb4d (patch) | |
| tree | cdf352502795e4fb84b125e3a9c6f4162f6f4d24 /compiler/rustc_attr/src | |
| parent | d5f9c40e6a9ecc62432e71e886cef83a4c2c9b98 (diff) | |
| download | rust-670f5c6ef385f251df5cd7bcba9e8039a80bdb4d.tar.gz rust-670f5c6ef385f251df5cd7bcba9e8039a80bdb4d.zip | |
More let_else adoptions
Diffstat (limited to 'compiler/rustc_attr/src')
| -rw-r--r-- | compiler/rustc_attr/src/builtin.rs | 138 | ||||
| -rw-r--r-- | compiler/rustc_attr/src/lib.rs | 2 |
2 files changed, 69 insertions, 71 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index bab50df3dd5..8c5beb10258 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -217,85 +217,81 @@ where let mut issue_num = None; let mut is_soft = false; for meta in metas { - if let Some(mi) = meta.meta_item() { - match mi.name_or_empty() { - sym::feature => { - if !get(mi, &mut feature) { - continue 'outer; - } + let Some(mi) = meta.meta_item() else { + handle_errors( + &sess.parse_sess, + meta.span(), + AttrError::UnsupportedLiteral("unsupported literal", false), + ); + continue 'outer; + }; + match mi.name_or_empty() { + sym::feature => { + if !get(mi, &mut feature) { + continue 'outer; } - sym::reason => { - if !get(mi, &mut reason) { - continue 'outer; - } + } + sym::reason => { + if !get(mi, &mut reason) { + continue 'outer; + } + } + sym::issue => { + if !get(mi, &mut issue) { + continue 'outer; } - sym::issue => { - 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 => { - let emit_diag = |msg: &str| { - struct_span_err!( - diagnostic, - mi.span, - E0545, - "`issue` must be a non-zero numeric string \ - or \"none\"", - ) - .span_label( - mi.name_value_literal_span().unwrap(), - msg, - ) - .emit(); - }; - match issue.parse() { - Ok(0) => { - emit_diag( - "`issue` must not be \"0\", \ - use \"none\" instead", - ); - continue 'outer; - } - Ok(num) => NonZeroU32::new(num), - Err(err) => { - emit_diag(&err.to_string()); - 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 => { + let emit_diag = |msg: &str| { + struct_span_err!( + diagnostic, + mi.span, + E0545, + "`issue` must be a non-zero numeric string \ + or \"none\"", + ) + .span_label(mi.name_value_literal_span().unwrap(), msg) + .emit(); + }; + match issue.parse() { + Ok(0) => { + emit_diag( + "`issue` must not be \"0\", \ + use \"none\" instead", + ); + continue 'outer; + } + Ok(num) => NonZeroU32::new(num), + Err(err) => { + emit_diag(&err.to_string()); + continue 'outer; } } - }; - } - sym::soft => { - if !mi.is_word() { - let msg = "`soft` should not have any arguments"; - sess.parse_sess.span_diagnostic.span_err(mi.span, msg); } - is_soft = true; - } - _ => { - handle_errors( - &sess.parse_sess, - meta.span(), - AttrError::UnknownMetaItem( - pprust::path_to_string(&mi.path), - &["feature", "reason", "issue", "soft"], - ), - ); - continue 'outer; + }; + } + sym::soft => { + if !mi.is_word() { + let msg = "`soft` should not have any arguments"; + sess.parse_sess.span_diagnostic.span_err(mi.span, msg); } + is_soft = true; + } + _ => { + handle_errors( + &sess.parse_sess, + meta.span(), + AttrError::UnknownMetaItem( + pprust::path_to_string(&mi.path), + &["feature", "reason", "issue", "soft"], + ), + ); + continue 'outer; } - } else { - handle_errors( - &sess.parse_sess, - meta.span(), - AttrError::UnsupportedLiteral("unsupported literal", false), - ); - continue 'outer; } } diff --git a/compiler/rustc_attr/src/lib.rs b/compiler/rustc_attr/src/lib.rs index 3fb11f77872..c95c1c40a34 100644 --- a/compiler/rustc_attr/src/lib.rs +++ b/compiler/rustc_attr/src/lib.rs @@ -4,6 +4,8 @@ //! The goal is to move the definition of `MetaItem` and things that don't need to be in `syntax` //! to this crate. +#![feature(let_else)] + #[macro_use] extern crate rustc_macros; |
