if let Some((did, field_ty)) = private_candidate {
let struct_path = self.tcx().item_path_str(did);
- let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
- let mut err = self.tcx().sess.struct_span_err(expr.span, &msg);
+ let mut err = struct_span_err!(self.tcx().sess, expr.span, E0616,
+ "field `{}` of struct `{}` is private",
+ field.node, struct_path);
// Also check if an accessible method exists, which is often what is meant.
if self.method_exists(field.span, field.node, expr_t, expr.id, false) {
err.note(&format!("a method `{}` also exists, perhaps you wish to call it",
pub fn new() -> Foo { Foo(0) }
// We add the getter function.
- pub fn get(&self) -> &u32 { self.0 }
+ pub fn get(&self) -> &u32 { &self.0 }
}
}
```
"##,
+E0616: r##"
+Attempted to access a private field on a struct.
+
+Erroneous code example:
+
+```compile_fail,E0616
+mod some_module {
+ pub struct Foo {
+ x: u32, // So `x` is private in here.
+ }
+
+ impl Foo {
+ pub fn new() -> Foo { Foo { x: 0 } }
+ }
+}
+
+let f = some_module::Foo::new();
+println!("{}", f.x); // error: field `x` of struct `some_module::Foo` is private
+```
+
+If you want to access this field, you have two options:
+
+1) Set the field public:
+
+```
+mod some_module {
+ pub struct Foo {
+ pub x: u32, // `x` is now public.
+ }
+
+ impl Foo {
+ pub fn new() -> Foo { Foo { x: 0 } }
+ }
+}
+
+let f = some_module::Foo::new();
+println!("{}", f.x); // ok!
+```
+
+2) Add a getter function:
+
+```
+mod some_module {
+ pub struct Foo {
+ x: u32, // So `x` is still private in here.
+ }
+
+ impl Foo {
+ pub fn new() -> Foo { Foo { x: 0 } }
+
+ // We create the getter function here:
+ pub fn get_x(&self) -> &u32 { &self.x }
+ }
+}
+
+let f = some_module::Foo::new();
+println!("{}", f.get_x()); // ok!
+```
+"##,
+
E0617: r##"
Attempted to pass an invalid type of variable into a variadic function.
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod a {
+ pub struct Foo {
+ x: u32,
+ }
+
+ impl Foo {
+ pub fn new() -> Foo { Foo { x: 0 } }
+ }
+}
+
+fn main() {
+ let f = a::Foo::new();
+ f.x; //~ ERROR E0616
+}