提交 f3f27a5c 编写于 作者: V Vadim Petrochenkov

Rewrite VisiblePrivateTypesVisitor

上级 48700be9
......@@ -2372,10 +2372,6 @@ The currently implemented features of the reference compiler are:
Such items should not be allowed by the compiler to exist,
so if you need this there probably is a compiler bug.
* `visible_private_types` - Allows public APIs to expose otherwise private
types, e.g. as the return type of a public function.
This capability may be removed in the future.
* `allow_internal_unstable` - Allows `macro_rules!` macros to be tagged with the
`#[allow_internal_unstable]` attribute, designed
to allow `std` macros to call
......
此差异已折叠。
......@@ -82,7 +82,7 @@
("advanced_slice_patterns", "1.0.0", Some(23121), Active),
("tuple_indexing", "1.0.0", None, Accepted),
("associated_types", "1.0.0", None, Accepted),
("visible_private_types", "1.0.0", Some(29627), Active),
("visible_private_types", "1.0.0", None, Removed),
("slicing_syntax", "1.0.0", None, Accepted),
("box_syntax", "1.0.0", Some(27779), Active),
("placement_in_syntax", "1.0.0", Some(27779), Active),
......@@ -514,7 +514,6 @@ pub enum AttributeGate {
pub struct Features {
pub unboxed_closures: bool,
pub rustc_diagnostic_macros: bool,
pub visible_private_types: bool,
pub allow_quote: bool,
pub allow_asm: bool,
pub allow_log_syntax: bool,
......@@ -551,7 +550,6 @@ pub fn new() -> Features {
Features {
unboxed_closures: false,
rustc_diagnostic_macros: false,
visible_private_types: false,
allow_quote: false,
allow_asm: false,
allow_log_syntax: false,
......@@ -1130,7 +1128,6 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
Features {
unboxed_closures: cx.has_feature("unboxed_closures"),
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
visible_private_types: cx.has_feature("visible_private_types"),
allow_quote: cx.has_feature("quote"),
allow_asm: cx.has_feature("asm"),
allow_log_syntax: cx.has_feature("log_syntax"),
......
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Checks for private types in public interfaces
mod y {
pub struct Foo { x: u32 }
struct Bar { x: u32 }
impl Foo {
pub fn foo(&self, x: Self, y: Bar) { } //~ ERROR private type in exported type signature
}
}
mod x {
pub struct Foo { pub x: u32 }
struct Bar { _x: u32 }
impl Foo {
pub fn foo(&self, _x: Self, _y: Bar) { } //~ ERROR private type in exported type signature
pub fn bar(&self) -> Bar { Bar { _x: self.x } }
//~^ ERROR private type in exported type signature
}
}
pub fn main() {
let f = x::Foo { x: 4 };
let b = f.bar();
f.foo(x::Foo { x: 5 }, b);
}
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Checks for private types in public interfaces
struct Priv;
pub use self::private::public;
mod private {
pub type Priv = super::Priv; //~ ERROR private type in exported type signature
pub fn public(_x: Priv) {
}
}
struct __CFArray;
pub type CFArrayRef = *const __CFArray; //~ ERROR private type in exported type signature
trait Pointer { type Pointee; }
impl<T> Pointer for *const T { type Pointee = T; }
pub type __CFArrayRevealed = <CFArrayRef as Pointer>::Pointee;
//~^ ERROR private type in exported type signature
type Foo = u8;
pub fn foo(f: Foo) {} //~ ERROR private type in exported type signature
pub trait Exporter {
type Output;
}
pub struct Helper;
pub fn block() -> <Helper as Exporter>::Output {
struct Inner;
impl Inner {
fn poke(&self) { println!("Hello!"); }
}
impl Exporter for Helper {
type Output = Inner; //~ ERROR private type in exported type signature
}
Inner
}
fn main() {
block().poke();
}
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Functions can return unnameable types
mod m1 {
mod m2 {
#[derive(Debug)]
pub struct A;
}
use self::m2::A;
pub fn x() -> A { A }
}
fn main() {
let x = m1::x();
println!("{:?}", x);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册