Skip to content

Commit 6de065d

Browse files
committedJan 23, 2024
Auto merge of #120279 - fmease:rollup-4nhar13, r=fmease
Rollup of 12 pull requests Successful merges: - #112806 (Small code improvements in `collect_intra_doc_links.rs`) - #119460 (coverage: Never emit improperly-ordered coverage regions) - #119766 (Split tait and impl trait in assoc items logic) - #120062 (llvm: change data layout bug to an error and make it trigger more) - #120099 (linker: Refactor library linking methods in `trait Linker`) - #120139 (Do not normalize closure signature when building `FnOnce` shim) - #120160 (Manually implement derived `NonZero` traits.) - #120171 (Fix assume and assert in jump threading) - #120183 (Add `#[coverage(off)]` to closures introduced by `#[test]` and `#[bench]`) - #120195 (add several resolution test cases) - #120259 (Split Diagnostics for Uncommon Codepoints: Add List to Display Characters Involved) - #120261 (Provide structured suggestion to use trait objects in some cases of `if` arm type divergence) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dfe53af + 4756975 commit 6de065d

File tree

99 files changed

+1950
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1950
-559
lines changed
 

‎compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![doc(rust_logo)]
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
88
#![feature(array_windows)]
9+
#![feature(assert_matches)]
910
#![feature(box_patterns)]
1011
#![feature(decl_macro)]
1112
#![feature(if_let_guard)]

‎compiler/rustc_builtin_macros/src/test.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder, Level};
99
use rustc_expand::base::*;
1010
use rustc_span::symbol::{sym, Ident, Symbol};
1111
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
12+
use std::assert_matches::assert_matches;
1213
use std::iter;
1314
use thin_vec::{thin_vec, ThinVec};
1415

@@ -182,6 +183,16 @@ pub fn expand_test_or_bench(
182183
// creates $name: $expr
183184
let field = |name, expr| cx.field_imm(sp, Ident::from_str_and_span(name, sp), expr);
184185

186+
// Adds `#[coverage(off)]` to a closure, so it won't be instrumented in
187+
// `-Cinstrument-coverage` builds.
188+
// This requires `#[allow_internal_unstable(coverage_attribute)]` on the
189+
// corresponding macro declaration in `core::macros`.
190+
let coverage_off = |mut expr: P<ast::Expr>| {
191+
assert_matches!(expr.kind, ast::ExprKind::Closure(_));
192+
expr.attrs.push(cx.attr_nested_word(sym::coverage, sym::off, sp));
193+
expr
194+
};
195+
185196
let test_fn = if is_bench {
186197
// A simple ident for a lambda
187198
let b = Ident::from_str_and_span("b", attr_sp);
@@ -190,8 +201,9 @@ pub fn expand_test_or_bench(
190201
sp,
191202
cx.expr_path(test_path("StaticBenchFn")),
192203
thin_vec![
204+
// #[coverage(off)]
193205
// |b| self::test::assert_test_result(
194-
cx.lambda1(
206+
coverage_off(cx.lambda1(
195207
sp,
196208
cx.expr_call(
197209
sp,
@@ -206,16 +218,17 @@ pub fn expand_test_or_bench(
206218
],
207219
),
208220
b,
209-
), // )
221+
)), // )
210222
],
211223
)
212224
} else {
213225
cx.expr_call(
214226
sp,
215227
cx.expr_path(test_path("StaticTestFn")),
216228
thin_vec![
229+
// #[coverage(off)]
217230
// || {
218-
cx.lambda0(
231+
coverage_off(cx.lambda0(
219232
sp,
220233
// test::assert_test_result(
221234
cx.expr_call(
@@ -230,7 +243,7 @@ pub fn expand_test_or_bench(
230243
), // )
231244
],
232245
), // }
233-
), // )
246+
)), // )
234247
],
235248
)
236249
};

0 commit comments

Comments
 (0)