Skip to content

Commit 362cbbe

Browse files
committed
auto merge of #11932 : dmanescu/rust/11741-stability-cross-crate, r=alexcrichton
Fixes #11741 Added tests and removed xfail-fast from run-pass/simd-experimental which is now fixed (see #11738).
2 parents 1d49419 + bc8983a commit 362cbbe

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

src/librustc/metadata/common.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub static tag_items_data_item_variant: uint = 0x0eu;
3535

3636
pub static tag_items_data_parent_item: uint = 0x0fu;
3737

38+
pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x10u;
39+
3840
pub static tag_index: uint = 0x11u;
3941

4042
pub static tag_index_buckets: uint = 0x12u;

src/librustc/metadata/decoder.rs

+17
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,26 @@ pub fn get_static_methods_if_impl(intr: @IdentInterner,
980980
return Some(static_impl_methods);
981981
}
982982

983+
/// If node_id is the constructor of a tuple struct, retrieve the NodeId of
984+
/// the actual type definition, otherwise, return None
985+
pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
986+
node_id: ast::NodeId) -> Option<ast::NodeId> {
987+
let item = lookup_item(node_id, cdata.data());
988+
let mut ret = None;
989+
reader::tagged_docs(item, tag_items_data_item_is_tuple_struct_ctor, |_| {
990+
ret = Some(item_reqd_and_translated_parent_item(cdata.cnum, item));
991+
false
992+
});
993+
ret.map(|x| x.node)
994+
}
995+
983996
pub fn get_item_attrs(cdata: Cmd,
984997
node_id: ast::NodeId,
985998
f: |~[@ast::MetaItem]|) {
999+
// The attributes for a tuple struct are attached to the definition, not the ctor;
1000+
// we assume that someone passing in a tuple struct ctor is actually wanting to
1001+
// look at the definition
1002+
let node_id = get_tuple_struct_definition_if_ctor(cdata, node_id).unwrap_or(node_id);
9861003
let item = lookup_item(node_id, cdata.data());
9871004
reader::tagged_docs(item, tag_attributes, |attributes| {
9881005
reader::tagged_docs(attributes, tag_attribute, |attribute| {

src/librustc/metadata/encoder.rs

+6
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,12 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
778778
encode_symbol(ecx, ebml_w, ctor_id);
779779
}
780780

781+
// indicate that this is a tuple struct ctor, because downstream users will normally want
782+
// the tuple struct definition, but without this there is no way for them to tell that
783+
// they actually have a ctor rather than a normal function
784+
ebml_w.start_tag(tag_items_data_item_is_tuple_struct_ctor);
785+
ebml_w.end_tag();
786+
781787
ebml_w.end_tag();
782788
}
783789

src/test/auxiliary/lint_stability.rs

+14
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,17 @@ pub enum Enum {
159159
#[locked]
160160
LockedVariant,
161161
}
162+
163+
#[deprecated]
164+
pub struct DeprecatedTupleStruct(int);
165+
#[experimental]
166+
pub struct ExperimentalTupleStruct(int);
167+
#[unstable]
168+
pub struct UnstableTupleStruct(int);
169+
pub struct UnmarkedTupleStruct(int);
170+
#[stable]
171+
pub struct StableTupleStruct(int);
172+
#[frozen]
173+
pub struct FrozenTupleStruct(int);
174+
#[locked]
175+
pub struct LockedTupleStruct(int);

src/test/compile-fail/lint-stability.rs

+30
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ mod cross_crate {
101101
let _ = StableVariant;
102102
let _ = FrozenVariant;
103103
let _ = LockedVariant;
104+
105+
let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
106+
let _ = ExperimentalTupleStruct (1); //~ ERROR use of experimental item
107+
let _ = UnstableTupleStruct (1); //~ ERROR use of unstable item
108+
let _ = UnmarkedTupleStruct (1); //~ ERROR use of unmarked item
109+
let _ = StableTupleStruct (1);
110+
let _ = FrozenTupleStruct (1);
111+
let _ = LockedTupleStruct (1);
104112
}
105113

106114
fn test_method_param<F: Trait>(foo: F) {
@@ -277,6 +285,20 @@ mod this_crate {
277285
LockedVariant,
278286
}
279287

288+
#[deprecated]
289+
pub struct DeprecatedTupleStruct(int);
290+
#[experimental]
291+
pub struct ExperimentalTupleStruct(int);
292+
#[unstable]
293+
pub struct UnstableTupleStruct(int);
294+
pub struct UnmarkedTupleStruct(int);
295+
#[stable]
296+
pub struct StableTupleStruct(int);
297+
#[frozen]
298+
pub struct FrozenTupleStruct(int);
299+
#[locked]
300+
pub struct LockedTupleStruct(int);
301+
280302
fn test() {
281303
let foo = MethodTester;
282304

@@ -356,6 +378,14 @@ mod this_crate {
356378
let _ = StableVariant;
357379
let _ = FrozenVariant;
358380
let _ = LockedVariant;
381+
382+
let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
383+
let _ = ExperimentalTupleStruct (1); //~ ERROR use of experimental item
384+
let _ = UnstableTupleStruct (1); //~ ERROR use of unstable item
385+
let _ = UnmarkedTupleStruct (1); //~ ERROR use of unmarked item
386+
let _ = StableTupleStruct (1);
387+
let _ = FrozenTupleStruct (1);
388+
let _ = LockedTupleStruct (1);
359389
}
360390

361391
fn test_method_param<F: Trait>(foo: F) {

src/test/compile-fail/simd-experimental.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test FIXME #11741 tuple structs ignore stability attributes
12-
1311
#[deny(experimental)];
1412

1513
use std::unstable::simd;

0 commit comments

Comments
 (0)