9572: fix: Work around older synstructure derives r=lnicola a=flodiebold

Fixes , until the proper fix  works which requires  to be released.

Also add an unrelated test, for .

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2021-07-11 14:19:25 +00:00 committed by GitHub
commit 3fc5f01f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions
crates
hir_def/src/item_tree
hir_ty/src/tests

@ -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);

@ -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<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(