From b7bd45574a03c3f93900059d65ec7264936d5b48 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 11 Jul 2021 13:22:11 +0200 Subject: [PATCH 1/2] Add workaround for #9562 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). --- crates/hir_def/src/item_tree/lower.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index aa2dbaba1006..44bd2fa9e579 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -448,7 +448,12 @@ impl<'a> Ctx<'a> { } fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId { - 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_")) { + // FIXME: this is a hack to treat consts generated by synstructure as unnamed + // remove this some time in the future + 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); From 44d3c329221efd0f3fbc9e987d426b158aa55fa6 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 11 Jul 2021 16:14:22 +0200 Subject: [PATCH 2/2] Add test for #9560 --- crates/hir_ty/src/tests/coercion.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index aecc482cfdcd..8db1592c9160 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -500,7 +500,7 @@ fn main() { } #[test] -fn coerce_unsize_expected_type() { +fn coerce_unsize_expected_type_1() { check_no_mismatches( r#" //- minicore: coerce_unsized @@ -520,6 +520,32 @@ fn main() { ); } +#[test] +fn coerce_unsize_expected_type_2() { + // FIXME: this is wrong, #9560 + check( + r#" +//- minicore: coerce_unsized +struct InFile; +impl InFile { + fn with_value(self, value: U) -> InFile { InFile } +} +struct RecordField; +trait AstNode {} +impl AstNode for RecordField {} + +fn takes_dyn(it: InFile<&dyn AstNode>) {} + +fn test() { + let x: InFile<()> = InFile; + let n = &RecordField; + takes_dyn(x.with_value(n)); + // ^^^^^^^^^^^^^^^ expected InFile<&dyn AstNode>, got InFile<&RecordField> +} + "#, + ); +} + #[test] fn coerce_array_elems_lub() { check_no_mismatches(