@@ -400,6 +400,72 @@ impl<'x, 'y, T, V, U: Default> Trait<'x, 'y, T, V, U> for () {
400400 ) ;
401401 }
402402
403+ #[ test]
404+ fn test_const_substitution ( ) {
405+ check_assist (
406+ add_missing_default_members,
407+ r#"
408+ struct Bar<const: N: bool> {
409+ bar: [i32, N]
410+ }
411+
412+ trait Foo<const N: usize, T> {
413+ fn get_n_sq(&self, arg: &T) -> usize { N * N }
414+ fn get_array(&self, arg: Bar<N>) -> [i32; N] { [1; N] }
415+ }
416+
417+ struct S<T> {
418+ wrapped: T
419+ }
420+
421+ impl<const X: usize, Y, Z> Foo<X, Z> for S<Y> {
422+ $0
423+ }"# ,
424+ r#"
425+ struct Bar<const: N: bool> {
426+ bar: [i32, N]
427+ }
428+
429+ trait Foo<const N: usize, T> {
430+ fn get_n_sq(&self, arg: &T) -> usize { N * N }
431+ fn get_array(&self, arg: Bar<N>) -> [i32; N] { [1; N] }
432+ }
433+
434+ struct S<T> {
435+ wrapped: T
436+ }
437+
438+ impl<const X: usize, Y, Z> Foo<X, Z> for S<Y> {
439+ $0fn get_n_sq(&self, arg: &Z) -> usize { X * X }
440+
441+ fn get_array(&self, arg: Bar<X>) -> [i32; X] { [1; X] }
442+ }"# ,
443+ )
444+ }
445+
446+ #[ test]
447+ fn test_const_substitution_2 ( ) {
448+ check_assist (
449+ add_missing_default_members,
450+ r#"
451+ trait Foo<const N: usize, const M: usize, T> {
452+ fn get_sum(&self, arg: &T) -> usize { N + M }
453+ }
454+
455+ impl<X> Foo<42, {20 + 22}, X> for () {
456+ $0
457+ }"# ,
458+ r#"
459+ trait Foo<const N: usize, const M: usize, T> {
460+ fn get_sum(&self, arg: &T) -> usize { N + M }
461+ }
462+
463+ impl<X> Foo<42, {20 + 22}, X> for () {
464+ $0fn get_sum(&self, arg: &X) -> usize { 42 + {20 + 22} }
465+ }"# ,
466+ )
467+ }
468+
403469 #[ test]
404470 fn test_cursor_after_empty_impl_def ( ) {
405471 check_assist (
@@ -781,6 +847,115 @@ impl Foo<T> for S<T> {
781847 )
782848 }
783849
850+ #[ test]
851+ fn test_qualify_generic_default_parameter ( ) {
852+ check_assist (
853+ add_missing_impl_members,
854+ r#"
855+ mod m {
856+ pub struct S;
857+ pub trait Foo<T = S> {
858+ fn bar(&self, other: &T);
859+ }
860+ }
861+
862+ struct S;
863+ impl m::Foo for S { $0 }"# ,
864+ r#"
865+ mod m {
866+ pub struct S;
867+ pub trait Foo<T = S> {
868+ fn bar(&self, other: &T);
869+ }
870+ }
871+
872+ struct S;
873+ impl m::Foo for S {
874+ fn bar(&self, other: &m::S) {
875+ ${0:todo!()}
876+ }
877+ }"# ,
878+ )
879+ }
880+
881+ #[ test]
882+ fn test_qualify_generic_default_parameter_2 ( ) {
883+ check_assist (
884+ add_missing_impl_members,
885+ r#"
886+ mod m {
887+ pub struct Wrapper<T, V> {
888+ one: T,
889+ another: V
890+ };
891+ pub struct S;
892+ pub trait Foo<T = Wrapper<S, bool>> {
893+ fn bar(&self, other: &T);
894+ }
895+ }
896+
897+ struct S;
898+ impl m::Foo for S { $0 }"# ,
899+ r#"
900+ mod m {
901+ pub struct Wrapper<T, V> {
902+ one: T,
903+ another: V
904+ };
905+ pub struct S;
906+ pub trait Foo<T = Wrapper<S, bool>> {
907+ fn bar(&self, other: &T);
908+ }
909+ }
910+
911+ struct S;
912+ impl m::Foo for S {
913+ fn bar(&self, other: &m::Wrapper<m::S, bool>) {
914+ ${0:todo!()}
915+ }
916+ }"# ,
917+ ) ;
918+ }
919+
920+ #[ test]
921+ fn test_qualify_generic_default_parameter_3 ( ) {
922+ check_assist (
923+ add_missing_impl_members,
924+ r#"
925+ mod m {
926+ pub struct Wrapper<T, V> {
927+ one: T,
928+ another: V
929+ };
930+ pub struct S;
931+ pub trait Foo<T = S, V = Wrapper<T, S>> {
932+ fn bar(&self, other: &V);
933+ }
934+ }
935+
936+ struct S;
937+ impl m::Foo for S { $0 }"# ,
938+ r#"
939+ mod m {
940+ pub struct Wrapper<T, V> {
941+ one: T,
942+ another: V
943+ };
944+ pub struct S;
945+ pub trait Foo<T = S, V = Wrapper<T, S>> {
946+ fn bar(&self, other: &V);
947+ }
948+ }
949+
950+ struct S;
951+ impl m::Foo for S {
952+ fn bar(&self, other: &m::Wrapper<m::S, m::S>) {
953+ ${0:todo!()}
954+ }
955+ }"# ,
956+ ) ;
957+ }
958+
784959 #[ test]
785960 fn test_assoc_type_bounds_are_removed ( ) {
786961 check_assist (
0 commit comments