Skip to content

Commit 785cbe0

Browse files
committed
Do not substitute type aliases during error reporting
Type aliases are still substituted when determining impl publicity
1 parent cda7244 commit 785cbe0

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/librustc_privacy/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,12 @@ struct SearchInterfaceForPrivateItemsVisitor<'a, 'tcx: 'a> {
14631463
impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
14641464
// Check if the type alias contain private types when substituted
14651465
fn is_public_type_alias(&self, item: &hir::Item, path: &hir::Path) -> bool {
1466+
// We substitute type aliases only when determining impl publicity
1467+
// FIXME: This will probably change and all type aliases will be substituted,
1468+
// requires an amendment to RFC 136.
1469+
if !self.is_quiet {
1470+
return false
1471+
}
14661472
// Type alias is considered public if the aliased type is
14671473
// public, even if the type alias itself is private. So, something
14681474
// like `type A = u8; pub fn f() -> A {...}` doesn't cause an error.

src/librustc_trans/back/msvc/registry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::os::windows::prelude::*;
1414
use std::ptr;
1515
use libc::{c_void, c_long};
1616

17-
type DWORD = u32;
17+
pub type DWORD = u32;
1818
type LPCWSTR = *const u16;
1919
type LONG = c_long;
2020
type LPDWORD = *mut DWORD;

src/test/compile-fail/private-in-public-warn.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ mod aliases_pub {
175175
impl PrivTr for Priv {}
176176

177177
pub fn f1(arg: PrivUseAlias) {} // OK
178-
pub fn f2(arg: PrivAlias) {} // OK
179178

180179
pub trait Tr1: PrivUseAliasTr {} // OK
181-
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
180+
// This should be OK, if type aliases are substituted
181+
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private type in public interface
182182

183183
impl PrivAlias {
184184
pub fn f(arg: Priv) {} //~ WARN private type in public interface
@@ -211,7 +211,6 @@ mod aliases_priv {
211211
use self::Priv1 as PrivUseAlias;
212212
use self::PrivTr1 as PrivUseAliasTr;
213213
type PrivAlias = Priv2;
214-
//~^ WARN private type in public interface
215214
trait PrivTr {
216215
type AssocAlias = Priv3;
217216
}
@@ -246,8 +245,6 @@ mod aliases_params {
246245
struct Priv;
247246
type PrivAliasGeneric<T = Priv> = T;
248247
type Result<T> = ::std::result::Result<T, Priv>;
249-
250-
pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
251248
}
252249

253250
#[rustc_error]

src/test/compile-fail/private-in-public.rs

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ mod aliases_pub {
105105
}
106106
impl PrivTr for Priv {}
107107

108+
// This should be OK, if type aliases are substituted
109+
pub fn f2(arg: PrivAlias) {} //~ ERROR private type in public interface
108110
// This should be OK, but associated type aliases are not substituted yet
109111
pub fn f3(arg: <Priv as PrivTr>::AssocAlias) {} //~ ERROR private type in public interface
110112

@@ -141,6 +143,8 @@ mod aliases_params {
141143
type PrivAliasGeneric<T = Priv> = T;
142144
type Result<T> = ::std::result::Result<T, Priv>;
143145

146+
// This should be OK, if type aliases are substituted
147+
pub fn f1(arg: PrivAliasGeneric<u8>) {} //~ ERROR private type in public interface
144148
pub fn f2(arg: PrivAliasGeneric) {} //~ ERROR private type in public interface
145149
pub fn f3(arg: Result<u8>) {} //~ ERROR private type in public interface
146150
}

0 commit comments

Comments
 (0)