-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Make privacy checking aware that a use
directive can point to two defintions (namespaces) with different privacy.
#12245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+550
−109
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
Submodule libuv
updated
from fd5308 to 800b56
This file contains hidden or 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,66 @@ | ||
// 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. | ||
|
||
// Check we do the correct privacy checks when we import a name and there is an | ||
// item with that name in both the value and type namespaces. | ||
|
||
#[feature(globs)]; | ||
#[allow(dead_code)]; | ||
#[allow(unused_imports)]; | ||
|
||
// public type, private value | ||
pub mod foo1 { | ||
pub trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
fn Bar() { } | ||
} | ||
|
||
fn test_glob1() { | ||
use foo1::*; | ||
|
||
Bar(); //~ ERROR unresolved name `Bar`. | ||
} | ||
|
||
// private type, public value | ||
pub mod foo2 { | ||
trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
pub fn Bar() { } | ||
} | ||
|
||
fn test_glob2() { | ||
use foo2::*; | ||
|
||
let _x: ~Bar; //~ ERROR use of undeclared type name `Bar` | ||
} | ||
|
||
// neither public | ||
pub mod foo3 { | ||
trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
fn Bar() { } | ||
} | ||
|
||
fn test_glob3() { | ||
use foo3::*; | ||
|
||
Bar(); //~ ERROR unresolved name `Bar`. | ||
let _x: ~Bar; //~ ERROR use of undeclared type name `Bar` | ||
} | ||
|
||
fn main() { | ||
} | ||
|
This file contains hidden or 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,91 @@ | ||
// 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. | ||
|
||
// Check we do the correct privacy checks when we import a name and there is an | ||
// item with that name in both the value and type namespaces. | ||
|
||
#[feature(globs)]; | ||
#[allow(dead_code)]; | ||
#[allow(unused_imports)]; | ||
|
||
// public type, private value | ||
pub mod foo1 { | ||
pub trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
fn Bar() { } | ||
} | ||
|
||
fn test_single1() { | ||
// In an ideal world, these would be private instead of inaccessible. | ||
use foo1::Bar; //~ ERROR `Bar` is inaccessible | ||
|
||
Bar(); | ||
} | ||
|
||
fn test_list1() { | ||
use foo1::{Bar,Baz}; //~ ERROR `Bar` is inaccessible | ||
|
||
Bar(); | ||
} | ||
|
||
// private type, public value | ||
pub mod foo2 { | ||
trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
pub fn Bar() { } | ||
} | ||
|
||
fn test_single2() { | ||
use foo2::Bar; //~ ERROR `Bar` is private | ||
|
||
let _x : ~Bar; | ||
} | ||
|
||
fn test_list2() { | ||
use foo2::{Bar,Baz}; //~ ERROR `Bar` is private | ||
|
||
let _x: ~Bar; | ||
} | ||
|
||
// neither public | ||
pub mod foo3 { | ||
trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
fn Bar() { } | ||
} | ||
|
||
fn test_unused3() { | ||
use foo3::Bar; //~ ERROR `Bar` is private | ||
use foo3::{Bar,Baz}; //~ ERROR `Bar` is private | ||
} | ||
|
||
fn test_single3() { | ||
use foo3::Bar; //~ ERROR `Bar` is private | ||
|
||
Bar(); | ||
let _x: ~Bar; | ||
} | ||
|
||
fn test_list3() { | ||
use foo3::{Bar,Baz}; //~ ERROR `Bar` is private | ||
|
||
Bar(); | ||
let _x: ~Bar; | ||
} | ||
|
||
fn main() { | ||
} | ||
|
This file contains hidden or 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,124 @@ | ||
// 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. | ||
|
||
// ignore-fast | ||
|
||
// Check we do the correct privacy checks when we import a name and there is an | ||
// item with that name in both the value and type namespaces. | ||
|
||
#[feature(globs)]; | ||
#[allow(dead_code)]; | ||
#[allow(unused_imports)]; | ||
|
||
// public type, private value | ||
pub mod foo1 { | ||
pub trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
fn Bar() { } | ||
} | ||
|
||
fn test_unused1() { | ||
use foo1::Bar; | ||
use foo1::{Bar,Baz}; | ||
use foo1::*; | ||
} | ||
|
||
fn test_single1() { | ||
use foo1::Bar; | ||
|
||
let _x: ~Bar; | ||
} | ||
|
||
fn test_list1() { | ||
use foo1::{Bar,Baz}; | ||
|
||
let _x: ~Bar; | ||
} | ||
|
||
fn test_glob1() { | ||
use foo1::*; | ||
|
||
let _x: ~Bar; | ||
} | ||
|
||
// private type, public value | ||
pub mod foo2 { | ||
trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
pub fn Bar() { } | ||
} | ||
|
||
fn test_unused2() { | ||
use foo2::Bar; | ||
use foo2::{Bar,Baz}; | ||
use foo2::*; | ||
} | ||
|
||
fn test_single2() { | ||
use foo2::Bar; | ||
|
||
Bar(); | ||
} | ||
|
||
fn test_list2() { | ||
use foo2::{Bar,Baz}; | ||
|
||
Bar(); | ||
} | ||
|
||
fn test_glob2() { | ||
use foo2::*; | ||
|
||
Bar(); | ||
} | ||
|
||
// public type, public value | ||
pub mod foo3 { | ||
pub trait Bar { | ||
} | ||
pub struct Baz; | ||
|
||
pub fn Bar() { } | ||
} | ||
|
||
fn test_unused3() { | ||
use foo3::Bar; | ||
use foo3::{Bar,Baz}; | ||
use foo3::*; | ||
} | ||
|
||
fn test_single3() { | ||
use foo3::Bar; | ||
|
||
Bar(); | ||
let _x: ~Bar; | ||
} | ||
|
||
fn test_list3() { | ||
use foo3::{Bar,Baz}; | ||
|
||
Bar(); | ||
let _x: ~Bar; | ||
} | ||
|
||
fn test_glob3() { | ||
use foo3::*; | ||
|
||
Bar(); | ||
let _x: ~Bar; | ||
} | ||
|
||
fn main() { | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this report method and I think it could be used in other places where the same form of reporting is necessary. What do you think about making this a default method in
ast::visit::Visitor
(or moving it somewhere else)? If you prefer to respect YAGNI, I can do it myself later, I've already a case where I'd benefit from this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe this could go in the session itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking about maybe pulling out CheckResult and report_error into somewhere more generic - I was thinking of some utils file somewhere. The session is probably a good place (I prefer Visitor since it is not really related to visiting). I decided not to for now since I didn't know if it was generally useful. If you think it would be, feel free to pull it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be useful and I could use it in the patch I'm currently working on. Also, the pattern Error + Note is used in other places too.
I can pull it out later. This is not a blocker for this patch at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case where this could be helpful #12347