]> git.lizzy.rs Git - rust.git/commitdiff
Add span label to primary error span
authorEsteban Küber <esteban@kuber.com.ar>
Sun, 22 Mar 2020 18:18:06 +0000 (11:18 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Sun, 22 Mar 2020 18:18:06 +0000 (11:18 -0700)
25 files changed:
src/librustc_typeck/check/expr.rs
src/test/ui/error-codes/E0615.stderr
src/test/ui/error-codes/E0616.stderr
src/test/ui/error-codes/ex-E0611.stderr
src/test/ui/explore-issue-38412.stderr
src/test/ui/hygiene/nested_macro_privacy.stderr
src/test/ui/implicit-method-bind.stderr
src/test/ui/issues/issue-13853-2.stderr
src/test/ui/issues/issue-25386.rs
src/test/ui/issues/issue-25386.stderr
src/test/ui/issues/issue-26472.stderr
src/test/ui/issues/issue-3763.stderr
src/test/ui/issues/issue-54062.stderr
src/test/ui/methods/assign-to-method.stderr
src/test/ui/methods/method-missing-call.stderr
src/test/ui/paren-span.stderr
src/test/ui/privacy/private-struct-field-cross-crate.stderr
src/test/ui/privacy/private-struct-field.stderr
src/test/ui/privacy/restricted/test.stderr
src/test/ui/privacy/union-field-privacy-2.stderr
src/test/ui/proc-macro/issue-50493.stderr
src/test/ui/structs/struct-field-privacy.stderr
src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr
src/test/ui/suggestions/method-missing-parentheses.stderr
src/test/ui/union/union-suggest-field.stderr

index 617c54a738e6eaf2b7298160cb6f5cfa93dbf241..22e1a188ddef1c4a9aca394562603655e6a690a1 100644 (file)
@@ -1583,13 +1583,14 @@ fn ban_private_field_access(
         };
         let mut err = struct_span_err!(
             self.tcx().sess,
-            expr.span,
+            field.span,
             E0616,
             "field `{}` of {} `{}` is private",
             field,
             kind_name,
             struct_path
         );
+        err.span_label(field.span, "private field");
         // Also check if an accessible method exists, which is often what is meant.
         if self.method_exists(field, expr_t, expr.hir_id, false) && !self.expr_in_place(expr.hir_id)
         {
@@ -1614,7 +1615,7 @@ fn ban_take_value_of_method(&self, expr: &hir::Expr<'_>, expr_t: Ty<'tcx>, field
             field,
             expr_t
         );
-
+        err.span_label(field.span, "method, not a field");
         if !self.expr_in_place(expr.hir_id) {
             self.suggest_method_call(
                 &mut err,
index 039d736673c08385c88df2894b65f8a217641fd7..1bc047dd356e03547dac219ec2692fda245cdddd 100644 (file)
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `method` on type `Foo`
   --> $DIR/E0615.rs:11:7
    |
 LL |     f.method;
-   |       ^^^^^^
+   |       ^^^^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 556e5db10a944fd3c53b93d821d3043b3e8237f7..422bf687e7bd43c080daf65f2d56db62f9e99494 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `x` of struct `a::Foo` is private
-  --> $DIR/E0616.rs:13:5
+  --> $DIR/E0616.rs:13:7
    |
 LL |     f.x;
-   |     ^^^
+   |       ^ private field
 
 error: aborting due to previous error
 
index 8bd00a392d4f809ecc25b258e4130550e1a29901..2d22bb395140b369966d033ce7c4ed1964b39384 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `0` of struct `a::Foo` is private
-  --> $DIR/ex-E0611.rs:11:4
+  --> $DIR/ex-E0611.rs:11:6
    |
 LL |    y.0;
-   |    ^^^
+   |      ^ private field
 
 error: aborting due to previous error
 
index 94a2cfe013d190778b696ab943611b3365f63fbc..b3d9214d3d12134b669ca76a96e65837a4cc6461 100644 (file)
@@ -17,22 +17,22 @@ LL |     r.a_unstable_undeclared_pub;
    = help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
 
 error[E0616]: field `b_crate` of struct `pub_and_stability::Record` is private
-  --> $DIR/explore-issue-38412.rs:31:5
+  --> $DIR/explore-issue-38412.rs:31:7
    |
 LL |     r.b_crate;
-   |     ^^^^^^^^^
+   |       ^^^^^^^ private field
 
 error[E0616]: field `c_mod` of struct `pub_and_stability::Record` is private
-  --> $DIR/explore-issue-38412.rs:32:5
+  --> $DIR/explore-issue-38412.rs:32:7
    |
 LL |     r.c_mod;
-   |     ^^^^^^^
+   |       ^^^^^ private field
 
 error[E0616]: field `d_priv` of struct `pub_and_stability::Record` is private
-  --> $DIR/explore-issue-38412.rs:33:5
+  --> $DIR/explore-issue-38412.rs:33:7
    |
 LL |     r.d_priv;
-   |     ^^^^^^^^
+   |       ^^^^^^ private field
 
 error[E0658]: use of unstable library feature 'unstable_undeclared'
   --> $DIR/explore-issue-38412.rs:37:5
@@ -44,22 +44,22 @@ LL |     t.2;
    = help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
 
 error[E0616]: field `3` of struct `pub_and_stability::Tuple` is private
-  --> $DIR/explore-issue-38412.rs:38:5
+  --> $DIR/explore-issue-38412.rs:38:7
    |
 LL |     t.3;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `4` of struct `pub_and_stability::Tuple` is private
-  --> $DIR/explore-issue-38412.rs:39:5
+  --> $DIR/explore-issue-38412.rs:39:7
    |
 LL |     t.4;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `5` of struct `pub_and_stability::Tuple` is private
-  --> $DIR/explore-issue-38412.rs:40:5
+  --> $DIR/explore-issue-38412.rs:40:7
    |
 LL |     t.5;
-   |     ^^^
+   |       ^ private field
 
 error[E0658]: use of unstable library feature 'unstable_undeclared'
   --> $DIR/explore-issue-38412.rs:44:7
index 6e78cb86d80f44034d770c8b3053749e9d34b5a9..482957a326437eaca84528d07ab8abc979b6f099 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `i` of struct `foo::S` is private
-  --> $DIR/nested_macro_privacy.rs:15:5
+  --> $DIR/nested_macro_privacy.rs:15:18
    |
 LL |     S::default().i;
-   |     ^^^^^^^^^^^^^^
+   |                  ^ private field
 
 error: aborting due to previous error
 
index e9616f8317f916ca25c98f1bb70d2560ae772d23..c6af47805ea5bdfd4f5983f5d2d0cc094528835a 100644 (file)
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `abs` on type `i32`
   --> $DIR/implicit-method-bind.rs:2:20
    |
 LL |     let _f = 10i32.abs;
-   |                    ^^^
+   |                    ^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 264faa0da333b71121cff022105f60d316e1693e..49b946b354e53a8b51ed38c7d073ddac14a38648 100644 (file)
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `get` on type `std::boxed::Box<(
   --> $DIR/issue-13853-2.rs:5:43
    |
 LL | fn foo(res : Box<dyn ResponseHook>) { res.get }
-   |                                           ^^^
+   |                                           ^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 607c9fceab84f304dbe74692ea5e84cdcff28d99..45775e0e4ae36d786f8126b17f8666a577112f48 100644 (file)
@@ -17,12 +17,12 @@ pub fn new() -> Item {
 macro_rules! check_ptr_exist {
     ($var:expr, $member:ident) => (
         (*$var.c_object).$member.is_some()
-        //~^ ERROR field `name` of struct `stuff::CObj` is private
-        //~^^ ERROR field `c_object` of struct `stuff::Item` is private
+        //~^ ERROR field `c_object` of struct `stuff::Item` is private
     );
 }
 
 fn main() {
     let item = stuff::Item::new();
     println!("{}", check_ptr_exist!(item, name));
+    //~^ ERROR field `name` of struct `stuff::CObj` is private
 }
index 76a4a5a493f5925e5d943cf3827508969cafe281..6419e7a557194a50b226f0e6421115fad128cb92 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `c_object` of struct `stuff::Item` is private
-  --> $DIR/issue-25386.rs:19:11
+  --> $DIR/issue-25386.rs:19:16
    |
 LL |         (*$var.c_object).$member.is_some()
-   |           ^^^^^^^^^^^^^
+   |                ^^^^^^^^ private field
 ...
 LL |     println!("{}", check_ptr_exist!(item, name));
    |                    ---------------------------- in this macro invocation
@@ -10,15 +10,10 @@ LL |     println!("{}", check_ptr_exist!(item, name));
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0616]: field `name` of struct `stuff::CObj` is private
-  --> $DIR/issue-25386.rs:19:9
+  --> $DIR/issue-25386.rs:26:43
    |
-LL |         (*$var.c_object).$member.is_some()
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^
-...
 LL |     println!("{}", check_ptr_exist!(item, name));
-   |                    ---------------------------- in this macro invocation
-   |
-   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+   |                                           ^^^^ private field
 
 error: aborting due to 2 previous errors
 
index 9073bfed8948ee50cccd2c310e95a13c9052fc9a..f7df5b6232bdac9780aebf84c7965c1e83da75fa 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `len` of struct `sub::S` is private
-  --> $DIR/issue-26472.rs:11:13
+  --> $DIR/issue-26472.rs:11:15
    |
 LL |     let v = s.len;
-   |             ^^^^^
+   |               ^^^ private field
    |
 help: a method `len` also exists, call it with parentheses
    |
@@ -10,10 +10,10 @@ LL |     let v = s.len();
    |                  ^^
 
 error[E0616]: field `len` of struct `sub::S` is private
-  --> $DIR/issue-26472.rs:12:5
+  --> $DIR/issue-26472.rs:12:7
    |
 LL |     s.len = v;
-   |     ^^^^^
+   |       ^^^ private field
 
 error: aborting due to 2 previous errors
 
index d548477a88ff80d1b1f585ce65771065704d4931..dab8f40015621f641667d23ddc8b5310b3d6159d 100644 (file)
@@ -1,14 +1,14 @@
 error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
-  --> $DIR/issue-3763.rs:18:19
+  --> $DIR/issue-3763.rs:18:32
    |
 LL |     let _woohoo = (&my_struct).priv_field;
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^
+   |                                ^^^^^^^^^^ private field
 
 error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
-  --> $DIR/issue-3763.rs:21:19
+  --> $DIR/issue-3763.rs:21:41
    |
 LL |     let _woohoo = (Box::new(my_struct)).priv_field;
-   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |                                         ^^^^^^^^^^ private field
 
 error[E0624]: associated function `happyfun` is private
   --> $DIR/issue-3763.rs:24:18
@@ -23,10 +23,10 @@ LL |     (Box::new(my_struct)).happyfun();
    |                           ^^^^^^^^
 
 error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
-  --> $DIR/issue-3763.rs:27:16
+  --> $DIR/issue-3763.rs:27:26
    |
 LL |     let nope = my_struct.priv_field;
-   |                ^^^^^^^^^^^^^^^^^^^^
+   |                          ^^^^^^^^^^ private field
 
 error: aborting due to 5 previous errors
 
index 5222e3ee95d5945bd52330be98219e17896356ec..f9aef08c353bb07c9500d7f9fef457d33c1bd028 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `inner` of struct `std::sync::Mutex` is private
-  --> $DIR/issue-54062.rs:10:13
+  --> $DIR/issue-54062.rs:10:24
    |
 LL |     let _ = test.comps.inner.lock().unwrap();
-   |             ^^^^^^^^^^^^^^^^
+   |                        ^^^^^ private field
 
 error[E0599]: no method named `unwrap` found for struct `std::sys_common::mutex::MutexGuard<'_>` in the current scope
   --> $DIR/issue-54062.rs:10:37
index c0dd529b6818ff9c7d9e3f02ece636c7fe8c9ca1..cafe9abae045dd0cf4b09ead6bd3f409290f9b29 100644 (file)
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `speak` on type `Cat`
   --> $DIR/assign-to-method.rs:22:10
    |
 LL |     nyan.speak = || println!("meow");
-   |          ^^^^^
+   |          ^^^^^ method, not a field
    |
    = help: methods are immutable and cannot be assigned to
 
@@ -10,7 +10,7 @@ error[E0615]: attempted to take value of method `speak` on type `Cat`
   --> $DIR/assign-to-method.rs:23:10
    |
 LL |     nyan.speak += || println!("meow");
-   |          ^^^^^
+   |          ^^^^^ method, not a field
    |
    = help: methods are immutable and cannot be assigned to
 
index 23f8970e9e79080714c9c1b000796f068b9c5a6e..bc8a1c85e561a354b75cbe16e09331e631ad4dc2 100644 (file)
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `get_x` on type `Point`
   --> $DIR/method-missing-call.rs:22:26
    |
 LL |                         .get_x;
-   |                          ^^^^^
+   |                          ^^^^^ method, not a field
    |
 help: use parentheses to call the method
    |
@@ -13,7 +13,7 @@ error[E0615]: attempted to take value of method `filter_map` on type `std::iter:
   --> $DIR/method-missing-call.rs:29:16
    |
 LL |               .filter_map;
-   |                ^^^^^^^^^^
+   |                ^^^^^^^^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 141378752d6f4102238bd7489a15f727606eee8c..ca22401f45bb47b6b27f2d542a6db3413b91cf9a 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `x` of struct `m::S` is private
-  --> $DIR/paren-span.rs:19:12
+  --> $DIR/paren-span.rs:19:14
    |
 LL |     paren!(s.x);
-   |            ^^^
+   |              ^ private field
 
 error: aborting due to previous error
 
index 857f2436aa82949d8cfb38b26aa91484ccd18bd1..ac00d82adab42e54f034de5f50b873c5b86f07aa 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `meows` of struct `cci_class::kitties::cat` is private
-  --> $DIR/private-struct-field-cross-crate.rs:7:14
+  --> $DIR/private-struct-field-cross-crate.rs:7:19
    |
 LL |   assert_eq!(nyan.meows, 52);
-   |              ^^^^^^^^^^
+   |                   ^^^^^ private field
 
 error: aborting due to previous error
 
index da53c73b4311c513698dd30dbbbf55cca6a52908..c89ae507ab5fd8a93b0946b3f951a1a8d97e138a 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `meows` of struct `cat::Cat` is private
-  --> $DIR/private-struct-field.rs:13:16
+  --> $DIR/private-struct-field.rs:13:21
    |
 LL |     assert_eq!(nyan.meows, 52);
-   |                ^^^^^^^^^^
+   |                     ^^^^^ private field
 
 error: aborting due to previous error
 
index e73f723ed0ab63bf7e65c31eb4d87fc1307d304f..4d616a0b81b1b63098d2eabd01a6611bfa8438cc 100644 (file)
@@ -47,10 +47,10 @@ LL |         pub(super) fn f() {}
    |         ^^^^^^^^^^^^^^^^^
 
 error[E0616]: field `x` of struct `foo::bar::S` is private
-  --> $DIR/test.rs:31:5
+  --> $DIR/test.rs:31:18
    |
 LL |     S::default().x;
-   |     ^^^^^^^^^^^^^^
+   |                  ^ private field
 
 error[E0624]: associated function `f` is private
   --> $DIR/test.rs:32:18
@@ -65,16 +65,16 @@ LL |     S::g();
    |     ^^^^
 
 error[E0616]: field `y` of struct `pub_restricted::Universe` is private
-  --> $DIR/test.rs:42:13
+  --> $DIR/test.rs:42:15
    |
 LL |     let _ = u.y;
-   |             ^^^
+   |               ^ private field
 
 error[E0616]: field `z` of struct `pub_restricted::Universe` is private
-  --> $DIR/test.rs:43:13
+  --> $DIR/test.rs:43:15
    |
 LL |     let _ = u.z;
-   |             ^^^
+   |               ^ private field
 
 error[E0624]: associated function `g` is private
   --> $DIR/test.rs:45:7
index 8789178caac26cc8bf7973669f0fb18b2b7236e6..a23cf90332b02e4b7b4f8844a9b1679568bd7a11 100644 (file)
@@ -1,8 +1,8 @@
 error[E0616]: field `c` of union `m::U` is private
-  --> $DIR/union-field-privacy-2.rs:14:13
+  --> $DIR/union-field-privacy-2.rs:14:15
    |
 LL |     let c = u.c;
-   |             ^^^
+   |               ^ private field
 
 error: aborting due to previous error
 
index 7997786b50bc97e552eb2f4af04ff10fe07a886a..e378a56713400b7d1323c10a1d7d1745fab521ef 100644 (file)
@@ -8,7 +8,7 @@ error[E0616]: field `field` of struct `Restricted` is private
   --> $DIR/issue-50493.rs:6:10
    |
 LL | #[derive(Derive)]
-   |          ^^^^^^
+   |          ^^^^^^ private field
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
@@ -16,7 +16,7 @@ error[E0616]: field `field` of struct `Restricted` is private
   --> $DIR/issue-50493.rs:6:10
    |
 LL | #[derive(Derive)]
-   |          ^^^^^^
+   |          ^^^^^^ private field
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
index 91d000b8672e0f97536b1ba8a723b1738fa27ce4..f8b16ec0d01b34a33d9ea7d01aa558d8d8779ae8 100644 (file)
@@ -1,32 +1,32 @@
 error[E0616]: field `a` of struct `inner::A` is private
-  --> $DIR/struct-field-privacy.rs:23:5
+  --> $DIR/struct-field-privacy.rs:23:7
    |
 LL |     b.a;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `b` of struct `inner::B` is private
-  --> $DIR/struct-field-privacy.rs:26:5
+  --> $DIR/struct-field-privacy.rs:26:7
    |
 LL |     c.b;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `a` of struct `xc::A` is private
-  --> $DIR/struct-field-privacy.rs:28:5
+  --> $DIR/struct-field-privacy.rs:28:7
    |
 LL |     d.a;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `b` of struct `xc::B` is private
-  --> $DIR/struct-field-privacy.rs:32:5
+  --> $DIR/struct-field-privacy.rs:32:7
    |
 LL |     e.b;
-   |     ^^^
+   |       ^ private field
 
 error[E0616]: field `1` of struct `inner::Z` is private
-  --> $DIR/struct-field-privacy.rs:35:5
+  --> $DIR/struct-field-privacy.rs:35:7
    |
 LL |     z.1;
-   |     ^^^
+   |       ^ private field
 
 error: aborting due to 5 previous errors
 
index 69aef0853cec3ceb305ea07edcabd9f0ccc5520c..b03bea1eddbf08391a6531e223912e3ae95e4c6a 100644 (file)
@@ -250,7 +250,7 @@ error[E0615]: attempted to take value of method `ban` on type `X`
   --> $DIR/fn-or-tuple-struct-without-args.rs:43:22
    |
 LL |     let _: usize = X.ban;
-   |                      ^^^
+   |                      ^^^ method, not a field
    |
 help: use parentheses to call the method
    |
@@ -261,7 +261,7 @@ error[E0615]: attempted to take value of method `bal` on type `X`
   --> $DIR/fn-or-tuple-struct-without-args.rs:44:22
    |
 LL |     let _: usize = X.bal;
-   |                      ^^^
+   |                      ^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 75a6091d56e93139aecde640daa3b0285b996f81..04c67ec6a06b6a7b7eb89e5476e751f53aee7bdf 100644 (file)
@@ -8,7 +8,7 @@ error[E0615]: attempted to take value of method `collect` on type `std::vec::Int
   --> $DIR/method-missing-parentheses.rs:2:32
    |
 LL |     let _ = vec![].into_iter().collect::<usize>;
-   |                                ^^^^^^^
+   |                                ^^^^^^^ method, not a field
    |
 help: use parentheses to call the method
    |
index 6ab84c4836af1e685d079dcb432c945f66403489..461db1712064fdcdcb698ba537908e95d42e1169 100644 (file)
@@ -14,7 +14,7 @@ error[E0615]: attempted to take value of method `calculate` on type `U`
   --> $DIR/union-suggest-field.rs:18:15
    |
 LL |     let y = u.calculate;
-   |               ^^^^^^^^^
+   |               ^^^^^^^^^ method, not a field
    |
 help: use parentheses to call the method
    |