Skip to content

fix: Work around older synstructure derives #9572

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

Merged
merged 2 commits into from
Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/hir_def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,12 @@ 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_")) {
// 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);
Expand Down
28 changes: 27 additions & 1 deletion crates/hir_ty/src/tests/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<T>;
impl<T> InFile<T> {
fn with_value<U>(self, value: U) -> InFile<U> { 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(
Expand Down