From 6c70619b0126bc0e40bd9df39dcd6e711cac69c5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 16:24:09 +0100 Subject: Deal better with implicit type parameters and argument lists --- crates/ra_hir_ty/src/tests/traits.rs | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 134cea8d8..f90dadc08 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -905,6 +905,114 @@ fn test(x: impl Trait, y: &impl Trait) { ); } +#[test] +fn argument_impl_trait_type_args_1() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +trait Foo { + // this function has an implicit Self param, an explicit type param, + // and an implicit impl Trait param! + fn bar(x: impl Trait) -> T { loop {} } +} +fn foo(x: impl Trait) -> T { loop {} } +struct S; +impl Trait for S {} +struct F; +impl Foo for F {} + +fn test() { + Foo::bar(S); + ::bar(S); + F::bar(S); + Foo::bar::(S); + ::bar::(S); + + foo(S); + foo::(S); + foo::(S); // we should ignore the extraneous i32 +} +"#, true), + @r###" + [156; 157) 'x': impl Trait + [176; 187) '{ loop {} }': T + [178; 185) 'loop {}': ! + [183; 185) '{}': () + [200; 201) 'x': impl Trait + [220; 231) '{ loop {} }': T + [222; 229) 'loop {}': ! + [227; 229) '{}': () + [301; 510) '{ ... i32 }': () + [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}, S>(S) -> {unknown} + [307; 318) 'Foo::bar(S)': {unknown} + [316; 317) 'S': S + [324; 339) '::bar': fn bar(S) -> {unknown} + [324; 342) '(S) -> {unknown} + [348; 357) 'F::bar(S)': {unknown} + [355; 356) 'S': S + [363; 378) 'Foo::bar::': fn bar<{unknown}, u32, S>(S) -> u32 + [363; 381) 'Foo::b...32>(S)': u32 + [379; 380) 'S': S + [387; 409) '': fn bar(S) -> u32 + [387; 412) '(S)': u32 + [410; 411) 'S': S + [419; 422) 'foo': fn foo<{unknown}, S>(S) -> {unknown} + [419; 425) 'foo(S)': {unknown} + [423; 424) 'S': S + [431; 441) 'foo::': fn foo(S) -> u32 + [431; 444) 'foo::(S)': u32 + [442; 443) 'S': S + [450; 465) 'foo::': fn foo(S) -> u32 + [450; 468) 'foo::<...32>(S)': u32 + [466; 467) 'S': S + "### + ); +} + +#[test] +fn argument_impl_trait_type_args_2() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +struct S; +impl Trait for S {} +struct F; +impl F { + fn foo(self, x: impl Trait) -> (T, U) { loop {} } +} + +fn test() { + F.foo(S); + F::.foo(S); + F::.foo::(S); + F::.foo::(S); // extraneous argument should be ignored +} +"#, true), + @r###" + [88; 92) 'self': F + [94; 95) 'x': impl Trait + [119; 130) '{ loop {} }': (T, U) + [121; 128) 'loop {}': ! + [126; 128) '{}': () + [144; 284) '{ ...ored }': () + [150; 151) 'F': F<{unknown}> + [150; 158) 'F.foo(S)': ({unknown}, {unknown}) + [156; 157) 'S': S + [164; 172) 'F::': F + [164; 179) 'F::.foo(S)': (u32, {unknown}) + [177; 178) 'S': S + [185; 193) 'F::': F + [185; 207) 'F::(S)': (u32, i32) + [205; 206) 'S': S + [213; 221) 'F::': F + [213; 240) 'F::(S)': (u32, i32) + [238; 239) 'S': S + "### + ); +} + #[test] #[ignore] fn impl_trait() { -- cgit v1.2.3