Skip to content

fix Const generics are handled incorrectly #3555

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 2 commits into from
May 16, 2019

Conversation

rchaser53
Copy link
Contributor

fix: #3554

@topecongiro
Copy link
Contributor

Thank you for the PR! The fix looks ok, though it seems a bit hacky. The actual problem is that we are somehow passing an invalid span to recover_missing_comment_in_span. I suspect it is because of the opening brace in const generics, which messes up the BytePos created below:

rustfmt/src/visitor.rs

Lines 363 to 365 in 531b2d9

let where_span_end = snippet
.find_uncommented("{")
.map(|x| BytePos(x as u32) + source!(self, item.span).lo());

I think that the where_span_end should be calculated from the span between the self type of impl and its closing brace. E.g., like the code snippet below:

                ast::ItemKind::Impl(_, _, _, _, _, ref self_ty, _) => {
                    let misssing_span = mk_sp(self_ty.span.hi(), item.span.hi());
                    let where_span_end = self.snippet_provider.opt_span_before(misssing_span, "{");

@rchaser53
Copy link
Contributor Author

Good idea. I fixed it.

@scampi
Copy link
Contributor

scampi commented May 16, 2019

Rand is failing because of the rename of format_doc_comments.

@scampi scampi merged commit c97aa15 into rust-lang:master May 16, 2019
@rchaser53 rchaser53 deleted the issue-3554 branch May 16, 2019 23:17
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.

Const generics are handled incorrectly
3 participants