Skip to content

stop to strip 'impl' from impl trait type alias #3816

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

Merged
merged 7 commits into from
Oct 4, 2019

Conversation

rchaser53
Copy link
Contributor

fix: #3815

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

IMHO we should handle whether to add impl by adding a wrapper GenericBounds and implement Rewrite trait against it:

struct GenericBounds<'a> {
    generic_bounds: &'a ast::GenericBounds,
    has_impl: bool,
}

impl<'a> Rewrite for GenericBounds<'a> {
    fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
        self.generic_bounds.rewrite(context, shape)
            .map(|s| if self.has_impl { format!("impl {}", s } else { s })
    }
}

and use it inside rewrite_type_alias and rewrite_opaque_type.

@rchaser53
Copy link
Contributor Author

I added the commit to remove has_impl in GenericBounds. I don't think it necessary.

Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

Good point, thanks for the update! The code looks good to me.

@topecongiro topecongiro merged commit 7926851 into rust-lang:master Oct 4, 2019
@topecongiro
Copy link
Contributor

Thank you!

@topecongiro topecongiro added this to the 1.4.9 milestone Oct 4, 2019
@rchaser53 rchaser53 deleted the issue-3815 branch October 4, 2019 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustfmt strips 'impl' from impl trait type alias
3 participants