Skip to content

Commit aad2334

Browse files
Make item spans more consistent
1 parent 1ba1fec commit aad2334

File tree

11 files changed

+83
-119
lines changed

11 files changed

+83
-119
lines changed

compiler/rustc_typeck/src/check/check.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,13 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
781781
id.def_id,
782782
tcx.def_path_str(id.def_id.to_def_id())
783783
);
784+
let item_span = tcx.def_span(id.def_id);
784785
let _indenter = indenter();
785786
match tcx.def_kind(id.def_id) {
786787
DefKind::Static(..) => {
787788
tcx.ensure().typeck(id.def_id);
788-
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id));
789-
check_static_inhabited(tcx, id.def_id, tcx.def_span(id.def_id));
789+
maybe_check_static_with_link_section(tcx, id.def_id, item_span);
790+
check_static_inhabited(tcx, id.def_id, item_span);
790791
}
791792
DefKind::Const => {
792793
tcx.ensure().typeck(id.def_id);
@@ -796,7 +797,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
796797
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
797798
return;
798799
};
799-
check_enum(tcx, item.span, &enum_definition.variants, item.def_id);
800+
check_enum(tcx, item_span, &enum_definition.variants, item.def_id);
800801
}
801802
DefKind::Fn => {} // entirely within check_item_body
802803
DefKind::Impl => {
@@ -847,10 +848,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
847848
}
848849
}
849850
DefKind::Struct => {
850-
check_struct(tcx, id.def_id, tcx.def_span(id.def_id));
851+
check_struct(tcx, id.def_id, item_span);
851852
}
852853
DefKind::Union => {
853-
check_union(tcx, id.def_id, tcx.def_span(id.def_id));
854+
check_union(tcx, id.def_id, item_span);
854855
}
855856
DefKind::OpaqueTy => {
856857
let item = tcx.hir().item(id);
@@ -863,7 +864,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
863864
// See https://github.com/rust-lang/rust/issues/75100
864865
if !tcx.sess.opts.actually_rustdoc {
865866
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
866-
check_opaque(tcx, item.def_id, substs, item.span, &origin);
867+
check_opaque(tcx, item.def_id, substs, item_span, &origin);
867868
}
868869
}
869870
DefKind::TyAlias => {
@@ -1328,7 +1329,6 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
13281329
if !adt.repr().transparent() {
13291330
return;
13301331
}
1331-
let sp = tcx.sess.source_map().guess_head_span(sp);
13321332

13331333
if adt.is_union() && !tcx.features().transparent_unions {
13341334
feature_err(

src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
error[E0732]: `#[repr(inttype)]` must be specified
22
--> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1
33
|
4-
LL | / enum Enum {
5-
LL | |
6-
LL | | Unit = 1,
7-
LL | | Tuple() = 2,
8-
LL | | Struct{} = 3,
9-
LL | | }
10-
| |_^
4+
LL | enum Enum {
5+
| ^^^^^^^^^
116

127
error: aborting due to previous error
138

src/test/ui/enum/enum-discrim-autosizing.stderr

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
error[E0081]: discriminant value `0` assigned more than once
22
--> $DIR/enum-discrim-autosizing.rs:6:1
33
|
4-
LL | / enum Eu64 {
5-
LL | |
6-
LL | | Au64 = 0,
7-
| | - first assignment of `0`
8-
LL | |
9-
LL | | Bu64 = 0x8000_0000_0000_0000
10-
| | --------------------- second assignment of `0` (overflowed from `9223372036854775808`)
11-
LL | |
12-
LL | | }
13-
| |_^
4+
LL | enum Eu64 {
5+
| ^^^^^^^^^
6+
LL |
7+
LL | Au64 = 0,
8+
| - first assignment of `0`
9+
LL |
10+
LL | Bu64 = 0x8000_0000_0000_0000
11+
| --------------------- second assignment of `0` (overflowed from `9223372036854775808`)
1412

1513
error: aborting due to previous error
1614

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

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
11
error[E0081]: discriminant value `3` assigned more than once
22
--> $DIR/E0081.rs:1:1
33
|
4-
LL | / enum Enum {
5-
LL | |
6-
LL | | P = 3,
7-
| | - first assignment of `3`
8-
LL | |
9-
LL | | X = 3,
10-
| | - second assignment of `3`
11-
LL | |
12-
LL | | Y = 5
13-
LL | | }
14-
| |_^
4+
LL | enum Enum {
5+
| ^^^^^^^^^
6+
LL |
7+
LL | P = 3,
8+
| - first assignment of `3`
9+
LL |
10+
LL | X = 3,
11+
| - second assignment of `3`
1512

1613
error[E0081]: discriminant value `1` assigned more than once
1714
--> $DIR/E0081.rs:11:1
1815
|
19-
LL | / enum EnumOverflowRepr {
20-
LL | |
21-
LL | | P = 257,
22-
| | --- first assignment of `1` (overflowed from `257`)
23-
LL | |
24-
LL | | X = 513,
25-
| | --- second assignment of `1` (overflowed from `513`)
26-
LL | |
27-
LL | | }
28-
| |_^
16+
LL | enum EnumOverflowRepr {
17+
| ^^^^^^^^^^^^^^^^^^^^^
18+
LL |
19+
LL | P = 257,
20+
| --- first assignment of `1` (overflowed from `257`)
21+
LL |
22+
LL | X = 513,
23+
| --- second assignment of `1` (overflowed from `513`)
2924

3025
error[E0081]: discriminant value `-1` assigned more than once
3126
--> $DIR/E0081.rs:20:1
3227
|
33-
LL | / enum NegDisEnum {
34-
LL | |
35-
LL | | First = -1,
36-
| | -- first assignment of `-1`
37-
LL | |
38-
LL | | Second = -2,
39-
| | ----------- assigned discriminant for `Last` was incremented from this discriminant
40-
LL | |
41-
LL | | Last,
42-
| | ---- second assignment of `-1`
43-
LL | |
44-
LL | | }
45-
| |_^
28+
LL | enum NegDisEnum {
29+
| ^^^^^^^^^^^^^^^
30+
LL |
31+
LL | First = -1,
32+
| -- first assignment of `-1`
33+
LL |
34+
LL | Second = -2,
35+
| ----------- assigned discriminant for `Last` was incremented from this discriminant
36+
LL |
37+
LL | Last,
38+
| ---- second assignment of `-1`
4639

4740
error: aborting due to 3 previous errors
4841

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0084]: unsupported representation for zero-variant enum
44
LL | #[repr(i32)]
55
| ^^^^^^^^^^^^
66
LL | enum Foo {}
7-
| ----------- zero-variant enum
7+
| -------- zero-variant enum
88

99
error: aborting due to previous error
1010

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0658]: repr with 128-bit type is unstable
22
--> $DIR/E0658.rs:2:1
33
|
4-
LL | / enum Foo {
5-
LL | | Bar(u64),
6-
LL | | }
7-
| |_^
4+
LL | enum Foo {
5+
| ^^^^^^^^
86
|
97
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
108
= help: add `#![feature(repr128)]` to the crate attributes to enable

src/test/ui/feature-gates/feature-gate-repr128.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0658]: repr with 128-bit type is unstable
22
--> $DIR/feature-gate-repr128.rs:2:1
33
|
4-
LL | / enum A {
5-
LL | | A(u64)
6-
LL | | }
7-
| |_^
4+
LL | enum A {
5+
| ^^^^^^
86
|
97
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
108
= help: add `#![feature(repr128)]` to the crate attributes to enable

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

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11
error[E0081]: discriminant value `1` assigned more than once
22
--> $DIR/issue-15524.rs:3:1
33
|
4-
LL | / enum Foo {
5-
LL | |
6-
LL | |
7-
LL | |
8-
LL | | A = 1,
9-
| | - first assignment of `1`
10-
LL | | B = 1,
11-
| | - second assignment of `1`
12-
... |
13-
LL | |
14-
LL | | }
15-
| |_^
4+
LL | enum Foo {
5+
| ^^^^^^^^
6+
...
7+
LL | A = 1,
8+
| - first assignment of `1`
9+
LL | B = 1,
10+
| - second assignment of `1`
1611

1712
error[E0081]: discriminant value `1` assigned more than once
1813
--> $DIR/issue-15524.rs:3:1
1914
|
20-
LL | / enum Foo {
21-
LL | |
22-
LL | |
23-
LL | |
24-
LL | | A = 1,
25-
| | - first assignment of `1`
26-
LL | | B = 1,
27-
LL | | C = 0,
28-
| | ----- assigned discriminant for `D` was incremented from this discriminant
29-
LL | | D,
30-
| | - second assignment of `1`
31-
... |
32-
LL | |
33-
LL | | }
34-
| |_^
15+
LL | enum Foo {
16+
| ^^^^^^^^
17+
...
18+
LL | A = 1,
19+
| - first assignment of `1`
20+
LL | B = 1,
21+
LL | C = 0,
22+
| ----- assigned discriminant for `D` was incremented from this discriminant
23+
LL | D,
24+
| - second assignment of `1`
3525

3626
error[E0081]: discriminant value `1` assigned more than once
3727
--> $DIR/issue-15524.rs:3:1
3828
|
39-
LL | / enum Foo {
40-
LL | |
41-
LL | |
42-
LL | |
43-
LL | | A = 1,
44-
| | - first assignment of `1`
45-
... |
46-
LL | | E = N,
47-
| | - second assignment of `1`
48-
LL | |
49-
LL | | }
50-
| |_^
29+
LL | enum Foo {
30+
| ^^^^^^^^
31+
...
32+
LL | A = 1,
33+
| - first assignment of `1`
34+
...
35+
LL | E = N,
36+
| - second assignment of `1`
5137

5238
error: aborting due to 3 previous errors
5339

src/test/ui/repr/issue-83505-repr-simd.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | #[repr(simd)]
2222
| ^^^^^^^^^^^^^
2323
...
2424
LL | enum Es {}
25-
| ---------- zero-variant enum
25+
| ------- zero-variant enum
2626

2727
error: aborting due to 3 previous errors
2828

src/test/ui/repr/repr-transparent.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error[E0084]: unsupported representation for zero-variant enum
3434
LL | #[repr(transparent)]
3535
| ^^^^^^^^^^^^^^^^^^^^
3636
LL | enum Void {}
37-
| ------------ zero-variant enum
37+
| --------- zero-variant enum
3838

3939
error[E0731]: transparent enum needs exactly one variant, but has 0
4040
--> $DIR/repr-transparent.rs:45:1

src/test/ui/tag-variant-disr-dup.stderr

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
error[E0081]: discriminant value `0` assigned more than once
22
--> $DIR/tag-variant-disr-dup.rs:3:1
33
|
4-
LL | / enum Color {
5-
LL | |
6-
LL | | Red = 0xff0000,
7-
LL | | Green = 0x00ff00,
8-
LL | | Blue = 0x0000ff,
9-
LL | | Black = 0x000000,
10-
| | -------- first assignment of `0`
11-
LL | | White = 0x000000,
12-
| | -------- second assignment of `0`
13-
LL | | }
14-
| |_^
4+
LL | enum Color {
5+
| ^^^^^^^^^^
6+
...
7+
LL | Black = 0x000000,
8+
| -------- first assignment of `0`
9+
LL | White = 0x000000,
10+
| -------- second assignment of `0`
1511

1612
error: aborting due to previous error
1713

0 commit comments

Comments
 (0)