Skip to content

Commit d36bdd1

Browse files
committedMar 24, 2024·
Auto merge of #123004 - matthiaskrgr:rollup-s3v4p50, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #122737 (conditionally ignore fatal diagnostic in the SilentEmitter) - #122757 (Fixed the `private-dependency` bug) - #122886 (add test for #90192) - #122937 (Unbox and unwrap the contents of `StatementKind::Coverage`) - #122949 (Add a regression test for #117310) - #122962 (Track run-make-support lib in common inputs stamp) - #122977 (Rename `Arguments::as_const_str` to `as_statically_known_str`) - #122983 (Fix build failure on ARM/AArch64/PowerPC/RISC-V FreeBSD/NetBSD) - #122984 (panic-in-panic-hook: formatting a message that's just a string is risk-free) - #122992 (std::thread: refine available_parallelism for solaris/illumos.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6e6c721 + cdf86bf commit d36bdd1

File tree

33 files changed

+176
-96
lines changed

33 files changed

+176
-96
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use rustc_codegen_ssa::traits::CoverageInfoBuilderMethods;
2-
use rustc_middle::mir::Coverage;
2+
use rustc_middle::mir::coverage::CoverageKind;
33
use rustc_middle::ty::Instance;
44

55
use crate::builder::Builder;
66

77
impl<'a, 'gcc, 'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
8-
fn add_coverage(&mut self, _instance: Instance<'tcx>, _coverage: &Coverage) {
8+
fn add_coverage(&mut self, _instance: Instance<'tcx>, _kind: &CoverageKind) {
99
// TODO(antoyo)
1010
}
1111
}

‎compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1414
use rustc_llvm::RustString;
1515
use rustc_middle::bug;
1616
use rustc_middle::mir::coverage::CoverageKind;
17-
use rustc_middle::mir::Coverage;
1817
use rustc_middle::ty::layout::HasTyCtxt;
1918
use rustc_middle::ty::Instance;
2019

@@ -75,7 +74,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
7574

7675
impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
7776
#[instrument(level = "debug", skip(self))]
78-
fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage) {
77+
fn add_coverage(&mut self, instance: Instance<'tcx>, kind: &CoverageKind) {
7978
// Our caller should have already taken care of inlining subtleties,
8079
// so we can assume that counter/expression IDs in this coverage
8180
// statement are meaningful for the given instance.
@@ -98,7 +97,6 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
9897
.entry(instance)
9998
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));
10099

