Skip to content
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

Formatter mis-formats the associated-type semicolon #6260

Open
Lukasz2891 opened this issue Jul 11, 2024 · 1 comment
Open

Formatter mis-formats the associated-type semicolon #6260

Lukasz2891 opened this issue Jul 11, 2024 · 1 comment
Assignees
Labels
bug Something isn't working formatter good first issue Good for newcomers triage This issue was opened with a template and needs to be triaged by code owners.

Comments

@Lukasz2891
Copy link

Lukasz2891 commented Jul 11, 2024

Related Component

forc-fmt

Problem

library;

use std::iterator::Iterator;

struct ListIter<T> {
    this: List<T>,
}

enum List<T> {
    Next: T,
    End: (),
}

impl List<T> {
    pub fn iter(self) -> ListIter<T> {
        Iterator { this: self }
    }
}

impl<T> Iterator for ListIter<T> {
    type Item = T;

    fn next(ref mut self) -> Option<Self::Item> {
        match self.this {
            Next(elt) => {
                this = elt;
                elt
            },
            End => None,
        }
    }
}

is formatted to

// ...
impl<T> Iterator for ListIter<T> {
    type Item = T
;    // <<< here is the formatted semicolon

    fn next(ref mut self) -> Option<Self::Item> {
        match self.this {
            Next(elt) => {
                this = elt;
                elt
            },
            End => None,
        }
    }
}

Then its formatted to:

// ...
impl<T> Iterator for ListIter<T> {
    type Item = T; // Missing the empty line
    fn next(ref mut self) -> Option<Self::Item> {
        match self.this {
            Next(elt) => {
                this = elt;
                elt
            },
            End => None,
        }
    }
}

Steps

Use the file and format it :)

Possible Solution(s)

Not to reformat the given file

Notes

No response

Installed components

active toolchain
----------------
testnet-aarch64-apple-darwin (override) (default), path: ...
  forc : 0.61.2
    - forc-client
      - forc-deploy : 0.61.2
      - forc-run : 0.61.2
    - forc-crypto : 0.61.2
    - forc-debug : 0.61.2
    - forc-doc : 0.61.2
    - forc-fmt : 0.61.2
    - forc-lsp : 0.61.2
    - forc-tx : 0.61.2
    - forc-wallet : 0.8.1
  fuel-core : 0.28.0
  fuel-core-keygen : 0.28.0

fuels versions
--------------
forc : 0.64.0
forc-wallet : 0.64.0
@Lukasz2891 Lukasz2891 added bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners. labels Jul 11, 2024
@sdankel sdankel added the good first issue Good for newcomers label Aug 19, 2024
@sdankel
Copy link
Member

sdankel commented Aug 19, 2024

Thanks for the bug report, I was able to reproduce it. The formatter should never produce different results on the second run, and the semicolon is definitely mis-formatted.

@alfiedotwtf alfiedotwtf self-assigned this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter good first issue Good for newcomers triage This issue was opened with a template and needs to be triaged by code owners.
Projects
None yet
Development

No branches or pull requests

4 participants