Skip to content

Metadata decoding of more than one attribute like mutable and non_owned broken #7017

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

Closed
bill-myers opened this issue Jun 8, 2013 · 3 comments
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)

Comments

@bill-myers
Copy link
Contributor

It seems the decoding of [mutable] and [non_owned] is broken: specifically it seems they are ignored when applied on a struct in an external module, when another attribute follows.

In particular, it seems that when more than one attribute is present, only the last attribute survives encode+decode, and the others are somehow lost.

extern mod std;
use core::cell::Cell;
use std::rc::RcMut;
use std::arc::RWARC;

fn check_const<T: Const>(v: &T)
{
}

fn check_owned<T: Owned>(v: &T)
{
}

#[mutable]
#[deriving(Clone)]
pub struct MyCell<T> {
    priv value: Option<T>
}


fn test(c: &Cell<u32>, m: &RcMut<u32>, a: &RWARC<u32>, mc: &MyCell<u32>)
{
    // these succeed but should fail
    check_const(c);
    check_owned(m);

    // these fail as expected
    check_const(m);
    check_const(a);
    check_const(mc);
}
@thestinger
Copy link
Contributor

Nominating for the production ready milestone.

@bill-myers
Copy link
Contributor Author

Should be fixable with the following patch:

diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index c51fba8..8b1100a 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -4179,7 +4179,7 @@ pub fn has_attr(tcx: ctxt, did: def_id, attr: &str) -> bool {
     } else {
         let mut ret = false;
         do csearch::get_item_attrs(tcx.cstore, did) |meta_items| {
-            ret = attr::contains_name(meta_items, attr);
+            ret = ret || attr::contains_name(meta_items, attr);
         }
         ret
     }

bill-myers added a commit to bill-myers/rust that referenced this issue Jun 9, 2013
We were just looking at the last because we were overwriting ret.
bill-myers added a commit to bill-myers/rust that referenced this issue Jun 9, 2013
bors added a commit that referenced this issue Jun 9, 2013
Minimally fixes #7017, we were overwriting the result and thus ignoring attributes before the last.

csearch::get_item_attrs and decoder::get_item_attrs should probably also be changed to each_item_attrs using the for protocol, but that's just a minor performance/style issue.
@Aatch
Copy link
Contributor

Aatch commented Jun 10, 2013

Fixed by #7018.

@Aatch Aatch closed this as completed Jun 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR)
Projects
None yet
Development

No branches or pull requests

3 participants