Skip to content

Commit 9337f7a

Browse files
committedAug 8, 2024
Auto merge of #128805 - tgross35:rollup-wajzi6w, r=tgross35
Rollup of 7 pull requests Successful merges: - #128520 (Skip over args when determining if async-closure's inner coroutine consumes its upvars) - #128552 (Emit an error for invalid use of the `#[no_sanitize]` attribute) - #128691 (Update `compiler-builtins` to 0.1.117) - #128702 (Add -Zmetrics-dir=PATH to save diagnostic metadata to disk) - #128797 (Fuchsia Test Runner: enable ffx repository server) - #128798 (refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary) - #128800 (Add tracking issue to core-pattern-type) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0d65e5a + 36b9aee commit 9337f7a

File tree

19 files changed

+321
-75
lines changed

19 files changed

+321
-75
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Session.vim
1919
*.iml
2020
.vscode
2121
.project
22+
.vim/
2223
.favorites.json
2324
.settings/
2425
.vs/

‎compiler/rustc_driver_impl/src/lib.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ use rustc_metadata::creader::MetadataLoader;
5151
use rustc_metadata::locator;
5252
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5353
use rustc_session::config::{
54-
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, CG_OPTIONS, Z_OPTIONS,
54+
nightly_options, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, CG_OPTIONS,
55+
Z_OPTIONS,
5556
};
5657
use rustc_session::getopts::{self, Matches};
5758
use rustc_session::lint::{Lint, LintId};
@@ -301,6 +302,8 @@ fn run_compiler(
301302
let Some(matches) = handle_options(&default_early_dcx, &args) else { return Ok(()) };
302303

303304
let sopts = config::build_session_options(&mut default_early_dcx, &matches);
305+
// fully initialize ice path static once unstable options are available as context
306+
let ice_file = ice_path_with_config(Some(&sopts.unstable_opts)).clone();
304307

305308
if let Some(ref code) = matches.opt_str("explain") {
306309
handle_explain(&default_early_dcx, diagnostics_registry(), code, sopts.color);
@@ -315,7 +318,7 @@ fn run_compiler(
315318
input: Input::File(PathBuf::new()),
316319
output_file: ofile,
317320
output_dir: odir,
318-
ice_file: ice_path().clone(),
321+
ice_file,
319322
file_loader,
320323
locale_resources: DEFAULT_LOCALE_RESOURCES,
321324
lint_caps: Default::default(),
@@ -1306,25 +1309,43 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
13061309

13071310
static ICE_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
13081311

1312+
// This function should only be called from the ICE hook.
1313+
//
1314+
// The intended behavior is that `run_compiler` will invoke `ice_path_with_config` early in the
1315+
// initialization process to properly initialize the ICE_PATH static based on parsed CLI flags.
1316+
//
1317+
// Subsequent calls to either function will then return the proper ICE path as configured by
1318+
// the environment and cli flags
13091319
fn ice_path() -> &'static Option<PathBuf> {
1320+
ice_path_with_config(None)
1321+
}
1322+
1323+
fn ice_path_with_config(config: Option<&UnstableOptions>) -> &'static Option<PathBuf> {
1324+
if ICE_PATH.get().is_some() && config.is_some() && cfg!(debug_assertions) {
1325+
tracing::warn!(
1326+
"ICE_PATH has already been initialized -- files may be emitted at unintended paths"
1327+
)
1328+
}
1329+
13101330
ICE_PATH.get_or_init(|| {
13111331
if !rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build() {
13121332
return None;
13131333
}
1314-
if let Some(s) = std::env::var_os("RUST_BACKTRACE")
1315-
&& s == "0"
1316-
{
1317-
return None;
1318-
}
13191334
let mut path = match std::env::var_os("RUSTC_ICE") {
13201335
Some(s) => {
13211336
if s == "0" {
13221337
// Explicitly opting out of writing ICEs to disk.
13231338
return None;
13241339
}
1340+
if let Some(unstable_opts) = config && unstable_opts.metrics_dir.is_some() {
1341+
tracing::warn!("ignoring -Zerror-metrics in favor of RUSTC_ICE for destination of ICE report files");
1342+
}
13251343
PathBuf::from(s)
13261344
}
1327-
None => std::env::current_dir().unwrap_or_default(),
1345+
None => config
1346+
.and_then(|unstable_opts| unstable_opts.metrics_dir.to_owned())
1347+
.or_else(|| std::env::current_dir().ok())
1348+
.unwrap_or_default(),
13281349
};
13291350
let now: OffsetDateTime = SystemTime::now().into();
13301351
let file_now = now

‎compiler/rustc_expand/src/mbe/diagnostics.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,40 @@ use std::borrow::Cow;
33
use rustc_ast::token::{self, Token, TokenKind};
44
use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
6-
use rustc_errors::{Applicability, Diag, DiagMessage};
6+
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, DiagMessage};
77
use rustc_macros::Subdiagnostic;
88
use rustc_parse::parser::{Parser, Recovery};
9+
use rustc_session::parse::ParseSess;
910
use rustc_span::source_map::SourceMap;
1011
use rustc_span::symbol::Ident;
1112
use rustc_span::{ErrorGuaranteed, Span};
1213
use tracing::debug;
1314

1415
use super::macro_rules::{parser_from_cx, NoopTracker};
15-
use crate::base::{DummyResult, ExtCtxt, MacResult};
1616
use crate::expand::{parse_ast_fragment, AstFragmentKind};
1717
use crate::mbe::macro_parser::ParseResult::*;
1818
use crate::mbe::macro_parser::{MatcherLoc, NamedParseResult, TtParser};
1919
use crate::mbe::macro_rules::{try_match_macro, Tracker};
2020

21-
pub(super) fn failed_to_match_macro<'cx>(
22-
cx: &'cx mut ExtCtxt<'_>,
21+
pub(super) fn failed_to_match_macro(
22+
psess: &ParseSess,
2323
sp: Span,
2424
def_span: Span,
2525
name: Ident,
2626
arg: TokenStream,
2727
lhses: &[Vec<MatcherLoc>],
28-
) -> Box<dyn MacResult + 'cx> {
29-
let psess = &cx.sess.psess;
30-
28+
) -> (Span, ErrorGuaranteed) {
3129
// An error occurred, try the expansion again, tracking the expansion closely for better
3230
// diagnostics.
33-
let mut tracker = CollectTrackerAndEmitter::new(cx, sp);
31+
let mut tracker = CollectTrackerAndEmitter::new(psess.dcx(), sp);
3432

3533
let try_success_result = try_match_macro(psess, name, &arg, lhses, &mut tracker);
3634

3735
if try_success_result.is_ok() {
3836
// Nonterminal parser recovery might turn failed matches into successful ones,
3937
// but for that it must have emitted an error already
4038
assert!(
41-
tracker.cx.dcx().has_errors().is_some(),
39+
tracker.dcx.has_errors().is_some(),
4240
"Macro matching returned a success on the second try"
4341
);
4442
}
@@ -50,15 +48,15 @@ pub(super) fn failed_to_match_macro<'cx>(
5048

5149
let Some(BestFailure { token, msg: label, remaining_matcher, .. }) = tracker.best_failure
5250
else {
53-
return DummyResult::any(sp, cx.dcx().span_delayed_bug(sp, "failed to match a macro"));
51+
return (sp, psess.dcx().span_delayed_bug(sp, "failed to match a macro"));
5452
};
5553

5654
let span = token.span.substitute_dummy(sp);
5755

58-
let mut err = cx.dcx().struct_span_err(span, parse_failure_msg(&token, None));
56+
let mut err = psess.dcx().struct_span_err(span, parse_failure_msg(&token, None));
5957
err.span_label(span, label);
60-
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
61-
err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
58+
if !def_span.is_dummy() && !psess.source_map().is_imported(def_span) {
59+
err.span_label(psess.source_map().guess_head_span(def_span), "when calling this macro");
6260
}
6361

6462
annotate_doc_comment(&mut err, psess.source_map(), span);
@@ -76,7 +74,7 @@ pub(super) fn failed_to_match_macro<'cx>(
7674
err.note("captured metavariables except for `:tt`, `:ident` and `:lifetime` cannot be compared to other tokens");
7775
err.note("see <https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment> for more information");
7876

79-
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
77+
if !def_span.is_dummy() && !psess.source_map().is_imported(def_span) {
8078
err.help("try using `:tt` instead in the macro definition");
8179
}
8280
}
@@ -104,18 +102,17 @@ pub(super) fn failed_to_match_macro<'cx>(
104102
}
105103
}
106104
let guar = err.emit();
107-
cx.trace_macros_diag();
108-
DummyResult::any(sp, guar)
105+
(sp, guar)
109106
}
110107

