Skip to content

Commit 530f2c7

Browse files
authored
Merge pull request dtolnay#934 from dtolnay/destructuring-assignment
Parse destructuring assignment
2 parents 785c8c9 + 8ae9129 commit 530f2c7

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/expr.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,8 @@ pub(crate) mod parsing {
10441044
use super::*;
10451045
use crate::parse::{Parse, ParseStream, Result};
10461046
use crate::path;
1047+
#[cfg(feature = "full")]
1048+
use proc_macro2::TokenTree;
10471049
use std::cmp::Ordering;
10481050

10491051
crate::custom_keyword!(raw);
@@ -1724,6 +1726,10 @@ pub(crate) mod parsing {
17241726
input.call(expr_block).map(Expr::Block)
17251727
} else if input.peek(Token![..]) {
17261728
expr_range(input, allow_struct).map(Expr::Range)
1729+
} else if input.peek(Token![_]) {
1730+
Ok(Expr::Verbatim(TokenStream::from(
1731+
input.parse::<TokenTree>()?,
1732+
)))
17271733
} else if input.peek(Lifetime) {
17281734
let the_label: Label = input.parse()?;
17291735
let mut expr = if input.peek(Token![while]) {
@@ -2451,7 +2457,11 @@ pub(crate) mod parsing {
24512457
path,
24522458
fields,
24532459
dot2_token: Some(content.parse()?),
2454-
rest: Some(Box::new(content.parse()?)),
2460+
rest: if content.is_empty() {
2461+
None
2462+
} else {
2463+
Some(Box::new(content.parse()?))
2464+
},
24552465
});
24562466
}
24572467

@@ -2672,8 +2682,6 @@ pub(crate) mod printing {
26722682
use super::*;
26732683
#[cfg(feature = "full")]
26742684
use crate::attr::FilterAttrs;
2675-
#[cfg(feature = "full")]
2676-
use crate::print::TokensOrDefault;
26772685
use proc_macro2::{Literal, TokenStream};
26782686
use quote::{ToTokens, TokenStreamExt};
26792687

@@ -3181,10 +3189,12 @@ pub(crate) mod printing {
31813189
self.brace_token.surround(tokens, |tokens| {
31823190
inner_attrs_to_tokens(&self.attrs, tokens);
31833191
self.fields.to_tokens(tokens);
3184-
if self.rest.is_some() {
3185-
TokensOrDefault(&self.dot2_token).to_tokens(tokens);
3186-
self.rest.to_tokens(tokens);
3192+
if let Some(dot2_token) = &self.dot2_token {
3193+
dot2_token.to_tokens(tokens);
3194+
} else if self.rest.is_some() {
3195+
Token![..](Span::call_site()).to_tokens(tokens);
31873196
}
3197+
self.rest.to_tokens(tokens);
31883198
})
31893199
}
31903200
}

tests/repo/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ const REVISION: &str = "72da5a9d85a522b11e80d0fdd1fd95247d442604";
1212

1313
#[rustfmt::skip]
1414
static EXCLUDE: &[&str] = &[
15-
// TODO destructuring assignment (#933)
16-
"src/test/ui/destructuring-assignment/drop-order.rs",
17-
"src/test/ui/destructuring-assignment/nested_destructure.rs",
18-
"src/test/ui/destructuring-assignment/slice_destructure.rs",
19-
"src/test/ui/destructuring-assignment/struct_destructure.rs",
20-
"src/test/ui/destructuring-assignment/tuple_destructure.rs",
21-
"src/test/ui/destructuring-assignment/tuple_struct_destructure.rs",
22-
2315
// Compile-fail expr parameter in const generic position: f::<1 + 2>()
2416
"src/test/ui/const-generics/closing-args-token.rs",
2517
"src/test/ui/const-generics/const-expression-parameter.rs",

0 commit comments

Comments
 (0)