Skip to content

Commit 03bfbe1

Browse files
Move item_span from check_item_type into each function
1 parent 78efaf4 commit 03bfbe1

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

compiler/rustc_typeck/src/check/check.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ fn check_alloc_error_fn(
375375
}
376376
}
377377

378-
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
378+
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {
379379
let def = tcx.adt_def(def_id);
380+
let span = tcx.def_span(def_id);
380381
def.destructor(tcx); // force the destructor to be evaluated
381382
check_representable(tcx, span, def_id);
382383

@@ -388,8 +389,9 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
388389
check_packed(tcx, span, def);
389390
}
390391

391-
fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
392+
fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
392393
let def = tcx.adt_def(def_id);
394+
let span = tcx.def_span(def_id);
393395
def.destructor(tcx); // force the destructor to be evaluated
394396
check_representable(tcx, span, def_id);
395397
check_transparent(tcx, span, def);
@@ -471,13 +473,14 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
471473
}
472474

473475
/// Check that a `static` is inhabited.
474-
fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
476+
fn check_static_inhabited<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) {
475477
// Make sure statics are inhabited.
476478
// Other parts of the compiler assume that there are no uninhabited places. In principle it
477479
// would be enough to check this for `extern` statics, as statics with an initializer will
478480
// have UB during initialization if they are uninhabited, but there also seems to be no good
479481
// reason to allow any statics to be uninhabited.
480482
let ty = tcx.type_of(def_id);
483+
let span = tcx.def_span(def_id);
481484
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
482485
Ok(l) => l,
483486
// Foreign statics that overflow their allowed size should emit an error
@@ -524,9 +527,9 @@ pub(super) fn check_opaque<'tcx>(
524527
tcx: TyCtxt<'tcx>,
525528
def_id: LocalDefId,
526529
substs: SubstsRef<'tcx>,
527-
span: Span,
528530
origin: &hir::OpaqueTyOrigin,
529531
) {
532+
let span = tcx.def_span(def_id);
530533
check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
531534
if tcx.type_of(def_id).references_error() {
532535
return;
@@ -781,13 +784,12 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
781784
id.def_id,
782785
tcx.def_path_str(id.def_id.to_def_id())
783786
);
784-
let item_span = tcx.def_span(id.def_id);
785787
let _indenter = indenter();
786788
match tcx.def_kind(id.def_id) {
787789
DefKind::Static(..) => {
788790
tcx.ensure().typeck(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);
791+
maybe_check_static_with_link_section(tcx, id.def_id);
792+
check_static_inhabited(tcx, id.def_id);
791793
}
792794
DefKind::Const => {
793795
tcx.ensure().typeck(id.def_id);
@@ -797,7 +799,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
797799
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
798800
return;
799801
};
800-
check_enum(tcx, item_span, &enum_definition.variants, item.def_id);
802+
check_enum(tcx, &enum_definition.variants, item.def_id);
801803
}
802804
DefKind::Fn => {} // entirely within check_item_body
803805
DefKind::Impl => {
@@ -848,10 +850,10 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
848850
}
849851
}
850852
DefKind::Struct => {
851-
check_struct(tcx, id.def_id, item_span);
853+
check_struct(tcx, id.def_id);
852854
}
853855
DefKind::Union => {
854-
check_union(tcx, id.def_id, item_span);
856+
check_union(tcx, id.def_id);
855857
}
856858
DefKind::OpaqueTy => {
857859
let item = tcx.hir().item(id);
@@ -864,7 +866,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
864866
// See https://github.com/rust-lang/rust/issues/75100
865867
if !tcx.sess.opts.actually_rustdoc {
866868
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
867-
check_opaque(tcx, item.def_id, substs, item_span, &origin);
869+
check_opaque(tcx, item.def_id, substs, &origin);
868870
}
869871
}
870872
DefKind::TyAlias => {
@@ -928,7 +930,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
928930
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
929931
}
930932
hir::ForeignItemKind::Static(..) => {
931-
check_static_inhabited(tcx, def_id, item.span);
933+
check_static_inhabited(tcx, def_id);
932934
}
933935
_ => {}
934936
}
@@ -1442,13 +1444,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: ty::AdtD
14421444
}
14431445

14441446
#[allow(trivial_numeric_casts)]
1445-
fn check_enum<'tcx>(
1446-
tcx: TyCtxt<'tcx>,
1447-
sp: Span,
1448-
vs: &'tcx [hir::Variant<'tcx>],
1449-
def_id: LocalDefId,
1450-
) {
1447+
fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: LocalDefId) {
14511448
let def = tcx.adt_def(def_id);
1449+
let sp = tcx.def_span(def_id);
14521450
def.destructor(tcx); // force the destructor to be evaluated
14531451

14541452
if vs.is_empty() {

compiler/rustc_typeck/src/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {
534534
}
535535
}
536536

537-
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: Span) {
537+
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
538538
// Only restricted on wasm target for now
539539
if !tcx.sess.target.is_like_wasm {
540540
return;
@@ -560,7 +560,7 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: S
560560
let msg = "statics with a custom `#[link_section]` must be a \
561561
simple list of bytes on the wasm target with no \
562562
extra levels of indirection such as references";
563-
tcx.sess.span_err(span, msg);
563+
tcx.sess.span_err(tcx.def_span(id), msg);
564564
}
565565
}
566566

src/test/ui/extern/extern-static-size-overflow.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ error: extern static is too large for the current architecture
22
--> $DIR/extern-static-size-overflow.rs:38:5
33
|
44
LL | static BAZ: [u8; max_size()];
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: extern static is too large for the current architecture
88
--> $DIR/extern-static-size-overflow.rs:39:5
99
|
1010
LL | static UWU: [usize; usize::MAX];
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: extern static is too large for the current architecture
1414
--> $DIR/extern-static-size-overflow.rs:40:5
1515
|
1616
LL | static A: ReallyBig;
17-
| ^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^^^^^^^^^^
1818

1919
error: aborting due to 3 previous errors
2020

src/test/ui/statics/uninhabited-static.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: static of uninhabited type
22
--> $DIR/uninhabited-static.rs:6:5
33
|
44
LL | static VOID: Void;
5-
| ^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/uninhabited-static.rs:2:9
@@ -17,7 +17,7 @@ error: static of uninhabited type
1717
--> $DIR/uninhabited-static.rs:8:5
1818
|
1919
LL | static NEVER: !;
20-
| ^^^^^^^^^^^^^^^^
20+
| ^^^^^^^^^^^^^^^
2121
|
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>

0 commit comments

Comments
 (0)