111108
/// The tracker used for the slow error path that collects useful info for diagnostics.
112-
struct CollectTrackerAndEmitter<'a, 'cx, 'matcher> {
113-
cx: &'a mut ExtCtxt<'cx>,
109+
struct CollectTrackerAndEmitter<'dcx, 'matcher> {
110+
dcx: DiagCtxtHandle<'dcx>,
114111
remaining_matcher: Option<&'matcher MatcherLoc>,
115112
/// Which arm's failure should we report? (the one furthest along)
116113
best_failure: Option<BestFailure>,
117114
root_span: Span,
118-
result: Option<Box<dyn MacResult + 'cx>>,
115+
result: Option<(Span, ErrorGuaranteed)>,
119116
}
120117

121118
struct BestFailure {
@@ -131,7 +128,7 @@ impl BestFailure {
131128
}
132129
}
133130

134-
impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx, 'matcher> {
131+
impl<'dcx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'dcx, 'matcher> {
135132
type Failure = (Token, u32, &'static str);
136133

137134
fn build_failure(tok: Token, position: u32, msg: &'static str) -> Self::Failure {
@@ -151,7 +148,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
151148
Success(_) => {
152149
// Nonterminal parser recovery might turn failed matches into successful ones,
153150
// but for that it must have emitted an error already
154-
self.cx.dcx().span_delayed_bug(
151+
self.dcx.span_delayed_bug(
155152
self.root_span,
156153
"should not collect detailed info for successful macro match",
157154
);
@@ -177,10 +174,10 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
177174
}
178175
Error(err_sp, msg) => {
179176
let span = err_sp.substitute_dummy(self.root_span);
180-
let guar = self.cx.dcx().span_err(span, msg.clone());
181-
self.result = Some(DummyResult::any(span, guar));
177+
let guar = self.dcx.span_err(span, msg.clone());
178+
self.result = Some((span, guar));
182179
}
183-
ErrorReported(guar) => self.result = Some(DummyResult::any(self.root_span, *guar)),
180+
ErrorReported(guar) => self.result = Some((self.root_span, *guar)),
184181
}
185182
}
186183

@@ -193,9 +190,9 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
193190
}
194191
}
195192

