Even less HIR.
This commit is contained in:
parent
68fb752035
commit
40cb4d1bc7
4 changed files with 28 additions and 33 deletions
|
@ -21,7 +21,9 @@ use rustc_middle::middle::stability::EvalResult;
|
||||||
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
|
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
||||||
use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
|
use rustc_middle::ty::{
|
||||||
|
self, AdtDef, DefIdTree, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
|
||||||
|
};
|
||||||
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
|
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{self, Span};
|
use rustc_span::{self, Span};
|
||||||
|
@ -174,16 +176,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
Ok(l) => l,
|
Ok(l) => l,
|
||||||
// Foreign statics that overflow their allowed size should emit an error
|
// Foreign statics that overflow their allowed size should emit an error
|
||||||
Err(LayoutError::SizeOverflow(_))
|
Err(LayoutError::SizeOverflow(_))
|
||||||
if {
|
if matches!(tcx.def_kind(def_id), DefKind::Static(_)
|
||||||
let node = tcx.hir().get_by_def_id(def_id);
|
if tcx.def_kind(tcx.local_parent(def_id)) == DefKind::ForeignMod) =>
|
||||||
matches!(
|
|
||||||
node,
|
|
||||||
hir::Node::ForeignItem(hir::ForeignItem {
|
|
||||||
kind: hir::ForeignItemKind::Static(..),
|
|
||||||
..
|
|
||||||
})
|
|
||||||
)
|
|
||||||
} =>
|
|
||||||
{
|
{
|
||||||
tcx.sess
|
tcx.sess
|
||||||
.struct_span_err(span, "extern static is too large for the current architecture")
|
.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) {
|
||||||
fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
||||||
let item = tcx.hir().item(id);
|
let item = tcx.hir().item(id);
|
||||||
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
|
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item.kind else {
|
||||||
tcx.sess.delay_span_bug(tcx.hir().span(id.hir_id()), "expected opaque item");
|
tcx.sess.delay_span_bug(item.span, "expected opaque item");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -414,7 +414,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
||||||
// Check that sym actually points to a function. Later passes
|
// Check that sym actually points to a function. Later passes
|
||||||
// depend on this.
|
// depend on this.
|
||||||
hir::InlineAsmOperand::SymFn { anon_const } => {
|
hir::InlineAsmOperand::SymFn { anon_const } => {
|
||||||
let ty = self.tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id);
|
let ty = self.tcx.type_of(anon_const.def_id);
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Never | ty::Error(_) => {}
|
ty::Never | ty::Error(_) => {}
|
||||||
ty::FnDef(..) => {}
|
ty::FnDef(..) => {}
|
||||||
|
@ -422,7 +422,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
|
||||||
let mut err =
|
let mut err =
|
||||||
self.tcx.sess.struct_span_err(*op_sp, "invalid `sym` operand");
|
self.tcx.sess.struct_span_err(*op_sp, "invalid `sym` operand");
|
||||||
err.span_label(
|
err.span_label(
|
||||||
self.tcx.hir().span(anon_const.body.hir_id),
|
self.tcx.def_span(anon_const.def_id),
|
||||||
&format!("is {} `{}`", ty.kind().article(), ty),
|
&format!("is {} `{}`", ty.kind().article(), ty),
|
||||||
);
|
);
|
||||||
err.help("`sym` operands must refer to either a function or a static");
|
err.help("`sym` operands must refer to either a function or a static");
|
||||||
|
|
|
@ -202,8 +202,7 @@ fn visit_implementation_of_coerce_unsized(tcx: TyCtxt<'_>, impl_did: LocalDefId)
|
||||||
fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
||||||
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
|
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
|
||||||
|
|
||||||
let impl_hir_id = tcx.hir().local_def_id_to_hir_id(impl_did);
|
let span = tcx.def_span(impl_did);
|
||||||
let span = tcx.hir().span(impl_hir_id);
|
|
||||||
|
|
||||||
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
|
let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span));
|
||||||
|
|
||||||
|
|
|
@ -38,26 +38,28 @@ fn do_orphan_check_impl<'tcx>(
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let trait_def_id = trait_ref.def_id;
|
let trait_def_id = trait_ref.def_id;
|
||||||
|
|
||||||
let item = tcx.hir().expect_item(def_id);
|
|
||||||
let hir::ItemKind::Impl(impl_) = item.kind else {
|
|
||||||
bug!("{:?} is not an impl: {:?}", def_id, item);
|
|
||||||
};
|
|
||||||
let sp = tcx.def_span(def_id);
|
let sp = tcx.def_span(def_id);
|
||||||
let tr = impl_.of_trait.as_ref().unwrap();
|
|
||||||
|
|
||||||
match traits::orphan_check(tcx, item.owner_id.to_def_id()) {
|
match traits::orphan_check(tcx, def_id.to_def_id()) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => emit_orphan_check_error(
|
Err(err) => {
|
||||||
tcx,
|
let item = tcx.hir().expect_item(def_id);
|
||||||
sp,
|
let hir::ItemKind::Impl(impl_) = item.kind else {
|
||||||
item.span,
|
bug!("{:?} is not an impl: {:?}", def_id, item);
|
||||||
tr.path.span,
|
};
|
||||||
trait_ref,
|
let tr = impl_.of_trait.as_ref().unwrap();
|
||||||
impl_.self_ty.span,
|
|
||||||
&impl_.generics,
|
emit_orphan_check_error(
|
||||||
err,
|
tcx,
|
||||||
)?,
|
sp,
|
||||||
|
item.span,
|
||||||
|
tr.path.span,
|
||||||
|
trait_ref,
|
||||||
|
impl_.self_ty.span,
|
||||||
|
&impl_.generics,
|
||||||
|
err,
|
||||||
|
)?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In addition to the above rules, we restrict impls of auto traits
|
// In addition to the above rules, we restrict impls of auto traits
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue