Skip to content

Handle attributes on cross-crate tuple-structs correctly #11932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub static tag_items_data_item_variant: uint = 0x0eu;

pub static tag_items_data_parent_item: uint = 0x0fu;

pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x10u;

pub static tag_index: uint = 0x11u;

pub static tag_index_buckets: uint = 0x12u;
Expand Down
17 changes: 17 additions & 0 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,26 @@ pub fn get_static_methods_if_impl(intr: @IdentInterner,
return Some(static_impl_methods);
}

/// If node_id is the constructor of a tuple struct, retrieve the NodeId of
/// the actual type definition, otherwise, return None
pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
node_id: ast::NodeId) -> Option<ast::NodeId> {
let item = lookup_item(node_id, cdata.data());
let mut ret = None;
reader::tagged_docs(item, tag_items_data_item_is_tuple_struct_ctor, |_| {
ret = Some(item_reqd_and_translated_parent_item(cdata.cnum, item));
false
});
ret.map(|x| x.node)
}

pub fn get_item_attrs(cdata: Cmd,
node_id: ast::NodeId,
f: |~[@ast::MetaItem]|) {
// The attributes for a tuple struct are attached to the definition, not the ctor;
// we assume that someone passing in a tuple struct ctor is actually wanting to
// look at the definition
let node_id = get_tuple_struct_definition_if_ctor(cdata, node_id).unwrap_or(node_id);
let item = lookup_item(node_id, cdata.data());
reader::tagged_docs(item, tag_attributes, |attributes| {
reader::tagged_docs(attributes, tag_attribute, |attribute| {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
encode_symbol(ecx, ebml_w, ctor_id);
}

// indicate that this is a tuple struct ctor, because downstream users will normally want
// the tuple struct definition, but without this there is no way for them to tell that
// they actually have a ctor rather than a normal function
ebml_w.start_tag(tag_items_data_item_is_tuple_struct_ctor);
ebml_w.end_tag();

ebml_w.end_tag();
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/auxiliary/lint_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,17 @@ pub enum Enum {
#[locked]
LockedVariant,
}

#[deprecated]
pub struct DeprecatedTupleStruct(int);
#[experimental]
pub struct ExperimentalTupleStruct(int);
#[unstable]
pub struct UnstableTupleStruct(int);
pub struct UnmarkedTupleStruct(int);
#[stable]
pub struct StableTupleStruct(int);
#[frozen]
pub struct FrozenTupleStruct(int);
#[locked]
pub struct LockedTupleStruct(int);
30 changes: 30 additions & 0 deletions src/test/compile-fail/lint-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ mod cross_crate {
let _ = StableVariant;
let _ = FrozenVariant;
let _ = LockedVariant;

let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
let _ = ExperimentalTupleStruct (1); //~ ERROR use of experimental item
let _ = UnstableTupleStruct (1); //~ ERROR use of unstable item
let _ = UnmarkedTupleStruct (1); //~ ERROR use of unmarked item
let _ = StableTupleStruct (1);
let _ = FrozenTupleStruct (1);
let _ = LockedTupleStruct (1);
}

fn test_method_param<F: Trait>(foo: F) {
Expand Down Expand Up @@ -277,6 +285,20 @@ mod this_crate {
LockedVariant,
}

#[deprecated]
pub struct DeprecatedTupleStruct(int);
#[experimental]
pub struct ExperimentalTupleStruct(int);
#[unstable]
pub struct UnstableTupleStruct(int);
pub struct UnmarkedTupleStruct(int);
#[stable]
pub struct StableTupleStruct(int);
#[frozen]
pub struct FrozenTupleStruct(int);
#[locked]
pub struct LockedTupleStruct(int);

fn test() {
let foo = MethodTester;

Expand Down Expand Up @@ -356,6 +378,14 @@ mod this_crate {
let _ = StableVariant;
let _ = FrozenVariant;
let _ = LockedVariant;

let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
let _ = ExperimentalTupleStruct (1); //~ ERROR use of experimental item
let _ = UnstableTupleStruct (1); //~ ERROR use of unstable item
let _ = UnmarkedTupleStruct (1); //~ ERROR use of unmarked item
let _ = StableTupleStruct (1);
let _ = FrozenTupleStruct (1);
let _ = LockedTupleStruct (1);
}

fn test_method_param<F: Trait>(foo: F) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail/simd-experimental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-test FIXME #11741 tuple structs ignore stability attributes

#[deny(experimental)];

use std::unstable::simd;
Expand Down