Skip to content

Commit 3fc5f01

Browse files
Merge #9572
9572: fix: Work around older synstructure derives r=lnicola a=flodiebold Fixes #9562, until the proper fix rust-lang/chalk#717 works which requires mystor/synstructure#47 to be released. Also add an unrelated test, for #9560. Co-authored-by: Florian Diebold <[email protected]>
2 parents 87621de + 44d3c32 commit 3fc5f01

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

crates/hir_def/src/item_tree/lower.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,12 @@ impl<'a> Ctx<'a> {
448448
}
449449

450450
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
451-
let name = konst.name().map(|it| it.as_name());
451+
let mut name = konst.name().map(|it| it.as_name());
452+
if name.as_ref().map_or(false, |n| n.to_string().starts_with("_DERIVE_")) {
453+
// FIXME: this is a hack to treat consts generated by synstructure as unnamed
454+
// remove this some time in the future
455+
name = None;
456+
}
452457
let type_ref = self.lower_type_ref_opt(konst.ty());
453458
let visibility = self.lower_visibility(konst);
454459
let ast_id = self.source_ast_id_map.ast_id(konst);

crates/hir_ty/src/tests/coercion.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ fn main() {
500500
}
501501

502502
#[test]
503-
fn coerce_unsize_expected_type() {
503+
fn coerce_unsize_expected_type_1() {
504504
check_no_mismatches(
505505
r#"
506506
//- minicore: coerce_unsized
@@ -520,6 +520,32 @@ fn main() {
520520
);
521521
}
522522

523+
#[test]
524+
fn coerce_unsize_expected_type_2() {
525+
// FIXME: this is wrong, #9560
526+
check(
527+
r#"
528+
//- minicore: coerce_unsized
529+
struct InFile<T>;
530+
impl<T> InFile<T> {
531+
fn with_value<U>(self, value: U) -> InFile<U> { InFile }
532+
}
533+
struct RecordField;
534+
trait AstNode {}
535+
impl AstNode for RecordField {}
536+
537+
fn takes_dyn(it: InFile<&dyn AstNode>) {}
538+
539+
fn test() {
540+
let x: InFile<()> = InFile;
541+
let n = &RecordField;
542+
takes_dyn(x.with_value(n));
543+
// ^^^^^^^^^^^^^^^ expected InFile<&dyn AstNode>, got InFile<&RecordField>
544+
}
545+
"#,
546+
);
547+
}
548+
523549
#[test]
524550
fn coerce_array_elems_lub() {
525551
check_no_mismatches(

0 commit comments

Comments
 (0)