use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::fold::TypeFoldable;
-use rustc_middle::ty::layout::MAX_SIMD_LANES;
+use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, OpaqueTypeKey, ParamEnv, Ty, TyCtxt};
pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
match tcx.sess.target.is_abi_supported(abi) {
Some(true) => (),
- Some(false) => struct_span_err!(
- tcx.sess,
- span,
- E0570,
- "`{}` is not a supported ABI for the current target",
- abi
- )
- .emit(),
+ Some(false) => {
+ struct_span_err!(
+ tcx.sess,
+ span,
+ E0570,
+ "`{}` is not a supported ABI for the current target",
+ abi
+ )
+ .emit();
+ }
None => {
tcx.struct_span_lint_hir(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
lint.build("use of calling convention not supported on this target").emit()
E0781,
"the `\"C-cmse-nonsecure-call\"` ABI is only allowed on function pointers"
)
- .emit()
+ .emit();
}
}
sess.span_err(decl.inputs[0].span, "argument should be `&PanicInfo`");
}
- if let Node::Item(item) = hir.get(fn_id) {
- if let ItemKind::Fn(_, ref generics, _) = item.kind {
- if !generics.params.is_empty() {
+ if let Node::Item(item) = hir.get(fn_id)
+ && let ItemKind::Fn(_, ref generics, _) = item.kind
+ && !generics.params.is_empty()
+ {
sess.span_err(span, "should have no type parameters");
}
- }
- }
} else {
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
sess.span_err(decl.inputs[0].span, "argument should be `Layout`");
}
- if let Node::Item(item) = hir.get(fn_id) {
- if let ItemKind::Fn(_, ref generics, _) = item.kind {
- if !generics.params.is_empty() {
+ if let Node::Item(item) = hir.get(fn_id)
+ && let ItemKind::Fn(_, ref generics, _) = item.kind
+ && !generics.params.is_empty()
+ {
sess.span_err(
span,
- "`#[alloc_error_handler]` function should have no type \
- parameters",
+ "`#[alloc_error_handler]` function should have no type parameters",
);
}
- }
- }
} else {
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
let ty = tcx.type_of(def_id);
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
Ok(l) => l,
- Err(_) => {
- // Generic statics are rejected, but we still reach this case.
- tcx.sess.delay_span_bug(span, "generic static must be rejected");
+ // Foreign statics that overflow their allowed size should emit an error
+ Err(LayoutError::SizeOverflow(_))
+ if {
+ let node = tcx.hir().get_by_def_id(def_id);
+ matches!(
+ node,
+ hir::Node::ForeignItem(hir::ForeignItem {
+ kind: hir::ForeignItemKind::Static(..),
+ ..
+ })
+ )
+ } =>
+ {
+ tcx.sess
+ .struct_span_err(span, "extern static is too large for the current architecture")
+ .emit();
+ return;
+ }
+ // Generic statics are rejected, but we still reach this case.
+ Err(e) => {
+ tcx.sess.delay_span_bug(span, &e.to_string());
return;
}
};
impl_id: DefId,
impl_item: &hir::ImplItemRef,
) {
- let ancestors = match trait_def.ancestors(tcx, impl_id) {
- Ok(ancestors) => ancestors,
- Err(_) => return,
- };
+ let Ok(ancestors) = trait_def.ancestors(tcx, impl_id) else { return };
let mut ancestor_impls = ancestors.skip(1).filter_map(|parent| {
if parent.is_from_trait() {
None
if repr.packed() {
for attr in tcx.get_attrs(def.did).iter() {
for r in attr::find_repr_attrs(&tcx.sess, attr) {
- if let attr::ReprPacked(pack) = r {
- if let Some(repr_pack) = repr.pack {
- if pack as u64 != repr_pack.bytes() {
+ if let attr::ReprPacked(pack) = r
+ && let Some(repr_pack) = repr.pack
+ && pack as u64 != repr_pack.bytes()
+ {
struct_span_err!(
tcx.sess,
sp,
"type has conflicting packed representation hints"
)
.emit();
- }
- }
}
}
}
) -> String {
if let Some(expr) = &variant.disr_expr {
let body = &tcx.hir().body(expr.body).value;
- if let hir::ExprKind::Lit(lit) = &body.kind {
- if let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node {
- if evaluated != *lit_value {
+ if let hir::ExprKind::Lit(lit) = &body.kind
+ && let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
+ && evaluated != *lit_value
+ {
return format!("`{}` (overflowed from `{}`)", evaluated, lit_value);
- }
- }
}
}
format!("`{}`", evaluated)