Skip to content

Commit

Permalink
Add span label to primary error span
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 22, 2020
1 parent 52fbd3e commit 94bbd46
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 80 deletions.
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0615.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0616.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/ex-E0611.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/explore-issue-38412.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/hygiene/nested_macro_privacy.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/implicit-method-bind.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-13853-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-25386.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 4 additions & 9 deletions src/test/ui/issues/issue-25386.stderr
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
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
|
= 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

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/issues/issue-26472.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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
|
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

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/issues/issue-3763.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-54062.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/methods/assign-to-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/methods/method-missing-call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/paren-span.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/privacy/private-struct-field-cross-crate.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/privacy/private-struct-field.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/privacy/restricted/test.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/privacy/union-field-privacy-2.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/proc-macro/issue-50493.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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)

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)

Expand Down
Loading

0 comments on commit 94bbd46

Please sign in to comment.