Skip to content

Commit

Permalink
Don't trigger unused_qualifications on global paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Mar 13, 2024
1 parent 9ce37dc commit a7b37fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4636,6 +4636,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}

fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finalize: Finalize) {
// Don't lint on global paths because the user explicitly wrote out the full path.
if let Some(seg) = path.first()
&& seg.ident.name == kw::PathRoot
{
return;
}

if path.iter().any(|seg| seg.ident.span.from_expansion()) {
return;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/lint/unused-qualifications-global-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Checks that `unused_qualifications` don't fire on explicit global paths.
// Issue: <https://github.com/rust-lang/rust/issues/122374>.

//@ check-pass

#![deny(unused_qualifications)]

pub fn bar() -> u64 {
::std::default::Default::default()
}

fn main() {}

0 comments on commit a7b37fa

Please sign in to comment.