Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: Don't insert default type parameters by Implement Member actions #6896

Merged
merged 1 commit into from Mar 15, 2021

Conversation

mchernyavsky
Copy link
Member

@mchernyavsky mchernyavsky commented Feb 26, 2021

Fixes #6186

Depends on #6948.

changelog: Don't insert default type parameters by Implement Member actions

@mchernyavsky mchernyavsky added the fix Pull requests that fix some bug(s) label Feb 26, 2021
@Undin
Copy link
Member

Undin commented Feb 26, 2021

@mchernyavsky could you resolve merge conflicts?

@mchernyavsky mchernyavsky force-pushed the undin/implement-members-defaul-type-params branch from 5e6a1c6 to b62cb22 Compare February 26, 2021 20:52
@mchernyavsky
Copy link
Member Author

@Undin Done.

@Kobzol
Copy link
Member

Kobzol commented Feb 26, 2021

I wonder if skipUnchangedDefaultTypeArguments should just be true by default?

Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation doesn't work with type aliases. For example, for the following code:

mod bar {
    use std::collections::hash_map::RandomState;

    pub(crate) type HashMap<T, K = i32, S = RandomState> = std::collections::HashMap<T, K, S>;
}

trait Foo {
    fn foo() -> bar::HashMap<String>;
}

impl Foo for i32 {
}

Implement memebers produces

use crate::bar::HashMap;

mod bar {
    use std::collections::hash_map::RandomState;

    pub(crate) type HashMap<T, K = i32, S = RandomState> = std::collections::HashMap<T, K, S>;
}

trait Foo {
    fn foo() -> bar::HashMap<String>;
}

impl Foo for i32 {
    fn foo() -> HashMap<String, i32, RandomState> {
        unimplemented!()
    }
}

although I expect

use crate::bar::HashMap;

mod bar {
    use std::collections::hash_map::RandomState;

    pub(crate) type HashMap<T, K = i32, S = RandomState> = std::collections::HashMap<T, K, S>;
}

trait Foo {
    fn foo() -> bar::HashMap<String>;
}

impl Foo for i32 {
    fn foo() -> HashMap<String> {
        unimplemented!()
    }
}

@@ -23,9 +23,10 @@ object RsImportHelper {
context: RsElement,
elements: Collection<RsElement>,
subst: Substitution = emptySubstitution,
useAliases: Boolean = false
useAliases: Boolean = false,
skipUnchangedDefaultTypeArguments: Boolean = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @Kobzol about default value
Let's make it true by default.
Also, it would be great to add test(s) for each feature where importTypeReferencesFromElements is used to check that we don't import something unexpected. For example, change signature also use it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW do we know cases when skipUnchangedDefaultTypeArguments is actually needed?
If no, maybe it's better just not to add this argument at all and change import logic for all cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I don't insist to make this investigation in this PR, i.e. we can investigate all other cases separately and decide if we need this param and which default value should be used or even we can drop it at all

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it make sense to change skipUnchangedDefaultTypeArguments to true for Ty.renderInsertionSafe, but not for Ty.render? And remove this parameter for importTypeReferencesFromElements / getTypeReferencesInfoFromTys?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. But it requires checking each feature that uses importing that may complicate this PR. But it's up to you

@mchernyavsky mchernyavsky force-pushed the undin/implement-members-defaul-type-params branch from b62cb22 to 2e3ae97 Compare March 4, 2021 13:41
@mchernyavsky
Copy link
Member Author

@Undin Fixed.

@Undin
Copy link
Member

Undin commented Mar 4, 2021

@mchernyavsky tests fail

@mchernyavsky mchernyavsky force-pushed the undin/implement-members-defaul-type-params branch from 2e3ae97 to 08442a1 Compare March 4, 2021 16:52
@mchernyavsky
Copy link
Member Author

@Undin fixed.

@mchernyavsky mchernyavsky force-pushed the undin/implement-members-defaul-type-params branch from 08442a1 to b3d81b3 Compare March 11, 2021 17:53
@mchernyavsky mchernyavsky force-pushed the undin/implement-members-defaul-type-params branch from b3d81b3 to 2ee1214 Compare March 14, 2021 20:05
@mchernyavsky
Copy link
Member Author

@Undin Rebased on master.

Copy link
Member

@Undin Undin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
bors r+

bors bot added a commit that referenced this pull request Mar 15, 2021
6896: REF: Don't insert default type parameters by Implement Member actions r=Undin a=mchernyavsky

Fixes #6186

Depends on #6948.

changelog: Don't insert default type parameters by `Implement Member` actions


Co-authored-by: mchernyavsky <chernyavsky.mikhail@gmail.com>
@bors
Copy link
Contributor

bors bot commented Mar 15, 2021

This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried.

@bors
Copy link
Contributor

bors bot commented Mar 15, 2021

Build succeeded:

@bors bors bot merged commit 8be653a into master Mar 15, 2021
@bors bors bot deleted the undin/implement-members-defaul-type-params branch March 15, 2021 15:34
@github-actions github-actions bot added this to the v144 milestone Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Pull requests that fix some bug(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary full generic substitution when implementing members
3 participants