From bf3ff77ec8c2049c3523842e341036a2c4c2281d Mon Sep 17 00:00:00 2001 From: rphmeier Date: Tue, 16 Feb 2016 20:31:52 -0500 Subject: [PATCH 1/2] Fix #31706 --- src/librustc_privacy/lib.rs | 2 +- src/test/compile-fail/privacy5.rs | 36 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 85c2fe0c0a5..865ecd79e27 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -710,7 +710,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { NamedField(name) => format!("field `{}` of {} is private", name, struct_desc), UnnamedField(idx) => format!("field #{} of {} is private", - idx + 1, struct_desc), + idx, struct_desc), }; span_err!(self.tcx.sess, span, E0451, "{}", &msg[..]); diff --git a/src/test/compile-fail/privacy5.rs b/src/test/compile-fail/privacy5.rs index 83e13ff52f6..588c9be3065 100644 --- a/src/test/compile-fail/privacy5.rs +++ b/src/test/compile-fail/privacy5.rs @@ -63,25 +63,25 @@ fn this_crate() { let c = a::C(2, 3); //~ ERROR: cannot invoke tuple struct constructor let d = a::D(4); - let a::A(()) = a; //~ ERROR: field #1 of struct `a::A` is private + let a::A(()) = a; //~ ERROR: field #0 of struct `a::A` is private let a::A(_) = a; - match a { a::A(()) => {} } //~ ERROR: field #1 of struct `a::A` is private + match a { a::A(()) => {} } //~ ERROR: field #0 of struct `a::A` is private match a { a::A(_) => {} } let a::B(_) = b; - let a::B(_b) = b; //~ ERROR: field #1 of struct `a::B` is private + let a::B(_b) = b; //~ ERROR: field #0 of struct `a::B` is private match b { a::B(_) => {} } - match b { a::B(_b) => {} } //~ ERROR: field #1 of struct `a::B` is private - match b { a::B(1) => {} a::B(_) => {} } //~ ERROR: field #1 of struct `a::B` is private + match b { a::B(_b) => {} } //~ ERROR: field #0 of struct `a::B` is private + match b { a::B(1) => {} a::B(_) => {} } //~ ERROR: field #0 of struct `a::B` is private let a::C(_, _) = c; let a::C(_a, _) = c; - let a::C(_, _b) = c; //~ ERROR: field #2 of struct `a::C` is private - let a::C(_a, _b) = c; //~ ERROR: field #2 of struct `a::C` is private + let a::C(_, _b) = c; //~ ERROR: field #1 of struct `a::C` is private + let a::C(_a, _b) = c; //~ ERROR: field #1 of struct `a::C` is private match c { a::C(_, _) => {} } match c { a::C(_a, _) => {} } - match c { a::C(_, _b) => {} } //~ ERROR: field #2 of struct `a::C` is private - match c { a::C(_a, _b) => {} } //~ ERROR: field #2 of struct `a::C` is private + match c { a::C(_, _b) => {} } //~ ERROR: field #1 of struct `a::C` is private + match c { a::C(_a, _b) => {} } //~ ERROR: field #1 of struct `a::C` is private let a::D(_) = d; let a::D(_d) = d; @@ -101,30 +101,30 @@ fn xcrate() { let c = other::C(2, 3); //~ ERROR: cannot invoke tuple struct constructor let d = other::D(4); - let other::A(()) = a; //~ ERROR: field #1 of struct `other::A` is private + let other::A(()) = a; //~ ERROR: field #0 of struct `other::A` is private let other::A(_) = a; match a { other::A(()) => {} } - //~^ ERROR: field #1 of struct `other::A` is private + //~^ ERROR: field #0 of struct `other::A` is private match a { other::A(_) => {} } let other::B(_) = b; - let other::B(_b) = b; //~ ERROR: field #1 of struct `other::B` is private + let other::B(_b) = b; //~ ERROR: field #0 of struct `other::B` is private match b { other::B(_) => {} } match b { other::B(_b) => {} } - //~^ ERROR: field #1 of struct `other::B` is private + //~^ ERROR: field #0 of struct `other::B` is private match b { other::B(1) => {} other::B(_) => {} } - //~^ ERROR: field #1 of struct `other::B` is private + //~^ ERROR: field #0 of struct `other::B` is private let other::C(_, _) = c; let other::C(_a, _) = c; - let other::C(_, _b) = c; //~ ERROR: field #2 of struct `other::C` is private - let other::C(_a, _b) = c; //~ ERROR: field #2 of struct `other::C` is private + let other::C(_, _b) = c; //~ ERROR: field #1 of struct `other::C` is private + let other::C(_a, _b) = c; //~ ERROR: field #1 of struct `other::C` is private match c { other::C(_, _) => {} } match c { other::C(_a, _) => {} } match c { other::C(_, _b) => {} } - //~^ ERROR: field #2 of struct `other::C` is private + //~^ ERROR: field #1 of struct `other::C` is private match c { other::C(_a, _b) => {} } - //~^ ERROR: field #2 of struct `other::C` is private + //~^ ERROR: field #1 of struct `other::C` is private let other::D(_) = d; let other::D(_d) = d; From 94499e3385fd42b2dbc75614e867183dd63c529a Mon Sep 17 00:00:00 2001 From: rphmeier Date: Tue, 16 Feb 2016 21:31:50 -0500 Subject: [PATCH 2/2] Fix sentence in E0451 diagnostic. --- src/librustc_privacy/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_privacy/diagnostics.rs b/src/librustc_privacy/diagnostics.rs index d124ead5091..673960338ea 100644 --- a/src/librustc_privacy/diagnostics.rs +++ b/src/librustc_privacy/diagnostics.rs @@ -205,8 +205,8 @@ let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo` // is private ``` -To fix this error, please ensure that all the fields of the struct, or -implement a function for easy instantiation. Examples: +To fix this error, please ensure that all the fields of the struct are public, +or implement a function for easy instantiation. Examples: ``` mod Bar {