Skip to content

Param attributes stripped when functions have certain length #4032

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

Closed
bbqsrc opened this issue Jan 29, 2020 · 1 comment · Fixed by #4047
Closed

Param attributes stripped when functions have certain length #4032

bbqsrc opened this issue Jan 29, 2020 · 1 comment · Fixed by #4047
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@bbqsrc
Copy link

bbqsrc commented Jan 29, 2020

Create a file with this input:

fn a1(#[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] a: u8) {}
fn b1(#[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] bb: u8) {}
fn a2(#[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] a: u8) {}
fn b2(#[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] bb: u8) {}

Run cargo fmt. a1 and b1 will have their attributes stripped. Remove one letter from the line and it will not be stripped as seen in a2 and b2.

fn a1(a: u8) {}
fn b1(bb: u8) {}
fn a2(
    #[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] a: u8,
) {
}
fn b2(
    #[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] bb: u8,
) {
}
@calebcartwright
Copy link
Member

Confirmed bug that's still reproducible on master/v2.0.0-rc.1-nightly.

I believe this could be fixed by updating the Spanned impl for Param

Changing:

impl Spanned for ast::Param {
fn span(&self) -> Span {
if crate::items::is_named_param(self) {
mk_sp(self.pat.span.lo(), self.ty.span.hi())
} else {
self.ty.span
}
}
}

to something like:

impl Spanned for ast::Param {
    fn span(&self) -> Span {
        if crate::items::is_named_param(self) {
            mk_sp(crate::items::span_lo_for_param(self), self.ty.span.hi())
        } else {
            self.ty.span
        }
    }
}

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants