Skip to content

Commit 4338683

Browse files
authored
Rollup merge of rust-lang#113161 - Bryanskiy:err_msg, r=petrochenkov
Fix type privacy lints error message Type privacy lints diagnostic messages are not related to spans. r? `@petrochenkov`
2 parents 5d74664 + 35c6a1d commit 4338683

19 files changed

+120
-109
lines changed

compiler/rustc_privacy/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ privacy_private_in_public_lint =
1818
})
1919
2020
privacy_private_interface_or_bounds_lint = {$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`
21-
.item_note = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`
21+
.item_label = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`
2222
.ty_note = but {$ty_kind} `{$ty_descr}` is only usable at visibility `{$ty_vis_descr}`
2323
2424
privacy_report_effective_visibility = {$descr}

compiler/rustc_privacy/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct UnnameableTypesLint<'a> {
116116
#[derive(LintDiagnostic)]
117117
#[diag(privacy_private_interface_or_bounds_lint)]
118118
pub struct PrivateInterfacesOrBoundsLint<'a> {
119-
#[note(privacy_item_note)]
119+
#[label(privacy_item_label)]
120120
pub item_span: Span,
121121
pub item_kind: &'a str,
122122
pub item_descr: DiagnosticArgFromDisplay<'a>,

compiler/rustc_privacy/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,9 +1865,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
18651865
} else {
18661866
lint::builtin::PRIVATE_BOUNDS
18671867
};
1868-
self.tcx.emit_lint(
1868+
self.tcx.emit_spanned_lint(
18691869
lint,
18701870
hir_id,
1871+
span,
18711872
PrivateInterfacesOrBoundsLint {
18721873
item_span: span,
18731874
item_kind: self.tcx.def_descr(self.item_def_id.to_def_id()),

tests/ui/associated-inherent-types/private-in-public.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
pub type PubAlias0 = PubTy::PrivAssocTy;
1313
//~^ ERROR private associated type `PubTy::PrivAssocTy` in public interface (error E0446)
1414
//~| WARNING this was previously accepted
15+
//~| WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
1516
pub type PubAlias1 = PrivTy::PubAssocTy;
1617
//~^ ERROR private type `PrivTy` in public interface (error E0446)
1718
//~| WARNING this was previously accepted
19+
//~| WARNING type `PrivTy` is more private than the item `PubAlias1`
1820
pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
1921
//~^ ERROR private type `PrivTy` in public interface (error E0446)
2022
//~| WARNING this was previously accepted
23+
//~| WARNING type `PrivTy` is more private than the item `PubAlias2`
2124

2225
pub struct PubTy;
2326
impl PubTy {

tests/ui/associated-inherent-types/private-in-public.stderr

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ LL | #![deny(private_in_public)]
1313
| ^^^^^^^^^^^^^^^^^
1414

1515
warning: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
16-
|
17-
note: type alias `PubAlias0` is reachable at visibility `pub`
1816
--> $DIR/private-in-public.rs:12:1
1917
|
2018
LL | pub type PubAlias0 = PubTy::PrivAssocTy;
21-
| ^^^^^^^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias0` is reachable at visibility `pub`
20+
|
2221
note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)`
23-
--> $DIR/private-in-public.rs:24:5
22+
--> $DIR/private-in-public.rs:27:5
2423
|
2524
LL | type PrivAssocTy = ();
2625
| ^^^^^^^^^^^^^^^^
@@ -31,7 +30,7 @@ LL | #![warn(private_interfaces)]
3130
| ^^^^^^^^^^^^^^^^^^
3231

3332
error: private type `PrivTy` in public interface (error E0446)
34-
--> $DIR/private-in-public.rs:15:1
33+
--> $DIR/private-in-public.rs:16:1
3534
|
3635
LL | pub type PubAlias1 = PrivTy::PubAssocTy;
3736
| ^^^^^^^^^^^^^^^^^^
@@ -40,20 +39,19 @@ LL | pub type PubAlias1 = PrivTy::PubAssocTy;
4039
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
4140

4241
warning: type `PrivTy` is more private than the item `PubAlias1`
43-
|
44-
note: type alias `PubAlias1` is reachable at visibility `pub`
45-
--> $DIR/private-in-public.rs:15:1
42+
--> $DIR/private-in-public.rs:16:1
4643
|
4744
LL | pub type PubAlias1 = PrivTy::PubAssocTy;
48-
| ^^^^^^^^^^^^^^^^^^
45+
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias1` is reachable at visibility `pub`
46+
|
4947
note: but type `PrivTy` is only usable at visibility `pub(crate)`
50-
--> $DIR/private-in-public.rs:28:1
48+
--> $DIR/private-in-public.rs:31:1
5149
|
5250
LL | struct PrivTy;
5351
| ^^^^^^^^^^^^^
5452

5553
error: private type `PrivTy` in public interface (error E0446)
56-
--> $DIR/private-in-public.rs:18:1
54+
--> $DIR/private-in-public.rs:20:1
5755
|
5856
LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
5957
| ^^^^^^^^^^^^^^^^^^
@@ -62,14 +60,13 @@ LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
6260
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
6361

