Skip to content

Commit 312e676

Browse files
authored
Rollup merge of #112413 - jieyouxu:fix-hidden-glob-reexports-span-order, r=petrochenkov
Adjust span labels for `HIDDEN_GLOB_REEXPORTS` Addresses #111378 (comment). ### Before This PR The possibility that the private item comes before the glob re-export was not account for, causing the span label messages to say "but private item here shadows it" before "the name `Foo` in the type namespace is supposed to be publicly re-exported here". ### After This PR ```rust warning: private item shadows public glob re-export --> $DIR/hidden_glob_reexports.rs:9:5 | LL | struct Foo; | ^^^^^^^^^^^ the private item here shadows the name `Foo` in the type namespace ... LL | pub use self::inner::*; | -------------- but it is supposed to be publicly re-exported here | = note: `#[warn(hidden_glob_reexports)]` on by default warning: private item shadows public glob re-export --> $DIR/hidden_glob_reexports.rs:27:9 | LL | pub use self::inner::*; | -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here LL | LL | use self::other::Foo; | ^^^^^^^^^^^^^^^^ but the private item here shadows it ```
2 parents 8744b1a + 80176a1 commit 312e676

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

compiler/rustc_lint/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ pub trait LintContext: Sized {
953953
db.span_label(duplicate_reexport_span, format!("but the name `{}` in the {} namespace is also re-exported here", name, namespace));
954954
}
955955
BuiltinLintDiagnostics::HiddenGlobReexports { name, namespace, glob_reexport_span, private_item_span } => {
956-
db.span_label(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace));
957-
db.span_label(private_item_span, "but the private item here shadows it");
956+
db.span_note(glob_reexport_span, format!("the name `{}` in the {} namespace is supposed to be publicly re-exported here", name, namespace));
957+
db.span_note(private_item_span, "but the private item here shadows it".to_owned());
958958
}
959959
}
960960
// Rewrap `db`, and pass control to the user.

tests/ui/resolve/hidden_glob_reexports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ pub mod upstream_a {
66
pub struct Bar {}
77
}
88

9-
pub use self::inner::*;
10-
119
struct Foo;
1210
//~^ WARN private item shadows public glob re-export
11+
12+
pub use self::inner::*;
1313
}
1414

1515
pub mod upstream_b {
+34-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
warning: private item shadows public glob re-export
2-
--> $DIR/hidden_glob_reexports.rs:11:5
2+
--> $DIR/hidden_glob_reexports.rs:9:5
33
|
4-
LL | pub use self::inner::*;
5-
| -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here
6-
LL |
74
LL | struct Foo;
8-
| ^^^^^^^^^^^ but the private item here shadows it
5+
| ^^^^^^^^^^^
6+
|
7+
note: the name `Foo` in the type namespace is supposed to be publicly re-exported here
8+
--> $DIR/hidden_glob_reexports.rs:12:13
9+
|
10+
LL | pub use self::inner::*;
11+
| ^^^^^^^^^^^^^^
12+
note: but the private item here shadows it
13+
--> $DIR/hidden_glob_reexports.rs:9:5
914
|
15+
LL | struct Foo;
16+
| ^^^^^^^^^^^
1017
= note: `#[warn(hidden_glob_reexports)]` on by default
1118

1219
warning: private item shadows public glob re-export
1320
--> $DIR/hidden_glob_reexports.rs:27:9
1421
|
22+
LL | use self::other::Foo;
23+
| ^^^^^^^^^^^^^^^^
24+
|
25+
note: the name `Foo` in the type namespace is supposed to be publicly re-exported here
26+
--> $DIR/hidden_glob_reexports.rs:25:13
27+
|
1528
LL | pub use self::inner::*;
16-
| -------------- the name `Foo` in the type namespace is supposed to be publicly re-exported here
17-
LL |
29+
| ^^^^^^^^^^^^^^
30+
note: but the private item here shadows it
31+
--> $DIR/hidden_glob_reexports.rs:27:9
32+
|
1833
LL | use self::other::Foo;
19-
| ^^^^^^^^^^^^^^^^ but the private item here shadows it
34+
| ^^^^^^^^^^^^^^^^
2035

2136
warning: private item shadows public glob re-export
2237
--> $DIR/hidden_glob_reexports.rs:40:9
2338
|
39+
LL | use std::primitive::u8;
40+
| ^^^^^^^^^^^^^^^^^^
41+
|
42+
note: the name `u8` in the type namespace is supposed to be publicly re-exported here
43+
--> $DIR/hidden_glob_reexports.rs:38:13
44+
|
2445
LL | pub use self::no_def_id::*;
25-
| ------------------ the name `u8` in the type namespace is supposed to be publicly re-exported here
26-
LL |
46+
| ^^^^^^^^^^^^^^^^^^
47+
note: but the private item here shadows it
48+
--> $DIR/hidden_glob_reexports.rs:40:9
49+
|
2750
LL | use std::primitive::u8;
28-
| ^^^^^^^^^^^^^^^^^^ but the private item here shadows it
51+
| ^^^^^^^^^^^^^^^^^^
2952

3053
warning: 3 warnings emitted
3154

0 commit comments

Comments
 (0)