diff options
| author | Andy Caldwell <andycaldwell@microsoft.com> | 2023-08-09 15:57:16 +0100 |
|---|---|---|
| committer | Andy Caldwell <andycaldwell@microsoft.com> | 2023-09-08 12:46:06 +0100 |
| commit | 8e03371fc3209b8b91989b108314e35f471d6b89 (patch) | |
| tree | e6daf752e96622b474af111105c489a8ebe9de22 /compiler/rustc_codegen_ssa | |
| parent | de4cba3a98a15a891ad708a049c7fb5682083d97 (diff) | |
| download | rust-8e03371fc3209b8b91989b108314e35f471d6b89.tar.gz rust-8e03371fc3209b8b91989b108314e35f471d6b89.zip | |
Rework no_coverage to coverage(off)
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/messages.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/errors.rs | 7 |
3 files changed, 28 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 3dc83f50b21..9ce13ff469c 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -23,6 +23,8 @@ codegen_ssa_erroneous_constant = erroneous constant encountered codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error} +codegen_ssa_expected_coverage_symbol = expected `coverage(off)` or `coverage(on)` + codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)` codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index f6936c80b77..287f2292f4d 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -16,7 +16,10 @@ use rustc_target::spec::{abi, SanitizerSet}; use crate::errors; use crate::target_features::from_target_feature; -use crate::{errors::ExpectedUsedSymbol, target_features::check_target_feature_trait_unsafe}; +use crate::{ + errors::{ExpectedCoverageSymbol, ExpectedUsedSymbol}, + target_features::check_target_feature_trait_unsafe, +}; fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { use rustc_middle::mir::mono::Linkage::*; @@ -128,7 +131,21 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { .emit(); } } - sym::no_coverage => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE, + sym::coverage => { + let inner = attr.meta_item_list(); + match inner.as_deref() { + Some([item]) if item.has_name(sym::off) => { + codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE; + } + Some([item]) if item.has_name(sym::on) => { + // Allow #[coverage(on)] for being explicit, maybe also in future to enable + // coverage on a smaller scope within an excluded larger scopy. + } + Some(_) | None => { + tcx.sess.emit_err(ExpectedCoverageSymbol { span: attr.span }); + } + } + } sym::rustc_std_internal_symbol => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 41602321ded..fa49095c9e8 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -562,6 +562,13 @@ pub struct UnknownArchiveKind<'a> { } #[derive(Diagnostic)] +#[diag(codegen_ssa_expected_coverage_symbol)] +pub struct ExpectedCoverageSymbol { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(codegen_ssa_expected_used_symbol)] pub struct ExpectedUsedSymbol { #[primary_span] |
