<commit_before>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rust.lang.core.resolve

import org.rust.lang.core.psi.ext.ArithmeticOp
import org.rust.lang.core.types.infer.TypeInferenceMarks

class RsTypeAwareGenericResolveTest : RsResolveTestBase() {
    fun `test fn`() = checkByCode("""
        fn foo<T>() -> T {
             //X
            let x: T = unimplemented!();
                 //^
            }
    """)

    fun `test impl method`() = checkByCode("""
        struct S;

        impl S {
            fn foo<Param>(
                    //X
                param: Param
            ) {}      //^
        }
    """)

    fun `test trait method`() = checkByCode("""
        trait T {
            fn f<Param>()
                //X
                -> Param;
                    //^
        }
    """)

    fun `test struct`() = checkByCode("""
        struct S<Thing> {
                //X
            field: Vec<Thing>
                      //^
        }
    """)

    fun `test enum`() = checkByCode("""
        enum E<T> {
             //X
            V(T)
            //^
        }
    """)

    fun `test trait`() = checkByCode("""
        trait T<Param> {
                //X
            fn new() -> Param;
                        //^
        }
    """)

    fun `test impl`() = checkByCode("""
        struct S<T> { field: T }

        impl<T> S<T> {
           //X
            fn foo() -> T { }
                      //^
        }
    """)

    fun `test type alias`() = checkByCode("""
        use std::result;

        pub type Result<T> =
                      //X
            result::Result<T, Error>;
                         //^
    """)

    fun `test no leak in enum`() = checkByCode("""
        enum E<T> { X }

        fn main() { let _ = E::T; }
                             //^ unresolved
    """)

    fun `test no leak in struct`() = checkByCode("""
        struct S<T>;

        fn main() { let _: S::T = unreachable!(); }
                            //^ unresolved
    """)

    fun `test don't check type parameter name when looking for impls`() = checkByCode("""
        struct S<FOO> { field: FOO }

        fn main() {
            let s: S = S;

            s.transmogrify();
                //^
        }

        impl<BAR> S<BAR> {
            fn transmogrify(&self) { }
                //X
        }
    """)

    fun `test method call on trait from bound`() = checkByCode("""
        trait Spam { fn eggs(&self); }
                        //X

        fn foo<T: Spam>(x: T) { x.eggs() }
                                  //^
    """)

    fun `test method call on trait from bound in where`() = checkByCode("""
        trait Spam { fn eggs(&self); }
                        //X

        fn foo<T>(x: T) where T: Spam { x.eggs() }
                                          //^
    """)

    fun `test method call on trait from bound's closure`() = checkByCode("""
        trait A { fn foo(&self) {} }
                    //X
        trait B : A {}
        trait C : B {}
        trait D : C {}

        struct X;
        impl D for X {}

        fn bar<T: D>(x: T) { x.foo() }
                              //^
    """)

    fun `test method call on trait with cyclic bounds`() = checkByCode("""
        trait A: B {}
        trait B: A {}

        fn bar<T: A>(x: T) { x.foo() }
                              //^ unresolved
    """)

    fun `test trait bound propagates type arguments`() = checkByCode("""
        trait I<A> {
            fn foo(&self) -> A;
        }

        struct S;
        impl S {
            fn bar(&self) {}
        }     //X

        fn baz<T: I<S>>(t: T) {
            t.foo().bar()
        }         //^
    """)

    fun `test method call on trait from bound on reference type`() = checkByCode("""
        struct S;
        trait Foo { fn foo(&self) {} }
                     //X
        impl Foo for &S {}

        fn foo<'a, T>(t: &'a T) where &'a T: Foo {
            t.foo();
        }   //^
    """)

    fun `test associated function call on trait from bound for type without type parameter`() = checkByCode("""
        struct S1;
        struct S2;
        trait From<T> { fn from(_: T) -> Self; }
                         //X
        fn foo<T>(t: T) -> S2 where S2: From<T> {
            S2::from(t)
        }     //^
    """)

    fun `test method call on trait from bound for associated type`() = checkByCode("""
        trait Foo {
            type Item;
            fn foo(&self) -> Self::Item;
        }
        trait Bar<A> { fn bar(&self); }
                        //X
        fn baz<T1, T2>(t: T1)
            where T1: Foo,
                  T1::Item: Bar<T2> {
            t.foo().bar();
        }         //^
    """)
<commit_msg>T: Cleanup<commit_after>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rust.lang.core.resolve

import org.rust.lang.core.psi.ext.ArithmeticOp
import org.rust.lang.core.types.infer.TypeInferenceMarks

class RsTypeAwareGenericResolveTest : RsResolveTestBase() {
    fun `test fn`() = checkByCode("""
        fn foo<T>() -> T {
             //X
            let x: T = unimplemented!();
                 //^
            }
    """)

