diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index a996188db0229..9b4e715a64fe8 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -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; } diff --git a/tests/ui/lint/unused-qualifications-global-paths.rs b/tests/ui/lint/unused-qualifications-global-paths.rs new file mode 100644 index 0000000000000..8265c8a169434 --- /dev/null +++ b/tests/ui/lint/unused-qualifications-global-paths.rs @@ -0,0 +1,12 @@ +// Checks that `unused_qualifications` don't fire on explicit global paths. +// Issue: . + +//@ check-pass + +#![deny(unused_qualifications)] + +pub fn bar() -> u64 { + ::std::default::Default::default() +} + +fn main() {}