Skip to content

Commit ffd80aa

Browse files
alexcrichtonemberian
authored andcommitted
Fix unit structs in cross-crate situtations
1 parent cc160a0 commit ffd80aa

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

src/librustc/middle/resolve.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use driver::session::Session;
1313
use metadata::csearch::{each_path, get_trait_method_def_ids};
1414
use metadata::csearch::get_method_name_and_explicit_self;
1515
use metadata::csearch::get_static_methods_if_impl;
16-
use metadata::csearch::get_type_name_if_impl;
16+
use metadata::csearch::{get_type_name_if_impl, get_struct_fields};
1717
use metadata::cstore::find_extern_mod_stmt_cnum;
1818
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
1919
use middle::lang_items::LanguageItems;
@@ -1700,9 +1700,12 @@ impl Resolver {
17001700
}
17011701
def_struct(def_id) => {
17021702
debug!("(building reduced graph for external \
1703-
crate) building type %s",
1703+
crate) building type and value for %s",
17041704
final_ident);
17051705
child_name_bindings.define_type(privacy, def, dummy_sp());
1706+
if get_struct_fields(self.session.cstore, def_id).len() == 0 {
1707+
child_name_bindings.define_value(privacy, def, dummy_sp());
1708+
}
17061709
self.structs.insert(def_id);
17071710
}
17081711
def_method(*) => {
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[crate_type = "lib"];
12+
13+
// used by the rpass test
14+
15+
pub struct Struct;
16+
17+
pub enum Unit {
18+
Unit,
19+
Argument(Struct)
20+
}
21+
22+
// used by the cfail test
23+
24+
pub struct StructWithFields {
25+
foo: int,
26+
}
27+
28+
pub enum EnumWithVariants {
29+
EnumVariant,
30+
EnumVariantArg(int)
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:xcrate_unit_struct.rs
12+
13+
// Make sure that when we have cross-crate unit structs we don't accidentally
14+
// make values out of cross-crate structs that aren't unit.
15+
16+
extern mod xcrate_unit_struct;
17+
18+
fn main() {
19+
let _ = xcrate_unit_struct::StructWithFields; //~ ERROR: unresolved name
20+
let _ = xcrate_unit_struct::Struct;
21+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:xcrate_unit_struct.rs
12+
13+
extern mod xcrate_unit_struct;
14+
15+
use std::util;
16+
17+
static s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct;
18+
static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit;
19+
static s3: xcrate_unit_struct::Unit =
20+
xcrate_unit_struct::Argument(xcrate_unit_struct::Struct);
21+
static s4: xcrate_unit_struct::Unit = xcrate_unit_struct::Argument(s1);
22+
23+
fn f1(_: xcrate_unit_struct::Struct) {}
24+
fn f2(_: xcrate_unit_struct::Unit) {}
25+
26+
fn main() {
27+
f1(xcrate_unit_struct::Struct);
28+
f2(xcrate_unit_struct::Unit);
29+
f2(xcrate_unit_struct::Argument(xcrate_unit_struct::Struct));
30+
31+
f1(s1);
32+
f2(s2);
33+
f2(s3);
34+
f2(s4);
35+
}

0 commit comments

Comments
 (0)