196-
impl<'a, 'cx> CollectTrackerAndEmitter<'a, 'cx, '_> {
197-
fn new(cx: &'a mut ExtCtxt<'cx>, root_span: Span) -> Self {
198-
Self { cx, remaining_matcher: None, best_failure: None, root_span, result: None }
193+
impl<'dcx> CollectTrackerAndEmitter<'dcx, '_> {
194+
fn new(dcx: DiagCtxtHandle<'dcx>, root_span: Span) -> Self {
195+
Self { dcx, remaining_matcher: None, best_failure: None, root_span, result: None }
199196
}
200197
}
201198

‎compiler/rustc_expand/src/mbe/macro_rules.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ fn expand_macro<'cx>(
268268
}
269269
Err(CanRetry::Yes) => {
270270
// Retry and emit a better error.
271-
diagnostics::failed_to_match_macro(cx, sp, def_span, name, arg, lhses)
271+
let (span, guar) =
272+
diagnostics::failed_to_match_macro(cx.psess(), sp, def_span, name, arg, lhses);
273+
cx.trace_macros_diag();
274+
DummyResult::any(span, guar)
272275
}
273276
}
274277
}

‎compiler/rustc_hir_typeck/src/upvar.rs

+53-13
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
219219
// `async-await/async-closures/force-move-due-to-inferred-kind.rs`.
220220
//
221221
// 2. If the coroutine-closure is forced to be `FnOnce` due to the way it
222-
// uses its upvars, but not *all* upvars would force the closure to `FnOnce`.
222+
// uses its upvars (e.g. it consumes a non-copy value), but not *all* upvars
223+
// would force the closure to `FnOnce`.
223224
// See the test: `async-await/async-closures/force-move-due-to-actually-fnonce.rs`.
224225
//
225226
// This would lead to an impossible to satisfy situation, since `AsyncFnOnce`
226227
// coroutine bodies can't borrow from their parent closure. To fix this,
227228
// we force the inner coroutine to also be `move`. This only matters for
228229
// coroutine-closures that are `move` since otherwise they themselves will
229230
// be borrowing from the outer environment, so there's no self-borrows occuring.
230-
//
231-
// One *important* note is that we do a call to `process_collected_capture_information`
232-
// to eagerly test whether the coroutine would end up `FnOnce`, but we do this
233-
// *before* capturing all the closure args by-value below, since that would always
234-
// cause the analysis to return `FnOnce`.
235231
if let UpvarArgs::Coroutine(..) = args
236232
&& let hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) =
237233
self.tcx.coroutine_kind(closure_def_id).expect("coroutine should have kind")
@@ -246,19 +242,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
246242
capture_clause = hir::CaptureBy::Value { move_kw };
247243
}
248244
// (2.) The way that the closure uses its upvars means it's `FnOnce`.
249-
else if let (_, ty::ClosureKind::FnOnce, _) = self
250-
.process_collected_capture_information(
251-
capture_clause,
252-
&delegate.capture_information,
253-
)
254-
{
245+
else if self.coroutine_body_consumes_upvars(closure_def_id, body) {
255246
capture_clause = hir::CaptureBy::Value { move_kw };
256247
}
257248
}
258249

259250
// As noted in `lower_coroutine_body_with_moved_arguments`, we default the capture mode
260251
// to `ByRef` for the `async {}` block internal to async fns/closure. This means
261-
// that we would *not* be moving all of the parameters into the async block by default.
252+
// that we would *not* be moving all of the parameters into the async block in all cases.
253+
// For example, when one of the arguments is `Copy`, we turn a consuming use into a copy of
254+
// a reference, so for `async fn x(t: i32) {}`, we'd only take a reference to `t`.
262255
//
263256
// We force all of these arguments to be captured by move before we do expr use analysis.
264257
//
@@ -535,6 +528,53 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
535528
}
536529
}
537530

531+
/// Determines whether the body of the coroutine uses its upvars in a way that
532+
/// consumes (i.e. moves) the value, which would force the coroutine to `FnOnce`.
533+
/// In a more detailed comment above, we care whether this happens, since if
534+
/// this happens, we want to force the coroutine to move all of the upvars it
535+
/// would've borrowed from the parent coroutine-closure.
536+
///
537+
/// This only really makes sense to be called on the child coroutine of a
538+
/// coroutine-closure.
539+
fn coroutine_body_consumes_upvars(
540+
&self,
541+
coroutine_def_id: LocalDefId,
542+
body: &'tcx hir::Body<'tcx>,
543+
) -> bool {
544+
// This block contains argument capturing details. Since arguments
545+
// aren't upvars, we do not care about them for determining if the
546+
// coroutine body actually consumes its upvars.
547+
let hir::ExprKind::Block(&hir::Block { expr: Some(body), .. }, None) = body.value.kind
548+
else {
549+
bug!();
550+
};
551+
// Specifically, we only care about the *real* body of the coroutine.
552+
// We skip out into the drop-temps within the block of the body in order
553+
// to skip over the args of the desugaring.
554+
let hir::ExprKind::DropTemps(body) = body.kind else {
555+
bug!();
556+
};
557+
558+
let mut delegate = InferBorrowKind {
559+
closure_def_id: coroutine_def_id,
560+
capture_information: Default::default(),
561+
fake_reads: Default::default(),
562+
};
563+
564+
let _ = euv::ExprUseVisitor::new(
565+
&FnCtxt::new(self, self.tcx.param_env(coroutine_def_id), coroutine_def_id),
566+
&mut delegate,
567+
)
568+
.consume_expr(body);
569+
570+
let (_, kind, _) = self.process_collected_capture_information(
571+
hir::CaptureBy::Ref,
572+
&delegate.capture_information,
573+
);
574+
575+
matches!(kind, ty::ClosureKind::FnOnce)
576+
}
577+
538578
// Returns a list of `Ty`s for each upvar.
539579
fn final_upvar_tys(&self, closure_id: LocalDefId) -> Vec<Ty<'tcx>> {
540580
self.typeck_results

