From a056d5869e808b7f26cb536eca1aadda26a8188f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Sep 2015 12:08:21 +0200 Subject: [PATCH] Add error code for tuple struct constructor error --- src/librustc_privacy/diagnostics.rs | 24 ++++++++++++++++++++++++ src/librustc_privacy/lib.rs | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) 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"); } } }