Skip to content

Commit fd7eefc

Browse files
committedJun 17, 2024·
Auto merge of rust-lang#126569 - jieyouxu:rollup-1uvkb2y, r=jieyouxu
Rollup of 8 pull requests Successful merges: - rust-lang#125258 (Resolve elided lifetimes in assoc const to static if no other lifetimes are in scope) - rust-lang#126250 (docs(change): Don't mention a Cargo 2024 edition change for 1.79) - rust-lang#126288 (doc: Added commas where needed) - rust-lang#126346 (export std::os::fd module on HermitOS) - rust-lang#126468 (div_euclid, rem_euclid: clarify/extend documentation) - rust-lang#126531 (Add codegen test for `Request::provide_*`) - rust-lang#126535 (coverage: Arrange span extraction/refinement as a series of passes) - rust-lang#126538 (coverage: Several small improvements to graph code) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e794b0f + d92aa56 commit fd7eefc

33 files changed

+731
-593
lines changed
 

‎RELEASES.md

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ Cargo
9797
- [Prevent dashes in `lib.name`, always normalizing to `_`.](https://github.com/rust-lang/cargo/pull/12783/)
9898
- [Stabilize MSRV-aware version requirement selection in `cargo add`.](https://github.com/rust-lang/cargo/pull/13608/)
9999
- [Switch to using `gitoxide` by default for listing files.](https://github.com/rust-lang/cargo/pull/13696/)
100-
- [Error on `[project]` in Edition 2024; `cargo fix --edition` will change it to `[package]`.](https://github.com/rust-lang/cargo/pull/13747/)
101100

102101
<a id="1.79.0-Rustdoc"></a>
103102

‎compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lint_associated_const_elided_lifetime = {$elided ->
1414
*[false] `'_` cannot be used here
1515
}
1616
.suggestion = use the `'static` lifetime
17+
.note = cannot automatically infer `'static` because of other lifetimes in scope
1718
1819
lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
1920
.note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`

‎compiler/rustc_lint/src/context/diagnostics.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,20 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
319319
BuiltinLintDiag::UnusedQualifications { removal_span } => {
320320
lints::UnusedQualifications { removal_span }.decorate_lint(diag);
321321
}
322-
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span: lt_span } => {
322+
BuiltinLintDiag::AssociatedConstElidedLifetime {
323+
elided,
324+
span: lt_span,
325+
lifetimes_in_scope,
326+
} => {
323327
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
324328
let code = if elided { "'static " } else { "'static" };
325-
lints::AssociatedConstElidedLifetime { span: lt_span, code, elided }
326-
.decorate_lint(diag);
329+
lints::AssociatedConstElidedLifetime {
330+
span: lt_span,
331+
code,
332+
elided,
333+
lifetimes_in_scope,
334+
}
335+
.decorate_lint(diag);
327336
}
328337
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
329338
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis }

‎compiler/rustc_lint/src/lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2873,6 +2873,8 @@ pub struct AssociatedConstElidedLifetime {
28732873

28742874
pub code: &'static str,
28752875
pub elided: bool,
2876+
#[note]
2877+
pub lifetimes_in_scope: MultiSpan,
28762878
}
28772879

28782880
#[derive(LintDiagnostic)]

‎compiler/rustc_lint_defs/src/builtin.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4593,16 +4593,18 @@ declare_lint! {
45934593

45944594
declare_lint! {
45954595
/// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
4596-
/// that were erroneously allowed in associated constants.
4596+
/// in associated constants when there are other lifetimes in scope. This was
4597+
/// accidentally supported, and this lint was later relaxed to allow eliding
4598+
/// lifetimes to `'static` when there are no lifetimes in scope.
45974599
///
45984600
/// ### Example
45994601
///
46004602
/// ```rust,compile_fail
46014603
/// #![deny(elided_lifetimes_in_associated_constant)]
46024604
///
4603-
/// struct Foo;
4605+
/// struct Foo<'a>(&'a ());
46044606
///
4605-
/// impl Foo {
4607+
/// impl<'a> Foo<'a> {
46064608
/// const STR: &str = "hello, world";
46074609
/// }
46084610
/// ```

‎compiler/rustc_lint_defs/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ pub enum BuiltinLintDiag {
696696
AssociatedConstElidedLifetime {
697697
elided: bool,
698698
span: Span,
699+
lifetimes_in_scope: MultiSpan,
699700
},
700701
RedundantImportVisibility {
701702
span: Span,

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

-5
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,6 @@ impl CoverageCounters {
168168
self.counter_increment_sites.len()
169169
}
170170

171-
#[cfg(test)]
172-
pub(super) fn num_expressions(&self) -> usize {
173-
self.expressions.len()
174-
}
175-
176171
fn set_bcb_counter(&mut self, bcb: BasicCoverageBlock, counter_kind: BcbCounter) -> BcbCounter {
177172
if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) {
178173
bug!(

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

+46-43
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ use std::ops::{Index, IndexMut};
1414
/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
1515
/// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
1616
#[derive(Debug)]
17-
pub(super) struct CoverageGraph {
17+
pub(crate) struct CoverageGraph {
1818
bcbs: IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
1919
bb_to_bcb: IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
20-
pub successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
21-
pub predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
20+
pub(crate) successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
21+
pub(crate) predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
2222
dominators: Option<Dominators<BasicCoverageBlock>>,
2323
}
2424

2525
impl CoverageGraph {
26-
pub fn from_mir(mir_body: &mir::Body<'_>) -> Self {
26+
pub(crate) fn from_mir(mir_body: &mir::Body<'_>) -> Self {
2727
let (bcbs, bb_to_bcb) = Self::compute_basic_coverage_blocks(mir_body);
2828

2929
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
@@ -135,24 +135,28 @@ impl CoverageGraph {
135135
}
136136

137137
#[inline(always)]
138-
pub fn iter_enumerated(
138+
pub(crate) fn iter_enumerated(
139139
&self,
140140
) -> impl Iterator<Item = (BasicCoverageBlock, &BasicCoverageBlockData)> {
141141
self.bcbs.iter_enumerated()
142142
}
143143

144144
#[inline(always)]
145-
pub fn bcb_from_bb(&self, bb: BasicBlock) -> Option<BasicCoverageBlock> {
145+
pub(crate) fn bcb_from_bb(&self, bb: BasicBlock) -> Option<BasicCoverageBlock> {
146146
if bb.index() < self.bb_to_bcb.len() { self.bb_to_bcb[bb] } else { None }
147147
}
148148

149149
#[inline(always)]
150-
pub fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
150+
pub(crate) fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
151151
self.dominators.as_ref().unwrap().dominates(dom, node)
152152
}
153153

154154
#[inline(always)]
155-
pub fn cmp_in_dominator_order(&self, a: BasicCoverageBlock, b: BasicCoverageBlock) -> Ordering {
155+
pub(crate) fn cmp_in_dominator_order(
156+
&self,
157+
a: BasicCoverageBlock,
158+
b: BasicCoverageBlock,
159+
) -> Ordering {
156160
self.dominators.as_ref().unwrap().cmp_in_dominator_order(a, b)
157161
}
158162

@@ -166,7 +170,7 @@ impl CoverageGraph {
166170
///
167171
/// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
168172
#[inline(always)]
169-
pub(super) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
173+
pub(crate) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
170174
// Even though bcb0 conceptually has an extra virtual in-edge due to
171175
// being the entry point, we've already asserted that it has no _other_
172176
// in-edges, so there's no possibility of it having _multiple_ in-edges.
@@ -212,7 +216,7 @@ impl graph::StartNode for CoverageGraph {
212216
impl graph::Successors for CoverageGraph {
213217
#[inline]
214218
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
215-
self.successors[node].iter().cloned()
219+
self.successors[node].iter().copied()
216220
}
217221
}
218222

@@ -227,7 +231,7 @@ rustc_index::newtype_index! {
227231
/// A node in the control-flow graph of CoverageGraph.
228232
#[orderable]
229233
#[debug_format = "bcb{}"]
230-
pub(super) struct BasicCoverageBlock {
234+
pub(crate) struct BasicCoverageBlock {
231235
const START_BCB = 0;
232236
}
233237
}
@@ -259,23 +263,23 @@ rustc_index::newtype_index! {
259263
/// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow)
260264
/// significance.
261265
#[derive(Debug, Clone)]
262-
pub(super) struct BasicCoverageBlockData {
263-
pub basic_blocks: Vec<BasicBlock>,
266+
pub(crate) struct BasicCoverageBlockData {
267+
pub(crate) basic_blocks: Vec<BasicBlock>,
264268
}
265269

266270
impl BasicCoverageBlockData {
267-
pub fn from(basic_blocks: Vec<BasicBlock>) -> Self {
271+
fn from(basic_blocks: Vec<BasicBlock>) -> Self {
268272
assert!(basic_blocks.len() > 0);
269273
Self { basic_blocks }
270274
}
271275

272276
#[inline(always)]
273-
pub fn leader_bb(&self) -> BasicBlock {
277+
pub(crate) fn leader_bb(&self) -> BasicBlock {
274278
self.basic_blocks[0]
275279
}
276280

277281
#[inline(always)]
278-
pub fn last_bb(&self) -> BasicBlock {
282+
pub(crate) fn last_bb(&self) -> BasicBlock {
279283
*self.basic_blocks.last().unwrap()
280284
}
281285
}
@@ -364,7 +368,7 @@ fn bcb_filtered_successors<'a, 'tcx>(terminator: &'a Terminator<'tcx>) -> Covera
364368
/// CoverageGraph outside all loops. This supports traversing the BCB CFG in a way that
365369
/// ensures a loop is completely traversed before processing Blocks after the end of the loop.
366370
#[derive(Debug)]
367-
pub(super) struct TraversalContext {
371+
struct TraversalContext {
368372
/// BCB with one or more incoming loop backedges, indicating which loop
369373
/// this context is for.
370374
///
@@ -375,7 +379,7 @@ pub(super) struct TraversalContext {
375379
worklist: VecDeque<BasicCoverageBlock>,
376380
}
377381

378-
pub(super) struct TraverseCoverageGraphWithLoops<'a> {
382+
pub(crate) struct TraverseCoverageGraphWithLoops<'a> {
379383
basic_coverage_blocks: &'a CoverageGraph,
380384

381385
backedges: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
@@ -384,7 +388,7 @@ pub(super) struct TraverseCoverageGraphWithLoops<'a> {
384388
}
385389

386390
impl<'a> TraverseCoverageGraphWithLoops<'a> {
387-
pub(super) fn new(basic_coverage_blocks: &'a CoverageGraph) -> Self {
391+
pub(crate) fn new(basic_coverage_blocks: &'a CoverageGraph) -> Self {
388392
let backedges = find_loop_backedges(basic_coverage_blocks);
389393

390394
let worklist = VecDeque::from([basic_coverage_blocks.start_node()]);
@@ -400,47 +404,46 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
400404

401405
/// For each loop on the loop context stack (top-down), yields a list of BCBs
402406
/// within that loop that have an outgoing edge back to the loop header.
403-
pub(super) fn reloop_bcbs_per_loop(&self) -> impl Iterator<Item = &[BasicCoverageBlock]> {
407+
pub(crate) fn reloop_bcbs_per_loop(&self) -> impl Iterator<Item = &[BasicCoverageBlock]> {
404408
self.context_stack
405409
.iter()
406410
.rev()
407411
.filter_map(|context| context.loop_header)
408412
.map(|header_bcb| self.backedges[header_bcb].as_slice())
409413
}
410414

411-
pub(super) fn next(&mut self) -> Option<BasicCoverageBlock> {
415+
pub(crate) fn next(&mut self) -> Option<BasicCoverageBlock> {
412416
debug!(
413417
"TraverseCoverageGraphWithLoops::next - context_stack: {:?}",
414418
self.context_stack.iter().rev().collect::<Vec<_>>()
415419
);
416420

417421
while let Some(context) = self.context_stack.last_mut() {
418-
if let Some(bcb) = context.worklist.pop_front() {
419-
if !self.visited.insert(bcb) {
420-
debug!("Already visited: {bcb:?}");
421-
continue;
422-
}
423-
debug!("Visiting {bcb:?}");
424-
425-
if self.backedges[bcb].len() > 0 {
426-
debug!("{bcb:?} is a loop header! Start a new TraversalContext...");
427-
self.context_stack.push(TraversalContext {
428-
loop_header: Some(bcb),
429-
worklist: VecDeque::new(),
430-
});
431-
}
432-
self.add_successors_to_worklists(bcb);
433-
return Some(bcb);
434-
} else {
435-
// Strip contexts with empty worklists from the top of the stack
422+
let Some(bcb) = context.worklist.pop_front() else {
423+
// This stack level is exhausted; pop it and try the next one.
436424
self.context_stack.pop();
425+
continue;
426+
};
427+
428+
if !self.visited.insert(bcb) {
429+
debug!("Already visited: {bcb:?}");
430+
continue;
431+
}
432+
debug!("Visiting {bcb:?}");
433+
434+
if self.backedges[bcb].len() > 0 {
435+
debug!("{bcb:?} is a loop header! Start a new TraversalContext...");
436+
self.context_stack
437+
.push(TraversalContext { loop_header: Some(bcb), worklist: VecDeque::new() });
437438
}
439+
self.add_successors_to_worklists(bcb);
440+
return Some(bcb);
438441
}
439442

440443
None
441444
}
442445

443-
pub fn add_successors_to_worklists(&mut self, bcb: BasicCoverageBlock) {
446+
fn add_successors_to_worklists(&mut self, bcb: BasicCoverageBlock) {
444447
let successors = &self.basic_coverage_blocks.successors[bcb];
445448
debug!("{:?} has {} successors:", bcb, successors.len());
446449

@@ -494,19 +497,19 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
494497
}
495498
}
496499

497-
pub fn is_complete(&self) -> bool {
500+
pub(crate) fn is_complete(&self) -> bool {
498501
self.visited.count() == self.visited.domain_size()
499502
}
500503

501-
pub fn unvisited(&self) -> Vec<BasicCoverageBlock> {
504+
pub(crate) fn unvisited(&self) -> Vec<BasicCoverageBlock> {
502505
let mut unvisited_set: BitSet<BasicCoverageBlock> =
503506
BitSet::new_filled(self.visited.domain_size());
504507
unvisited_set.subtract(&self.visited);
505508
unvisited_set.iter().collect::<Vec<_>>()
506509
}
507510
}
508511

509-
pub(super) fn find_loop_backedges(
512+
fn find_loop_backedges(
510513
basic_coverage_blocks: &CoverageGraph,
511514
) -> IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>> {
512515
let num_bcbs = basic_coverage_blocks.num_nodes();

0 commit comments

Comments
 (0)
Please sign in to comment.