Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Factor out pluralisation checks in diagnostics #64238

Description

@varkor

The following pattern is common in diagnostic messages in rustc:

format!("found {} thing{}", x, if x != 1 { "s" } else { "" })

It would be good to extract all of these pluralisation checks into a function or macro:

format!("found {} thing{}", x, pluralise(x))

There's already one in src/librustc/ty/error.rs, but it's not used anywhere else, so we could move it to somewhere in src/librustc_errors, and replace the occurrences of this pattern with the macro.

macro_rules! pluralise {
($x:expr) => {
if $x != 1 { "s" } else { "" }
};
}

This issue has been assigned to @V1shvesh via this comment.

Activity

  1. added
    E-easy
    C-cleanup
    E-mentor
    on Sep 6, 2019
  2. added
    T-compiler
    E-help-wanted
    on Sep 6, 2019
  3. V1shvesh commented on Sep 7, 2019

    @V1shvesh
    Contributor

    I'd love to be assigned to this issue!

  4. Centril commented on Sep 7, 2019

    @Centril
    Contributor
  5. self-assigned this
    on Sep 7, 2019
  6. V1shvesh commented on Sep 7, 2019

    @V1shvesh
    Contributor

    So, I have moved the macro under src/librustc_errors in a file called pluralise.rs. I have also located all the occurrences of the pattern.

    I am a bit new to Rust, so I still am learning about the module system. How shall I pull the macro into the scope of all the relevant files?

  7. varkor commented on Sep 7, 2019

    @varkor
    ContributorAuthor

    @V1shvesh: I'd put it in src/librustc_errors/lib.rs, so we don't have one new file for a single macro. Then you can use it from use syntax::errors;.

  8. V1shvesh commented on Sep 7, 2019

    @V1shvesh
    Contributor

    Thanks for pointing me in the right direction @varkor!

  9. added a commit that references this issue on Sep 8, 2019
    1716678
  10. varkor commented on Sep 9, 2019

    @varkor
    ContributorAuthor

    @V1shvesh: searching for { "s" } else { "" } and { "" } else { "s" } in rustc, I can see a few cases that weren't caught by #64280, e.g. in resolve_lifetime.rs, diagnostics.rs, etc. Let's keep this issue open until they've all been replaced with the new macro.

  11. reopened this on Sep 9, 2019
  12. glorv commented on Sep 10, 2019

    @glorv

    I have open a pr to refactor the pluralisations remain, @Centril please have a look at it, thanks.

  13. V1shvesh commented on Sep 10, 2019

    @V1shvesh
    Contributor

    @varkor Oh, my bad. @glorv thanks for helping out!

  14. added 2 commits that reference this issue on Sep 20, 2019
    906f74c
    d26540b
  15. added 5 commits that reference this issue on Sep 20, 2019
    f4225f8
    23483e7
    a5bd08f
    0eea621
    b9412b0
  16. added 2 commits that reference this issue on Sep 21, 2019
    9d7cafa
    d021dba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-cleanupE-easyE-help-wantedE-mentorT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions