Skip to content

Commit 5e9bfcd

Browse files
Add new error code for trait privacy error
1 parent a7d63fd commit 5e9bfcd

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/librustc_privacy/diagnostics.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2014 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+
#![allow(non_snake_case)]
12+
13+
register_long_diagnostics! {
14+
15+
E0445: r##"
16+
A private trait was used on a "public" type. Erroneous code example:
17+
18+
```
19+
trait Foo {
20+
fn dummy(&self) { }
21+
}
22+
23+
pub trait Bar : Foo {} // error: private trait in exported type parameter bound
24+
```
25+
26+
To solve this error, please ensure the trait is accessible at the same level of
27+
the type(s) on which it's implemented. Example:
28+
29+
```
30+
pub trait Foo { // we set the Foo trait public
31+
fn dummy(&self) { }
32+
}
33+
34+
pub trait Bar : Foo {} // ok!
35+
```
36+
"##,
37+
38+
}

src/librustc_privacy/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,8 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
11931193
if !self.tcx.sess.features.borrow().visible_private_types &&
11941194
self.path_is_private_type(trait_ref.trait_ref.ref_id) {
11951195
let span = trait_ref.trait_ref.path.span;
1196-
self.tcx.sess.span_err(span, "private trait in exported type \
1197-
parameter bound");
1196+
span_err!(self.tcx.sess, span, E0445,
1197+
"private trait in exported type parameter bound");
11981198
}
11991199
}
12001200
}

0 commit comments

Comments
 (0)