Skip to content

Auto-fix incorrect commas in use list #6757

@nk9

Description

@nk9

Today, this code is auto-fixed:

use sqlx::{PgPool, };
use std::path::{Path, PathBuf, };

The correct replacement is:

use sqlx::PgPool;
use std::path::{Path, PathBuf};

But the following code results in parse errors and is not auto-fixed by rust-analyzer:

use sqlx::{, PgPool};
use std::path::{Path, , PathBuf};

It is always possible to remove stray/duplicate commas and any number of spaces in use directives like this to produce correct code. In almost every circumstance, this will be what the user intended. I don't think it's necessary to attempt to properly parse a use without curly braces, that seems much more fraught. But I often find myself wanting to remove an import I no longer need, and I have to take the extra step of removing the comma too, despite the intention being unambiguous once the symbol is gone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions