Skip to content

Commit 40cb4d1

Browse files
committed
Even less HIR.
1 parent 68fb752 commit 40cb4d1

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use rustc_middle::middle::stability::EvalResult;
2121
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2222
use rustc_middle::ty::subst::GenericArgKind;
2323
use rustc_middle::ty::util::{Discr, IntTypeExt};
24-
use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
24+
use rustc_middle::ty::{
25+
self, AdtDef, DefIdTree, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
26+
};
2527
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
2628
use rustc_span::symbol::sym;
2729
use rustc_span::{self, Span};
@@ -174,16 +176,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
174176
Ok(l) => l,
175177
// Foreign statics that overflow their allowed size should emit an error
176178
Err(LayoutError::SizeOverflow(_))
177-
if {
178-
let node = tcx.hir().get_by_def_id(def_id);
179-
matches!(
180-
node,
181-
hir::Node::ForeignItem(hir::ForeignItem {
182-
kind: hir::ForeignItemKind::Static(..),
183-
..
184-
})
185-
)
186-
} =>
179+
if matches!(tcx.def_kind(def_id), DefKind::Static(_)
180+
if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) =>
187181
{
188182
tcx.sess
189183
.struct_span_err(span, "extern static is too large for the current architecture")
@@ -215,7 +209,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
215209
fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
216210
let item = tcx.hir().item(id);
217211
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
218-
tcx.sess.delay_span_bug(tcx.hir().span(id.hir_id()), "expected opaque item");
212+
tcx.sess.delay_span_bug(item.span, "expected opaque item");
219213
return;
220214
};
221215

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,15 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
414414
// Check that sym actually points to a function. Later passes
415415
// depend on this.
416416
hir::InlineAsmOperand::SymFn { anon_const } => {
417-
let ty = self.tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
417+
let ty = self.tcx.type_of(anon_const.def_id);
418418
match ty.kind() {
419419
ty::Never | ty::Error(_) => {}
420420
ty::FnDef(..) => {}
421421
_ => {
422422
let mut err =
423423
self.tcx.sess.struct_span_err(*op_sp, "invalid `sym` operand");
424424
err.span_label(
425-
self.tcx.hir().span(anon_const.body.hir_id),
425+
self.tcx.def_span(anon_const.def_id),
426426
&format!("is {} `{}`", ty.kind().article(), ty),
427427
);
428428
err.help("`sym` operands must refer to either a function or a static");

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'_>, impl_did: LocalDefId)
202202
fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
203203
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
204204

205-
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
206-
let span = tcx.hir().span(impl_hir_id);
205+
let span = tcx.def_span(impl_did);
207206

208207
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
209208

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,28 @@ fn do_orphan_check_impl<'tcx>(
3838
def_id: LocalDefId,
3939
) -> Result<(), ErrorGuaranteed> {
4040
let trait_def_id = trait_ref.def_id;
41-
42-
let item = tcx.hir().expect_item(def_id);
43-
let hir::ItemKind::Impl(impl_) = item.kind else {
44-
bug!("{:?} is not an impl: {:?}", def_id, item);
45-
};
4641
let sp = tcx.def_span(def_id);
47-
let tr = impl_.of_trait.as_ref().unwrap();
4842

49-
match traits::orphan_check(tcx, item.owner_id.to_def_id()) {
43+
match traits::orphan_check(tcx, def_id.to_def_id()) {
5044
Ok(()) => {}
51-
Err(err) => emit_orphan_check_error(
52-
tcx,
53-
sp,
54-
item.span,
55-
tr.path.span,
56-
trait_ref,
57-
impl_.self_ty.span,
58-
&impl_.generics,
59-
err,
60-
)?,
45+
Err(err) => {
46+
let item = tcx.hir().expect_item(def_id);
47+
let hir::ItemKind::Impl(impl_) = item.kind else {
48+
bug!("{:?} is not an impl: {:?}", def_id, item);
49+
};
50+
let tr = impl_.of_trait.as_ref().unwrap();
51+
52+
emit_orphan_check_error(
53+
tcx,
54+
sp,
55+
item.span,
56+
tr.path.span,
57+
trait_ref,
58+
impl_.self_ty.span,
59+
&impl_.generics,
60+
err,
61+
)?
62+
}
6163
}
6264

6365
// In addition to the above rules, we restrict impls of auto traits

0 commit comments

Comments
 (0)