Skip to content

Commit 0d61eae

Browse files
jieyouxuMark-Simulacrum
authored andcommitted
Don't trigger unused_qualifications on global paths
1 parent 21dcfbd commit 0d61eae

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

compiler/rustc_resolve/src/late.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4665,6 +4665,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
46654665
}
46664666

46674667
fn lint_unused_qualifications(&mut self, path: &[Segment], ns: Namespace, finalize: Finalize) {
4668+
// Don't lint on global paths because the user explicitly wrote out the full path.
4669+
if let Some(seg) = path.first()
4670+
&& seg.ident.name == kw::PathRoot
4671+
{
4672+
return;
4673+
}
4674+
46684675
if path.iter().any(|seg| seg.ident.span.from_expansion()) {
46694676
return;
46704677
}

tests/ui/lint/lint-qualification.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn main() {
1616
let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345
1717

1818
let _ = String::new(); //~ ERROR: unnecessary qualification
19-
let _ = std::env::current_dir(); //~ ERROR: unnecessary qualification
2019

2120
let _: Vec<String> = Vec::<String>::new();
2221
//~^ ERROR: unnecessary qualification
@@ -27,7 +26,7 @@ fn main() {
2726
let _: std::fmt::Result = Ok(());
2827
// don't report unnecessary qualification because fix(#122373) for issue #121331
2928

30-
let _ = <bool as Default>::default(); // issue #121999
29+
let _ = <bool as Default>::default(); // issue #121999 (modified)
3130
//~^ ERROR: unnecessary qualification
3231

3332
macro_rules! m { ($a:ident, $b:ident) => {

tests/ui/lint/lint-qualification.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn main() {
1616
let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345
1717

1818
let _ = std::string::String::new(); //~ ERROR: unnecessary qualification
19-
let _ = ::std::env::current_dir(); //~ ERROR: unnecessary qualification
2019

2120
let _: std::vec::Vec<String> = std::vec::Vec::<String>::new();
2221
//~^ ERROR: unnecessary qualification
@@ -27,7 +26,7 @@ fn main() {
2726
let _: std::fmt::Result = Ok(());
2827
// don't report unnecessary qualification because fix(#122373) for issue #121331
2928

30-
let _ = <bool as ::std::default::Default>::default(); // issue #121999
29+
let _ = <bool as std::default::Default>::default(); // issue #121999 (modified)
3130
//~^ ERROR: unnecessary qualification
3231

3332
macro_rules! m { ($a:ident, $b:ident) => {

tests/ui/lint/lint-qualification.stderr

+9-21
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,7 @@ LL + let _ = String::new();
4040
|
4141

4242
error: unnecessary qualification
43-
--> $DIR/lint-qualification.rs:19:13
44-
|
45-
LL | let _ = ::std::env::current_dir();
46-
| ^^^^^^^^^^^^^^^^^^^^^^^
47-
|
48-
help: remove the unnecessary path segments
49-
|
50-
LL - let _ = ::std::env::current_dir();
51-
LL + let _ = std::env::current_dir();
52-
|
53-
54-
error: unnecessary qualification
55-
--> $DIR/lint-qualification.rs:21:12
43+
--> $DIR/lint-qualification.rs:20:12
5644
|
5745
LL | let _: std::vec::Vec<String> = std::vec::Vec::<String>::new();
5846
| ^^^^^^^^^^^^^^^^^^^^^
@@ -64,7 +52,7 @@ LL + let _: Vec<String> = std::vec::Vec::<String>::new();
6452
|
6553

6654
error: unnecessary qualification
67-
--> $DIR/lint-qualification.rs:21:36
55+
--> $DIR/lint-qualification.rs:20:36
6856
|
6957
LL | let _: std::vec::Vec<String> = std::vec::Vec::<String>::new();
7058
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -76,7 +64,7 @@ LL + let _: std::vec::Vec<String> = Vec::<String>::new();
7664
|
7765

7866
error: unused import: `std::fmt`
79-
--> $DIR/lint-qualification.rs:25:9
67+
--> $DIR/lint-qualification.rs:24:9
8068
|
8169
LL | use std::fmt;
8270
| ^^^^^^^^
@@ -88,16 +76,16 @@ LL | #![deny(unused_imports)]
8876
| ^^^^^^^^^^^^^^
8977

9078
error: unnecessary qualification
91-
--> $DIR/lint-qualification.rs:30:13
79+
--> $DIR/lint-qualification.rs:29:13
9280
|
93-
LL | let _ = <bool as ::std::default::Default>::default(); // issue #121999
94-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
LL | let _ = <bool as std::default::Default>::default(); // issue #121999 (modified)
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9583
|
9684
help: remove the unnecessary path segments
9785
|
98-
LL - let _ = <bool as ::std::default::Default>::default(); // issue #121999
99-
LL + let _ = <bool as Default>::default(); // issue #121999
86+
LL - let _ = <bool as std::default::Default>::default(); // issue #121999 (modified)
87+
LL + let _ = <bool as Default>::default(); // issue #121999 (modified)
10088
|
10189

102-
error: aborting due to 8 previous errors
90+
error: aborting due to 7 previous errors
10391

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Checks that `unused_qualifications` don't fire on explicit global paths.
2+
// Issue: <https://github.com/rust-lang/rust/issues/122374>.
3+
4+
//@ check-pass
5+
6+
#![deny(unused_qualifications)]
7+
8+
pub fn bar() -> u64 {
9+
::std::default::Default::default()
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)