6462
warning: type `PrivTy` is more private than the item `PubAlias2`
65-
|
66-
note: type alias `PubAlias2` is reachable at visibility `pub`
67-
--> $DIR/private-in-public.rs:18:1
63+
--> $DIR/private-in-public.rs:20:1
6864
|
6965
LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
70-
| ^^^^^^^^^^^^^^^^^^
66+
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias2` is reachable at visibility `pub`
67+
|
7168
note: but type `PrivTy` is only usable at visibility `pub(crate)`
72-
--> $DIR/private-in-public.rs:28:1
69+
--> $DIR/private-in-public.rs:31:1
7370
|
7471
LL | struct PrivTy;
7572
| ^^^^^^^^^^^^^

tests/ui/const-generics/generic_const_exprs/eval-privacy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ where
2121
{
2222
type AssocTy = Const<{ my_const_fn(U) }>;
2323
//~^ ERROR private type
24+
//~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
2425
fn assoc_fn() -> Self::AssocTy {
2526
Const
2627
}

tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ LL | const fn my_const_fn(val: u8) -> u8 {
88
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
99

1010
warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
11-
|
12-
note: associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub`
1311
--> $DIR/eval-privacy.rs:22:5
1412
|
1513
LL | type AssocTy = Const<{ my_const_fn(U) }>;
16-
| ^^^^^^^^^^^^
14+
| ^^^^^^^^^^^^ associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub`
15+
|
1716
note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)`
18-
--> $DIR/eval-privacy.rs:29:1
17+
--> $DIR/eval-privacy.rs:30:1
1918
|
2019
LL | const fn my_const_fn(val: u8) -> u8 {
2120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/error-codes/E0445.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ trait Foo {
1212

1313
pub trait Bar : Foo {}
1414
//~^ ERROR private trait `Foo` in public interface [E0445]
15+
//~| WARNING trait `Foo` is more private than the item `Bar`
1516
pub struct Bar2<T: Foo>(pub T);
1617
//~^ ERROR private trait `Foo` in public interface [E0445]
18+
//~| WARNING trait `Foo` is more private than the item `Bar2`
1719
pub fn foo<T: Foo> (t: T) {}
1820
//~^ ERROR private trait `Foo` in public interface [E0445]
21+
//~| WARNING trait `Foo` is more private than the item `foo`
1922

2023
fn main() {}

tests/ui/error-codes/E0445.stderr

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ LL | pub trait Bar : Foo {}
88
| ^^^^^^^^^^^^^^^^^^^ can't leak private trait
99

1010
warning: trait `Foo` is more private than the item `Bar`
11-
|
12-
note: trait `Bar` is reachable at visibility `pub`
1311
--> $DIR/E0445.rs:13:1
1412
|
1513
LL | pub trait Bar : Foo {}
16-
| ^^^^^^^^^^^^^^^^^^^
14+
| ^^^^^^^^^^^^^^^^^^^ trait `Bar` is reachable at visibility `pub`
15+
|
1716
note: but trait `Foo` is only usable at visibility `pub(crate)`
1817
--> $DIR/E0445.rs:9:1
1918
|
@@ -26,7 +25,7 @@ LL | #[warn(private_bounds)]
2625
| ^^^^^^^^^^^^^^
2726

2827
error[E0445]: private trait `Foo` in public interface
29-
--> $DIR/E0445.rs:15:1
28+
--> $DIR/E0445.rs:16:1
3029
|
3130
LL | trait Foo {
3231
| --------- `Foo` declared as private
@@ -35,20 +34,19 @@ LL | pub struct Bar2<T: Foo>(pub T);
3534
| ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
3635

3736
warning: trait `Foo` is more private than the item `Bar2`
38-
|
39-
note: struct `Bar2` is reachable at visibility `pub`
40-
--> $DIR/E0445.rs:15:1
37+
--> $DIR/E0445.rs:16:1
4138
|
4239
LL | pub struct Bar2<T: Foo>(pub T);
43-
| ^^^^^^^^^^^^^^^^^^^^^^^
40+
| ^^^^^^^^^^^^^^^^^^^^^^^ struct `Bar2` is reachable at visibility `pub`
41+
|
4442
note: but trait `Foo` is only usable at visibility `pub(crate)`
4543
--> $DIR/E0445.rs:9:1
4644
|
4745
LL | trait Foo {
4846
| ^^^^^^^^^
4947

5048
error[E0445]: private trait `Foo` in public interface
51-
--> $DIR/E0445.rs:17:1
49+
--> $DIR/E0445.rs:19:1
5250
|
5351
LL | trait Foo {
5452
| --------- `Foo` declared as private
@@ -57,12 +55,11 @@ LL | pub fn foo<T: Foo> (t: T) {}
5755
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
5856

5957
warning: trait `Foo` is more private than the item `foo`
60-
|
61-
note: function `foo` is reachable at visibility `pub`
62-
--> $DIR/E0445.rs:17:1
58+
--> $DIR/E0445.rs:19:1
6359
|
6460
LL | pub fn foo<T: Foo> (t: T) {}
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub`
62+
|
6663
note: but trait `Foo` is only usable at visibility `pub(crate)`
6764
--> $DIR/E0445.rs:9:1
6865
|

tests/ui/issues/issue-18389.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trait Private<P, R> {
1313
}
1414
pub trait Public: Private<
1515
//~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
16+
//~| WARNING trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
1617
<Self as Public>::P,
1718
<Self as Public>::R
1819
> {

0 commit comments

Comments
 (0)