Skip to content

Commit f2973f6

Browse files
author
Jakub Wieczorek
committed
Fix cross-crate tuple structs in statics
Fixes #17169. Fixes #17649.
1 parent b224dfe commit f2973f6

File tree

8 files changed

+13
-14
lines changed

8 files changed

+13
-14
lines changed

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) {
149149
}
150150
ExprCall(ref callee, _) => {
151151
match v.tcx.def_map.borrow().find(&callee.id) {
152-
Some(&DefStruct(..)) => {} // OK.
152+
Some(&DefStruct(..)) |
153153
Some(&DefVariant(..)) => {} // OK.
154154
_ => {
155155
span_err!(v.tcx.sess, e.span, E0015,

src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
757757
DefStatic(..) =>
758758
cx.tcx.sess.span_bug(pat_span, "static pattern should've been rewritten"),
759759
DefVariant(_, id, _) if *constructor != Variant(id) => None,
760-
DefVariant(..) | DefFn(..) | DefStruct(..) => {
760+
DefVariant(..) | DefStruct(..) => {
761761
Some(match args {
762762
&Some(ref args) => args.iter().map(|p| &**p).collect(),
763763
&None => Vec::from_elem(arity, &DUMMY_WILD_PAT)

src/librustc/middle/mem_categorization.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
10831083
if_ok!(self.cat_pattern(subcmt, &**subpat, |x,y,z| op(x,y,z)));
10841084
}
10851085
}
1086-
Some(&def::DefFn(..)) |
10871086
Some(&def::DefStruct(..)) => {
10881087
for (i, subpat) in subpats.iter().enumerate() {
10891088
let subpat_ty = if_ok!(self.pat_ty(&**subpat)); // see (*2)

src/librustc/middle/privacy.rs

-9
Original file line numberDiff line numberDiff line change
@@ -931,15 +931,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
931931
maybe_did.unwrap_or(did)
932932
})
933933
}
934-
// Tuple struct constructors across crates are identified as
935-
// DefFn types, so we explicitly handle that case here.
936-
Some(&def::DefFn(did, _, _)) if !is_local(did) => {
937-
match csearch::get_tuple_struct_definition_if_ctor(
938-
&self.tcx.sess.cstore, did) {
939-
Some(did) => guard(did),
940-
None => {}
941-
}
942-
}
943934
_ => {}
944935
}
945936
}

src/librustc/middle/resolve.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,11 @@ impl<'a> Resolver<'a> {
18241824
child_name_bindings.define_value(def, DUMMY_SP, is_exported);
18251825
}
18261826
}
1827+
DefFn(ctor_id, _, true) => {
1828+
child_name_bindings.define_value(
1829+
csearch::get_tuple_struct_definition_if_ctor(&self.session.cstore, ctor_id)
1830+
.map_or(def, |_| DefStruct(ctor_id)), DUMMY_SP, is_public);
1831+
}
18271832
DefFn(..) | DefStaticMethod(..) | DefStatic(..) => {
18281833
debug!("(building reduced graph for external \
18291834
crate) building value (fn/static) {}", final_ident);

src/librustc/middle/trans/_match.rs

-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: uint) -> bool {
698698
}
699699
ast::PatEnum(..) | ast::PatIdent(_, _, None) => {
700700
match tcx.def_map.borrow().find(&pat.id) {
701-
Some(&def::DefFn(..)) |
702701
Some(&def::DefStruct(..)) => true,
703702
_ => false
704703
}
@@ -1646,7 +1645,6 @@ fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
16461645
}
16471646
}
16481647
}
1649-
Some(def::DefFn(..)) |
16501648
Some(def::DefStruct(..)) => {
16511649
match *sub_pats {
16521650
None => {

src/test/auxiliary/xcrate_unit_struct.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub enum Unit {
1919
Argument(Struct)
2020
}
2121

22+
pub struct TupleStruct(pub uint, pub &'static str);
23+
2224
// used by the cfail test
2325

2426
pub struct StructWithFields {

src/test/run-pass/xcrate-unit-struct.rs

+4
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::UnitVariant;
1616
static s3: xcrate_unit_struct::Unit =
1717
xcrate_unit_struct::Argument(xcrate_unit_struct::Struct);
1818
static s4: xcrate_unit_struct::Unit = xcrate_unit_struct::Argument(s1);
19+
static s5: xcrate_unit_struct::TupleStruct = xcrate_unit_struct::TupleStruct(20, "foo");
1920

2021
fn f1(_: xcrate_unit_struct::Struct) {}
2122
fn f2(_: xcrate_unit_struct::Unit) {}
23+
fn f3(_: xcrate_unit_struct::TupleStruct) {}
2224

2325
pub fn main() {
2426
f1(xcrate_unit_struct::Struct);
2527
f2(xcrate_unit_struct::UnitVariant);
2628
f2(xcrate_unit_struct::Argument(xcrate_unit_struct::Struct));
29+
f3(xcrate_unit_struct::TupleStruct(10, "bar"));
2730

2831
f1(s1);
2932
f2(s2);
3033
f2(s3);
3134
f2(s4);
35+
f3(s5);
3236
}

0 commit comments

Comments
 (0)