-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #29726 - petrochenkov:privsan, r=alexcrichton
- Check privacy sanity in all blocks, not only function bodies - Check all fields, not only named - Check all impl items, not only methods - Check default impls - Move the sanity check in the beginning of privacy checking, so others could rely on it Technically it's a [breaking-change], but I expect no breakage because, well, it's *sane* privacy visitor, if code is broken it must be insane by definition!
- Loading branch information
Showing
4 changed files
with
167 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// 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. | ||
|
||
#![feature(associated_consts)] | ||
#![feature(optin_builtin_traits)] | ||
|
||
trait MarkerTr {} | ||
pub trait Tr { | ||
fn f(); | ||
const C: u8; | ||
type T; | ||
} | ||
pub struct S { | ||
pub a: u8 | ||
} | ||
struct Ts(pub u8); | ||
|
||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier | ||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier | ||
pub fn f() {} //~ ERROR unnecessary visibility qualifier | ||
pub const C: u8 = 0; //~ ERROR unnecessary visibility qualifier | ||
pub type T = u8; //~ ERROR unnecessary visibility qualifier | ||
} | ||
pub impl S { //~ ERROR unnecessary visibility qualifier | ||
pub fn f() {} | ||
pub const C: u8 = 0; | ||
// pub type T = u8; | ||
} | ||
pub extern "C" { //~ ERROR unnecessary visibility qualifier | ||
pub fn f(); | ||
pub static St: u8; | ||
} | ||
|
||
const MAIN: u8 = { | ||
trait MarkerTr {} | ||
pub trait Tr { //~ ERROR visibility has no effect inside functions or block | ||
fn f(); | ||
const C: u8; | ||
type T; | ||
} | ||
pub struct S { //~ ERROR visibility has no effect inside functions or block | ||
pub a: u8 //~ ERROR visibility has no effect inside functions or block | ||
} | ||
struct Ts(pub u8); //~ ERROR visibility has no effect inside functions or block | ||
|
||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f() {} //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub const C: u8 = 0; //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub type T = u8; //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
} | ||
pub impl S { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f() {} //~ ERROR visibility has no effect inside functions or block | ||
pub const C: u8 = 0; //~ ERROR visibility has no effect inside functions or block | ||
// pub type T = u8; // ERROR visibility has no effect inside functions or block | ||
} | ||
pub extern "C" { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f(); //~ ERROR visibility has no effect inside functions or block | ||
pub static St: u8; //~ ERROR visibility has no effect inside functions or block | ||
} | ||
|
||
0 | ||
}; | ||
|
||
fn main() { | ||
trait MarkerTr {} | ||
pub trait Tr { //~ ERROR visibility has no effect inside functions or block | ||
fn f(); | ||
const C: u8; | ||
type T; | ||
} | ||
pub struct S { //~ ERROR visibility has no effect inside functions or block | ||
pub a: u8 //~ ERROR visibility has no effect inside functions or block | ||
} | ||
struct Ts(pub u8); //~ ERROR visibility has no effect inside functions or block | ||
|
||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f() {} //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub const C: u8 = 0; //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub type T = u8; //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
} | ||
pub impl S { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f() {} //~ ERROR visibility has no effect inside functions or block | ||
pub const C: u8 = 0; //~ ERROR visibility has no effect inside functions or block | ||
// pub type T = u8; // ERROR visibility has no effect inside functions or block | ||
} | ||
pub extern "C" { //~ ERROR unnecessary visibility qualifier | ||
//~^ ERROR visibility has no effect inside functions or block | ||
pub fn f(); //~ ERROR visibility has no effect inside functions or block | ||
pub static St: u8; //~ ERROR visibility has no effect inside functions or block | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters