Auto merge of #45401 - zackmdavis:crate_shorthand_visibility_modifier, r=nikomatsakis

`crate` shorthand visibility modifier

cc #45388.

r? @nikomatsakis
This commit is contained in:
bors 2017-10-24 12:24:16 +00:00
commit fbc3642ef1
14 changed files with 97 additions and 10 deletions

View file

@ -0,0 +1,18 @@
// Copyright 2017 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.
crate struct Bender { //~ ERROR `crate` visibility modifier is experimental
earth: bool,
fire: bool,
air: bool,
water: bool,
}
fn main() {}

View file

@ -8,14 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(crate_visibility_modifier)]
pub(crate) struct Crate;
#[derive(Default)]
pub struct Universe {
pub x: i32,
pub(crate) y: i32
pub(crate) y: i32,
crate z: i32,
}
impl Universe {
pub fn f(&self) {}
pub(crate) fn g(&self) {}
crate fn h(&self) {}
}

View file

@ -8,12 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(crate_visibility_modifier)]
mod foo {
struct Priv;
mod bar {
use foo::Priv;
pub(super) fn f(_: Priv) {}
pub(crate) fn g(_: Priv) {} //~ ERROR E0446
crate fn h(_: Priv) {} //~ ERROR E0446
}
}

View file

@ -50,8 +50,10 @@ fn main() {
let u = Universe::default();
let _ = u.x;
let _ = u.y; //~ ERROR private
let _ = u.z; //~ ERROR private
u.f();
u.g(); //~ ERROR private
u.h(); //~ ERROR private
}
mod pathological {

View file

@ -16,6 +16,6 @@ impl Foo {
fn foo() {}
#[stable(feature = "rust1", since = "1.0.0")]
} //~ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`
} //~ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`
fn main() {}

View file

@ -14,6 +14,6 @@ struct Foo;
impl Foo {
#[stable(feature = "rust1", since = "1.0.0")]
} //~ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`
} //~ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`
fn main() {}

View file

@ -15,4 +15,4 @@ struct S;
impl S {
static fn f() {}
}
//~^^ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`
//~^^ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`

View file

@ -9,7 +9,7 @@
// except according to those terms.
#![allow(dead_code, unused_imports)]
#![feature(macro_vis_matcher)]
#![feature(macro_vis_matcher, crate_visibility_modifier)]
/**
Ensure that `:vis` matches can be captured in existing positions, and passed
@ -64,6 +64,18 @@ mod with_pub_restricted {
vis_passthru! { pub(crate) use A as I; }
}
mod with_crate {
vis_passthru! { crate const A: i32 = 0; }
vis_passthru! { crate enum B {} }
vis_passthru! { crate extern "C" fn c() {} }
vis_passthru! { crate mod d {} }
vis_passthru! { crate static E: i32 = 0; }
vis_passthru! { crate struct F; }
vis_passthru! { crate trait G {} }
vis_passthru! { crate type H = i32; }
vis_passthru! { crate use A as I; }
}
mod garden {
mod with_pub_restricted_path {
vis_passthru! { pub(in garden) const A: i32 = 0; }