‎compiler/rustc_passes/src/check_attr.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
125125
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
126126
[sym::coverage, ..] => self.check_coverage(attr, span, target),
127127
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
128+
[sym::no_sanitize, ..] => self.check_no_sanitize(hir_id, attr, span, target),
128129
[sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target),
129130
[sym::marker, ..] => self.check_marker(hir_id, attr, span, target),
130131
[sym::target_feature, ..] => {
@@ -256,7 +257,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
256257
| sym::may_dangle // FIXME(dropck_eyepatch)
257258
| sym::pointee // FIXME(derive_smart_pointer)
258259
| sym::linkage // FIXME(linkage)
259-
| sym::no_sanitize // FIXME(no_sanitize)
260260
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
261261
| sym::used // handled elsewhere to restrict to static items
262262
| sym::repr // handled elsewhere to restrict to type decls items
@@ -451,6 +451,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
451451
}
452452
}
453453

454+
/// Checks that `#[no_sanitize(..)]` is applied to a function or method.
455+
fn check_no_sanitize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
456+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
457+
}
458+
454459
fn check_generic_attr(
455460
&self,
456461
hir_id: HirId,

‎compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,8 @@ options! {
18271827
the same values as the target option of the same name"),
18281828
meta_stats: bool = (false, parse_bool, [UNTRACKED],
18291829
"gather metadata statistics (default: no)"),
1830+
metrics_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1831+
"stores metrics about the errors being emitted by rustc to disk"),
18301832
mir_emit_retag: bool = (false, parse_bool, [TRACKED],
18311833
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
18321834
(default: no)"),

‎library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ dependencies = [
5858

5959
[[package]]
6060
name = "compiler_builtins"
61-
version = "0.1.114"
61+
version = "0.1.117"
6262
source = "registry+https://github.com/rust-lang/crates.io-index"
63-
checksum = "eb58b199190fcfe0846f55a3b545cd6b07a34bdd5930a476ff856f3ebcc5558a"
63+
checksum = "a91dae36d82fe12621dfb5b596d7db766187747749b22e33ac068e1bfc356f4a"
6464
dependencies = [
6565
"cc",
6666
"rustc-std-workspace-core",

‎library/alloc/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.114", features = ['rustc-dep-of-std'] }
14-
15-
[target.'cfg(not(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")))'.dependencies]
16-
compiler_builtins = { version = "0.1.114", features = ["no-f16-f128"] }
13+
compiler_builtins = { version = "0.1.117", features = ['rustc-dep-of-std'] }
1714

1815
[dev-dependencies]
1916
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

‎library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub mod net;
391391
pub mod option;
392392
pub mod panic;
393393
pub mod panicking;
394-
#[unstable(feature = "core_pattern_types", issue = "none")]
394+
#[unstable(feature = "core_pattern_types", issue = "123646")]
395395
pub mod pat;
396396
pub mod pin;
397397
#[unstable(feature = "new_range_api", issue = "125687")]

‎library/core/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// ```
77
#[macro_export]
88
#[rustc_builtin_macro(pattern_type)]
9-
#[unstable(feature = "core_pattern_type", issue = "none")]
9+
#[unstable(feature = "core_pattern_type", issue = "123646")]
1010
macro_rules! pattern_type {
1111
($($arg:tt)*) => {
1212
/* compiler built-in */

‎library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
compiler_builtins = { version = "0.1.114" }
20+
compiler_builtins = { version = "0.1.117" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.14", default-features = false, features = [

‎library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ pub mod net;
586586
pub mod num;
587587
pub mod os;
588588
pub mod panic;
589-
#[unstable(feature = "core_pattern_types", issue = "none")]
589+
#[unstable(feature = "core_pattern_types", issue = "123646")]
590590
pub mod pat;
591591
pub mod path;
592592
#[unstable(feature = "anonymous_pipe", issue = "127154")]

‎src/ci/docker/scripts/fuchsia-test-runner.py

+13
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,19 @@ def start(self):
571571
)
572572

573573
# Start repository server
574+
# Note that we must first enable the repository server daemon.
575+
check_call_with_logging(
576+
[
577+
ffx_path,
578+
"config",
579+
"set",
580+
"repository.server.enabled",
581+
"true",
582+
],
583+
env=ffx_env,
584+
stdout_handler=self.subprocess_logger.debug,
585+
stderr_handler=self.subprocess_logger.debug,
586+
)
574587
check_call_with_logging(
575588
[
576589
ffx_path,

‎tests/run-make/dump-ice-to-disk/rmake.rs

+71-15
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
// or full.
55
// - Check that disabling ICE logging results in zero files created.
66
// - Check that the ICE files contain some of the expected strings.
7+
// - exercise the -Zmetrics-dir nightly flag
8+
// - verify what happens when both the nightly flag and env variable are set
9+
// - test the RUST_BACKTRACE=0 behavior against the file creation
10+
711
// See https://github.com/rust-lang/rust/pull/108714
812

913
use run_make_support::{cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files};
1014

1115
fn main() {
1216
rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
1317
let default = get_text_from_ice(".").lines().count();
14-
clear_ice_files();
1518

19+
clear_ice_files();
1620
rustc().env("RUSTC_ICE", cwd()).input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
1721
let ice_text = get_text_from_ice(cwd());
1822
let default_set = ice_text.lines().count();
@@ -25,7 +29,28 @@ fn main() {
2529
ice_files.first().and_then(|f| f.file_name()).and_then(|n| n.to_str()).unwrap();
2630
// Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows.
2731
assert!(!ice_file_name.contains(":"), "{ice_file_name}");
32+
assert_eq!(default, default_set);
33+
assert!(default > 0);
34+
// Some of the expected strings in an ICE file should appear.
35+
assert!(content.contains("thread 'rustc' panicked at"));
36+
assert!(content.contains("stack backtrace:"));
37+
38+
test_backtrace_short(default);
39+
test_backtrace_full(default);
40+
test_backtrace_disabled(default);
41+
42+
clear_ice_files();
43+
// The ICE dump is explicitly disabled. Therefore, this should produce no files.
44+
rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
45+
let ice_files = shallow_find_files(cwd(), |path| {
46+
has_prefix(path, "rustc-ice") && has_extension(path, "txt")
47+
});
48+
assert!(ice_files.is_empty()); // There should be 0 ICE files.
49+
50+
metrics_dir(default);
51+
}
2852

53+
fn test_backtrace_short(baseline: usize) {
2954
clear_ice_files();
3055
rustc()
3156
.env("RUSTC_ICE", cwd())
@@ -34,6 +59,11 @@ fn main() {
3459
.arg("-Ztreat-err-as-bug=1")
3560
.run_fail();
3661
let short = get_text_from_ice(cwd()).lines().count();
62+
// backtrace length in dump shouldn't be changed by RUST_BACKTRACE
63+
assert_eq!(short, baseline);
64+
}
65+
66+
fn test_backtrace_full(baseline: usize) {
3767
clear_ice_files();
3868
rustc()
3969
.env("RUSTC_ICE", cwd())
@@ -42,23 +72,49 @@ fn main() {
4272
.arg("-Ztreat-err-as-bug=1")
4373
.run_fail();
4474
let full = get_text_from_ice(cwd()).lines().count();
75+
// backtrace length in dump shouldn't be changed by RUST_BACKTRACE
76+
assert_eq!(full, baseline);
77+
}
78+
79+
fn test_backtrace_disabled(baseline: usize) {
4580
clear_ice_files();
81+
rustc()
82+
.env("RUSTC_ICE", cwd())
83+
.input("lib.rs")
84+
.env("RUST_BACKTRACE", "0")
85+
.arg("-Ztreat-err-as-bug=1")
86+
.run_fail();
87+
let disabled = get_text_from_ice(cwd()).lines().count();
88+
// backtrace length in dump shouldn't be changed by RUST_BACKTRACE
89+
assert_eq!(disabled, baseline);
90+
}
4691

47-
// The ICE dump is explicitly disabled. Therefore, this should produce no files.
48-
rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
49-
let ice_files = shallow_find_files(cwd(), |path| {
50-
has_prefix(path, "rustc-ice") && has_extension(path, "txt")
51-
});
52-
assert!(ice_files.is_empty()); // There should be 0 ICE files.
92+
fn metrics_dir(baseline: usize) {
93+
test_flag_only(baseline);
94+
test_flag_and_env(baseline);
95+
}
5396

54-
// The line count should not change.
55-
assert_eq!(short, default_set);
56-
assert_eq!(short, default);
57-
assert_eq!(full, default_set);
58-
assert!(default > 0);
59-
// Some of the expected strings in an ICE file should appear.
60-
assert!(content.contains("thread 'rustc' panicked at"));
61-
assert!(content.contains("stack backtrace:"));
97+
fn test_flag_only(baseline: usize) {
98+
clear_ice_files();
99+
let metrics_arg = format!("-Zmetrics-dir={}", cwd().display());
100+
rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").arg(metrics_arg).run_fail();
101+
let output = get_text_from_ice(cwd()).lines().count();
102+
assert_eq!(output, baseline);
103+
}
104+
105+
fn test_flag_and_env(baseline: usize) {
106+
clear_ice_files();
107+
let metrics_arg = format!("-Zmetrics-dir={}", cwd().display());
108+
let real_dir = cwd().join("actually_put_ice_here");
109+
rfs::create_dir(real_dir.clone());
110+
rustc()
111+
.input("lib.rs")
112+
.env("RUSTC_ICE", real_dir.clone())
113+
.arg("-Ztreat-err-as-bug=1")
114+
.arg(metrics_arg)
115+
.run_fail();
116+
let output = get_text_from_ice(real_dir).lines().count();
117+
assert_eq!(output, baseline);
62118
}
63119

64120
fn clear_ice_files() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ aux-build:block-on.rs
2+
//@ edition:2021
3+
//@ build-pass
4+
5+
#![feature(async_closure)]
6+
7+
extern crate block_on;
8+
9+
fn wrapper(f: impl Fn(String)) -> impl async Fn(String) {
10+
async move |s| f(s)
11+
}
12+
13+
fn main() {
14+
block_on::block_on(async {
15+
wrapper(|who| println!("Hello, {who}!"))(String::from("world")).await;
16+
});
17+
}

‎tests/ui/attributes/no-sanitize.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(no_sanitize)]
2+
#![feature(stmt_expr_attributes)]
3+
#![deny(unused_attributes)]
4+
#![allow(dead_code)]
5+
6+
fn invalid() {
7+
#[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
8+
{
9+
1
10+
};
11+
}
12+
13+
#[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
14+
type InvalidTy = ();
15+
16+
#[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
17+
mod invalid_module {}
18+
19+
fn main() {
20+
let _ = #[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
21+
(|| 1);
22+
}
23+
24+
#[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
25+
struct F;
26+
27+
#[no_sanitize(memory)] //~ ERROR attribute should be applied to a function definition
28+
impl F {
29+
#[no_sanitize(memory)]
30+
fn valid(&self) {}
31+
}
32+
33+
#[no_sanitize(memory)]
34+
fn valid() {}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: attribute should be applied to a function definition
2+
--> $DIR/no-sanitize.rs:7:5
3+
|
4+
LL | #[no_sanitize(memory)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
LL | / {
7+
LL | | 1
8+
LL | | };
9+
| |_____- not a function definition
10+
11+
error: attribute should be applied to a function definition
12+
--> $DIR/no-sanitize.rs:13:1
13+
|
14+
LL | #[no_sanitize(memory)]
15+
| ^^^^^^^^^^^^^^^^^^^^^^
16+
LL | type InvalidTy = ();
17+
| -------------------- not a function definition
18+
19+
error: attribute should be applied to a function definition
20+
--> $DIR/no-sanitize.rs:16:1
21+
|
22+
LL | #[no_sanitize(memory)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
LL | mod invalid_module {}
25+
| --------------------- not a function definition
26+
27+
error: attribute should be applied to a function definition
28+
--> $DIR/no-sanitize.rs:20:13
29+
|
30+
LL | let _ = #[no_sanitize(memory)]
31+
| ^^^^^^^^^^^^^^^^^^^^^^
32+
LL | (|| 1);
33+
| ------ not a function definition
34+
35+
error: attribute should be applied to a function definition
36+
--> $DIR/no-sanitize.rs:24:1
37+
|
38+
LL | #[no_sanitize(memory)]
39+
| ^^^^^^^^^^^^^^^^^^^^^^
40+
LL | struct F;
41+
| --------- not a function definition
42+
43+
error: attribute should be applied to a function definition
44+
--> $DIR/no-sanitize.rs:27:1
45+
|
46+
LL | #[no_sanitize(memory)]
47+
| ^^^^^^^^^^^^^^^^^^^^^^
48+
LL | / impl F {
49+
LL | | #[no_sanitize(memory)]
50+
LL | | fn valid(&self) {}
51+
LL | | }
52+
| |_- not a function definition
53+
54+
error: aborting due to 6 previous errors
55+

‎tests/ui/type/pattern_types/feature-gate-pattern_types.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error[E0658]: use of unstable library feature 'core_pattern_type'
44
LL | type NonNullU32 = pattern_type!(u32 is 1..);
55
| ^^^^^^^^^^^^
66
|
7+
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/123646> for more information
78
= help: add `#![feature(core_pattern_type)]` to the crate attributes to enable
89
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
910

@@ -13,6 +14,7 @@ error[E0658]: use of unstable library feature 'core_pattern_type'
1314
LL | type Percent = pattern_type!(u32 is 0..=100);
1415
| ^^^^^^^^^^^^
1516
|
17+
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/123646> for more information
1618
= help: add `#![feature(core_pattern_type)]` to the crate attributes to enable
1719
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1820

@@ -22,6 +24,7 @@ error[E0658]: use of unstable library feature 'core_pattern_type'
2224
LL | type Negative = pattern_type!(i32 is ..=0);
2325
| ^^^^^^^^^^^^
2426
|
27+
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/123646> for more information
2528
= help: add `#![feature(core_pattern_type)]` to the crate attributes to enable
2629
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2730

@@ -31,6 +34,7 @@ error[E0658]: use of unstable library feature 'core_pattern_type'
3134
LL | type Positive = pattern_type!(i32 is 0..);
3235
| ^^^^^^^^^^^^
3336
|
37+
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/123646> for more information
3438
= help: add `#![feature(core_pattern_type)]` to the crate attributes to enable
3539
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3640

@@ -40,6 +44,7 @@ error[E0658]: use of unstable library feature 'core_pattern_type'
4044
LL | type Always = pattern_type!(Option<u32> is Some(_));
4145
| ^^^^^^^^^^^^
4246
|
47+
= note: see issue #123646 <https://github.com/rust-lang/rust/issues/123646> for more information
4348
= help: add `#![feature(core_pattern_type)]` to the crate attributes to enable
4449
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4550

0 commit comments

Comments
 (0)
Please sign in to comment.