-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Chalk HasInterner
derive macro doesn't work because it expands to named constant
#9562
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
Labels
Comments
10 tasks
HasInterner
derive macro not expandedHasInterner
derive macro doesn't work because it expands to named constant
This patch does indeed fix it: diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index aa2dbaba1..48e6bb4a6 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -448,7 +448,10 @@ impl<'a> Ctx<'a> {
}
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
- let name = konst.name().map(|it| it.as_name());
+ let mut name = konst.name().map(|it| it.as_name());
+ if name.as_ref().map_or(false, |n| n.to_string().starts_with("_DERIVE_")) {
+ name = None;
+ }
let type_ref = self.lower_type_ref_opt(konst.ty());
let visibility = self.lower_visibility(konst);
let ast_id = self.source_ast_id_map.ast_id(konst); |
Ah, nice |
flodiebold
added a commit
to flodiebold/chalk
that referenced
this issue
Jul 11, 2021
This makes the derives work in rust-analyzer. CC rust-lang/rust-analyzer#9562
flodiebold
added a commit
to flodiebold/rust-analyzer
that referenced
this issue
Jul 11, 2021
This treats the consts generated by older synstructure versions like unnamed consts. We should remove this at some point (at least after Chalk has switched).
flodiebold
added a commit
to flodiebold/chalk
that referenced
this issue
Jul 11, 2021
This makes the derives work in rust-analyzer. CC rust-lang/rust-analyzer#9562
bors
added a commit
to rust-lang/chalk
that referenced
this issue
Jul 12, 2021
Use unnamed consts in chalk-derive This makes the derives work in rust-analyzer. CC rust-lang/rust-analyzer#9562
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Reproduction:
With
chalk_ir
andchalk_derive
dependencies.x
should be typeI
, which works if I write theHasInterner
impl by hand, but not in the above code.It turns out that the
synstructure
derive macro expands to an impl in a named constant:Which we don't support. Maybe we can change synstructure to use unnamed consts, or build a hack to treat
_DERIVE
consts like unnamed ones 😬The text was updated successfully, but these errors were encountered: