Skip to content

Commit 94bbd46

Browse files
committed
Add span label to primary error span
1 parent 52fbd3e commit 94bbd46

25 files changed

+76
-80
lines changed

src/librustc_typeck/check/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,13 +1583,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15831583
};
15841584
let mut err = struct_span_err!(
15851585
self.tcx().sess,
1586-
expr.span,
1586+
field.span,
15871587
E0616,
15881588
"field `{}` of {} `{}` is private",
15891589
field,
15901590
kind_name,
15911591
struct_path
15921592
);
1593+
err.span_label(field.span, "private field");
15931594
// Also check if an accessible method exists, which is often what is meant.
15941595
if self.method_exists(field, expr_t, expr.hir_id, false) && !self.expr_in_place(expr.hir_id)
15951596
{
@@ -1614,7 +1615,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16141615
field,
16151616
expr_t
16161617
);
1617-
1618+
err.span_label(field.span, "method, not a field");
16181619
if !self.expr_in_place(expr.hir_id) {
16191620
self.suggest_method_call(
16201621
&mut err,

src/test/ui/error-codes/E0615.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `method` on type `Foo`
22
--> $DIR/E0615.rs:11:7
33
|
44
LL | f.method;
5-
| ^^^^^^
5+
| ^^^^^^ method, not a field
66
|
77
help: use parentheses to call the method
88
|

src/test/ui/error-codes/E0616.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `x` of struct `a::Foo` is private
2-
--> $DIR/E0616.rs:13:5
2+
--> $DIR/E0616.rs:13:7
33
|
44
LL | f.x;
5-
| ^^^
5+
| ^ private field
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/ex-E0611.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `0` of struct `a::Foo` is private
2-
--> $DIR/ex-E0611.rs:11:4
2+
--> $DIR/ex-E0611.rs:11:6
33
|
44
LL | y.0;
5-
| ^^^
5+
| ^ private field
66

77
error: aborting due to previous error
88

src/test/ui/explore-issue-38412.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ LL | r.a_unstable_undeclared_pub;
1717
= help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
1818

1919
error[E0616]: field `b_crate` of struct `pub_and_stability::Record` is private
20-
--> $DIR/explore-issue-38412.rs:31:5
20+
--> $DIR/explore-issue-38412.rs:31:7
2121
|
2222
LL | r.b_crate;
23-
| ^^^^^^^^^
23+
| ^^^^^^^ private field
2424

2525
error[E0616]: field `c_mod` of struct `pub_and_stability::Record` is private
26-
--> $DIR/explore-issue-38412.rs:32:5
26+
--> $DIR/explore-issue-38412.rs:32:7
2727
|
2828
LL | r.c_mod;
29-
| ^^^^^^^
29+
| ^^^^^ private field
3030

3131
error[E0616]: field `d_priv` of struct `pub_and_stability::Record` is private
32-
--> $DIR/explore-issue-38412.rs:33:5
32+
--> $DIR/explore-issue-38412.rs:33:7
3333
|
3434
LL | r.d_priv;
35-
| ^^^^^^^^
35+
| ^^^^^^ private field
3636

3737
error[E0658]: use of unstable library feature 'unstable_undeclared'
3838
--> $DIR/explore-issue-38412.rs:37:5
@@ -44,22 +44,22 @@ LL | t.2;
4444
= help: add `#![feature(unstable_undeclared)]` to the crate attributes to enable
4545

4646
error[E0616]: field `3` of struct `pub_and_stability::Tuple` is private
47-
--> $DIR/explore-issue-38412.rs:38:5
47+
--> $DIR/explore-issue-38412.rs:38:7
4848
|
4949
LL | t.3;
50-
| ^^^
50+
| ^ private field
5151

5252
error[E0616]: field `4` of struct `pub_and_stability::Tuple` is private
53-
--> $DIR/explore-issue-38412.rs:39:5
53+
--> $DIR/explore-issue-38412.rs:39:7
5454
|
5555
LL | t.4;
56-
| ^^^
56+
| ^ private field
5757

5858
error[E0616]: field `5` of struct `pub_and_stability::Tuple` is private
59-
--> $DIR/explore-issue-38412.rs:40:5
59+
--> $DIR/explore-issue-38412.rs:40:7
6060
|
6161
LL | t.5;
62-
| ^^^
62+
| ^ private field
6363

6464
error[E0658]: use of unstable library feature 'unstable_undeclared'
6565
--> $DIR/explore-issue-38412.rs:44:7

src/test/ui/hygiene/nested_macro_privacy.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `i` of struct `foo::S` is private
2-
--> $DIR/nested_macro_privacy.rs:15:5
2+
--> $DIR/nested_macro_privacy.rs:15:18
33
|
44
LL | S::default().i;
5-
| ^^^^^^^^^^^^^^
5+
| ^ private field
66

77
error: aborting due to previous error
88

src/test/ui/implicit-method-bind.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `abs` on type `i32`
22
--> $DIR/implicit-method-bind.rs:2:20
33
|
44
LL | let _f = 10i32.abs;
5-
| ^^^
5+
| ^^^ method, not a field
66
|
77
help: use parentheses to call the method
88
|

src/test/ui/issues/issue-13853-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `get` on type `std::boxed::Box<(
22
--> $DIR/issue-13853-2.rs:5:43
33
|
44
LL | fn foo(res : Box<dyn ResponseHook>) { res.get }
5-
| ^^^
5+
| ^^^ method, not a field
66
|
77
help: use parentheses to call the method
88
|

src/test/ui/issues/issue-25386.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ mod stuff {
1717
macro_rules! check_ptr_exist {
1818
($var:expr, $member:ident) => (
1919
(*$var.c_object).$member.is_some()
20-
//~^ ERROR field `name` of struct `stuff::CObj` is private
21-
//~^^ ERROR field `c_object` of struct `stuff::Item` is private
20+
//~^ ERROR field `c_object` of struct `stuff::Item` is private
2221
);
2322
}
2423

2524
fn main() {
2625
let item = stuff::Item::new();
2726
println!("{}", check_ptr_exist!(item, name));
27+
//~^ ERROR field `name` of struct `stuff::CObj` is private
2828
}

src/test/ui/issues/issue-25386.stderr

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
error[E0616]: field `c_object` of struct `stuff::Item` is private
2-
--> $DIR/issue-25386.rs:19:11
2+
--> $DIR/issue-25386.rs:19:16
33
|
44
LL | (*$var.c_object).$member.is_some()
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^ private field
66
...
77
LL | println!("{}", check_ptr_exist!(item, name));
88
| ---------------------------- in this macro invocation
99
|
1010
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error[E0616]: field `name` of struct `stuff::CObj` is private
13-
--> $DIR/issue-25386.rs:19:9
13+
--> $DIR/issue-25386.rs:26:43
1414
|
15-
LL | (*$var.c_object).$member.is_some()
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^
17-
...
1815
LL | println!("{}", check_ptr_exist!(item, name));
19-
| ---------------------------- in this macro invocation
20-
|
21-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
16+
| ^^^^ private field
2217

2318
error: aborting due to 2 previous errors
2419

src/test/ui/issues/issue-26472.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error[E0616]: field `len` of struct `sub::S` is private
2-
--> $DIR/issue-26472.rs:11:13
2+
--> $DIR/issue-26472.rs:11:15
33
|
44
LL | let v = s.len;
5-
| ^^^^^
5+
| ^^^ private field
66
|
77
help: a method `len` also exists, call it with parentheses
88
|
99
LL | let v = s.len();
1010
| ^^
1111

1212
error[E0616]: field `len` of struct `sub::S` is private
13-
--> $DIR/issue-26472.rs:12:5
13+
--> $DIR/issue-26472.rs:12:7
1414
|
1515
LL | s.len = v;
16-
| ^^^^^
16+
| ^^^ private field
1717

1818
error: aborting due to 2 previous errors
1919

src/test/ui/issues/issue-3763.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
2-
--> $DIR/issue-3763.rs:18:19
2+
--> $DIR/issue-3763.rs:18:32
33
|
44
LL | let _woohoo = (&my_struct).priv_field;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^ private field
66

77
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
8-
--> $DIR/issue-3763.rs:21:19
8+
--> $DIR/issue-3763.rs:21:41
99
|
1010
LL | let _woohoo = (Box::new(my_struct)).priv_field;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^ private field
1212

1313
error[E0624]: associated function `happyfun` is private
1414
--> $DIR/issue-3763.rs:24:18
@@ -23,10 +23,10 @@ LL | (Box::new(my_struct)).happyfun();
2323
| ^^^^^^^^
2424

2525
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
26-
--> $DIR/issue-3763.rs:27:16
26+
--> $DIR/issue-3763.rs:27:26
2727
|
2828
LL | let nope = my_struct.priv_field;
29-
| ^^^^^^^^^^^^^^^^^^^^
29+
| ^^^^^^^^^^ private field
3030

3131
error: aborting due to 5 previous errors
3232

src/test/ui/issues/issue-54062.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `inner` of struct `std::sync::Mutex` is private
2-
--> $DIR/issue-54062.rs:10:13
2+
--> $DIR/issue-54062.rs:10:24
33
|
44
LL | let _ = test.comps.inner.lock().unwrap();
5-
| ^^^^^^^^^^^^^^^^
5+
| ^^^^^ private field
66

77
error[E0599]: no method named `unwrap` found for struct `std::sys_common::mutex::MutexGuard<'_>` in the current scope
88
--> $DIR/issue-54062.rs:10:37

src/test/ui/methods/assign-to-method.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error[E0615]: attempted to take value of method `speak` on type `Cat`
22
--> $DIR/assign-to-method.rs:22:10
33
|
44
LL | nyan.speak = || println!("meow");
5-
| ^^^^^
5+
| ^^^^^ method, not a field
66
|
77
= help: methods are immutable and cannot be assigned to
88

99
error[E0615]: attempted to take value of method `speak` on type `Cat`
1010
--> $DIR/assign-to-method.rs:23:10
1111
|
1212
LL | nyan.speak += || println!("meow");
13-
| ^^^^^
13+
| ^^^^^ method, not a field
1414
|
1515
= help: methods are immutable and cannot be assigned to
1616

src/test/ui/methods/method-missing-call.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0615]: attempted to take value of method `get_x` on type `Point`
22
--> $DIR/method-missing-call.rs:22:26
33
|
44
LL | .get_x;
5-
| ^^^^^
5+
| ^^^^^ method, not a field
66
|
77
help: use parentheses to call the method
88
|
@@ -13,7 +13,7 @@ error[E0615]: attempted to take value of method `filter_map` on type `std::iter:
1313
--> $DIR/method-missing-call.rs:29:16
1414
|
1515
LL | .filter_map;
16-
| ^^^^^^^^^^
16+
| ^^^^^^^^^^ method, not a field
1717
|
1818
help: use parentheses to call the method
1919
|

src/test/ui/paren-span.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `x` of struct `m::S` is private
2-
--> $DIR/paren-span.rs:19:12
2+
--> $DIR/paren-span.rs:19:14
33
|
44
LL | paren!(s.x);
5-
| ^^^
5+
| ^ private field
66

77
error: aborting due to previous error
88

src/test/ui/privacy/private-struct-field-cross-crate.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `meows` of struct `cci_class::kitties::cat` is private
2-
--> $DIR/private-struct-field-cross-crate.rs:7:14
2+
--> $DIR/private-struct-field-cross-crate.rs:7:19
33
|
44
LL | assert_eq!(nyan.meows, 52);
5-
| ^^^^^^^^^^
5+
| ^^^^^ private field
66

77
error: aborting due to previous error
88

src/test/ui/privacy/private-struct-field.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `meows` of struct `cat::Cat` is private
2-
--> $DIR/private-struct-field.rs:13:16
2+
--> $DIR/private-struct-field.rs:13:21
33
|
44
LL | assert_eq!(nyan.meows, 52);
5-
| ^^^^^^^^^^
5+
| ^^^^^ private field
66

77
error: aborting due to previous error
88

src/test/ui/privacy/restricted/test.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ LL | pub(super) fn f() {}
4747
| ^^^^^^^^^^^^^^^^^
4848

4949
error[E0616]: field `x` of struct `foo::bar::S` is private
50-
--> $DIR/test.rs:31:5
50+
--> $DIR/test.rs:31:18
5151
|
5252
LL | S::default().x;
53-
| ^^^^^^^^^^^^^^
53+
| ^ private field
5454

5555
error[E0624]: associated function `f` is private
5656
--> $DIR/test.rs:32:18
@@ -65,16 +65,16 @@ LL | S::g();
6565
| ^^^^
6666

6767
error[E0616]: field `y` of struct `pub_restricted::Universe` is private
68-
--> $DIR/test.rs:42:13
68+
--> $DIR/test.rs:42:15
6969
|
7070
LL | let _ = u.y;
71-
| ^^^
71+
| ^ private field
7272

7373
error[E0616]: field `z` of struct `pub_restricted::Universe` is private
74-
--> $DIR/test.rs:43:13
74+
--> $DIR/test.rs:43:15
7575
|
7676
LL | let _ = u.z;
77-
| ^^^
77+
| ^ private field
7878

7979
error[E0624]: associated function `g` is private
8080
--> $DIR/test.rs:45:7

src/test/ui/privacy/union-field-privacy-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0616]: field `c` of union `m::U` is private
2-
--> $DIR/union-field-privacy-2.rs:14:13
2+
--> $DIR/union-field-privacy-2.rs:14:15
33
|
44
LL | let c = u.c;
5-
| ^^^
5+
| ^ private field
66

77
error: aborting due to previous error
88

src/test/ui/proc-macro/issue-50493.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ error[E0616]: field `field` of struct `Restricted` is private
88
--> $DIR/issue-50493.rs:6:10
99
|
1010
LL | #[derive(Derive)]
11-
| ^^^^^^
11+
| ^^^^^^ private field
1212
|
1313
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
1414

1515
error[E0616]: field `field` of struct `Restricted` is private
1616
--> $DIR/issue-50493.rs:6:10
1717
|
1818
LL | #[derive(Derive)]
19-
| ^^^^^^
19+
| ^^^^^^ private field
2020
|
2121
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
2222

0 commit comments

Comments
 (0)