Skip to content

Commit 57488db

Browse files
authored
Rollup merge of rust-lang#94400 - c410-f3r:more-let-chains, r=Dylan-DPC
2 - Make more use of `let_chains` Continuation of rust-lang#94376. cc rust-lang#53667
2 parents 27ee2e7 + ef5601b commit 57488db

File tree

5 files changed

+53
-59
lines changed

5 files changed

+53
-59
lines changed

compiler/rustc_ast/src/attr/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ impl NestedMetaItem {
7575
pub fn name_value_literal(&self) -> Option<(Symbol, &Lit)> {
7676
self.meta_item().and_then(|meta_item| {
7777
meta_item.meta_item_list().and_then(|meta_item_list| {
78-
if meta_item_list.len() == 1 {
79-
if let Some(ident) = meta_item.ident() {
80-
if let Some(lit) = meta_item_list[0].literal() {
81-
return Some((ident.name, lit));
82-
}
83-
}
78+
if meta_item_list.len() == 1
79+
&& let Some(ident) = meta_item.ident()
80+
&& let Some(lit) = meta_item_list[0].literal()
81+
{
82+
return Some((ident.name, lit));
8483
}
8584
None
8685
})

compiler/rustc_ast/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
#![feature(crate_visibility_modifier)]
1313
#![feature(if_let_guard)]
1414
#![feature(label_break_value)]
15-
#![feature(nll)]
15+
#![feature(let_chains)]
1616
#![feature(min_specialization)]
17-
#![recursion_limit = "256"]
17+
#![feature(nll)]
1818
#![feature(slice_internals)]
1919
#![feature(stmt_expr_attributes)]
20+
#![recursion_limit = "256"]
2021

2122
#[macro_use]
2223
extern crate rustc_macros;

compiler/rustc_ast/src/token.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -504,10 +504,8 @@ impl Token {
504504

505505
/// Returns `true` if the token is an interpolated path.
506506
fn is_path(&self) -> bool {
507-
if let Interpolated(ref nt) = self.kind {
508-
if let NtPath(..) = **nt {
509-
return true;
510-
}
507+
if let Interpolated(ref nt) = self.kind && let NtPath(..) = **nt {
508+
return true;
511509
}
512510
false
513511
}
@@ -516,21 +514,19 @@ impl Token {
516514
/// That is, is this a pre-parsed expression dropped into the token stream
517515
/// (which happens while parsing the result of macro expansion)?
518516
pub fn is_whole_expr(&self) -> bool {
519-
if let Interpolated(ref nt) = self.kind {
520-
if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
521-
return true;
522-
}
517+
if let Interpolated(ref nt) = self.kind
518+
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt
519+
{
520+
return true;
523521
}
524522

525523
false
526524
}
527525

528526
// Is the token an interpolated block (`$b:block`)?
529527
pub fn is_whole_block(&self) -> bool {
530-
if let Interpolated(ref nt) = self.kind {
531-
if let NtBlock(..) = **nt {
532-
return true;
533-
}
528+
if let Interpolated(ref nt) = self.kind && let NtBlock(..) = **nt {
529+
return true;
534530
}
535531
false
536532
}

compiler/rustc_ast/src/tokenstream.rs

+33-35
Original file line numberDiff line numberDiff line change
@@ -497,42 +497,40 @@ impl TokenStreamBuilder {
497497

498498
// If `self` is not empty and the last tree within the last stream is a
499499
// token tree marked with `Joint`...
500-
if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut() {
501-
if let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last() {
502-
// ...and `stream` is not empty and the first tree within it is
503-
// a token tree...
504-
let TokenStream(ref mut stream_lrc) = stream;
505-
if let Some((TokenTree::Token(token), spacing)) = stream_lrc.first() {
506-
// ...and the two tokens can be glued together...
507-
if let Some(glued_tok) = last_token.glue(&token) {
508-
// ...then do so, by overwriting the last token
509-
// tree in `self` and removing the first token tree
510-
// from `stream`. This requires using `make_mut()`
511-
// on the last stream in `self` and on `stream`,
512-
// and in practice this doesn't cause cloning 99.9%
513-
// of the time.
514-
515-
// Overwrite the last token tree with the merged
516-
// token.
517-
let last_vec_mut = Lrc::make_mut(last_stream_lrc);
518-
*last_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing);
519-
520-
// Remove the first token tree from `stream`. (This
521-
// is almost always the only tree in `stream`.)
522-
let stream_vec_mut = Lrc::make_mut(stream_lrc);
523-
stream_vec_mut.remove(0);
524-
525-
// Don't push `stream` if it's empty -- that could
526-
// block subsequent token gluing, by getting
527-
// between two token trees that should be glued
528-
// together.
529-
if !stream.is_empty() {
530-
self.0.push(stream);
531-
}
532-
return;
533-
}
534-
}
500+
if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut()
501+
&& let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last()
502+
// ...and `stream` is not empty and the first tree within it is
503+
// a token tree...
504+
&& let TokenStream(ref mut stream_lrc) = stream
505+
&& let Some((TokenTree::Token(token), spacing)) = stream_lrc.first()
506+
// ...and the two tokens can be glued together...
507+
&& let Some(glued_tok) = last_token.glue(&token)
508+
{
509+
// ...then do so, by overwriting the last token
510+
// tree in `self` and removing the first token tree
511+
// from `stream`. This requires using `make_mut()`
512+
// on the last stream in `self` and on `stream`,
513+
// and in practice this doesn't cause cloning 99.9%
514+
// of the time.
515+
516+
// Overwrite the last token tree with the merged
517+
// token.
518+
let last_vec_mut = Lrc::make_mut(last_stream_lrc);
519+
*last_vec_mut.last_mut().unwrap() = (TokenTree::Token(glued_tok), *spacing);
520+
521+
// Remove the first token tree from `stream`. (This
522+
// is almost always the only tree in `stream`.)
523+
let stream_vec_mut = Lrc::make_mut(stream_lrc);
524+
stream_vec_mut.remove(0);
525+
526+
// Don't push `stream` if it's empty -- that could
527+
// block subsequent token gluing, by getting
528+
// between two token trees that should be glued
529+
// together.
530+
if !stream.is_empty() {
531+
self.0.push(stream);
535532
}
533+
return;
536534
}
537535
self.0.push(stream);
538536
}

compiler/rustc_ast/src/util/literal.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ impl Lit {
222222
}
223223
token::Literal(lit) => lit,
224224
token::Interpolated(ref nt) => {
225-
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
226-
if let ast::ExprKind::Lit(lit) = &expr.kind {
227-
return Ok(lit.clone());
228-
}
225+
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt
226+
&& let ast::ExprKind::Lit(lit) = &expr.kind
227+
{
228+
return Ok(lit.clone());
229229
}
230230
return Err(LitError::NotLiteral);
231231
}

0 commit comments

Comments
 (0)