Make item spans more consistent

This commit is contained in:
Michael Goulet 2022-07-08 01:50:10 +00:00
parent 1ba1fec234
commit aad2334ecb
11 changed files with 83 additions and 119 deletions

View file

@ -781,12 +781,13 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
id.def_id,
tcx.def_path_str(id.def_id.to_def_id())
);
let item_span = tcx.def_span(id.def_id);
let _indenter = indenter();
match tcx.def_kind(id.def_id) {
DefKind::Static(..) => {
tcx.ensure().typeck(id.def_id);
maybe_check_static_with_link_section(tcx, id.def_id, tcx.def_span(id.def_id));
check_static_inhabited(tcx, id.def_id, tcx.def_span(id.def_id));
maybe_check_static_with_link_section(tcx, id.def_id, item_span);
check_static_inhabited(tcx, id.def_id, item_span);
}
DefKind::Const => {
tcx.ensure().typeck(id.def_id);
@ -796,7 +797,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
return;
};
check_enum(tcx, item.span, &enum_definition.variants, item.def_id);
check_enum(tcx, item_span, &enum_definition.variants, item.def_id);
}
DefKind::Fn => {} // entirely within check_item_body
DefKind::Impl => {
@ -847,10 +848,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
}
}
DefKind::Struct => {
check_struct(tcx, id.def_id, tcx.def_span(id.def_id));
check_struct(tcx, id.def_id, item_span);
}
DefKind::Union => {
check_union(tcx, id.def_id, tcx.def_span(id.def_id));
check_union(tcx, id.def_id, item_span);
}
DefKind::OpaqueTy => {
let item = tcx.hir().item(id);
@ -863,7 +864,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
// See https://github.com/rust-lang/rust/issues/75100
if !tcx.sess.opts.actually_rustdoc {
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
check_opaque(tcx, item.def_id, substs, item.span, &origin);
check_opaque(tcx, item.def_id, substs, item_span, &origin);
}
}
DefKind::TyAlias => {
@ -1328,7 +1329,6 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
if !adt.repr().transparent() {
return;
}
let sp = tcx.sess.source_map().guess_head_span(sp);
if adt.is_union() && !tcx.features().transparent_unions {
feature_err(

View file

@ -1,13 +1,8 @@
error[E0732]: `#[repr(inttype)]` must be specified
--> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1
|
LL | / enum Enum {
LL | |
LL | | Unit = 1,
LL | | Tuple() = 2,
LL | | Struct{} = 3,
LL | | }
| |_^
LL | enum Enum {
| ^^^^^^^^^
error: aborting due to previous error

View file

@ -1,16 +1,14 @@
error[E0081]: discriminant value `0` assigned more than once
--> $DIR/enum-discrim-autosizing.rs:6:1
|
LL | / enum Eu64 {
LL | |
LL | | Au64 = 0,
| | - first assignment of `0`
LL | |
LL | | Bu64 = 0x8000_0000_0000_0000
| | --------------------- second assignment of `0` (overflowed from `9223372036854775808`)
LL | |
LL | | }
| |_^
LL | enum Eu64 {
| ^^^^^^^^^
LL |
LL | Au64 = 0,
| - first assignment of `0`
LL |
LL | Bu64 = 0x8000_0000_0000_0000
| --------------------- second assignment of `0` (overflowed from `9223372036854775808`)
error: aborting due to previous error

View file

@ -1,48 +1,41 @@
error[E0081]: discriminant value `3` assigned more than once
--> $DIR/E0081.rs:1:1
|
LL | / enum Enum {
LL | |
LL | | P = 3,
| | - first assignment of `3`
LL | |
LL | | X = 3,
| | - second assignment of `3`
LL | |
LL | | Y = 5
LL | | }
| |_^
LL | enum Enum {
| ^^^^^^^^^
LL |
LL | P = 3,
| - first assignment of `3`
LL |
LL | X = 3,
| - second assignment of `3`
error[E0081]: discriminant value `1` assigned more than once
--> $DIR/E0081.rs:11:1
|
LL | / enum EnumOverflowRepr {
LL | |
LL | | P = 257,
| | --- first assignment of `1` (overflowed from `257`)
LL | |
LL | | X = 513,
| | --- second assignment of `1` (overflowed from `513`)
LL | |
LL | | }
| |_^
LL | enum EnumOverflowRepr {
| ^^^^^^^^^^^^^^^^^^^^^
LL |
LL | P = 257,
| --- first assignment of `1` (overflowed from `257`)
LL |
LL | X = 513,
| --- second assignment of `1` (overflowed from `513`)
error[E0081]: discriminant value `-1` assigned more than once
--> $DIR/E0081.rs:20:1
|
LL | / enum NegDisEnum {
LL | |
LL | | First = -1,
| | -- first assignment of `-1`
LL | |
LL | | Second = -2,
| | ----------- assigned discriminant for `Last` was incremented from this discriminant
LL | |
LL | | Last,
| | ---- second assignment of `-1`
LL | |
LL | | }
| |_^
LL | enum NegDisEnum {
| ^^^^^^^^^^^^^^^
LL |
LL | First = -1,
| -- first assignment of `-1`
LL |
LL | Second = -2,
| ----------- assigned discriminant for `Last` was incremented from this discriminant
LL |
LL | Last,
| ---- second assignment of `-1`
error: aborting due to 3 previous errors

View file

@ -4,7 +4,7 @@ error[E0084]: unsupported representation for zero-variant enum
LL | #[repr(i32)]
| ^^^^^^^^^^^^
LL | enum Foo {}
| ----------- zero-variant enum
| -------- zero-variant enum
error: aborting due to previous error

View file

@ -1,10 +1,8 @@
error[E0658]: repr with 128-bit type is unstable
--> $DIR/E0658.rs:2:1
|
LL | / enum Foo {
LL | | Bar(u64),
LL | | }
| |_^
LL | enum Foo {
| ^^^^^^^^
|
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
= help: add `#![feature(repr128)]` to the crate attributes to enable

View file

@ -1,10 +1,8 @@
error[E0658]: repr with 128-bit type is unstable
--> $DIR/feature-gate-repr128.rs:2:1
|
LL | / enum A {
LL | | A(u64)
LL | | }
| |_^
LL | enum A {
| ^^^^^^
|
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
= help: add `#![feature(repr128)]` to the crate attributes to enable

View file

@ -1,53 +1,39 @@
error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1
|
LL | / enum Foo {
LL | |
LL | |
LL | |
LL | | A = 1,
| | - first assignment of `1`
LL | | B = 1,
| | - second assignment of `1`
... |
LL | |
LL | | }
| |_^
LL | enum Foo {
| ^^^^^^^^
...
LL | A = 1,
| - first assignment of `1`
LL | B = 1,
| - second assignment of `1`
error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1
|
LL | / enum Foo {
LL | |
LL | |
LL | |
LL | | A = 1,
| | - first assignment of `1`
LL | | B = 1,
LL | | C = 0,
| | ----- assigned discriminant for `D` was incremented from this discriminant
LL | | D,
| | - second assignment of `1`
... |
LL | |
LL | | }
| |_^
LL | enum Foo {
| ^^^^^^^^
...
LL | A = 1,
| - first assignment of `1`
LL | B = 1,
LL | C = 0,
| ----- assigned discriminant for `D` was incremented from this discriminant
LL | D,
| - second assignment of `1`
error[E0081]: discriminant value `1` assigned more than once
--> $DIR/issue-15524.rs:3:1
|
LL | / enum Foo {
LL | |
LL | |
LL | |
LL | | A = 1,
| | - first assignment of `1`
... |
LL | | E = N,
| | - second assignment of `1`
LL | |
LL | | }
| |_^
LL | enum Foo {
| ^^^^^^^^
...
LL | A = 1,
| - first assignment of `1`
...
LL | E = N,
| - second assignment of `1`
error: aborting due to 3 previous errors

View file

@ -22,7 +22,7 @@ LL | #[repr(simd)]
| ^^^^^^^^^^^^^
...
LL | enum Es {}
| ---------- zero-variant enum
| ------- zero-variant enum
error: aborting due to 3 previous errors

View file

@ -34,7 +34,7 @@ error[E0084]: unsupported representation for zero-variant enum
LL | #[repr(transparent)]
| ^^^^^^^^^^^^^^^^^^^^
LL | enum Void {}
| ------------ zero-variant enum
| --------- zero-variant enum
error[E0731]: transparent enum needs exactly one variant, but has 0
--> $DIR/repr-transparent.rs:45:1

View file

@ -1,17 +1,13 @@
error[E0081]: discriminant value `0` assigned more than once
--> $DIR/tag-variant-disr-dup.rs:3:1
|
LL | / enum Color {
LL | |
LL | | Red = 0xff0000,
LL | | Green = 0x00ff00,
LL | | Blue = 0x0000ff,
LL | | Black = 0x000000,
| | -------- first assignment of `0`
LL | | White = 0x000000,
| | -------- second assignment of `0`
LL | | }
| |_^
LL | enum Color {
| ^^^^^^^^^^
...
LL | Black = 0x000000,
| -------- first assignment of `0`
LL | White = 0x000000,
| -------- second assignment of `0`
error: aborting due to previous error