Skip to content
Myr

Resolve manual_let_else pedantic clippy lint

Before adoption: this commit came in with the history the project adopted, so no landing records it.

warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1460:5 | 1460 | / let string = match get_lit_str(cx, attr_name, meta)? { 1461 | | Some(string) => string, 1462 | | None => return Ok(None), 1463 | | }; | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else = note: `-W clippy::manual-let-else` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::manual_let_else)]` warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1482:5 | 1482 | / let string = match get_lit_str(cx, attr_name, meta)? { 1483 | | Some(string) => string, 1484 | | None => return Ok(None), 1485 | | }; | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1505:5 | 1505 | / let string = match get_lit_str2(cx, attr_name, meta_item_name, meta)? { 1506 | | Some(string) => string, 1507 | | None => return Ok(Vec::new()), 1508 | | }; | |______^ help: consider writing: `let Some(string) = get_lit_str2(cx, attr_name, meta_item_name, meta)? else { return Ok(Vec::new()) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1526:5 | 1526 | / let string = match get_lit_str(cx, attr_name, meta)? { 1527 | | Some(string) => string, 1528 | | None => return Ok(None), 1529 | | }; | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, attr_name, meta)? else { return Ok(None) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1549:5 | 1549 | / let string = match get_lit_str(cx, BORROW, meta)? { 1550 | | Some(string) => string, 1551 | | None => return Ok(BTreeSet::new()), 1552 | | }; | |______^ help: consider writing: `let Some(string) = get_lit_str(cx, BORROW, meta)? else { return Ok(BTreeSet::new()) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1621:5 | 1621 | / let seg = match path.segments.last() { 1622 | | Some(seg) => seg, 1623 | | None => { 1624 | | return false; 1625 | | } 1626 | | }; | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else help: consider writing | 1621 ~ let Some(seg) = path.segments.last() else { 1622 + return false; 1623 + }; | warning: this could be rewritten as `let...else` --> serde_derive/src/internals/attr.rs:1648:5 | 1648 | / let seg = match path.segments.last() { 1649 | | Some(seg) => seg, 1650 | | None => { 1651 | | return false; 1652 | | } 1653 | | }; | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else help: consider writing | 1648 ~ let Some(seg) = path.segments.last() else { 1649 + return false; 1650 + }; | warning: this could be rewritten as `let...else` --> serde_derive/src/internals/ctxt.rs:49:9 | 49 | / let mut combined = match errors.next() { 50 | | Some(first) => first, 51 | | None => return Ok(()), 52 | | }; | |__________^ help: consider writing: `let Some(mut combined) = errors.next() else { return Ok(()) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/de.rs:29:5 | 29 | / let cont = match Container::from_ast(&ctxt, input, Derive::Deserialize, &private... 30 | | Some(cont) => cont, 31 | | None => return Err(ctxt.check().unwrap_err()), 32 | | }; | |______^ help: consider writing: `let Some(cont) = Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident()) else { return Err(ctxt.check().unwrap_err()) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else warning: this could be rewritten as `let...else` --> serde_derive/src/ser.rs:16:5 | 16 | / let cont = match Container::from_ast(&ctxt, input, Derive::Serialize, &private.i... 17 | | Some(cont) => cont, 18 | | None => return Err(ctxt.check().unwrap_err()), 19 | | }; | |______^ help: consider writing: `let Some(cont) = Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) else { return Err(ctxt.check().unwrap_err()) };` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else

authored by David Tolnay · committed by David Tolnay · parent d656b4d · Browse files · 4 files+21 added−34 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+21 added−34 removed

  • other:+21 added−34 removed

4 files+21 added−34 removed

modified:serde_derive/src/internals/attr.rs+14 added-25 removed
1455 unmodified lines
1456 cx: &Ctxt,1457 attr_name: Symbol,1458 meta: &ParseNestedMeta,1459) -> syn::Result<Option<syn::Path>> {1460 let string = match get_lit_str(cx, attr_name, meta)? {1461 Some(string) => string,1462 None => return Ok(None),1460 let Some(string) = get_lit_str(cx, attr_name, meta)? else {1461 return Ok(None);1462 };14631464 Ok(match string.parse() {1465 Ok(path) => Some(path),
11 unmodified lines
1477 cx: &Ctxt,1478 attr_name: Symbol,1479 meta: &ParseNestedMeta,1480) -> syn::Result<Option<syn::ExprPath>> {1482 let string = match get_lit_str(cx, attr_name, meta)? {1483 Some(string) => string,1484 None => return Ok(None),1481 let Some(string) = get_lit_str(cx, attr_name, meta)? else {1482 return Ok(None);1483 };14841485 Ok(match string.parse() {1486 Ok(expr) => Some(expr),
12 unmodified lines
1499 attr_name: Symbol,1500 meta_item_name: Symbol,1501 meta: &ParseNestedMeta,1502) -> syn::Result<Vec<syn::WherePredicate>> {1505 let string = match get_lit_str2(cx, attr_name, meta_item_name, meta)? {1506 Some(string) => string,1507 None => return Ok(Vec::new()),1503 let Some(string) = get_lit_str2(cx, attr_name, meta_item_name, meta)? else {1504 return Ok(Vec::new());1505 };15061507 Ok(1508 match string.parse_with(Punctuated::<syn::WherePredicate, Token![,]>::parse_terminated) {
10 unmodified lines
1519 cx: &Ctxt,1520 attr_name: Symbol,1521 meta: &ParseNestedMeta,1522) -> syn::Result<Option<syn::Type>> {1526 let string = match get_lit_str(cx, attr_name, meta)? {1527 Some(string) => string,1528 None => return Ok(None),1523 let Some(string) = get_lit_str(cx, attr_name, meta)? else {1524 return Ok(None);1525 };15261527 Ok(match string.parse() {1528 Ok(ty) => Some(ty),
12 unmodified lines
1541fn parse_lit_into_lifetimes(1542 cx: &Ctxt,1543 meta: &ParseNestedMeta,1544) -> syn::Result<BTreeSet<syn::Lifetime>> {1549 let string = match get_lit_str(cx, BORROW, meta)? {1550 Some(string) => string,1551 None => return Ok(BTreeSet::new()),1545 let Some(string) = get_lit_str(cx, BORROW, meta)? else {1546 return Ok(BTreeSet::new());1547 };15481549 if let Ok(lifetimes) = string.parse_with(|input: ParseStream| {1550 let mut set = BTreeSet::new();
61 unmodified lines
1612 _ => {1613 return false;1614 }1615 };1621 let seg = match path.segments.last() {1622 Some(seg) => seg,1623 None => {1624 return false;1625 }1616 let Some(seg) = path.segments.last() else {1617 return false;1618 };1619 let args = match &seg.arguments {1620 syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,1621 _ => {
14 unmodified lines
1636 _ => {1637 return false;1638 }1639 };1648 let seg = match path.segments.last() {1649 Some(seg) => seg,1650 None => {1651 return false;1652 }1640 let Some(seg) = path.segments.last() else {1641 return false;1642 };1643 let args = match &seg.arguments {1644 syn::PathArguments::AngleBracketed(bracketed) => &bracketed.args,1645 _ => {
173 unmodified lines
modified:serde_derive/src/internals/ctxt.rs+2 added-3 removed
44 unmodified lines
45 /// Consume this object, producing a formatted error string if there are errors.46 pub fn check(self) -> syn::Result<()> {47 let mut errors = self.errors.borrow_mut().take().unwrap().into_iter();4849 let mut combined = match errors.next() {50 Some(first) => first,51 None => return Ok(()),49 let Some(mut combined) = errors.next() else {50 return Ok(());51 };5253 for rest in errors {54 combined.combine(rest);
13 unmodified lines
modified:serde_derive/src/de.rs+3 added-3 removed
24 unmodified lines
25pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {26 replace_receiver(input);2728 let ctxt = Ctxt::new();29 let cont = match Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident()) {30 Some(cont) => cont,31 None => return Err(ctxt.check().unwrap_err()),29 let Some(cont) = Container::from_ast(&ctxt, input, Derive::Deserialize, &private.ident())30 else {31 return Err(ctxt.check().unwrap_err());32 };33 precondition(&ctxt, &cont);34 ctxt.check()?;35
941 unmodified lines
modified:serde_derive/src/ser.rs+2 added-3 removed
11 unmodified lines
12pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {13 replace_receiver(input);1415 let ctxt = Ctxt::new();16 let cont = match Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) {17 Some(cont) => cont,18 None => return Err(ctxt.check().unwrap_err()),16 let Some(cont) = Container::from_ast(&ctxt, input, Derive::Serialize, &private.ident()) else {17 return Err(ctxt.check().unwrap_err());18 };19 precondition(&ctxt, &cont);20 ctxt.check()?;21
1347 unmodified lines