1
Fork 0

librustc: Forbid private types in public APIs.

This breaks code like:

    struct Foo {
        ...
    }

    pub fn make_foo() -> Foo {
        ...
    }

Change this code to:

    pub struct Foo {    // note `pub`
        ...
    }

    pub fn make_foo() -> Foo {
        ...
    }

The `visible_private_types` lint has been removed, since it is now an
error to attempt to expose a private type in a public API. In its place
a `#[feature(visible_private_types)]` gate has been added.

Closes #16463.

RFC #48.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-09-19 12:30:07 -07:00
parent 43fd619819
commit e9ad12c0ca
49 changed files with 169 additions and 80 deletions

View file

@ -94,7 +94,7 @@ pub enum Void { }
pub trait Any: AnyPrivate {} pub trait Any: AnyPrivate {}
/// An inner trait to ensure that only this module can call `get_type_id()`. /// An inner trait to ensure that only this module can call `get_type_id()`.
trait AnyPrivate { pub trait AnyPrivate {
/// Get the `TypeId` of `self` /// Get the `TypeId` of `self`
fn get_type_id(&self) -> TypeId; fn get_type_id(&self) -> TypeId;
} }

View file

@ -2178,7 +2178,6 @@ pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>;
/// Creates a new iterator that produces an infinite sequence of /// Creates a new iterator that produces an infinite sequence of
/// repeated applications of the given function `f`. /// repeated applications of the given function `f`.
#[allow(visible_private_types)]
pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> { pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> {
Unfold::new((f, Some(seed), true), |st| { Unfold::new((f, Some(seed), true), |st| {
let &(ref mut f, ref mut val, ref mut first) = st; let &(ref mut f, ref mut val, ref mut first) = st;

View file

@ -32,7 +32,7 @@ macro_rules! try( ($me:expr, $e:expr) => (
/// Representations /// Representations
trait Repr { pub trait Repr {
fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()>; fn write_repr(&self, writer: &mut io::Writer) -> io::IoResult<()>;
} }

View file

@ -218,7 +218,7 @@
// NB this does *not* include globs, please keep it that way. // NB this does *not* include globs, please keep it that way.
#![feature(macro_rules, phase, default_type_params)] #![feature(macro_rules, phase, default_type_params)]
#![allow(visible_private_types, deprecated)] #![allow(deprecated)]
#[cfg(test)] #[phase(plugin, link)] extern crate log; #[cfg(test)] #[phase(plugin, link)] extern crate log;
#[cfg(test)] extern crate rustuv; #[cfg(test)] extern crate rustuv;
@ -385,7 +385,7 @@ pub struct SchedPool {
/// keep track of how many tasks are currently running in the pool and then /// keep track of how many tasks are currently running in the pool and then
/// sending on a channel once the entire pool has been drained of all tasks. /// sending on a channel once the entire pool has been drained of all tasks.
#[deriving(Clone)] #[deriving(Clone)]
struct TaskState { pub struct TaskState {
cnt: Arc<AtomicUint>, cnt: Arc<AtomicUint>,
done: Sender<()>, done: Sender<()>,
} }

View file

@ -66,7 +66,7 @@ pub struct Timer {
inner: Option<Box<Inner>>, inner: Option<Box<Inner>>,
} }
struct Inner { pub struct Inner {
cb: Option<Box<rtio::Callback + Send>>, cb: Option<Box<rtio::Callback + Send>>,
interval: u64, interval: u64,
repeat: bool, repeat: bool,
@ -74,7 +74,6 @@ struct Inner {
id: uint, id: uint,
} }
#[allow(visible_private_types)]
pub enum Req { pub enum Req {
// Add a new timer to the helper thread. // Add a new timer to the helper thread.
NewTimer(Box<Inner>), NewTimer(Box<Inner>),

View file

@ -10,7 +10,6 @@
// Enable this to squash warnings due to exporting pieces of the representation // Enable this to squash warnings due to exporting pieces of the representation
// for use with the regex! macro. See lib.rs for explanation. // for use with the regex! macro. See lib.rs for explanation.
#![allow(visible_private_types)]
use std::cmp; use std::cmp;
use parse; use parse;

View file

@ -102,7 +102,6 @@ pub fn is_match(regex: &str, text: &str) -> Result<bool, parse::Error> {
/// More details about the `regex!` macro can be found in the `regex` crate /// More details about the `regex!` macro can be found in the `regex` crate
/// documentation. /// documentation.
#[deriving(Clone)] #[deriving(Clone)]
#[allow(visible_private_types)]
pub enum Regex { pub enum Regex {
// The representation of `Regex` is exported to support the `regex!` // The representation of `Regex` is exported to support the `regex!`
// syntax extension. Do not rely on it. // syntax extension. Do not rely on it.
@ -516,7 +515,6 @@ impl Regex {
} }
#[doc(hidden)] #[doc(hidden)]
#[allow(visible_private_types)]
#[experimental] #[experimental]
pub fn names_iter<'a>(&'a self) -> NamesIter<'a> { pub fn names_iter<'a>(&'a self) -> NamesIter<'a> {
match *self { match *self {
@ -534,7 +532,7 @@ impl Regex {
} }
enum NamesIter<'a> { pub enum NamesIter<'a> {
NamesIterNative(::std::slice::Items<'a, Option<&'static str>>), NamesIterNative(::std::slice::Items<'a, Option<&'static str>>),
NamesIterDynamic(::std::slice::Items<'a, Option<String>>) NamesIterDynamic(::std::slice::Items<'a, Option<String>>)
} }

View file

@ -1601,9 +1601,6 @@ declare_lint!(pub DEAD_ASSIGNMENT, Warn,
declare_lint!(pub DEAD_CODE, Warn, declare_lint!(pub DEAD_CODE, Warn,
"detect piece of code that will never be used") "detect piece of code that will never be used")
declare_lint!(pub VISIBLE_PRIVATE_TYPES, Warn,
"detect use of private types in exported type signatures")
declare_lint!(pub UNREACHABLE_CODE, Warn, declare_lint!(pub UNREACHABLE_CODE, Warn,
"detects unreachable code") "detects unreachable code")
@ -1636,7 +1633,6 @@ impl LintPass for HardwiredLints {
UNUSED_VARIABLE, UNUSED_VARIABLE,
DEAD_ASSIGNMENT, DEAD_ASSIGNMENT,
DEAD_CODE, DEAD_CODE,
VISIBLE_PRIVATE_TYPES,
UNREACHABLE_CODE, UNREACHABLE_CODE,
WARNINGS, WARNINGS,
UNKNOWN_FEATURES, UNKNOWN_FEATURES,

View file

@ -224,7 +224,7 @@ pub fn deref_kind(tcx: &ty::ctxt, t: ty::t) -> deref_kind {
} }
} }
trait ast_node { pub trait ast_node {
fn id(&self) -> ast::NodeId; fn id(&self) -> ast::NodeId;
fn span(&self) -> Span; fn span(&self) -> Span;
} }

View file

@ -16,7 +16,6 @@ use std::mem::replace;
use metadata::csearch; use metadata::csearch;
use middle::def; use middle::def;
use lint;
use middle::resolve; use middle::resolve;
use middle::ty; use middle::ty;
use middle::typeck::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam}; use middle::typeck::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam};
@ -1289,12 +1288,15 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
}; };
// A path can only be private if: // A path can only be private if:
// it's in this crate... // it's in this crate...
is_local(did) && if !is_local(did) {
// ... it's not exported (obviously) ... return false
!self.exported_items.contains(&did.node) && }
// .. and it corresponds to a type in the AST (this returns None for // .. and it corresponds to a private type in the AST (this returns
// type parameters) // None for type parameters)
self.tcx.map.find(did.node).is_some() match self.tcx.map.find(did.node) {
Some(ast_map::NodeItem(ref item)) => item.vis != ast::Public,
Some(_) | None => false,
}
} }
fn trait_is_public(&self, trait_id: ast::NodeId) -> bool { fn trait_is_public(&self, trait_id: ast::NodeId) -> bool {
@ -1302,6 +1304,22 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
// traits are exported currently (see `EmbargoVisitor.exported_trait`) // traits are exported currently (see `EmbargoVisitor.exported_trait`)
self.public_items.contains(&trait_id) self.public_items.contains(&trait_id)
} }
fn check_ty_param_bound(&self,
span: Span,
ty_param_bound: &ast::TyParamBound) {
match *ty_param_bound {
ast::TraitTyParamBound(ref trait_ref) => {
if !self.tcx.sess.features.borrow().visible_private_types &&
self.path_is_private_type(trait_ref.ref_id) {
self.tcx.sess.span_err(span,
"private type in exported type \
parameter bound");
}
}
_ => {}
}
}
} }
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> { impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
@ -1338,7 +1356,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
// namespace (the contents have their own privacies). // namespace (the contents have their own privacies).
ast::ItemForeignMod(_) => {} ast::ItemForeignMod(_) => {}
ast::ItemTrait(..) if !self.trait_is_public(item.id) => return, ast::ItemTrait(_, _, ref bounds, _) => {
if !self.trait_is_public(item.id) {
return
}
for bound in bounds.iter() {
self.check_ty_param_bound(item.span, bound)
}
}
// impls need some special handling to try to offer useful // impls need some special handling to try to offer useful
// error messages without (too many) false positives // error messages without (too many) false positives
@ -1471,6 +1497,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
visit::walk_item(self, item); visit::walk_item(self, item);
} }
fn visit_generics(&mut self, generics: &ast::Generics) {
for ty_param in generics.ty_params.iter() {
for bound in ty_param.bounds.iter() {
self.check_ty_param_bound(ty_param.span, bound)
}
}
for predicate in generics.where_clause.predicates.iter() {
for bound in predicate.bounds.iter() {
self.check_ty_param_bound(predicate.span, bound)
}
}
}
fn visit_foreign_item(&mut self, item: &ast::ForeignItem) { fn visit_foreign_item(&mut self, item: &ast::ForeignItem) {
if self.exported_items.contains(&item.id) { if self.exported_items.contains(&item.id) {
visit::walk_foreign_item(self, item) visit::walk_foreign_item(self, item)
@ -1488,12 +1527,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
fn visit_ty(&mut self, t: &ast::Ty) { fn visit_ty(&mut self, t: &ast::Ty) {
match t.node { match t.node {
ast::TyPath(ref p, _, path_id) => { ast::TyPath(ref p, _, path_id) => {
if self.path_is_private_type(path_id) { if !self.tcx.sess.features.borrow().visible_private_types &&
self.tcx.sess.add_lint( self.path_is_private_type(path_id) {
lint::builtin::VISIBLE_PRIVATE_TYPES, self.tcx.sess.span_err(p.span,
path_id, p.span, "private type in exported type \
"private type in exported type \ signature");
signature".to_string());
} }
} }
_ => {} _ => {}

View file

@ -1645,7 +1645,7 @@ impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> {
} }
} }
trait Resolvable { pub trait Resolvable {
fn resolve(&self, infcx: &InferCtxt) -> Self; fn resolve(&self, infcx: &InferCtxt) -> Self;
fn contains_error(&self) -> bool; fn contains_error(&self) -> bool;
} }

View file

@ -153,7 +153,7 @@ pub enum AttributeSet {
FunctionIndex = !0 FunctionIndex = !0
} }
trait AttrHelper { pub trait AttrHelper {
fn apply_llfn(&self, idx: c_uint, llfn: ValueRef); fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
fn apply_callsite(&self, idx: c_uint, callsite: ValueRef); fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
} }

View file

@ -26,7 +26,6 @@ pub trait Local<Borrowed> {
unsafe fn try_unsafe_borrow() -> Option<*mut Self>; unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
} }
#[allow(visible_private_types)]
impl Local<local_ptr::Borrowed<Task>> for Task { impl Local<local_ptr::Borrowed<Task>> for Task {
#[inline] #[inline]
fn put(value: Box<Task>) { unsafe { local_ptr::put(value) } } fn put(value: Box<Task>) { unsafe { local_ptr::put(value) } }

View file

@ -374,7 +374,6 @@ pub mod native {
#[inline] #[inline]
#[cfg(not(test))] #[cfg(not(test))]
#[allow(visible_private_types)]
pub fn maybe_tls_key() -> Option<tls::Key> { pub fn maybe_tls_key() -> Option<tls::Key> {
unsafe { unsafe {
// NB: This is a little racy because, while the key is // NB: This is a little racy because, while the key is

View file

@ -237,7 +237,6 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class {
#[cfg(not(target_arch = "arm"), not(windows, target_arch = "x86_64"), not(test))] #[cfg(not(target_arch = "arm"), not(windows, target_arch = "x86_64"), not(test))]
#[doc(hidden)] #[doc(hidden)]
#[allow(visible_private_types)]
pub mod eabi { pub mod eabi {
use libunwind as uw; use libunwind as uw;
use libc::c_int; use libc::c_int;
@ -291,7 +290,6 @@ pub mod eabi {
#[cfg(target_os = "ios", target_arch = "arm", not(test))] #[cfg(target_os = "ios", target_arch = "arm", not(test))]
#[doc(hidden)] #[doc(hidden)]
#[allow(visible_private_types)]
pub mod eabi { pub mod eabi {
use libunwind as uw; use libunwind as uw;
use libc::c_int; use libc::c_int;
@ -347,7 +345,6 @@ pub mod eabi {
// but otherwise works the same. // but otherwise works the same.
#[cfg(target_arch = "arm", not(target_os = "ios"), not(test))] #[cfg(target_arch = "arm", not(target_os = "ios"), not(test))]
#[doc(hidden)] #[doc(hidden)]
#[allow(visible_private_types)]
pub mod eabi { pub mod eabi {
use libunwind as uw; use libunwind as uw;
use libc::c_int; use libc::c_int;
@ -397,21 +394,20 @@ pub mod eabi {
#[cfg(windows, target_arch = "x86_64", not(test))] #[cfg(windows, target_arch = "x86_64", not(test))]
#[doc(hidden)] #[doc(hidden)]
#[allow(visible_private_types)]
#[allow(non_camel_case_types, non_snake_case)] #[allow(non_camel_case_types, non_snake_case)]
pub mod eabi { pub mod eabi {
use libunwind as uw; use libunwind as uw;
use libc::{c_void, c_int}; use libc::{c_void, c_int};
#[repr(C)] #[repr(C)]
struct EXCEPTION_RECORD; pub struct EXCEPTION_RECORD;
#[repr(C)] #[repr(C)]
struct CONTEXT; pub struct CONTEXT;
#[repr(C)] #[repr(C)]
struct DISPATCHER_CONTEXT; pub struct DISPATCHER_CONTEXT;
#[repr(C)] #[repr(C)]
enum EXCEPTION_DISPOSITION { pub enum EXCEPTION_DISPOSITION {
ExceptionContinueExecution, ExceptionContinueExecution,
ExceptionContinueSearch, ExceptionContinueSearch,
ExceptionNestedException, ExceptionNestedException,

View file

@ -19,7 +19,7 @@ use net;
use super::{Loop, UvError, Request, wait_until_woken_after, wakeup}; use super::{Loop, UvError, Request, wait_until_woken_after, wakeup};
use uvll; use uvll;
struct Addrinfo { pub struct Addrinfo {
handle: *const libc::addrinfo, handle: *const libc::addrinfo,
} }

View file

@ -46,7 +46,6 @@ via `close` and `delete` methods.
#![feature(macro_rules, unsafe_destructor)] #![feature(macro_rules, unsafe_destructor)]
#![deny(unused_result, unused_must_use)] #![deny(unused_result, unused_must_use)]
#![allow(visible_private_types)]
#![reexport_test_harness_main = "test_main"] #![reexport_test_harness_main = "test_main"]

View file

@ -69,6 +69,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("advanced_slice_patterns", Active), ("advanced_slice_patterns", Active),
("tuple_indexing", Active), ("tuple_indexing", Active),
("associated_types", Active), ("associated_types", Active),
("visible_private_types", Active),
// if you change this list without updating src/doc/rust.md, cmr will be sad // if you change this list without updating src/doc/rust.md, cmr will be sad
@ -100,6 +101,7 @@ pub struct Features {
pub overloaded_calls: bool, pub overloaded_calls: bool,
pub rustc_diagnostic_macros: bool, pub rustc_diagnostic_macros: bool,
pub import_shadowing: bool, pub import_shadowing: bool,
pub visible_private_types: bool,
} }
impl Features { impl Features {
@ -109,6 +111,7 @@ impl Features {
overloaded_calls: false, overloaded_calls: false,
rustc_diagnostic_macros: false, rustc_diagnostic_macros: false,
import_shadowing: false, import_shadowing: false,
visible_private_types: false,
} }
} }
} }
@ -479,6 +482,7 @@ pub fn check_crate(span_handler: &SpanHandler, krate: &ast::Crate) -> (Features,
overloaded_calls: cx.has_feature("overloaded_calls"), overloaded_calls: cx.has_feature("overloaded_calls"),
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"), rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
import_shadowing: cx.has_feature("import_shadowing"), import_shadowing: cx.has_feature("import_shadowing"),
visible_private_types: cx.has_feature("visible_private_types"),
}, },
unknown_features) unknown_features)
} }

View file

@ -12,7 +12,7 @@
// part of issue-6919.rs // part of issue-6919.rs
struct C<'a> { pub struct C<'a> {
pub k: ||: 'a, pub k: ||: 'a,
} }

View file

@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type oint = Option<int>; pub type oint = Option<int>;
pub fn foo() -> oint { Some(3) } pub fn foo() -> oint { Some(3) }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait A { pub trait A {
fn frob(&self); fn frob(&self);
} }

View file

@ -16,7 +16,7 @@ pub enum MaybeOwned<'a> {
Borrowed(&'a int) Borrowed(&'a int)
} }
struct Inv<'a> { // invariant w/r/t 'a pub struct Inv<'a> { // invariant w/r/t 'a
x: &'a mut &'a int x: &'a mut &'a int
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Struct { pub struct Struct {
field: int field: int
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Struct { pub struct Struct {
field: int field: int
} }

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct Stuff { pub struct Stuff {
a: int, a: int,
b: f64 b: f64
} }
trait Trait { pub trait Trait {
fn method(&self) -> Stuff; fn method(&self) -> Stuff;
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait Trait { pub trait Trait {
fn method(&self) -> int; fn method(&self) -> int;
} }

View file

@ -11,7 +11,6 @@
#![no_std] #![no_std]
#![allow(unused_variable)] #![allow(unused_variable)]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(visible_private_types)]
#![deny(dead_code)] #![deny(dead_code)]
#![feature(lang_items)] #![feature(lang_items)]
@ -54,7 +53,7 @@ impl SemiUsedStruct {
fn la_la_la() {} fn la_la_la() {}
} }
struct StructUsedAsField; struct StructUsedAsField;
struct StructUsedInEnum; pub struct StructUsedInEnum;
struct StructUsedInGeneric; struct StructUsedInGeneric;
pub struct PubStruct2 { pub struct PubStruct2 {
#[allow(dead_code)] #[allow(dead_code)]

View file

@ -0,0 +1,26 @@
// Copyright 2014 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.
trait Foo {}
pub fn f<T:Foo>() {} //~ ERROR private type in exported type
pub fn g<T>() where T: Foo {} //~ ERROR private type in exported type
pub struct H<T:Foo> { //~ ERROR private type in exported type
x: T,
}
pub struct I<T> where T: Foo { //~ ERROR private type in exported type
x: T,
}
fn main() {}

View file

@ -0,0 +1,16 @@
// Copyright 2014 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.
trait Foo {}
pub trait Bar : Foo {} //~ ERROR private type in exported type
fn main() {}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
type task_id = int; pub type task_id = int;
#[deriving(PartialEq)] #[deriving(PartialEq)]
pub enum Task { pub enum Task {

View file

@ -12,7 +12,7 @@
// by value. // by value.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct TwoU16s { pub struct TwoU16s {
one: u16, two: u16 one: u16, two: u16
} }

View file

@ -12,7 +12,7 @@
// by value. // by value.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct TwoU32s { pub struct TwoU32s {
one: u32, two: u32 one: u32, two: u32
} }

View file

@ -12,7 +12,7 @@
// by value. // by value.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct TwoU64s { pub struct TwoU64s {
one: u64, two: u64 one: u64, two: u64
} }

View file

@ -12,7 +12,7 @@
// by value. // by value.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct TwoU8s { pub struct TwoU8s {
one: u8, two: u8 one: u8, two: u8
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct TwoU16s { pub struct TwoU16s {
one: u16, two: u16 one: u16, two: u16
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct TwoU32s { pub struct TwoU32s {
one: u32, two: u32 one: u32, two: u32
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct TwoU64s { pub struct TwoU64s {
one: u64, two: u64 one: u64, two: u64
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
struct TwoU8s { pub struct TwoU8s {
one: u8, two: u8 one: u8, two: u8
} }

View file

@ -9,16 +9,16 @@
// except according to those terms. // except according to those terms.
pub mod two_tuple { pub mod two_tuple {
trait T {} pub trait T {}
struct P<'a>(&'a T + 'a, &'a T + 'a); pub struct P<'a>(&'a T + 'a, &'a T + 'a);
pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> { pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> {
P(car, cdr) P(car, cdr)
} }
} }
pub mod two_fields { pub mod two_fields {
trait T {} pub trait T {}
struct P<'a> { car: &'a T + 'a, cdr: &'a T + 'a } pub struct P<'a> { car: &'a T + 'a, cdr: &'a T + 'a }
pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> { pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> {
P{ car: car, cdr: cdr } P{ car: car, cdr: cdr }
} }

View file

@ -15,7 +15,7 @@
extern crate libc; extern crate libc;
use libc::{c_uint, uint32_t, c_void}; use libc::{c_uint, uint32_t, c_void};
struct KEYGEN { pub struct KEYGEN {
hash_algorithm: [c_uint, ..2], hash_algorithm: [c_uint, ..2],
count: uint32_t, count: uint32_t,
salt: *const c_void, salt: *const c_void,

View file

@ -14,7 +14,7 @@
use std::f64; use std::f64;
struct Point { pub struct Point {
x: f64, x: f64,
y: f64 y: f64
} }

View file

@ -48,7 +48,7 @@ pub fn main() {
// minimal // minimal
trait MyTrait<T> { } pub trait MyTrait<T> { }
pub struct MyContainer<'a, T> { pub struct MyContainer<'a, T> {
foos: Vec<&'a MyTrait<T>+'a> , foos: Vec<&'a MyTrait<T>+'a> ,

View file

@ -12,7 +12,7 @@
// should not upset the variance inference for actual occurrences of // should not upset the variance inference for actual occurrences of
// that lifetime in type expressions. // that lifetime in type expressions.
trait HasLife<'a> { } pub trait HasLife<'a> { }
trait UseLife01 { trait UseLife01 {
fn refs<'a, H: HasLife<'a>>(&'a self) -> H; fn refs<'a, H: HasLife<'a>>(&'a self) -> H;
@ -23,7 +23,7 @@ trait UseLife02 {
} }
trait HasType<T> { } pub trait HasType<T> { }
trait UseLife03<T> { trait UseLife03<T> {
fn refs<'a, H: HasType<&'a T>>(&'a self) -> H; fn refs<'a, H: HasType<&'a T>>(&'a self) -> H;

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct Partial<T> { x: T, y: T } pub struct Partial<T> { x: T, y: T }
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct S { val: int } struct S { val: int }

View file

@ -9,14 +9,14 @@
// except according to those terms. // except according to those terms.
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct Partial<T> { x: T, y: T } pub struct Partial<T> { x: T, y: T }
#[deriving(PartialEq, Show)] #[deriving(PartialEq, Show)]
struct S { val: int } struct S { val: int }
impl S { fn new(v: int) -> S { S { val: v } } } impl S { fn new(v: int) -> S { S { val: v } } }
impl Drop for S { fn drop(&mut self) { } } impl Drop for S { fn drop(&mut self) { } }
type Two<T> = (Partial<T>, Partial<T>); pub type Two<T> = (Partial<T>, Partial<T>);
pub fn f<T>((b1, b2): (T, T), (b3, b4): (T, T), f: |T| -> T) -> Two<T> { pub fn f<T>((b1, b2): (T, T), (b3, b4): (T, T), f: |T| -> T) -> Two<T> {
let p = Partial { x: b1, y: b2 }; let p = Partial { x: b1, y: b2 };

View file

@ -13,7 +13,7 @@
use std::num::NumCast; use std::num::NumCast;
trait Num { pub trait Num {
fn from_int(i: int) -> Self; fn from_int(i: int) -> Self;
fn gt(&self, other: &Self) -> bool; fn gt(&self, other: &Self) -> bool;
} }

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait MyNum { pub trait MyNum {
fn from_int(int) -> Self; fn from_int(int) -> Self;
} }

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
trait MyEq { } pub trait MyEq { }
trait MyNum { pub trait MyNum {
fn from_int(int) -> Self; fn from_int(int) -> Self;
} }

View file

@ -0,0 +1,22 @@
// Copyright 2014 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.
#![feature(visible_private_types)]
trait Foo {}
pub trait Bar : Foo {}
struct Baz;
pub fn f(_: Baz) {}
fn main() {}