Do not substitute type aliases during error reporting

Type aliases are still substituted when determining impl publicity
This commit is contained in:
Vadim Petrochenkov 2015-12-18 20:57:36 +03:00
parent cda7244a2a
commit 785cbe0200
4 changed files with 13 additions and 6 deletions

View File

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

View File

@ -14,7 +14,7 @@ use std::os::windows::prelude::*;
use std::ptr;
use libc::{c_void, c_long};
type DWORD = u32;
pub type DWORD = u32;
type LPCWSTR = *const u16;
type LONG = c_long;
type LPDWORD = *mut DWORD;

View File

@ -175,10 +175,10 @@ mod aliases_pub {
impl PrivTr for Priv {}
pub fn f1(arg: PrivUseAlias) {} // OK
pub fn f2(arg: PrivAlias) {} // OK
pub trait Tr1: PrivUseAliasTr {} // OK
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
// This should be OK, if type aliases are substituted
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ WARN private type in public interface
impl PrivAlias {
pub fn f(arg: Priv) {} //~ WARN private type in public interface
@ -211,7 +211,6 @@ mod aliases_priv {
use self::Priv1 as PrivUseAlias;
use self::PrivTr1 as PrivUseAliasTr;
type PrivAlias = Priv2;
//~^ WARN private type in public interface
trait PrivTr {
type AssocAlias = Priv3;
}
@ -246,8 +245,6 @@ mod aliases_params {
struct Priv;
type PrivAliasGeneric<T = Priv> = T;
type Result<T> = ::std::result::Result<T, Priv>;
pub fn f1(arg: PrivAliasGeneric<u8>) {} // OK, not an error
}
#[rustc_error]

View File

@ -105,6 +105,8 @@ mod aliases_pub {
}
impl PrivTr for Priv {}
// This should be OK, if type aliases are substituted
pub fn f2(arg: PrivAlias) {} //~ ERROR private type in public interface
// This should be OK, but associated type aliases are not substituted yet
pub fn f3(arg: <Priv as PrivTr>::AssocAlias) {} //~ ERROR private type in public interface
@ -141,6 +143,8 @@ mod aliases_params {
type PrivAliasGeneric<T = Priv> = T;
type Result<T> = ::std::result::Result<T, Priv>;
// This should be OK, if type aliases are substituted
pub fn f1(arg: PrivAliasGeneric<u8>) {} //~ ERROR private type in public interface
pub fn f2(arg: PrivAliasGeneric) {} //~ ERROR private type in public interface
pub fn f3(arg: Result<u8>) {} //~ ERROR private type in public interface
}