Skip to content

Commit a056d58

Browse files
Add error code for tuple struct constructor error
1 parent 6090cea commit a056d58

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/librustc_privacy/diagnostics.rs

+24
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,28 @@ To fix this error, please remove the visibility qualifier when it is not
125125
required.
126126
"##,
127127

128+
E0450: r##"
129+
A tuple constructor was invoked while some of its fields are private. Erroneous
130+
code example:
131+
132+
```
133+
mod Bar {
134+
pub struct Foo(isize);
135+
}
136+
137+
let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with
138+
// private fields
139+
```
140+
141+
To solve this issue, please ensure that all tuple's fields are public. Example:
142+
143+
```
144+
mod Bar {
145+
pub struct Foo(pub isize); // we set its field to public
146+
}
147+
148+
let f = Bar::Foo(0); // ok!
149+
```
150+
"##,
151+
128152
}

src/librustc_privacy/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
931931
});
932932

933933
if any_priv {
934-
self.tcx.sess.span_err(expr.span,
935-
"cannot invoke tuple struct constructor \
936-
with private fields");
934+
span_err!(self.tcx.sess, expr.span, E0450,
935+
"cannot invoke tuple struct constructor with private \
936+
fields");
937937
}
938938
}
939939
}

0 commit comments

Comments
 (0)