Skip to content

Commit

Permalink
librustc: Fix bug preventing cross-crate struct destructuring from wo…
Browse files Browse the repository at this point in the history
…rking. rs=bugfix
  • Loading branch information
pcwalton committed Dec 10, 2012
1 parent ac2b045 commit 3f78e0e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4454,11 +4454,17 @@ impl Resolver {
let class_def = def_class(class_id);
self.record_def(pattern.id, class_def);
}
Some(definition @ def_class(class_id))
if self.structs.contains_key(class_id) => {
self.record_def(pattern.id, definition);
}
Some(definition @ def_variant(_, variant_id))
if self.structs.contains_key(variant_id) => {
self.record_def(pattern.id, definition);
}
_ => {
result => {
debug!("(resolving pattern) didn't find struct \
def: %?", result);
self.session.span_err(
path.span,
fmt!("`%s` does not name a structure",
Expand Down
7 changes: 7 additions & 0 deletions src/test/auxiliary/struct_destructuring_cross_crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[crate_type="lib"];

pub struct S {
x: int,
y: int
}

9 changes: 9 additions & 0 deletions src/test/run-pass/struct-destructuring-cross-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// xfail-fast
extern mod struct_destructuring_cross_crate;

fn main() {
let x = struct_destructuring_cross_crate::S { x: 1, y: 2 };
let struct_destructuring_cross_crate::S { x: a, y: b } = x;
assert a == 1;
assert b == 2;
}

0 comments on commit 3f78e0e

Please sign in to comment.