diff --git a/src/librustc_privacy/diagnostics.rs b/src/librustc_privacy/diagnostics.rs index 78f5cc4bbf2..ac83ee2b029 100644 --- a/src/librustc_privacy/diagnostics.rs +++ b/src/librustc_privacy/diagnostics.rs @@ -125,4 +125,28 @@ To fix this error, please remove the visibility qualifier when it is not required. "##, +E0450: r##" +A tuple constructor was invoked while some of its fields are private. Erroneous +code example: + +``` +mod Bar { + pub struct Foo(isize); +} + +let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with + // private fields +``` + +To solve this issue, please ensure that all tuple's fields are public. Example: + +``` +mod Bar { + pub struct Foo(pub isize); // we set its field to public +} + +let f = Bar::Foo(0); // ok! +``` +"##, + } \ No newline at end of file diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 2dbab840ba2..9f5387dd9d6 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -931,9 +931,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { }); if any_priv { - self.tcx.sess.span_err(expr.span, - "cannot invoke tuple struct constructor \ - with private fields"); + span_err!(self.tcx.sess, expr.span, E0450, + "cannot invoke tuple struct constructor with private \ + fields"); } } }