Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_config::Conf;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::is_in_test;
use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
Expand Down Expand Up @@ -164,14 +164,19 @@ impl WildcardImports {
// `;`. In nested imports, like `use _::{inner::*, _}` there is no `;` and we
// can just use the end of the item span
let mut span = use_path.span;
if snippet(cx, span, "").ends_with(';') {
span = use_path.span.with_hi(span.hi() - BytePos(1));
if snippet_opt(cx, span).is_some_and(|snippet| snippet.ends_with(';')) {
span = span.with_hi(span.hi() - BytePos(1));
}
while !snippet(cx, span, "").ends_with('*') {
span = use_path.span.with_hi(span.hi() + BytePos(1));

let Ok(extended) = cx.sess().source_map().span_extend_while(span, |c| c != '*') else {
return;
};
let with_star = extended.with_hi(extended.hi() + BytePos(1));
if !snippet_opt(cx, with_star).is_some_and(|snippet| snippet.ends_with('*')) {
return;
}

(span, false)
(with_star, false)
};

let mut imports: Vec<_> = used_imports.iter().map(ToString::to_string).collect();
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/crashes/ice-17799.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@check-pass
#![warn(clippy::wildcard_imports)]

macro_rules! glob_import {
($p:path) => {
use $p::*;
fn __glob_used(_e: Error) {}
};
}

glob_import!(std::io);
Loading