Auto merge of #42387 - GuillaumeGomez:error-codes-next, r=Susurrus
Add E0603 error code Part of #42229. cc @Susurrus
This commit is contained in:
commit
6684d176c7
@ -1578,6 +1578,35 @@ fn print_on_failure(state: &State) {
|
|||||||
```
|
```
|
||||||
"##,
|
"##,
|
||||||
|
|
||||||
|
E0603: r##"
|
||||||
|
A private item was used outside its scope.
|
||||||
|
|
||||||
|
Erroneous code example:
|
||||||
|
|
||||||
|
```compile_fail,E0603
|
||||||
|
mod SomeModule {
|
||||||
|
const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
|
||||||
|
// can't use it outside of the
|
||||||
|
// `SomeModule` module.
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("const value: {}", SomeModule::PRIVATE); // error: constant `CONSTANT`
|
||||||
|
// is private
|
||||||
|
```
|
||||||
|
|
||||||
|
In order to fix this error, you need to make the item public by using the `pub`
|
||||||
|
keyword. Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
mod SomeModule {
|
||||||
|
pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
|
||||||
|
// `pub` keyword.
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("const value: {}", SomeModule::PRIVATE); // ok!
|
||||||
|
```
|
||||||
|
"##,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
register_diagnostics! {
|
register_diagnostics! {
|
||||||
|
@ -3428,7 +3428,7 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
for &PrivacyError(span, name, binding) in &self.privacy_errors {
|
for &PrivacyError(span, name, binding) in &self.privacy_errors {
|
||||||
if !reported_spans.insert(span) { continue }
|
if !reported_spans.insert(span) { continue }
|
||||||
self.session.span_err(span, &format!("{} `{}` is private", binding.descr(), name));
|
span_err!(self.session, span, E0603, "{} `{}` is private", binding.descr(), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/test/compile-fail/E0603.rs
Normal file
17
src/test/compile-fail/E0603.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
mod SomeModule {
|
||||||
|
const PRIVATE: u32 = 0x_a_bad_1dea_u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
SomeModule::PRIVATE; //~ ERROR E0603
|
||||||
|
}
|
@ -35,31 +35,31 @@ error[E0423]: expected value, found struct `xcrate::S`
|
|||||||
help: possible better candidate is found in another module, you can import it into scope
|
help: possible better candidate is found in another module, you can import it into scope
|
||||||
| use m::S;
|
| use m::S;
|
||||||
|
|
||||||
error: tuple struct `Z` is private
|
error[E0603]: tuple struct `Z` is private
|
||||||
--> $DIR/privacy-struct-ctor.rs:25:9
|
--> $DIR/privacy-struct-ctor.rs:25:9
|
||||||
|
|
|
|
||||||
25 | n::Z; //~ ERROR tuple struct `Z` is private
|
25 | n::Z; //~ ERROR tuple struct `Z` is private
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: tuple struct `S` is private
|
error[E0603]: tuple struct `S` is private
|
||||||
--> $DIR/privacy-struct-ctor.rs:35:5
|
--> $DIR/privacy-struct-ctor.rs:35:5
|
||||||
|
|
|
|
||||||
35 | m::S; //~ ERROR tuple struct `S` is private
|
35 | m::S; //~ ERROR tuple struct `S` is private
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: tuple struct `Z` is private
|
error[E0603]: tuple struct `Z` is private
|
||||||
--> $DIR/privacy-struct-ctor.rs:39:5
|
--> $DIR/privacy-struct-ctor.rs:39:5
|
||||||
|
|
|
|
||||||
39 | m::n::Z; //~ ERROR tuple struct `Z` is private
|
39 | m::n::Z; //~ ERROR tuple struct `Z` is private
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: tuple struct `S` is private
|
error[E0603]: tuple struct `S` is private
|
||||||
--> $DIR/privacy-struct-ctor.rs:41:5
|
--> $DIR/privacy-struct-ctor.rs:41:5
|
||||||
|
|
|
|
||||||
41 | xcrate::m::S; //~ ERROR tuple struct `S` is private
|
41 | xcrate::m::S; //~ ERROR tuple struct `S` is private
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error: tuple struct `Z` is private
|
error[E0603]: tuple struct `Z` is private
|
||||||
--> $DIR/privacy-struct-ctor.rs:45:5
|
--> $DIR/privacy-struct-ctor.rs:45:5
|
||||||
|
|
|
|
||||||
45 | xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
|
45 | xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private
|
||||||
|
Loading…
x
Reference in New Issue
Block a user