Stream: t-compiler/wg-rls-2.0

Topic: Inner crate attributes

Jonas Schievink (Apr 25 2020 at 13:22, on Zulip):

Hi! I'm trying to query whether there's a #![no_std] attribute on the crate, but for some reason db.attrs always returns an empty attribute list. Are crate-level attributes not recorded?

matklad (Apr 25 2020 at 13:23, on Zulip):

Probably just a bug with handling of inner attributes

matklad (Apr 25 2020 at 13:28, on Zulip):
    pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
        match def {
            AttrDefId::ModuleId(module) => {
                let def_map = db.crate_def_map(module.krate);
                let src = match def_map[module.local_id].declaration_source(db) {
                    Some(it) => it,
                    None => return Attrs::default(),
                Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
matklad (Apr 25 2020 at 13:29, on Zulip):

Yup, so here we only look at declaration_source (the mod foo;), we don't look at the definition_source

matklad (Apr 25 2020 at 13:29, on Zulip):

For crate root module (and only for crate root module) the declaration_source is None.

matklad (Apr 25 2020 at 13:30, on Zulip):

That is, we hit the return Attrs::defualt branch

Jonas Schievink (Apr 25 2020 at 14:22, on Zulip):

Oh awesome, that helps!

Last update: Sep 30 2020 at 17:00UTC