101-
let Coverage { kind } = coverage;
102100
match *kind {
103101
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!(
104102
"marker statement {kind:?} should have been removed by CleanupPostBorrowck"
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::traits::*;
22

3-
use rustc_middle::mir::Coverage;
3+
use rustc_middle::mir::coverage::CoverageKind;
44
use rustc_middle::mir::SourceScope;
55

66
use super::FunctionCx;
77

88
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9-
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: &Coverage, scope: SourceScope) {
9+
pub fn codegen_coverage(&self, bx: &mut Bx, kind: &CoverageKind, scope: SourceScope) {
1010
// Determine the instance that coverage data was originally generated for.
1111
let instance = if let Some(inlined) = scope.inlined_instance(&self.mir.source_scopes) {
1212
self.monomorphize(inlined)
@@ -15,6 +15,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1515
};
1616

1717
// Handle the coverage info in a backend-specific way.
18-
bx.add_coverage(instance, coverage);
18+
bx.add_coverage(instance, kind);
1919
}
2020
}

‎compiler/rustc_codegen_ssa/src/mir/statement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6464
cg_indirect_place.storage_dead(bx);
6565
}
6666
}
67-
mir::StatementKind::Coverage(box ref coverage) => {
68-
self.codegen_coverage(bx, coverage, statement.source_info.scope);
67+
mir::StatementKind::Coverage(ref kind) => {
68+
self.codegen_coverage(bx, kind, statement.source_info.scope);
6969
}
7070
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(ref op)) => {
7171
if !matches!(bx.tcx().sess.opts.optimize, OptLevel::No | OptLevel::Less) {
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::BackendTypes;
2-
use rustc_middle::mir::Coverage;
2+
use rustc_middle::mir::coverage::CoverageKind;
33
use rustc_middle::ty::Instance;
44

55
pub trait CoverageInfoBuilderMethods<'tcx>: BackendTypes {
66
/// Handle the MIR coverage info in a backend-specific way.
77
///
88
/// This can potentially be a no-op in backends that don't support
99
/// coverage instrumentation.
10-
fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage);
10+
fn add_coverage(&mut self, instance: Instance<'tcx>, kind: &CoverageKind);
1111
}

‎compiler/rustc_const_eval/src/transform/validate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
346346
self.fail(location, format!("explicit `{kind:?}` is forbidden"));
347347
}
348348
}
349-
StatementKind::Coverage(coverage) => {
350-
let kind = &coverage.kind;
349+
StatementKind::Coverage(kind) => {
351350
if self.mir_phase >= MirPhase::Analysis(AnalysisPhase::PostCleanup)
352351
&& let CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. } = kind
353352
{

‎compiler/rustc_errors/src/emitter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ pub struct SilentEmitter {
541541
pub fallback_bundle: LazyFallbackBundle,
542542
pub fatal_dcx: DiagCtxt,
543543
pub fatal_note: Option<String>,
544+
pub emit_fatal_diagnostic: bool,
544545
}
545546

546547
impl Translate for SilentEmitter {
@@ -561,7 +562,7 @@ impl Emitter for SilentEmitter {
561562
}
562563

563564
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
564-
if diag.level == Level::Fatal {
565+
if self.emit_fatal_diagnostic && diag.level == Level::Fatal {
565566
if let Some(fatal_note) = &self.fatal_note {
566567
diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new());
567568
}

‎compiler/rustc_errors/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,18 @@ impl DiagCtxt {
612612
Self { inner: Lock::new(DiagCtxtInner::new(emitter)) }
613613
}
614614

615-
pub fn make_silent(&mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option<String>) {
615+
pub fn make_silent(
616+
&mut self,
617+
fallback_bundle: LazyFallbackBundle,
618+
fatal_note: Option<String>,
619+
emit_fatal_diagnostic: bool,
620+
) {
616621
self.wrap_emitter(|old_dcx| {
617622
Box::new(emitter::SilentEmitter {
618623
fallback_bundle,
619624
fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) },
620625
fatal_note,
626+
emit_fatal_diagnostic,
621627
})
622628
});
623629
}

‎compiler/rustc_interface/src/interface.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec<String>) -> Cfg {
4848
let psess = ParseSess::with_silent_emitter(
4949
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
5050
format!("this error occurred on the command line: `--cfg={s}`"),
51+
true,
5152
);
5253
let filename = FileName::cfg_spec_source_code(&s);
5354

@@ -111,6 +112,7 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec<String>) -> CheckCfg {
111112
let psess = ParseSess::with_silent_emitter(
112113
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
113114
format!("this error occurred on the command line: `--check-cfg={s}`"),
115+
true,
114116
);
115117
let filename = FileName::cfg_spec_source_code(&s);
116118

‎compiler/rustc_metadata/src/creader.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
389389
None
390390
}
391391

392+
// The `dependency` type is determined by the command line arguments(`--extern`) and
393+
// `private_dep`. However, sometimes the directly dependent crate is not specified by
394+
// `--extern`, in this case, `private-dep` is none during loading. This is equivalent to the
395+
// scenario where the command parameter is set to `public-dependency`
396+
fn is_private_dep(&self, name: &str, private_dep: Option<bool>) -> bool {
397+
self.sess.opts.externs.get(name).map_or(private_dep.unwrap_or(false), |e| e.is_private_dep)
398+
&& private_dep.unwrap_or(true)
399+
}
400+
392401
fn register_crate(
393402
&mut self,
394403
host_lib: Option<Library>,
@@ -404,14 +413,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
404413
let Library { source, metadata } = lib;
405414
let crate_root = metadata.get_root();
406415
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
407-
408-
let private_dep = self
409-
.sess
410-
.opts
411-
.externs
412-
.get(name.as_str())
413-
.map_or(private_dep.unwrap_or(false), |e| e.is_private_dep)
414-
&& private_dep.unwrap_or(true);
416+
let private_dep = self.is_private_dep(name.as_str(), private_dep);
415417

416418
// Claim this crate number and cache it
417419
let cnum = self.cstore.intern_stable_crate_id(&crate_root)?;
@@ -601,14 +603,17 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
601603

602604
match result {
603605
(LoadResult::Previous(cnum), None) => {
606+
// When `private_dep` is none, it indicates the directly dependent crate. If it is
607+
// not specified by `--extern` on command line parameters, it may be
608+
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
609+
// `public-dependency` here.
610+
let private_dep = self.is_private_dep(name.as_str(), private_dep);
604611
let data = self.cstore.get_crate_data_mut(cnum);
605612
if data.is_proc_macro_crate() {
606613
dep_kind = CrateDepKind::MacrosOnly;
607614
}
608615
data.set_dep_kind(cmp::max(data.dep_kind(), dep_kind));
609-
if let Some(private_dep) = private_dep {
610-
data.update_and_private_dep(private_dep);
611-
}
616+
data.update_and_private_dep(private_dep);
612617
Ok(cnum)
613618
}
614619
(LoadResult::Loaded(library), host_library) => {

‎compiler/rustc_middle/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::interpret::{
1313
Provenance,
1414
};
1515
use rustc_middle::mir::visit::Visitor;
16-
use rustc_middle::mir::{self, *};
16+
use rustc_middle::mir::*;
1717
use rustc_target::abi::Size;
1818

1919
const INDENT: &str = " ";
@@ -711,7 +711,7 @@ impl Debug for Statement<'_> {
711711
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
712712
write!(fmt, "AscribeUserType({place:?}, {variance:?}, {c_ty:?})")
713713
}
714-
Coverage(box mir::Coverage { ref kind }) => write!(fmt, "Coverage::{kind:?}"),
714+
Coverage(ref kind) => write!(fmt, "Coverage::{kind:?}"),
715715
Intrinsic(box ref intrinsic) => write!(fmt, "{intrinsic}"),
716716
ConstEvalCounter => write!(fmt, "ConstEvalCounter"),
717717
Nop => write!(fmt, "nop"),

‎compiler/rustc_middle/src/mir/syntax.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub enum StatementKind<'tcx> {
373373
///
374374
/// Interpreters and codegen backends that don't support coverage instrumentation
375375
/// can usually treat this as a no-op.
376-
Coverage(Box<Coverage>),
376+
Coverage(CoverageKind),
377377

378378
/// Denotes a call to an intrinsic that does not require an unwind path and always returns.
379379
/// This avoids adding a new block and a terminator for simple intrinsics.
@@ -517,12 +517,6 @@ pub enum FakeReadCause {
517517
ForIndex,
518518
}
519519

520-
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
521-
#[derive(TypeFoldable, TypeVisitable)]
522-
pub struct Coverage {
523-
pub kind: CoverageKind,
524-
}
525-
526520
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
527521
#[derive(TypeFoldable, TypeVisitable)]
528522
pub struct CopyNonOverlapping<'tcx> {
@@ -1458,5 +1452,6 @@ mod size_asserts {
14581452
static_assert_size!(Place<'_>, 16);
14591453
static_assert_size!(PlaceElem<'_>, 24);
14601454
static_assert_size!(Rvalue<'_>, 40);
1455+
static_assert_size!(StatementKind<'_>, 16);
14611456
// tidy-alphabetical-end
14621457
}

‎compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ macro_rules! make_mir_visitor {
156156

157157
fn visit_coverage(
158158
&mut self,
159-
coverage: & $($mutability)? Coverage,
159+
kind: & $($mutability)? coverage::CoverageKind,
160160
location: Location,
161161
) {
162-
self.super_coverage(coverage, location);
162+
self.super_coverage(kind, location);
163163
}
164164

165165
fn visit_retag(
@@ -803,7 +803,7 @@ macro_rules! make_mir_visitor {
803803
}
804804

805805
fn super_coverage(&mut self,
806-
_coverage: & $($mutability)? Coverage,
806+
_kind: & $($mutability)? coverage::CoverageKind,
807807
_location: Location) {
808808
}
809809

‎compiler/rustc_mir_build/src/build/cfg.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ impl<'tcx> CFG<'tcx> {
107107
/// This results in more accurate coverage reports for certain kinds of
108108
/// syntax (e.g. `continue` or `if !`) that would otherwise not appear in MIR.
109109
pub(crate) fn push_coverage_span_marker(&mut self, block: BasicBlock, source_info: SourceInfo) {
110-
let kind = StatementKind::Coverage(Box::new(Coverage {
111-
kind: coverage::CoverageKind::SpanMarker,
112-
}));
110+
let kind = StatementKind::Coverage(coverage::CoverageKind::SpanMarker);
113111
let stmt = Statement { source_info, kind };
114112
self.push(block, stmt);
115113
}

‎compiler/rustc_mir_build/src/build/coverageinfo.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ impl Builder<'_, '_> {
127127

128128
let marker_statement = mir::Statement {
129129
source_info,
130-
kind: mir::StatementKind::Coverage(Box::new(mir::Coverage {
131-
kind: CoverageKind::BlockMarker { id },
132-
})),
130+
kind: mir::StatementKind::Coverage(CoverageKind::BlockMarker { id }),
133131
};
134132
self.cfg.push(block, marker_statement);
135133

‎compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use crate::MirPass;
2020
use rustc_middle::mir::coverage::CoverageKind;
21-
use rustc_middle::mir::{Body, BorrowKind, Coverage, Rvalue, StatementKind, TerminatorKind};
21+
use rustc_middle::mir::{Body, BorrowKind, Rvalue, StatementKind, TerminatorKind};
2222
use rustc_middle::ty::TyCtxt;
2323

2424
pub struct CleanupPostBorrowck;
@@ -30,12 +30,11 @@ impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck {
3030
match statement.kind {
3131
StatementKind::AscribeUserType(..)
3232
| StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Fake, _)))
33-
| StatementKind::Coverage(box Coverage {
33+
| StatementKind::Coverage(
3434
// These kinds of coverage statements are markers inserted during
3535
// MIR building, and are not needed after InstrumentCoverage.
36-
kind: CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. },
37-
..
38-
})
36+
CoverageKind::BlockMarker { .. } | CoverageKind::SpanMarker { .. },
37+
)
3938
| StatementKind::FakeRead(..) => statement.make_nop(),
4039
_ => (),
4140
}

‎compiler/rustc_mir_transform/src/coverage/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::MirPass;
1515

1616
use rustc_middle::mir::coverage::*;
1717
use rustc_middle::mir::{
18-
self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator,
18+
self, BasicBlock, BasicBlockData, SourceInfo, Statement, StatementKind, Terminator,
1919
TerminatorKind,
2020
};
2121
use rustc_middle::ty::TyCtxt;
@@ -230,10 +230,7 @@ fn inject_statement(mir_body: &mut mir::Body<'_>, counter_kind: CoverageKind, bb
230230
debug!(" injecting statement {counter_kind:?} for {bb:?}");
231231
let data = &mut mir_body[bb];
232232
let source_info = data.terminator().source_info;
233-
let statement = Statement {
234-
source_info,
235-
kind: StatementKind::Coverage(Box::new(Coverage { kind: counter_kind })),
236-
};
233+
let statement = Statement { source_info, kind: StatementKind::Coverage(counter_kind) };
237234
data.statements.insert(0, statement);
238235
}
239236

‎compiler/rustc_mir_transform/src/coverage/query.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
33
use rustc_middle::mir::coverage::{CounterId, CoverageKind};
4-
use rustc_middle::mir::{Body, Coverage, CoverageIdsInfo, Statement, StatementKind};
4+
use rustc_middle::mir::{Body, CoverageIdsInfo, Statement, StatementKind};
55
use rustc_middle::query::TyCtxtAt;
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_middle::util::Providers;
@@ -54,7 +54,7 @@ fn coverage_ids_info<'tcx>(
5454
let mir_body = tcx.instance_mir(instance_def);
5555

5656
let max_counter_id = all_coverage_in_mir_body(mir_body)
57-
.filter_map(|coverage| match coverage.kind {
57+
.filter_map(|kind| match *kind {
5858
CoverageKind::CounterIncrement { id } => Some(id),
5959
_ => None,
6060
})
@@ -66,12 +66,10 @@ fn coverage_ids_info<'tcx>(
6666

6767
fn all_coverage_in_mir_body<'a, 'tcx>(
6868
body: &'a Body<'tcx>,
69-
) -> impl Iterator<Item = &'a Coverage> + Captures<'tcx> {
69+
) -> impl Iterator<Item = &'a CoverageKind> + Captures<'tcx> {
7070
body.basic_blocks.iter().flat_map(|bb_data| &bb_data.statements).filter_map(|statement| {
7171
match statement.kind {
72-
StatementKind::Coverage(box ref coverage) if !is_inlined(body, statement) => {
73-
Some(coverage)
74-
}
72+
StatementKind::Coverage(ref kind) if !is_inlined(body, statement) => Some(kind),
7573
_ => None,
7674
}
7775
})

‎compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
187187
// for their parent `BasicBlock`.
188188
StatementKind::StorageLive(_)
189189
| StatementKind::StorageDead(_)
190-
// Ignore `ConstEvalCounter`s
191190
| StatementKind::ConstEvalCounter
192-
// Ignore `Nop`s
193191
| StatementKind::Nop => None,
194192

195193
// FIXME(#78546): MIR InstrumentCoverage - Can the source_info.span for `FakeRead`
@@ -211,30 +209,28 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
211209
StatementKind::FakeRead(box (FakeReadCause::ForGuardBinding, _)) => None,
212210

213211
// Retain spans from most other statements.
214-
StatementKind::FakeRead(box (_, _)) // Not including `ForGuardBinding`
212+
StatementKind::FakeRead(_)
215213
| StatementKind::Intrinsic(..)
216-
| StatementKind::Coverage(box mir::Coverage {
214+
| StatementKind::Coverage(
217215
// The purpose of `SpanMarker` is to be matched and accepted here.
218-
kind: CoverageKind::SpanMarker
219-
})
216+
CoverageKind::SpanMarker,
217+
)
220218
| StatementKind::Assign(_)
221219
| StatementKind::SetDiscriminant { .. }
222220
| StatementKind::Deinit(..)
223221
| StatementKind::Retag(_, _)
224222
| StatementKind::PlaceMention(..)
225-
| StatementKind::AscribeUserType(_, _) => {
226-
Some(statement.source_info.span)
227-
}
223+
| StatementKind::AscribeUserType(_, _) => Some(statement.source_info.span),
228224

229-
StatementKind::Coverage(box mir::Coverage {
230-
// Block markers are used for branch coverage, so ignore them here.
231-
kind: CoverageKind::BlockMarker {..}
232-
}) => None,
225+
// Block markers are used for branch coverage, so ignore them here.
226+
StatementKind::Coverage(CoverageKind::BlockMarker { .. }) => None,
233227

234-
StatementKind::Coverage(box mir::Coverage {
235-
// These coverage statements should not exist prior to coverage instrumentation.
236-
kind: CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
237-
}) => bug!("Unexpected coverage statement found during coverage instrumentation: {statement:?}"),
228+
// These coverage statements should not exist prior to coverage instrumentation.
229+
StatementKind::Coverage(
230+
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. },
231+
) => bug!(
232+
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
233+
),
238234
}
239235
}
240236

@@ -382,9 +378,7 @@ pub(super) fn extract_branch_mappings(
382378
// Fill out the mapping from block marker IDs to their enclosing blocks.
383379
for (bb, data) in mir_body.basic_blocks.iter_enumerated() {
384380
for statement in &data.statements {
385-
if let StatementKind::Coverage(coverage) = &statement.kind
386-
&& let CoverageKind::BlockMarker { id } = coverage.kind
387-
{
381+
if let StatementKind::Coverage(CoverageKind::BlockMarker { id }) = statement.kind {
388382
block_markers[id] = Some(bb);
389383
}
390384
}

‎compiler/rustc_session/src/parse.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ impl ParseSess {
269269
}
270270
}
271271

272-
pub fn with_silent_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self {
272+
pub fn with_silent_emitter(
273+
locale_resources: Vec<&'static str>,
274+
fatal_note: String,
275+
emit_fatal_diagnostic: bool,
276+
) -> Self {
273277
let fallback_bundle = fallback_fluent_bundle(locale_resources, false);
274278
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
275279
let emitter = Box::new(HumanEmitter::new(
@@ -281,6 +285,7 @@ impl ParseSess {
281285
fallback_bundle,
282286
fatal_dcx,
283287
fatal_note: Some(fatal_note),
288+
emit_fatal_diagnostic,
284289
}))
285290
.disable_warnings();
286291
ParseSess::with_dcx(dcx, sm)

‎library/core/src/fmt/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub trait Write {
201201
impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
202202
#[inline]
203203
default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
204-
if let Some(s) = args.as_const_str() {
204+
if let Some(s) = args.as_statically_known_str() {
205205
self.write_str(s)
206206
} else {
207207
write(&mut self, args)
@@ -212,7 +212,7 @@ pub trait Write {
212212
impl<W: Write> SpecWriteFmt for &mut W {
213213
#[inline]
214214
fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
215-
if let Some(s) = args.as_const_str() {
215+
if let Some(s) = args.as_statically_known_str() {
216216
self.write_str(s)
217217
} else {
218218
write(self, args)
@@ -442,7 +442,7 @@ impl<'a> Arguments<'a> {
442442
/// Same as [`Arguments::as_str`], but will only return `Some(s)` if it can be determined at compile time.
443443
#[must_use]
444444
#[inline]
445-
fn as_const_str(&self) -> Option<&'static str> {
445+
fn as_statically_known_str(&self) -> Option<&'static str> {
446446
let s = self.as_str();
447447
if core::intrinsics::is_val_statically_known(s.is_some()) { s } else { None }
448448
}
@@ -1617,7 +1617,11 @@ impl<'a> Formatter<'a> {
16171617
#[stable(feature = "rust1", since = "1.0.0")]
16181618
#[inline]
16191619
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
1620-
if let Some(s) = fmt.as_const_str() { self.buf.write_str(s) } else { write(self.buf, fmt) }
1620+
if let Some(s) = fmt.as_statically_known_str() {
1621+
self.buf.write_str(s)
1622+
} else {
1623+
write(self.buf, fmt)
1624+
}
16211625
}
16221626

16231627
/// Flags for formatting
@@ -2308,7 +2312,7 @@ impl Write for Formatter<'_> {
23082312

23092313
#[inline]
23102314
fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
2311-
if let Some(s) = args.as_const_str() {
2315+
if let Some(s) = args.as_statically_known_str() {
23122316
self.buf.write_str(s)
23132317
} else {
23142318
write(self.buf, args)

‎library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
#![feature(float_gamma)]
329329
#![feature(float_minimum_maximum)]
330330
#![feature(float_next_up_down)]
331+
#![feature(fmt_internals)]
331332
#![feature(generic_nonzero)]
332333
#![feature(hasher_prefixfree_extras)]
333334
#![feature(hashmap_internals)]

‎library/std/src/panicking.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ pub mod panic_count {
391391
pub fn increase(run_panic_hook: bool) -> Option<MustAbort> {
392392
let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed);
393393
if global_count & ALWAYS_ABORT_FLAG != 0 {
394+
// Do *not* access thread-local state, we might be after a `fork`.
394395
return Some(MustAbort::AlwaysAbort);
395396
}
396397

@@ -744,19 +745,22 @@ fn rust_panic_with_hook(
744745
if let Some(must_abort) = must_abort {
745746
match must_abort {
746747
panic_count::MustAbort::PanicInHook => {
747-
// Don't try to print the message in this case
748-
// - perhaps that is causing the recursive panics.
748+
// Don't try to format the message in this case, perhaps that is causing the
749+
// recursive panics. However if the message is just a string, no user-defined
750+
// code is involved in printing it, so that is risk-free.
751+
let msg_str = message.and_then(|m| m.as_str()).map(|m| [m]);
752+
let message = msg_str.as_ref().map(|m| fmt::Arguments::new_const(m));
749753
let panicinfo = PanicInfo::internal_constructor(
750-
None, // no message
751-
location, // but we want to show the location!
754+
message.as_ref(),
755+
location,
752756
can_unwind,
753757
force_no_backtrace,
754758
);
755759
rtprintpanic!("{panicinfo}\nthread panicked while processing panic. aborting.\n");
756760
}
757761
panic_count::MustAbort::AlwaysAbort => {
758762
// Unfortunately, this does not print a backtrace, because creating
759-
// a `Backtrace` will allocate, which we must to avoid here.
763+
// a `Backtrace` will allocate, which we must avoid here.
760764
let panicinfo = PanicInfo::internal_constructor(
761765
message,
762766
location,

‎library/std/src/sys/pal/unix/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl Socket {
459459
const AF_NAME_MAX: usize = 16;
460460
let mut buf = [0; AF_NAME_MAX];
461461
for (src, dst) in name.to_bytes().iter().zip(&mut buf[..AF_NAME_MAX - 1]) {
462-
*dst = *src as i8;
462+
*dst = *src as libc::c_char;
463463
}
464464
let mut arg: libc::accept_filter_arg = unsafe { mem::zeroed() };
465465
arg.af_name = buf;

‎library/std/src/sys/pal/unix/thread.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
355355
target_os = "tvos",
356356
target_os = "linux",
357357
target_os = "macos",
358-
target_os = "solaris",
359-
target_os = "illumos",
360358
target_os = "aix",
361359
))] {
362360
#[allow(unused_assignments)]
@@ -483,6 +481,12 @@ pub fn available_parallelism() -> io::Result<NonZero<usize>> {
483481
.ok_or(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"))
484482
}
485483
}
484+
} else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
485+
let mut cpus = 0u32;
486+
if unsafe { libc::pset_info(libc::PS_MYID, core::ptr::null_mut(), &mut cpus, core::ptr::null_mut()) } != 0 {
487+
return Err(io::const_io_error!(io::ErrorKind::NotFound, "The number of hardware threads is not known for the target platform"));
488+
}
489+
Ok(unsafe { NonZero::new_unchecked(cpus as usize) })
486490
} else if #[cfg(target_os = "haiku")] {
487491
// system_info cpu_count field gets the static data set at boot time with `smp_set_num_cpus`
488492
// `get_system_info` calls then `smp_get_num_cpus`

‎src/tools/compiletest/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ fn common_inputs_stamp(config: &Config) -> Stamp {
609609
stamp.add_path(&rust_src_dir.join("src/etc/htmldocck.py"));
610610
}
611611

612+
stamp.add_dir(&rust_src_dir.join("src/tools/run-make-support"));
613+
612614
// Compiletest itself.
613615
stamp.add_dir(&rust_src_dir.join("src/tools/compiletest/"));
614616

‎src/tools/rustfmt/src/parse/session.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ fn default_dcx(
121121
fallback_bundle,
122122
fatal_dcx: DiagCtxt::new(emitter),
123123
fatal_note: None,
124+
emit_fatal_diagnostic: false,
124125
})
125126
} else {
126127
emitter
@@ -209,7 +210,7 @@ impl ParseSess {
209210
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
210211
false,
211212
);
212-
self.raw_psess.dcx.make_silent(fallback_bundle, None);
213+
self.raw_psess.dcx.make_silent(fallback_bundle, None, false);
213214
}
214215

215216
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
panicked at $DIR/panic-in-message-fmt.rs:18:9:
2+
not yet implemented
23
thread panicked while processing panic. aborting.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// issue: rust-lang/rust#90192
2+
// ICE assertion failed: matches!(ty.kind(), ty :: Param(_))
3+
//@ compile-flags:-Zpolymorphize=on -Zmir-opt-level=3
4+
//@ build-pass
5+
6+
fn test<T>() {
7+
std::mem::size_of::<T>();
8+
}
9+
10+
pub fn foo<T>(_: T) -> &'static fn() {
11+
&(test::<T> as fn())
12+
}
13+
14+
fn outer<T>() {
15+
foo(|| ());
16+
}
17+
18+
fn main() {
19+
outer::<u8>();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ aux-crate:priv:foo=foo.rs
2+
//@ compile-flags: -Zunstable-options
3+
4+
#![crate_type = "rlib"]
5+
extern crate foo;
6+
pub struct Bar(pub i32);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#![crate_type = "rlib"]
2+
pub struct Foo(pub i32);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ aux-build: bar.rs
2+
//@ aux-build: foo.rs
3+
//@ build-pass
4+
5+
#![deny(exported_private_dependencies)]
6+
7+
// Ensure the libbar.rlib is loaded first. If the command line parameter `--extern foo` does not
8+
// exist, previus version would fail to compile
9+
#![crate_type = "rlib"]
10+
extern crate bar;
11+
extern crate foo;
12+
pub fn baz() -> (Option<foo::Foo>, Option<bar::Bar>) { (None, None) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
#![allow(dead_code)]
5+
6+
use std::ops::Deref;
7+
8+
trait Trait {}
9+
impl<A, B> Trait for (A, B, u8) where A: Deref, B: Deref<Target = A::Target>, {}
10+
impl<A, B> Trait for (A, B, i8) {}
11+
12+
type TaitSized = impl Sized;
13+
fn def_tait1() -> TaitSized {}
14+
15+
type TaitCopy = impl Copy;
16+
fn def_tait2() -> TaitCopy {}
17+
18+
fn impl_trait<T: Trait> () {}
19+
20+
fn test() {
21+
impl_trait::<(&TaitSized, &TaitCopy, _)>();
22+
impl_trait::<(&TaitCopy, &TaitSized, _)>();
23+
24+
impl_trait::<(&TaitCopy, &String, _)>();
25+
impl_trait::<(&TaitSized, &String, _)>();
26+
}
27+
28+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.