rust-analyzer/crates/hir_ty/src/tests/display_source_code.rs

139 lines
2.1 KiB
Rust
Raw Normal View History

2020-06-29 15:22:47 +00:00
use super::check_types_source_code;
#[test]
fn qualify_path_to_submodule() {
2020-06-29 15:22:47 +00:00
check_types_source_code(
r#"
mod foo {
pub struct Foo;
}
fn bar() {
let foo: foo::Foo = foo::Foo;
foo;
} //^^^ foo::Foo
"#,
);
}
#[test]
fn omit_default_type_parameters() {
2020-06-29 15:22:47 +00:00
check_types_source_code(
r#"
struct Foo<T = u8> { t: T }
fn main() {
let foo = Foo { t: 5u8 };
foo;
} //^^^ Foo
2020-06-29 15:22:47 +00:00
"#,
);
2020-06-29 15:22:47 +00:00
check_types_source_code(
r#"
struct Foo<K, T = u8> { k: K, t: T }
fn main() {
let foo = Foo { k: 400, t: 5u8 };
foo;
} //^^^ Foo<i32>
2020-06-29 15:22:47 +00:00
"#,
);
}
#[test]
fn render_raw_ptr_impl_ty() {
2021-06-15 18:28:37 +00:00
// FIXME: remove parens, they apper because there is an implicit Sized bound
check_types_source_code(
r#"
2021-06-15 22:23:04 +00:00
//- minicore: sized
trait Unpin {}
2021-06-15 18:28:37 +00:00
fn foo() -> *const impl Unpin { loop {} }
fn main() {
let foo = foo();
foo;
2021-06-15 18:28:37 +00:00
} //^^^ *const (impl Unpin)
"#,
);
}
2021-06-29 23:34:51 +00:00
#[test]
fn render_dyn_for_ty() {
// FIXME
check_types_source_code(
r#"
trait Foo<'a> {}
fn foo(foo: &dyn for<'a> Foo<'a>) {}
// ^^^ &dyn Foo
"#,
);
}
#[test]
fn sized_bounds_apit() {
check_types_source_code(
r#"
2021-06-15 22:23:04 +00:00
//- minicore: sized
trait Foo {}
trait Bar<T> {}
struct S<T>;
fn test(
a: impl Foo,
b: impl Foo + Sized,
c: &(impl Foo + ?Sized),
d: S<impl Foo>,
2021-06-15 18:28:37 +00:00
ref_any: &impl ?Sized,
empty: impl,
) {
a;
//^ impl Foo
b;
//^ impl Foo
c;
//^ &impl Foo + ?Sized
d;
//^ S<impl Foo>
2021-06-15 18:28:37 +00:00
ref_any;
//^ &impl ?Sized
empty;
} //^ impl Sized
"#,
);
}
#[test]
fn sized_bounds_rpit() {
check_types_source_code(
r#"
2021-06-15 22:23:04 +00:00
//- minicore: sized
trait Foo {}
fn foo() -> impl Foo { loop {} }
fn test<T: Foo>() {
let foo = foo();
foo;
} //^ impl Foo
"#,
);
}
#[test]
fn sized_bounds_impl_traits_in_fn_signature() {
check_types_source_code(
r#"
2021-06-15 22:23:04 +00:00
//- minicore: sized
trait Foo {}
fn test(
a: fn(impl Foo) -> impl Foo,
b: fn(impl Foo + Sized) -> impl Foo + Sized,
c: fn(&(impl Foo + ?Sized)) -> &(impl Foo + ?Sized),
) {
a;
//^ fn(impl Foo) -> impl Foo
b;
//^ fn(impl Foo) -> impl Foo
c;
} //^ fn(&impl Foo + ?Sized) -> &impl Foo + ?Sized
"#,
);
}