Skip to content

Commit 6675bb3

Browse files
Add E0603 error code
1 parent 4ed2eda commit 6675bb3

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

src/librustc_resolve/diagnostics.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,35 @@ fn print_on_failure(state: &State) {
15781578
```
15791579
"##,
15801580

1581+
E0603: r##"
1582+
A private item was used outside its scope.
1583+
1584+
Erroneous code example:
1585+
1586+
```compile_fail,E0603
1587+
mod SomeModule {
1588+
const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
1589+
// can't use it outside of the
1590+
// `SomeModule` module.
1591+
}
1592+
1593+
println!("const value: {}", SomeModule::PRIVATE); // error: constant `CONSTANT`
1594+
// is private
1595+
```
1596+
1597+
In order to fix this error, you need to make the item public by using the `pub`
1598+
keyword. Example:
1599+
1600+
```
1601+
mod SomeModule {
1602+
pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
1603+
// `pub` keyword.
1604+
}
1605+
1606+
println!("const value: {}", SomeModule::PRIVATE); // ok!
1607+
```
1608+
"##,
1609+
15811610
}
15821611

15831612
register_diagnostics! {

src/librustc_resolve/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ impl<'a> Resolver<'a> {
34283428

34293429
for &PrivacyError(span, name, binding) in &self.privacy_errors {
34303430
if !reported_spans.insert(span) { continue }
3431-
self.session.span_err(span, &format!("{} `{}` is private", binding.descr(), name));
3431+
span_err!(self.session, span, E0603, "{} `{}` is private", binding.descr(), name);
34323432
}
34333433
}
34343434

src/test/compile-fail/E0603.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod SomeModule {
12+
const PRIVATE: u32 = 0x_a_bad_1dea_u32;
13+
}
14+
15+
fn main() {
16+
SomeModule::PRIVATE; //~ ERROR E0603
17+
}

src/test/ui/resolve/privacy-struct-ctor.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ error[E0423]: expected value, found struct `xcrate::S`
3535
help: possible better candidate is found in another module, you can import it into scope
3636
| use m::S;
3737

38-
error: tuple struct `Z` is private
38+
error[E0603]: tuple struct `Z` is private
3939
--> $DIR/privacy-struct-ctor.rs:25:9
4040
|
4141
25 | n::Z; //~ ERROR tuple struct `Z` is private
4242
| ^^^^
4343

44-
error: tuple struct `S` is private
44+
error[E0603]: tuple struct `S` is private
4545
--> $DIR/privacy-struct-ctor.rs:35:5
4646
|
4747
35 | m::S; //~ ERROR tuple struct `S` is private
4848
| ^^^^
4949

50-
error: tuple struct `Z` is private
50+
error[E0603]: tuple struct `Z` is private
5151
--> $DIR/privacy-struct-ctor.rs:39:5
5252
|
5353
39 | m::n::Z; //~ ERROR tuple struct `Z` is private
5454
| ^^^^^^^
5555

56-
error: tuple struct `S` is private
56+
error[E0603]: tuple struct `S` is private
5757
--> $DIR/privacy-struct-ctor.rs:41:5
5858
|
5959
41 | xcrate::m::S; //~ ERROR tuple struct `S` is private
6060
| ^^^^^^^^^^^^
6161

62-
error: tuple struct `Z` is private
62+
error[E0603]: tuple struct `Z` is private
6363
--> $DIR/privacy-struct-ctor.rs:45:5
6464
|
6565
45 | xcrate::m::n::Z; //~ ERROR tuple struct `Z` is private

0 commit comments

Comments
 (0)