Skip to content

when suggesting to remove a crate, we leave a blank line #51176

Closed

Description

@nikomatsakis

As of #51015, the rustfix result for:

#![warn(unused_crates)]
extern crate foo;
fn main() { }

is

#![warn(unused_crates)]

fn main() { }

but not

#![warn(unused_crates)]
fn main() { }

Activity

  1. added
    T-compiler
    WG-epoch
    on May 29, 2018
  2. nikomatsakis commented on May 29, 2018

    @nikomatsakis
    ContributorAuthor

    Probably the easiest way to fix this is to extend the replacement span by one character if the character after it is \n, somewhere around here:

    https://github.com/nikomatsakis/rust/blob/7b7901bf710085a601eed58bf26efb571fe5d25b/src/librustc_typeck/check_unused.rs#L174

  3. nikomatsakis commented on May 29, 2018

    @nikomatsakis
    ContributorAuthor

    Partial diffs here (doesn't work): https://gist.github.com/nikomatsakis/7351f61938624c8e5a9921bbef63add3

    One complication: extending to trailing newlines is not enough, we want to be sure that extern is at the start of the line too! i.e., this test:

    #![warn(unused_crates)]
    /* bar! */ extern crate foo;
    fn main() { }

    should probably result in

    #![warn(unused_crates)]
    /* bar! */ 
    fn main() { }

    not

    #![warn(unused_crates)]
    /* bar! */ fn main() { }

    (Plausibly, though, we might kill trailing whitespace? How much do we care anyway... maybe rustfix wants to do this?)

  4. added
    A-diagnostics
    on May 30, 2018
  5. added a commit that references this issue on Jun 2, 2018
  6. added
    C-enhancement
    on Oct 2, 2018
  7. rylev commented on Jul 5, 2021

    @rylev
    Contributor

    Triage: this is still an issue. Here's the code updated code considering the lint changed since this issues was filed:

    #![warn(unused_extern_crates)]
    extern crate foo;
    fn main() {}
  8. added
    E-help-wanted
    on Nov 15, 2023
  9. heiseish commented on Feb 20, 2025

    @heiseish
    Contributor

    @rustbot claim

  10. added
    A-suggestion-diagnostics
    D-papercut
    A-edition-2018
    and removed
    WG-epoch
    C-enhancement
    on Jul 24, 2025
  11. heiseish commented on Aug 21, 2025

    @heiseish
    Contributor

    Sorry for the late response, just got time to look into this issue.

    I cannot seem to reproduce it with later version of rust.

  12. clarfonthey commented on Aug 21, 2025

    @clarfonthey
    Contributor

    Yeah, can also confirm. I would assume this has been fixed and should be closed.

  13. ehuss commented on Nov 7, 2025

    @ehuss
    Contributor

    Closing as fixed by #120305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsA-edition-2018A-suggestion-diagnosticsD-papercutE-help-wantedT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions