Skip to content

Commit e81c393

Browse files
ashvin021calebcartwright
authored andcommitted
fix: remove wrong reformatting of qualified paths in struct patterns
1 parent fd6b025 commit e81c393

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

src/patterns.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ impl Rewrite for Pat {
244244
.collect();
245245
Some(format!("[{}]", rw.join(", ")))
246246
}
247-
PatKind::Struct(_, ref path, ref fields, ellipsis) => {
248-
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
247+
PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => {
248+
rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape)
249249
}
250250
PatKind::MacCall(ref mac) => {
251251
rewrite_macro(mac, None, context, shape, MacroPosition::Pat)
@@ -258,6 +258,7 @@ impl Rewrite for Pat {
258258
}
259259

260260
fn rewrite_struct_pat(
261+
qself: &Option<ast::QSelf>,
261262
path: &ast::Path,
262263
fields: &[ast::PatField],
263264
ellipsis: bool,
@@ -267,7 +268,7 @@ fn rewrite_struct_pat(
267268
) -> Option<String> {
268269
// 2 = ` {`
269270
let path_shape = shape.sub_width(2)?;
270-
let path_str = rewrite_path(context, PathContext::Expr, None, path, path_shape)?;
271+
let path_str = rewrite_path(context, PathContext::Expr, qself.as_ref(), path, path_shape)?;
271272

272273
if fields.is_empty() && !ellipsis {
273274
return Some(format!("{} {{}}", path_str));

tests/target/issue-4908-2.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(more_qualified_paths)]
2+
3+
fn main() {
4+
// destructure through a qualified path
5+
let <Foo as A>::Assoc { br } = StructStruct { br: 2 };
6+
}
7+
8+
struct StructStruct {
9+
br: i8,
10+
}
11+
12+
struct Foo;
13+
14+
trait A {
15+
type Assoc;
16+
}
17+
18+
impl A for Foo {
19+
type Assoc = StructStruct;
20+
}

tests/target/issue-4908.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(more_qualified_paths)]
2+
3+
mod foo_bar {
4+
pub enum Example {
5+
Example1 {},
6+
Example2 {},
7+
}
8+
}
9+
10+
fn main() {
11+
foo!(crate::foo_bar::Example, Example1);
12+
13+
let i1 = foo_bar::Example::Example1 {};
14+
15+
assert_eq!(i1.foo_example(), 1);
16+
17+
let i2 = foo_bar::Example::Example2 {};
18+
19+
assert_eq!(i2.foo_example(), 2);
20+
}
21+
22+
#[macro_export]
23+
macro_rules! foo {
24+
($struct:path, $variant:ident) => {
25+
impl $struct {
26+
pub fn foo_example(&self) -> i32 {
27+
match self {
28+
<$struct>::$variant { .. } => 1,
29+
_ => 2,
30+
}
31+
}
32+
}
33+
};
34+
}

0 commit comments

Comments
 (0)