Skip to content

std_instead_of_core/etc. should emit MultiLine help messages #17261

Description

@bushrat011899

Description

For a multi-import statement, the std_instead_of_core family of lints will either:

  1. Emit a single suggestion if the root of the import can be replaced with core/alloc
  2. Emit one help for each member of the import that can be updated.

This can be quite frustrating for larger import statements, since it's not uncommon for only one or two items in the statement to be unavailable from core or alloc. Consider the below:

use std::{
    sync::atomic::{Ordering, AtomicBool},
    fmt::Debug,
    ops::{self, Add},
};

This emits 1 suggestion, replace std with core. However, if I add Mutex to the statement:

use std::{
    sync::{
        atomic::{Ordering, AtomicBool},
        Mutex,
    },
    fmt::Debug,
    ops::{self, Add},
};

This will now produce 5 std_instead_of_core lints, each only showing a small part of the overall statement, when only a single item needs to be moved (Mutex) into it's own std import to allow for the whole original statement to be from core.

If instead a multiline help was emitted, the number of lints emitted stays the same (one), but it changes from a suggestion on std to a help on each applicable item.

#17252 sets up the required changes to how multi-imports are handled to allow for this change. All that would be required is to emit the MultiSpans it computes directly, instead of iterating their primary_spans.

Version

rustc 1.98.0-nightly (485ec3fbc 2026-06-10)
binary: rustc
commit-hash: 485ec3fbcc12fa14ef6596dabb125ad710499c9e
commit-date: 2026-06-10
host: x86_64-pc-windows-msvc
release: 1.98.0-nightly
LLVM version: 22.1.6

Additional Labels

@rustbot label +C-enhancement

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions