2020-06-29 15:22:47 +00:00
|
|
|
use super::check_types_source_code;
|
2020-04-25 14:57:59 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn qualify_path_to_submodule() {
|
2020-06-29 15:22:47 +00:00
|
|
|
check_types_source_code(
|
2020-04-25 14:57:59 +00:00
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub struct Foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() {
|
|
|
|
let foo: foo::Foo = foo::Foo;
|
2021-06-20 17:10:45 +00:00
|
|
|
foo;
|
|
|
|
} //^^^ foo::Foo
|
2020-04-25 14:57:59 +00:00
|
|
|
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
2020-05-10 16:09:22 +00:00
|
|
|
|
|
|
|
#[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;
|
2021-06-20 17:10:45 +00:00
|
|
|
} //^^^ Foo
|
2020-06-29 15:22:47 +00:00
|
|
|
"#,
|
2020-05-10 16:09:22 +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;
|
2021-06-20 17:10:45 +00:00
|
|
|
} //^^^ Foo<i32>
|
2020-06-29 15:22:47 +00:00
|
|
|
"#,
|
2020-05-10 16:09:22 +00:00
|
|
|
);
|
|
|
|
}
|
2021-01-12 19:19:13 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn render_raw_ptr_impl_ty() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
2021-06-15 22:23:04 +00:00
|
|
|
//- minicore: sized
|
2021-01-12 19:19:13 +00:00
|
|
|
trait Unpin {}
|
2021-08-03 12:01:00 +00:00
|
|
|
fn foo() -> *const (impl Unpin + Sized) { loop {} }
|
2021-01-12 19:19:13 +00:00
|
|
|
fn main() {
|
|
|
|
let foo = foo();
|
|
|
|
foo;
|
2021-08-03 12:01:00 +00:00
|
|
|
} //^^^ *const impl Unpin
|
2021-01-12 19:19:13 +00:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
2021-06-29 23:34:51 +00:00
|
|
|
|
2022-10-10 10:32:24 +00:00
|
|
|
#[test]
|
|
|
|
fn render_dyn_ty_independent_of_order() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
|
|
|
auto trait Send {}
|
|
|
|
trait A {
|
|
|
|
type Assoc;
|
|
|
|
}
|
|
|
|
trait B: A {}
|
|
|
|
|
|
|
|
fn test(
|
|
|
|
_: &(dyn A<Assoc = ()> + Send),
|
|
|
|
//^ &(dyn A<Assoc = ()> + Send)
|
|
|
|
_: &(dyn Send + A<Assoc = ()>),
|
|
|
|
//^ &(dyn A<Assoc = ()> + Send)
|
|
|
|
_: &dyn B<Assoc = ()>,
|
|
|
|
//^ &(dyn B<Assoc = ()>)
|
|
|
|
) {}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
2021-06-15 08:53:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sized_bounds_apit() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
2021-06-15 22:23:04 +00:00
|
|
|
//- minicore: sized
|
2021-06-15 08:53:20 +00:00
|
|
|
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,
|
2021-06-15 08:53:20 +00:00
|
|
|
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;
|
2021-08-03 12:01:00 +00:00
|
|
|
//^^^^^^^ &impl ?Sized
|
2021-06-15 08:53:20 +00:00
|
|
|
empty;
|
2021-08-03 12:01:00 +00:00
|
|
|
} //^^^^^ impl Sized
|
2021-06-15 08:53:20 +00:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sized_bounds_rpit() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
2021-06-15 22:23:04 +00:00
|
|
|
//- minicore: sized
|
2021-06-15 08:53:20 +00:00
|
|
|
trait Foo {}
|
2021-08-03 12:01:00 +00:00
|
|
|
fn foo1() -> impl Foo { loop {} }
|
|
|
|
fn foo2() -> impl Foo + Sized { loop {} }
|
|
|
|
fn foo3() -> impl Foo + ?Sized { loop {} }
|
|
|
|
fn test() {
|
|
|
|
let foo = foo1();
|
|
|
|
foo;
|
|
|
|
//^^^ impl Foo
|
|
|
|
let foo = foo2();
|
|
|
|
foo;
|
|
|
|
//^^^ impl Foo
|
|
|
|
let foo = foo3();
|
|
|
|
foo;
|
|
|
|
} //^^^ impl Foo + ?Sized
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parenthesize_ptr_rpit_sized_bounds() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
|
|
|
//- minicore: sized
|
|
|
|
trait Foo {}
|
|
|
|
fn foo1() -> *const impl Foo { loop {} }
|
|
|
|
fn foo2() -> *const (impl Foo + Sized) { loop {} }
|
|
|
|
fn foo3() -> *const (impl Sized + Foo) { loop {} }
|
|
|
|
fn foo4() -> *const (impl Foo + ?Sized) { loop {} }
|
|
|
|
fn foo5() -> *const (impl ?Sized + Foo) { loop {} }
|
|
|
|
fn test() {
|
|
|
|
let foo = foo1();
|
|
|
|
foo;
|
|
|
|
//^^^ *const impl Foo
|
|
|
|
let foo = foo2();
|
|
|
|
foo;
|
|
|
|
//^^^ *const impl Foo
|
|
|
|
let foo = foo3();
|
|
|
|
foo;
|
|
|
|
//^^^ *const impl Foo
|
|
|
|
let foo = foo4();
|
|
|
|
foo;
|
|
|
|
//^^^ *const (impl Foo + ?Sized)
|
|
|
|
let foo = foo5();
|
2021-06-15 08:53:20 +00:00
|
|
|
foo;
|
2021-08-03 12:01:00 +00:00
|
|
|
} //^^^ *const (impl Foo + ?Sized)
|
2021-06-15 08:53:20 +00:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sized_bounds_impl_traits_in_fn_signature() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
2021-06-15 22:23:04 +00:00
|
|
|
//- minicore: sized
|
2021-06-15 08:53:20 +00:00
|
|
|
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
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
2022-10-27 08:05:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn projection_type_correct_arguments_order() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
|
|
|
trait Foo<T> {
|
|
|
|
type Assoc<U>;
|
|
|
|
}
|
|
|
|
fn f<T: Foo<i32>>(a: T::Assoc<usize>) {
|
|
|
|
a;
|
|
|
|
//^ <T as Foo<i32>>::Assoc<usize>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn generic_associated_type_binding_in_impl_trait() {
|
|
|
|
check_types_source_code(
|
|
|
|
r#"
|
|
|
|
//- minicore: sized
|
|
|
|
trait Foo<T> {
|
|
|
|
type Assoc<U>;
|
|
|
|
}
|
|
|
|
fn f(a: impl Foo<i8, Assoc<i16> = i32>) {
|
|
|
|
a;
|
|
|
|
//^ impl Foo<i8, Assoc<i16> = i32>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|