diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_passes/messages.ftl | 25 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/abi_test.rs | 31 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/errors.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/layout_test.rs | 35 |
4 files changed, 76 insertions, 45 deletions
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index aa7db3348d0..602d614295c 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -4,15 +4,11 @@ -passes_see_issue = see issue #{$issue} <https://github.com/rust-lang/rust/issues/{$issue}> for more information -passes_abi = - abi: {$abi} - +passes_abi_invalid_attribute = + `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions passes_abi_of = fn_abi_of({$fn_name}) = {$fn_abi} -passes_align = - align: {$align} - passes_allow_incoherent_impl = `rustc_allow_incoherent_impl` attribute should be applied to impl items. .label = the only currently supported targets are inherent methods @@ -318,9 +314,6 @@ passes_has_incoherent_inherent_impl = `rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits. .label = only adts, extern types and traits are supported -passes_homogeneous_aggregate = - homogeneous_aggregate: {$homogeneous_aggregate} - passes_ignored_attr = `#[{$sym}]` is ignored on struct fields and match arms .warn = {-passes_previously_accepted} @@ -404,9 +397,18 @@ passes_lang_item_on_incorrect_target = passes_layout = layout error: {$layout_error} - +passes_layout_abi = + abi: {$abi} +passes_layout_align = + align: {$align} +passes_layout_homogeneous_aggregate = + homogeneous_aggregate: {$homogeneous_aggregate} +passes_layout_invalid_attribute = + `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases passes_layout_of = layout_of({$normalized_ty}) = {$ty_layout} +passes_layout_size = + size: {$size} passes_link = attribute should be applied to an `extern` block with non-Rust ABI @@ -662,9 +664,6 @@ passes_should_be_applied_to_trait = attribute should be applied to a trait .label = not a trait -passes_size = - size: {$size} - passes_skipping_const_checks = skipping const checks passes_stability_promotable = diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index aeaa264216d..4653a9c2b39 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -7,7 +7,7 @@ use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; use rustc_target::abi::call::FnAbi; -use crate::errors::{AbiOf, UnrecognizedField}; +use crate::errors::{AbiInvalidAttribute, AbiOf, UnrecognizedField}; pub fn test_abi(tcx: TyCtxt<'_>) { if !tcx.features().rustc_attrs { @@ -15,28 +15,33 @@ pub fn test_abi(tcx: TyCtxt<'_>) { return; } for id in tcx.hir().items() { - match tcx.def_kind(id.owner_id) { - DefKind::Fn => { - for attr in tcx.get_attrs(id.owner_id, sym::rustc_abi) { + for attr in tcx.get_attrs(id.owner_id, sym::rustc_abi) { + match tcx.def_kind(id.owner_id) { + DefKind::Fn => { dump_abi_of_fn_item(tcx, id.owner_id.def_id.into(), attr); } - } - DefKind::TyAlias { .. } => { - for attr in tcx.get_attrs(id.owner_id, sym::rustc_abi) { + DefKind::TyAlias { .. } => { dump_abi_of_fn_type(tcx, id.owner_id.def_id.into(), attr); } + _ => { + tcx.sess.emit_err(AbiInvalidAttribute { span: tcx.def_span(id.owner_id) }); + } } - DefKind::Impl { .. } => { - // To find associated functions we need to go into the child items here. - for &id in tcx.associated_item_def_ids(id.owner_id) { - if matches!(tcx.def_kind(id), DefKind::AssocFn) { - for attr in tcx.get_attrs(id, sym::rustc_abi) { + } + if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) { + // To find associated functions we need to go into the child items here. + for &id in tcx.associated_item_def_ids(id.owner_id) { + for attr in tcx.get_attrs(id, sym::rustc_abi) { + match tcx.def_kind(id) { + DefKind::AssocFn => { dump_abi_of_fn_item(tcx, id, attr); } + _ => { + tcx.sess.emit_err(AbiInvalidAttribute { span: tcx.def_span(id) }); + } } } } - _ => {} } } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 32dd02a4aa9..de55b5ec2cb 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -873,32 +873,32 @@ pub struct DuplicateDiagnosticItemInCrate { } #[derive(Diagnostic)] -#[diag(passes_abi)] -pub struct Abi { +#[diag(passes_layout_abi)] +pub struct LayoutAbi { #[primary_span] pub span: Span, pub abi: String, } #[derive(Diagnostic)] -#[diag(passes_align)] -pub struct Align { +#[diag(passes_layout_align)] +pub struct LayoutAlign { #[primary_span] pub span: Span, pub align: String, } #[derive(Diagnostic)] -#[diag(passes_size)] -pub struct Size { +#[diag(passes_layout_size)] +pub struct LayoutSize { #[primary_span] pub span: Span, pub size: String, } #[derive(Diagnostic)] -#[diag(passes_homogeneous_aggregate)] -pub struct HomogeneousAggregate { +#[diag(passes_layout_homogeneous_aggregate)] +pub struct LayoutHomogeneousAggregate { #[primary_span] pub span: Span, pub homogeneous_aggregate: String, @@ -914,6 +914,13 @@ pub struct LayoutOf { } #[derive(Diagnostic)] +#[diag(passes_layout_invalid_attribute)] +pub struct LayoutInvalidAttribute { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(passes_abi_of)] pub struct AbiOf { #[primary_span] @@ -923,6 +930,13 @@ pub struct AbiOf { } #[derive(Diagnostic)] +#[diag(passes_abi_invalid_attribute)] +pub struct AbiInvalidAttribute { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(passes_unrecognized_field)] pub struct UnrecognizedField { #[primary_span] diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index d839fee07a6..f3c12e0746d 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -8,7 +8,10 @@ use rustc_span::symbol::sym; use rustc_span::Span; use rustc_target::abi::{HasDataLayout, TargetDataLayout}; -use crate::errors::{Abi, Align, HomogeneousAggregate, LayoutOf, Size, UnrecognizedField}; +use crate::errors::{ + LayoutAbi, LayoutAlign, LayoutHomogeneousAggregate, LayoutInvalidAttribute, LayoutOf, + LayoutSize, UnrecognizedField, +}; pub fn test_layout(tcx: TyCtxt<'_>) { if !tcx.features().rustc_attrs { @@ -16,12 +19,22 @@ pub fn test_layout(tcx: TyCtxt<'_>) { return; } for id in tcx.hir().items() { - if matches!( - tcx.def_kind(id.owner_id), - DefKind::TyAlias { .. } | DefKind::Enum | DefKind::Struct | DefKind::Union - ) { - for attr in tcx.get_attrs(id.owner_id, sym::rustc_layout) { - dump_layout_of(tcx, id.owner_id.def_id, attr); + for attr in tcx.get_attrs(id.owner_id, sym::rustc_layout) { + match tcx.def_kind(id.owner_id) { + DefKind::TyAlias { .. } | DefKind::Enum | DefKind::Struct | DefKind::Union => { + dump_layout_of(tcx, id.owner_id.def_id, attr); + } + _ => { + tcx.sess.emit_err(LayoutInvalidAttribute { span: tcx.def_span(id.owner_id) }); + } + } + } + if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) { + // To find associated functions we need to go into the child items here. + for &id in tcx.associated_item_def_ids(id.owner_id) { + for _attr in tcx.get_attrs(id, sym::rustc_layout) { + tcx.sess.emit_err(LayoutInvalidAttribute { span: tcx.def_span(id) }); + } } } } @@ -38,28 +51,28 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) { for meta_item in meta_items { match meta_item.name_or_empty() { sym::abi => { - tcx.sess.emit_err(Abi { + tcx.sess.emit_err(LayoutAbi { span: tcx.def_span(item_def_id.to_def_id()), abi: format!("{:?}", ty_layout.abi), }); } sym::align => { - tcx.sess.emit_err(Align { + tcx.sess.emit_err(LayoutAlign { span: tcx.def_span(item_def_id.to_def_id()), align: format!("{:?}", ty_layout.align), }); } sym::size => { - tcx.sess.emit_err(Size { + tcx.sess.emit_err(LayoutSize { span: tcx.def_span(item_def_id.to_def_id()), size: format!("{:?}", ty_layout.size), }); } sym::homogeneous_aggregate => { - tcx.sess.emit_err(HomogeneousAggregate { + tcx.sess.emit_err(LayoutHomogeneousAggregate { span: tcx.def_span(item_def_id.to_def_id()), homogeneous_aggregate: format!( "{:?}", |
