Add span label to primary error span

This commit is contained in:
Esteban Küber 2020-03-22 11:18:06 -07:00
parent 52fbd3e569
commit 94bbd46682
25 changed files with 76 additions and 80 deletions

View File

@ -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,

View 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
|

View 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

View 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

View 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

View 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

View 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
|

View 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
|

View File

@ -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
}

View 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

View 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

View 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

View 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

View 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

View 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
|

View 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

View 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

View 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

View 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

View 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

View 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)

View 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

View 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
|

View 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
|

View 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
|