Skip to content

Commit 4338683

Browse files
authored
Rollup merge of #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

+1-1
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

+1-1
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

+2-1
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

+3
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

+13-16
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

+1
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

+3-4
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

+3
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

+10-13
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

+1
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
> {

tests/ui/issues/issue-18389.stderr

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ LL | trait Private<P, R> {
66
...
77
LL | / pub trait Public: Private<
88
LL | |
9+
LL | |
910
LL | | <Self as Public>::P,
1011
LL | | <Self as Public>::R
1112
LL | | > {
1213
| |_^ can't leak private trait
1314

1415
warning: trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
15-
|
16-
note: trait `Public` is reachable at visibility `pub`
1716
--> $DIR/issue-18389.rs:14:1
1817
|
1918
LL | / pub trait Public: Private<
2019
LL | |
20+
LL | |
2121
LL | | <Self as Public>::P,
2222
LL | | <Self as Public>::R
2323
LL | | > {
24-
| |_^
24+
| |_^ trait `Public` is reachable at visibility `pub`
25+
|
2526
note: but trait `Private<<Self as Public>::P, <Self as Public>::R>` is only usable at visibility `pub(crate)`
2627
--> $DIR/issue-18389.rs:11:1
2728
|

tests/ui/privacy/private-in-public-non-principal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ auto trait PrivNonPrincipal {}
1313
pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
1414
//~^ WARN private trait `PrivNonPrincipal` in public interface
1515
//~| WARN this was previously accepted
16+
//~| ERROR trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
1617

1718
#[deny(missing_docs)]
1819
fn container() {

tests/ui/privacy/private-in-public-non-principal.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal>
99
= note: `#[warn(private_in_public)]` on by default
1010

1111
error: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
12-
|
13-
note: function `leak_dyn_nonprincipal` is reachable at visibility `pub`
1412
--> $DIR/private-in-public-non-principal.rs:13:1
1513
|
1614
LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub`
16+
|
1817
note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)`
1918
--> $DIR/private-in-public-non-principal.rs:11:1
2019
|
@@ -27,13 +26,13 @@ LL | #![deny(private_interfaces)]
2726
| ^^^^^^^^^^^^^^^^^^
2827

2928
error: missing documentation for an associated function
30-
--> $DIR/private-in-public-non-principal.rs:20:9
29+
--> $DIR/private-in-public-non-principal.rs:21:9
3130
|
3231
LL | pub fn check_doc_lint() {}
3332
| ^^^^^^^^^^^^^^^^^^^^^^^
3433
|
3534
note: the lint level is defined here
36-
--> $DIR/private-in-public-non-principal.rs:17:8
35+
--> $DIR/private-in-public-non-principal.rs:18:8
3736
|
3837
LL | #[deny(missing_docs)]
3938
| ^^^^^^^^^^^^

tests/ui/privacy/where-priv-type.rs

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; }
2525
pub struct S
2626
//~^ WARNING private type `PrivTy` in public interface
2727
//~| WARNING hard error
28+
//~| WARNING type `PrivTy` is more private than the item `S`
2829
where
2930
PrivTy:
3031
{}
@@ -33,6 +34,7 @@ where
3334
pub enum E
3435
//~^ WARNING private type `PrivTy` in public interface
3536
//~| WARNING hard error
37+
//~| WARNING type `PrivTy` is more private than the item `E`
3638
where
3739
PrivTy:
3840
{}
@@ -41,19 +43,22 @@ where
4143
pub fn f()
4244
//~^ WARNING private type `PrivTy` in public interface
4345
//~| WARNING hard error
46+
//~| WARNING type `PrivTy` is more private than the item `f`
4447
where
4548
PrivTy:
4649
{}
4750

4851

4952
impl S
5053
//~^ ERROR private type `PrivTy` in public interface
54+
//~| WARNING type `PrivTy` is more private than the item `S`
5155
where
5256
PrivTy:
5357
{
5458
pub fn f()
5559
//~^ WARNING private type `PrivTy` in public interface
5660
//~| WARNING hard error
61+
//~| WARNING type `PrivTy` is more private than the item `S::f`
5762
where
5863
PrivTy:
5964
{}
@@ -85,6 +90,7 @@ where
8590
{
8691
type AssocTy = Const<{ my_const_fn(U) }>;
8792
//~^ ERROR private type
93+
//~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
8894
fn assoc_fn() -> Self::AssocTy {
8995
Const
9096
}

0 commit comments

Comments
 (0)