Skip to content

Fix overlong function signature #1089

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 9 commits into from
Aug 1, 2016
Merged

Fix overlong function signature #1089

merged 9 commits into from
Aug 1, 2016

Conversation

fabric-and-ink
Copy link
Contributor

@fabric-and-ink fabric-and-ink commented Jul 10, 2016

Fix off-by-one error in rewrite_fn_base. #1049

Also remove a line break.

@fabric-and-ink fabric-and-ink changed the title Fix issue-1049 Fix overlong function signature Jul 10, 2016
@pepyakin
Copy link
Contributor

Hi, consider following test case:

impl Handle {
    pub fn merge(a: Abcd) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::Edge> {
    }
}

I suspect, that there is more than one-by-off issue. We can be under max_width but still can exceed maximum length after adding " {".

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Jul 10, 2016

You are right. I try to fix it tomorrow.

@@ -1359,8 +1359,9 @@ fn rewrite_fn_base(context: &RewriteContext,
_ => {
// If we've already gone multi-line, or the return type would push
// over the max width, then put the return type on a new line.
result.contains("\n") || multi_line_ret_str ||
result.len() + indent.width() + ret_str_len > context.config.max_width
let overlong_ret = result.len() + indent.width() + ret_str_len >
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment explaining why we need the -1

@fabric-and-ink
Copy link
Contributor Author

Will continue to work on this and the other issue next weekend. No spare time until then.

@fabric-and-ink
Copy link
Contributor Author

fabric-and-ink commented Jul 16, 2016

Nightly seems to have problems but i think it is not because of my changes.

Edit: master does not compile on nightly either.

@nrc
Copy link
Member

nrc commented Jul 17, 2016

Yeah, the nightly issue is probably a bug in Rust.

@nrc
Copy link
Member

nrc commented Jul 17, 2016

And in fact that should be fixed now. I restarted the tests here.


// If there is no where clause, take into account the space after the return type
// and the brace.
if where_clause.predicates.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check if the return type exists? I.e., not do this if there is no return type?

Also, nit, brace = {}, I think you mean parenthesis in this comment and above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. No return type means no arrow means no additional space.

Copy link

Choose a reason for hiding this comment

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

Isn't this checked on ln 1354 already? if !ret_str.is_empty()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I overlooked that... 😅 but to be sure I will add a test for that case later.

@jefftt
Copy link

jefftt commented Jul 31, 2016

@dawirstejeck whats left to do here? lgtm

@fabric-and-ink
Copy link
Contributor Author

@juicejitsu you are probably right. But thank you for having a look at it!

PS: I'm sorry for being so slow. I love to participate but I only got 1 or 2 hours per week 🐌.

@nrc
Copy link
Member

nrc commented Jul 31, 2016

@juicejitsu, @dawirstejeck: does this PR cover everything that #1108 does? Is there a reason to land one or the other?

@jefftt
Copy link

jefftt commented Aug 1, 2016

@nrc yeah this covers the bug in that PR as well, although there are some extra test case that are not in this one.

@nrc nrc merged commit 22de7ce into rust-lang:master Aug 1, 2016
@nrc
Copy link
Member

nrc commented Aug 1, 2016

Thank you!

@nrc nrc mentioned this pull request Aug 1, 2016
@fabric-and-ink fabric-and-ink deleted the issue-1049 branch August 5, 2016 18:45
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.

4 participants