    fun `test impl method`() = checkByCode("""
        struct S;

        impl S {
            fn foo<Param>(
                    //X
                param: Param
            ) {}      //^
        }
    """)

    fun `test trait method`() = checkByCode("""
        trait T {
            fn f<Param>()
                //X
                -> Param;
                    //^
        }
    """)

    fun `test struct`() = checkByCode("""
        struct S<Thing> {
                //X
            field: Vec<Thing>
                      //^
        }
    """)

    fun `test enum`() = checkByCode("""
        enum E<T> {
             //X
            V(T)
            //^
        }
    """)

    fun `test trait`() = checkByCode("""
        trait T<Param> {
                //X
            fn new() -> Param;
                        //^
        }
    """)

    fun `test impl`() = checkByCode("""
        struct S<T> { field: T }

        impl<T> S<T> {
           //X
            fn foo() -> T { }
                      //^
        }
    """)

    fun `test type alias`() = checkByCode("""
        use std::result;

        pub type Result<T> =
                      //X
            result::Result<T, Error>;
                         //^
    """)

    fun `test no leak in enum`() = checkByCode("""
        enum E<T> { X }

        fn main() { let _ = E::T; }
                             //^ unresolved
    """)

    fun `test no leak in struct`() = checkByCode("""
        struct S<T>;

        fn main() { let _: S::T = unreachable!(); }
                            //^ unresolved
    """)

    fun `test don't check type parameter name when looking for impls`() = checkByCode("""
        struct S<FOO> { field: FOO }

        fn main() {
            let s: S = S;

            s.transmogrify();
                //^
        }

        impl<BAR> S<BAR> {
            fn transmogrify(&self) { }
                //X
        }
    """)

    fun `test method call on trait from bound`() = checkByCode("""
        trait Spam { fn eggs(&self); }
                        //X

        fn foo<T: Spam>(x: T) { x.eggs() }
                                  //^
    """)

    fun `test method call on trait from bound in where`() = checkByCode("""
        trait Spam { fn eggs(&self); }
                        //X

        fn foo<T>(x: T) where T: Spam { x.eggs() }
                                          //^
    """)

    fun `test method call on trait from bound's closure`() = checkByCode("""
        trait A { fn foo(&self) {} }
                    //X
        trait B : A {}
        trait C : B {}
        trait D : C {}

        struct X;
        impl D for X {}

        fn bar<T: D>(x: T) { x.foo() }
                              //^
    """)

    fun `test method call on trait with cyclic bounds`() = checkByCode("""
        trait A: B {}
        trait B: A {}

        fn bar<T: A>(x: T) { x.foo() }
                              //^ unresolved
    """)

    fun `test trait bound propagates type arguments`() = checkByCode("""
        trait I<A> {
            fn foo(&self) -> A;
        }

        struct S;
        impl S {
            fn bar(&self) {}
        }     //X

        fn baz<T: I<S>>(t: T) {
            t.foo().bar()
        }         //^
    """)

    fun `test method call on trait from bound on reference type`() = checkByCode("""
        trait Foo { fn foo(&self) {} }
                     //X
        fn foo<'a, T>(t: &'a T) where &'a T: Foo {
            t.foo();
        }   //^
    """)

    fun `test associated function call on trait from bound for type without type parameter`() = checkByCode("""
        struct S2;
        trait From<T> { fn from(_: T) -> Self; }
                         //X
        fn foo<T>(t: T) -> S2 where S2: From<T> {
            S2::from(t)
        }     //^
    """)

    fun `test method call on trait from bound for associated type`() = checkByCode("""
        trait Foo {
            type Item;
            fn foo(&self) -> Self::Item;
        }
        trait Bar<A> { fn bar(&self); }
                        //X
        fn baz<T1, T2>(t: T1)
            where T1: Foo,
                  T1::Item: Bar<T2> {
            t.foo().bar();
        }         //^
    """)

{'fraction_non_alphanumeric': 0.15063025210084033, 'fraction_numerical': 0.0022058823529411764, 'mean_word_length': 1.0545964609408718, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6722903', 'n_tokens_mistral': 2961, 'n_tokens_neox': 2858, 'n_words': 799}