From 94bbd46682fdf37aae7fe661e9f925649d439c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sun, 22 Mar 2020 11:18:06 -0700 Subject: [PATCH] Add span label to primary error span --- src/librustc_typeck/check/expr.rs | 5 ++-- src/test/ui/error-codes/E0615.stderr | 2 +- src/test/ui/error-codes/E0616.stderr | 4 ++-- src/test/ui/error-codes/ex-E0611.stderr | 4 ++-- src/test/ui/explore-issue-38412.stderr | 24 +++++++++---------- .../ui/hygiene/nested_macro_privacy.stderr | 4 ++-- src/test/ui/implicit-method-bind.stderr | 2 +- src/test/ui/issues/issue-13853-2.stderr | 2 +- src/test/ui/issues/issue-25386.rs | 4 ++-- src/test/ui/issues/issue-25386.stderr | 13 ++++------ src/test/ui/issues/issue-26472.stderr | 8 +++---- src/test/ui/issues/issue-3763.stderr | 12 +++++----- src/test/ui/issues/issue-54062.stderr | 4 ++-- src/test/ui/methods/assign-to-method.stderr | 4 ++-- .../ui/methods/method-missing-call.stderr | 4 ++-- src/test/ui/paren-span.stderr | 4 ++-- .../private-struct-field-cross-crate.stderr | 4 ++-- .../ui/privacy/private-struct-field.stderr | 4 ++-- src/test/ui/privacy/restricted/test.stderr | 12 +++++----- .../ui/privacy/union-field-privacy-2.stderr | 4 ++-- src/test/ui/proc-macro/issue-50493.stderr | 4 ++-- .../ui/structs/struct-field-privacy.stderr | 20 ++++++++-------- .../fn-or-tuple-struct-without-args.stderr | 4 ++-- .../method-missing-parentheses.stderr | 2 +- src/test/ui/union/union-suggest-field.stderr | 2 +- 25 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 617c54a738e..22e1a188dde 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -1583,13 +1583,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; 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 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { 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, diff --git a/src/test/ui/error-codes/E0615.stderr b/src/test/ui/error-codes/E0615.stderr index 039d736673c..1bc047dd356 100644 --- a/src/test/ui/error-codes/E0615.stderr +++ b/src/test/ui/error-codes/E0615.stderr @@ -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 | diff --git a/src/test/ui/error-codes/E0616.stderr b/src/test/ui/error-codes/E0616.stderr index 556e5db10a9..422bf687e7b 100644 --- a/src/test/ui/error-codes/E0616.stderr +++ b/src/test/ui/error-codes/E0616.stderr @@ -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 diff --git a/src/test/ui/error-codes/ex-E0611.stderr b/src/test/ui/error-codes/ex-E0611.stderr index 8bd00a392d4..2d22bb39514 100644 --- a/src/test/ui/error-codes/ex-E0611.stderr +++ b/src/test/ui/error-codes/ex-E0611.stderr @@ -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 diff --git a/src/test/ui/explore-issue-38412.stderr b/src/test/ui/explore-issue-38412.stderr index 94a2cfe013d..b3d9214d3d1 100644 --- a/src/test/ui/explore-issue-38412.stderr +++ b/src/test/ui/explore-issue-38412.stderr @@ -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 diff --git a/src/test/ui/hygiene/nested_macro_privacy.stderr b/src/test/ui/hygiene/nested_macro_privacy.stderr index 6e78cb86d80..482957a3264 100644 --- a/src/test/ui/hygiene/nested_macro_privacy.stderr +++ b/src/test/ui/hygiene/nested_macro_privacy.stderr @@ -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 diff --git a/src/test/ui/implicit-method-bind.stderr b/src/test/ui/implicit-method-bind.stderr index e9616f8317f..c6af47805ea 100644 --- a/src/test/ui/implicit-method-bind.stderr +++ b/src/test/ui/implicit-method-bind.stderr @@ -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 | diff --git a/src/test/ui/issues/issue-13853-2.stderr b/src/test/ui/issues/issue-13853-2.stderr index 264faa0da33..49b946b354e 100644 --- a/src/test/ui/issues/issue-13853-2.stderr +++ b/src/test/ui/issues/issue-13853-2.stderr @@ -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) { res.get } - | ^^^ + | ^^^ method, not a field | help: use parentheses to call the method | diff --git a/src/test/ui/issues/issue-25386.rs b/src/test/ui/issues/issue-25386.rs index 607c9fceab8..45775e0e4ae 100644 --- a/src/test/ui/issues/issue-25386.rs +++ b/src/test/ui/issues/issue-25386.rs @@ -17,12 +17,12 @@ mod stuff { 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 } diff --git a/src/test/ui/issues/issue-25386.stderr b/src/test/ui/issues/issue-25386.stderr index 76a4a5a493f..6419e7a5571 100644 --- a/src/test/ui/issues/issue-25386.stderr +++ b/src/test/ui/issues/issue-25386.stderr @@ -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 diff --git a/src/test/ui/issues/issue-26472.stderr b/src/test/ui/issues/issue-26472.stderr index 9073bfed894..f7df5b6232b 100644 --- a/src/test/ui/issues/issue-26472.stderr +++ b/src/test/ui/issues/issue-26472.stderr @@ -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 diff --git a/src/test/ui/issues/issue-3763.stderr b/src/test/ui/issues/issue-3763.stderr index d548477a88f..dab8f400156 100644 --- a/src/test/ui/issues/issue-3763.stderr +++ b/src/test/ui/issues/issue-3763.stderr @@ -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 diff --git a/src/test/ui/issues/issue-54062.stderr b/src/test/ui/issues/issue-54062.stderr index 5222e3ee95d..f9aef08c353 100644 --- a/src/test/ui/issues/issue-54062.stderr +++ b/src/test/ui/issues/issue-54062.stderr @@ -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 diff --git a/src/test/ui/methods/assign-to-method.stderr b/src/test/ui/methods/assign-to-method.stderr index c0dd529b681..cafe9abae04 100644 --- a/src/test/ui/methods/assign-to-method.stderr +++ b/src/test/ui/methods/assign-to-method.stderr @@ -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 diff --git a/src/test/ui/methods/method-missing-call.stderr b/src/test/ui/methods/method-missing-call.stderr index 23f8970e9e7..bc8a1c85e56 100644 --- a/src/test/ui/methods/method-missing-call.stderr +++ b/src/test/ui/methods/method-missing-call.stderr @@ -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 | diff --git a/src/test/ui/paren-span.stderr b/src/test/ui/paren-span.stderr index 141378752d6..ca22401f45b 100644 --- a/src/test/ui/paren-span.stderr +++ b/src/test/ui/paren-span.stderr @@ -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 diff --git a/src/test/ui/privacy/private-struct-field-cross-crate.stderr b/src/test/ui/privacy/private-struct-field-cross-crate.stderr index 857f2436aa8..ac00d82adab 100644 --- a/src/test/ui/privacy/private-struct-field-cross-crate.stderr +++ b/src/test/ui/privacy/private-struct-field-cross-crate.stderr @@ -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 diff --git a/src/test/ui/privacy/private-struct-field.stderr b/src/test/ui/privacy/private-struct-field.stderr index da53c73b431..c89ae507ab5 100644 --- a/src/test/ui/privacy/private-struct-field.stderr +++ b/src/test/ui/privacy/private-struct-field.stderr @@ -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 diff --git a/src/test/ui/privacy/restricted/test.stderr b/src/test/ui/privacy/restricted/test.stderr index e73f723ed0a..4d616a0b81b 100644 --- a/src/test/ui/privacy/restricted/test.stderr +++ b/src/test/ui/privacy/restricted/test.stderr @@ -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 diff --git a/src/test/ui/privacy/union-field-privacy-2.stderr b/src/test/ui/privacy/union-field-privacy-2.stderr index 8789178caac..a23cf90332b 100644 --- a/src/test/ui/privacy/union-field-privacy-2.stderr +++ b/src/test/ui/privacy/union-field-privacy-2.stderr @@ -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 diff --git a/src/test/ui/proc-macro/issue-50493.stderr b/src/test/ui/proc-macro/issue-50493.stderr index 7997786b50b..e378a567134 100644 --- a/src/test/ui/proc-macro/issue-50493.stderr +++ b/src/test/ui/proc-macro/issue-50493.stderr @@ -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) diff --git a/src/test/ui/structs/struct-field-privacy.stderr b/src/test/ui/structs/struct-field-privacy.stderr index 91d000b8672..f8b16ec0d01 100644 --- a/src/test/ui/structs/struct-field-privacy.stderr +++ b/src/test/ui/structs/struct-field-privacy.stderr @@ -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 diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index 69aef0853ce..b03bea1eddb 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -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 | diff --git a/src/test/ui/suggestions/method-missing-parentheses.stderr b/src/test/ui/suggestions/method-missing-parentheses.stderr index 75a6091d56e..04c67ec6a06 100644 --- a/src/test/ui/suggestions/method-missing-parentheses.stderr +++ b/src/test/ui/suggestions/method-missing-parentheses.stderr @@ -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::; - | ^^^^^^^ + | ^^^^^^^ method, not a field | help: use parentheses to call the method | diff --git a/src/test/ui/union/union-suggest-field.stderr b/src/test/ui/union/union-suggest-field.stderr index 6ab84c4836a..461db171206 100644 --- a/src/test/ui/union/union-suggest-field.stderr +++ b/src/test/ui/union/union-suggest-field.stderr @@ -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 |