Skip to content

leave the comment in parentheses of argumentless Fn #3518

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 4 commits into from
Apr 23, 2019

Conversation

rchaser53
Copy link
Contributor

related: #3508

@rchaser53
Copy link
Contributor Author

rchaser53 commented Apr 21, 2019

I didn't implement the logic for the below case.

fn foo(
    bar: impl PartialEq<
        // this comment is deleted
    >
) {}

Because rustfmt can format and leave the comment for below code.

// same meaning above code.
fn foo(
    bar: impl PartialEq,
    // this comment is not deleted
) {
}

Copy link
Contributor

@scampi scampi left a comment

Choose a reason for hiding this comment

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

Thanks @rchaser53 for the fix

src/types.rs Outdated
&Vec::<ListItem>::new(),
ListTactic::HorizontalVertical,
Separator::Comma,
shape.width.saturating_sub(2 + output.len()),
Copy link
Contributor

Choose a reason for hiding this comment

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

What does 2 represent ? Can you add a comment that describes its meaning ?
I've seen the following format: for example // 1 = "{" which means the digit 1 is about the opening curly bracket.

src/types.rs Outdated
shape.width.saturating_sub(2 + output.len()),
)
};
let list_hi = context.snippet_provider.span_after_last(span, ")");
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can add a new method in source_map::SpanUtils called span_before_last, this way the following could be simplified and avoid the BytePos(1) substraction.

- create span_before_last
- create get_tactics and add comment
@rchaser53
Copy link
Contributor Author

Thank you the review. I changed my source.

@rchaser53
Copy link
Contributor Author

Thanks. I fixed about indents.

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.

Sorry for nitpicking and requesting changes multiple times, though with those fixed I think this is ready to merge!

src/types.rs Outdated
@@ -381,6 +392,22 @@ fn type_bound_colon(context: &RewriteContext<'_>) -> &'static str {
colon_spaces(context.config)
}

// If the return type is multi-lined, then force to use multiple lines for
// arguments as well.
fn get_tactics(item_vec: &Vec<ListItem>, output: &str, shape: &Shape) -> DefinitiveListTactic {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to use &[_] over &Vec<_>. Also Shape implements Copy so we need not take a reference:

Suggested change
fn get_tactics(item_vec: &Vec<ListItem>, output: &str, shape: &Shape) -> DefinitiveListTactic {
fn get_tactics(item_vec: &[ListItem], output: &str, shape: Shape) -> DefinitiveListTactic {

src/types.rs Outdated
DefinitiveListTactic::Vertical
} else {
definitive_tactic(
&*item_vec,
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified with the above change:

Suggested change
&*item_vec,
item_vec,

@rchaser53
Copy link
Contributor Author

I improved it.

@topecongiro
Copy link
Contributor

Thank you!

@topecongiro topecongiro merged commit 05547d9 into rust-lang:master Apr 23, 2019
@rchaser53 rchaser53 deleted the issue-3508 branch April 24, 2019 00:58
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.

3 participants