From b6f441d9861868eefd81460e0c3e4295fca12ffe Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 28 Feb 2016 14:50:58 +0300 Subject: [PATCH] Add some tests --- src/test/run-pass/issue-31776.rs | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/test/run-pass/issue-31776.rs diff --git a/src/test/run-pass/issue-31776.rs b/src/test/run-pass/issue-31776.rs new file mode 100644 index 000000000000..a12e569df2bc --- /dev/null +++ b/src/test/run-pass/issue-31776.rs @@ -0,0 +1,64 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Various scenarios in which `pub` is required in blocks + +struct S; + +mod m { + fn f() { + impl ::S { + pub fn s(&self) {} + } + } +} + +// ------------------------------------------------------ + +pub trait Tr { + type A; +} +pub struct S1; + +fn f() { + pub struct Z; + + impl ::Tr for ::S1 { + type A = Z; // Private-in-public error unless `struct Z` is pub + } +} + +// ------------------------------------------------------ + +trait Tr1 { + type A; + fn pull(&self) -> Self::A; +} +struct S2; + +mod m1 { + fn f() { + struct Z { + pub field: u8 + } + + impl ::Tr1 for ::S2 { + type A = Z; + fn pull(&self) -> Self::A { Z{field: 10} } + } + } +} + +// ------------------------------------------------------ + +fn main() { + S.s(); // Privacy error, unless `fn s` is pub + let a = S2.pull().field; // Privacy error unless `field: u8` is pub +}