Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #126914

Merged
merged 28 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3af6242
rustc_codegen_ssa: Remove unused ModuleConfig::inline_threshold
Enselic May 4, 2024
651ff64
Fix typo in `-Cno-stack-check` deprecation warning
Enselic Jun 14, 2024
f5f067b
Deprecate no-op codegen option `-Cinline-threshold=...`
Enselic May 4, 2024
d630f5d
Show notice about "never used" for enum
long-long-float Apr 28, 2024
3f2f843
Ensure we don't accidentally succeed when we want to report an error
oli-obk Jun 13, 2024
f1be59f
SmartPointer derive-macro
dingxiangfei2009 May 26, 2024
b5dfeba
coverage: Forbid multiple `#[coverage(..)]` attributes
Zalathar Jun 19, 2024
a000fa8
coverage: Tighten validation of `#[coverage(off)]` and `#[coverage(on)]`
Zalathar Jun 20, 2024
b7c057c
coverage: Always error on `#[coverage(..)]` in unexpected places
Zalathar Jun 19, 2024
1852141
coverage: Bless coverage attribute tests
Zalathar Jun 20, 2024
ba5ec1f
Suggest inline const blocks for array initialization
GrigorenkoPV Jun 24, 2024
8ffb5f9
compiletest: make the crash test error message abit more informative
matthiaskrgr Jun 13, 2024
1c4d0ce
Separate the lifetimes of the `BorrowckInferCtxt` from the other borr…
oli-obk Jun 20, 2024
8fc6b3d
Separate the mir body lifetime from the other lifetimes
oli-obk Jun 24, 2024
84474a2
Small fixme in core now that NonZero is generic
GrigorenkoPV Jun 24, 2024
45261ff
add @kobzol to bootstrap team for triagebot
onur-ozkan Jun 24, 2024
13fca73
Replace `MaybeUninit::uninit_array()` with array repeat expression.
kpreid May 13, 2024
00e5f58
Rollup merge of #124460 - long-long-float:show-notice-about-enum-with…
compiler-errors Jun 24, 2024
faa28be
Rollup merge of #124712 - Enselic:deprecate-inline-threshold, r=pnkfelix
compiler-errors Jun 24, 2024
c77dc28
Rollup merge of #125082 - kpreid:const-uninit, r=dtolnay
compiler-errors Jun 24, 2024
ed460d2
Rollup merge of #125575 - dingxiangfei2009:derive-smart-ptr, r=davidtwco
compiler-errors Jun 24, 2024
46e4398
Rollup merge of #126413 - matthiaskrgr:crshmsg, r=oli-obk
compiler-errors Jun 24, 2024
49bdf46
Rollup merge of #126673 - oli-obk:dont_rely_on_err_reporting, r=compi…
compiler-errors Jun 24, 2024
9ce2a07
Rollup merge of #126682 - Zalathar:coverage-attr, r=lcnr
compiler-errors Jun 24, 2024
a7721a0
Rollup merge of #126899 - GrigorenkoPV:suggest-const-block, r=davidtwco
compiler-errors Jun 24, 2024
85eb835
Rollup merge of #126904 - GrigorenkoPV:nonzero-fixme, r=joboet
compiler-errors Jun 24, 2024
59c258f
Rollup merge of #126909 - onur-ozkan:add-kobzol, r=matthiaskrgr
compiler-errors Jun 24, 2024
16bd6e2
Rollup merge of #126911 - oli-obk:do_not_count_errors, r=compiler-errors
compiler-errors Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
coverage: Always error on #[coverage(..)] in unexpected places
This upgrades some warnings to errors, and also catches cases where the
attribute was silently ignored.
  • Loading branch information
Zalathar committed Jun 24, 2024
commit b7c057c9b2a00558594b854a3d01211d1767cfc6
15 changes: 3 additions & 12 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,9 @@ passes_continue_labeled_block =
.label = labeled blocks cannot be `continue`'d
.block_label = labeled block the `continue` points to

passes_coverage_fn_defn =
`#[coverage]` may only be applied to function definitions

passes_coverage_ignored_function_prototype =
`#[coverage]` is ignored on function prototypes

passes_coverage_not_coverable =
`#[coverage]` must be applied to coverable code
.label = not coverable code

passes_coverage_propagate =
`#[coverage]` does not propagate into items and must be applied to the contained functions directly
passes_coverage_not_fn_or_closure =
attribute should be applied to a function definition or closure
.label = not a function or closure

passes_dead_codes =
{ $multiple ->
Expand Down
42 changes: 5 additions & 37 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
}
[sym::inline] => self.check_inline(hir_id, attr, span, target),
[sym::coverage] => self.check_coverage(hir_id, attr, span, target),
[sym::coverage] => self.check_coverage(attr, span, target),
[sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target),
[sym::marker] => self.check_marker(hir_id, attr, span, target),
[sym::target_feature] => {
Expand Down Expand Up @@ -369,47 +369,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks if a `#[coverage]` is applied directly to a function
fn check_coverage(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
/// Checks that `#[coverage(..)]` is applied to a function or closure.
fn check_coverage(&self, attr: &Attribute, span: Span, target: Target) -> bool {
match target {
// #[coverage] on function is fine
// #[coverage(..)] on function is fine
Target::Fn
| Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,

// function prototypes can't be covered
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoverageFnProto,
);
true
}

Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoveragePropagate,
);
true
}

Target::Expression | Target::Statement | Target::Arm => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoverageFnDefn,
);
true
}

_ => {
self.dcx().emit_err(errors::IgnoredCoverageNotCoverable {
self.dcx().emit_err(errors::CoverageNotFnOrClosure {
attr_span: attr.span,
defn_span: span,
});
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,9 @@ pub struct InlineNotFnOrClosure {
pub defn_span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes_coverage_ignored_function_prototype)]
pub struct IgnoredCoverageFnProto;

#[derive(LintDiagnostic)]
#[diag(passes_coverage_propagate)]
pub struct IgnoredCoveragePropagate;

#[derive(LintDiagnostic)]
#[diag(passes_coverage_fn_defn)]
pub struct IgnoredCoverageFnDefn;

#[derive(Diagnostic)]
#[diag(passes_coverage_not_coverable, code = E0788)]
pub struct IgnoredCoverageNotCoverable {
#[diag(passes_coverage_not_fn_or_closure, code = E0788)]
pub struct CoverageNotFnOrClosure {
#[primary_span]
pub attr_span: Span,
#[label]
Expand Down