Skip to content

Rollup of 8 pull requests #126569

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

Merged
merged 27 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9bcc133
docs(change): Don't mention a Cargo 2024 edition change for 1.79
epage Jun 11, 2024
c462328
export std::os::fd module on HermitOS
stlankes Jun 12, 2024
9e85104
div_euclid, rem_euclid: clarify/extend documentation
RalfJung Jun 14, 2024
4f97ab5
Resolve elided lifetimes in assoc const to static if no other lifetim…
compiler-errors May 18, 2024
805397c
Add more tests
compiler-errors Jun 14, 2024
5f3357c
Resolve const lifetimes to static in trait too
compiler-errors Jun 14, 2024
6cce488
update comment
slanterns Jun 15, 2024
2404783
add codegen test for `Error::provide`
slanterns Jun 15, 2024
e102d2d
coverage: More consistent variable names for span processing
Zalathar Jun 15, 2024
bf74fb1
coverage: Move most span processing back into `coverage::spans`
Zalathar Jun 15, 2024
88ade9c
coverage: Eagerly convert coverage spans to a simpler form
Zalathar Jun 15, 2024
118f66c
coverage: Split out a function for dividing coverage spans into buckets
Zalathar Jun 15, 2024
2d3e6c8
coverage: Split span refinement into two separate steps
Zalathar Jun 15, 2024
5eb30f0
coverage: Remove some old low-value unit tests for graph traversal
Zalathar Jun 16, 2024
917b455
coverage: Reduce/simplify visibility in `coverage::graph`
Zalathar Jun 16, 2024
dca6b5e
coverage: Flatten some graph code with let-else
Zalathar Jun 16, 2024
e5b43c3
coverage: Prefer `Iterator::copied`
Zalathar Jun 16, 2024
51d9546
Apply suggestion.
slanterns Jun 16, 2024
fe9154c
doc: Added commas where needed
x4exr Jun 11, 2024
23b936f
Rollup merge of #125258 - compiler-errors:static-if-no-lt, r=nnethercote
jieyouxu Jun 17, 2024
6e50dbc
Rollup merge of #126250 - epage:change, r=Mark-Simulacrum
jieyouxu Jun 17, 2024
a8ccf97
Rollup merge of #126288 - x4exr:patch-1, r=dtolnay
jieyouxu Jun 17, 2024
cd4c0f0
Rollup merge of #126346 - hermit-os:fd, r=Amanieu
jieyouxu Jun 17, 2024
f39327b
Rollup merge of #126468 - RalfJung:euclid, r=Mark-Simulacrum
jieyouxu Jun 17, 2024
61577a8
Rollup merge of #126531 - slanterns:error_provider, r=workingjubilee
jieyouxu Jun 17, 2024
d9af579
Rollup merge of #126535 - Zalathar:covspans, r=nnethercote
jieyouxu Jun 17, 2024
d92aa56
Rollup merge of #126538 - Zalathar:graph, r=nnethercote
jieyouxu Jun 17, 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
1 change: 0 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ Cargo
- [Prevent dashes in `lib.name`, always normalizing to `_`.](https://github.com/rust-lang/cargo/pull/12783/)
- [Stabilize MSRV-aware version requirement selection in `cargo add`.](https://github.com/rust-lang/cargo/pull/13608/)
- [Switch to using `gitoxide` by default for listing files.](https://github.com/rust-lang/cargo/pull/13696/)
- [Error on `[project]` in Edition 2024; `cargo fix --edition` will change it to `[package]`.](https://github.com/rust-lang/cargo/pull/13747/)

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lint_associated_const_elided_lifetime = {$elided ->
*[false] `'_` cannot be used here
}
.suggestion = use the `'static` lifetime
.note = cannot automatically infer `'static` because of other lifetimes in scope

lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
.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`
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,20 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
BuiltinLintDiag::UnusedQualifications { removal_span } => {
lints::UnusedQualifications { removal_span }.decorate_lint(diag);
}
BuiltinLintDiag::AssociatedConstElidedLifetime { elided, span: lt_span } => {
BuiltinLintDiag::AssociatedConstElidedLifetime {
elided,
span: lt_span,
lifetimes_in_scope,
} => {
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
let code = if elided { "'static " } else { "'static" };
lints::AssociatedConstElidedLifetime { span: lt_span, code, elided }
.decorate_lint(diag);
lints::AssociatedConstElidedLifetime {
span: lt_span,
code,
elided,
lifetimes_in_scope,
}
.decorate_lint(diag);
}
BuiltinLintDiag::RedundantImportVisibility { max_vis, span: vis_span, import_vis } => {
lints::RedundantImportVisibility { span: vis_span, help: (), max_vis, import_vis }
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,8 @@ pub struct AssociatedConstElidedLifetime {

pub code: &'static str,
pub elided: bool,
#[note]
pub lifetimes_in_scope: MultiSpan,
}

#[derive(LintDiagnostic)]
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4593,16 +4593,18 @@ declare_lint! {

declare_lint! {
/// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
/// that were erroneously allowed in associated constants.
/// in associated constants when there are other lifetimes in scope. This was
/// accidentally supported, and this lint was later relaxed to allow eliding
/// lifetimes to `'static` when there are no lifetimes in scope.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(elided_lifetimes_in_associated_constant)]
///
/// struct Foo;
/// struct Foo<'a>(&'a ());
///
/// impl Foo {
/// impl<'a> Foo<'a> {
/// const STR: &str = "hello, world";
/// }
/// ```
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ pub enum BuiltinLintDiag {
AssociatedConstElidedLifetime {
elided: bool,
span: Span,
lifetimes_in_scope: MultiSpan,
},
RedundantImportVisibility {
span: Span,
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir_transform/src/coverage/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ impl CoverageCounters {
self.counter_increment_sites.len()
}

#[cfg(test)]
pub(super) fn num_expressions(&self) -> usize {
self.expressions.len()
}

fn set_bcb_counter(&mut self, bcb: BasicCoverageBlock, counter_kind: BcbCounter) -> BcbCounter {
if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) {
bug!(
Expand Down
89 changes: 46 additions & 43 deletions compiler/rustc_mir_transform/src/coverage/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ use std::ops::{Index, IndexMut};
/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
/// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
#[derive(Debug)]
pub(super) struct CoverageGraph {
pub(crate) struct CoverageGraph {
bcbs: IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
bb_to_bcb: IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
pub successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
pub predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
pub(crate) successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
pub(crate) predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
dominators: Option<Dominators<BasicCoverageBlock>>,
}

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

// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
Expand Down Expand Up @@ -135,24 +135,28 @@ impl CoverageGraph {
}

#[inline(always)]
pub fn iter_enumerated(
pub(crate) fn iter_enumerated(
&self,
) -> impl Iterator<Item = (BasicCoverageBlock, &BasicCoverageBlockData)> {
self.bcbs.iter_enumerated()
}

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

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

#[inline(always)]
pub fn cmp_in_dominator_order(&self, a: BasicCoverageBlock, b: BasicCoverageBlock) -> Ordering {
pub(crate) fn cmp_in_dominator_order(
&self,
a: BasicCoverageBlock,
b: BasicCoverageBlock,
) -> Ordering {
self.dominators.as_ref().unwrap().cmp_in_dominator_order(a, b)
}

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

Expand All @@ -227,7 +231,7 @@ rustc_index::newtype_index! {
/// A node in the control-flow graph of CoverageGraph.
#[orderable]
#[debug_format = "bcb{}"]
pub(super) struct BasicCoverageBlock {
pub(crate) struct BasicCoverageBlock {
const START_BCB = 0;
}
}
Expand Down Expand Up @@ -259,23 +263,23 @@ rustc_index::newtype_index! {
/// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow)
/// significance.
#[derive(Debug, Clone)]
pub(super) struct BasicCoverageBlockData {
pub basic_blocks: Vec<BasicBlock>,
pub(crate) struct BasicCoverageBlockData {
pub(crate) basic_blocks: Vec<BasicBlock>,
}

impl BasicCoverageBlockData {
pub fn from(basic_blocks: Vec<BasicBlock>) -> Self {
fn from(basic_blocks: Vec<BasicBlock>) -> Self {
assert!(basic_blocks.len() > 0);
Self { basic_blocks }
}

#[inline(always)]
pub fn leader_bb(&self) -> BasicBlock {
pub(crate) fn leader_bb(&self) -> BasicBlock {
self.basic_blocks[0]
}

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

pub(super) struct TraverseCoverageGraphWithLoops<'a> {
pub(crate) struct TraverseCoverageGraphWithLoops<'a> {
basic_coverage_blocks: &'a CoverageGraph,

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

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

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

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

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

while let Some(context) = self.context_stack.last_mut() {
if let Some(bcb) = context.worklist.pop_front() {
if !self.visited.insert(bcb) {
debug!("Already visited: {bcb:?}");
continue;
}
debug!("Visiting {bcb:?}");

if self.backedges[bcb].len() > 0 {
debug!("{bcb:?} is a loop header! Start a new TraversalContext...");
self.context_stack.push(TraversalContext {
loop_header: Some(bcb),
worklist: VecDeque::new(),
});
}
self.add_successors_to_worklists(bcb);
return Some(bcb);
} else {
// Strip contexts with empty worklists from the top of the stack
let Some(bcb) = context.worklist.pop_front() else {
// This stack level is exhausted; pop it and try the next one.
self.context_stack.pop();
continue;
};

if !self.visited.insert(bcb) {
debug!("Already visited: {bcb:?}");
continue;
}
debug!("Visiting {bcb:?}");

if self.backedges[bcb].len() > 0 {
debug!("{bcb:?} is a loop header! Start a new TraversalContext...");
self.context_stack
.push(TraversalContext { loop_header: Some(bcb), worklist: VecDeque::new() });
}
self.add_successors_to_worklists(bcb);
return Some(bcb);
}

None
}

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

Expand Down Expand Up @@ -494,19 +497,19 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
}
}

pub fn is_complete(&self) -> bool {
pub(crate) fn is_complete(&self) -> bool {
self.visited.count() == self.visited.domain_size()
}

pub fn unvisited(&self) -> Vec<BasicCoverageBlock> {
pub(crate) fn unvisited(&self) -> Vec<BasicCoverageBlock> {
let mut unvisited_set: BitSet<BasicCoverageBlock> =
BitSet::new_filled(self.visited.domain_size());
unvisited_set.subtract(&self.visited);
unvisited_set.iter().collect::<Vec<_>>()
}
}

pub(super) fn find_loop_backedges(
fn find_loop_backedges(
basic_coverage_blocks: &CoverageGraph,
) -> IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>> {
let num_bcbs = basic_coverage_blocks.num_nodes();
Expand Down
Loading
Loading