Skip to content

Commit 5f45e62

Browse files
committed
Auto merge of rust-lang#127762 - matthiaskrgr:rollup-965c2du, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#124921 (offset_from: always allow pointers to point to the same address) - rust-lang#127407 (Make parse error suggestions verbose and fix spans) - rust-lang#127675 (Remove invalid help diagnostics for const pointer) - rust-lang#127684 (consolidate miri-unleashed tests for mutable refs into one file) - rust-lang#127758 (coverage: Restrict `ExpressionUsed` simplification to `Code` mappings) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d3dd34a + 78c6622 commit 5f45e62

File tree

184 files changed

+3591
-1303
lines changed

Some content is hidden

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

184 files changed

+3591
-1303
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1198,18 +1198,21 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
11981198
sugg.push(s);
11991199
}
12001200

1201-
err.multipart_suggestion_verbose(
1202-
format!(
1203-
"consider changing this to be a mutable {pointer_desc}{}",
1204-
if is_trait_sig {
1205-
" in the `impl` method and the `trait` definition"
1206-
} else {
1207-
""
1208-
}
1209-
),
1210-
sugg,
1211-
Applicability::MachineApplicable,
1212-
);
1201+
if sugg.iter().all(|(span, _)| !self.infcx.tcx.sess.source_map().is_imported(*span))
1202+
{
1203+
err.multipart_suggestion_verbose(
1204+
format!(
1205+
"consider changing this to be a mutable {pointer_desc}{}",
1206+
if is_trait_sig {
1207+
" in the `impl` method and the `trait` definition"
1208+
} else {
1209+
""
1210+
}
1211+
),
1212+
sugg,
1213+
Applicability::MachineApplicable,
1214+
);
1215+
}
12131216
}
12141217
Some((false, err_label_span, message, _)) => {
12151218
let def_id = self.body.source.def_id();

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
6666
// For each expression ID that is directly used by one or more mappings,
6767
// mark it as not-yet-seen. This indicates that we expect to see a
6868
// corresponding `ExpressionUsed` statement during MIR traversal.
69-
for term in function_coverage_info.mappings.iter().flat_map(|m| m.kind.terms()) {
70-
if let CovTerm::Expression(id) = term {
69+
for mapping in function_coverage_info.mappings.iter() {
70+
// Currently we only worry about ordinary code mappings.
71+
// For branch and MC/DC mappings, expressions might not correspond
72+
// to any particular point in the control-flow graph.
73+
// (Keep this in sync with the injection of `ExpressionUsed`
74+
// statements in the `InstrumentCoverage` MIR pass.)
75+
if let MappingKind::Code(term) = mapping.kind
76+
&& let CovTerm::Expression(id) = term
77+
{
7178
expressions_seen.remove(id);
7279
}
7380
}

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::{
2020
err_inval, err_ub_custom, err_unsup_format, memory::MemoryKind, throw_inval, throw_ub_custom,
2121
throw_ub_format, util::ensure_monomorphic_enough, Allocation, CheckInAllocMsg, ConstAllocation,
2222
GlobalId, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, Pointer, PointerArithmetic,
23-
Scalar,
23+
Provenance, Scalar,
2424
};
2525

2626
use crate::fluent_generated as fluent;
@@ -259,25 +259,28 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
259259
// This will always return 0.
260260
(a, b)
261261
}
262-
(Err(_), _) | (_, Err(_)) => {
263-
// We managed to find a valid allocation for one pointer, but not the other.
264-
// That means they are definitely not pointing to the same allocation.
262+
_ if M::Provenance::OFFSET_IS_ADDR && a.addr() == b.addr() => {
263+
// At least one of the pointers has provenance, but they also point to
264+
// the same address so it doesn't matter; this is fine. `(0, 0)` means
265+
// we pass all the checks below and return 0.
266+
(0, 0)
267+
}
268+
// From here onwards, the pointers are definitely for different addresses
269+
// (or we can't determine their absolute address).
270+
(Ok((a_alloc_id, a_offset, _)), Ok((b_alloc_id, b_offset, _)))
271+
if a_alloc_id == b_alloc_id =>
272+
{
273+
// Found allocation for both, and it's the same.
274+
// Use these offsets for distance calculation.
275+
(a_offset.bytes(), b_offset.bytes())
276+
}
277+
_ => {
278+
// Not into the same allocation -- this is UB.
265279
throw_ub_custom!(
266280
fluent::const_eval_offset_from_different_allocations,
267281
name = intrinsic_name,
268282
);
269283
}
270-
(Ok((a_alloc_id, a_offset, _)), Ok((b_alloc_id, b_offset, _))) => {
271-
// Found allocation for both. They must be into the same allocation.
272-
if a_alloc_id != b_alloc_id {
273-
throw_ub_custom!(
274-
fluent::const_eval_offset_from_different_allocations,
275-
name = intrinsic_name,
276-
);
277-
}
278-
// Use these offsets for distance calculation.
279-
(a_offset.bytes(), b_offset.bytes())
280-
}
281284
};
282285

283286
// Compute distance.

compiler/rustc_middle/src/mir/coverage.rs

-13
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,6 @@ pub enum MappingKind {
220220
}
221221

222222
impl MappingKind {
223-
/// Iterator over all coverage terms in this mapping kind.
224-
pub fn terms(&self) -> impl Iterator<Item = CovTerm> {
225-
let zero = || None.into_iter().chain(None);
226-
let one = |a| Some(a).into_iter().chain(None);
227-
let two = |a, b| Some(a).into_iter().chain(Some(b));
228-
match *self {
229-
Self::Code(term) => one(term),
230-
Self::Branch { true_term, false_term } => two(true_term, false_term),
231-
Self::MCDCBranch { true_term, false_term, .. } => two(true_term, false_term),
232-
Self::MCDCDecision(_) => zero(),
233-
}
234-
}
235-
236223
/// Returns a copy of this mapping kind, in which all coverage terms have
237224
/// been replaced with ones returned by the given function.
238225
pub fn map_terms(&self, map_fn: impl Fn(CovTerm) -> CovTerm) -> Self {

compiler/rustc_mir_transform/src/coverage/mappings.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub(super) struct MCDCDecision {
5656

5757
#[derive(Default)]
5858
pub(super) struct ExtractedMappings {
59+
/// Store our own copy of [`CoverageGraph::num_nodes`], so that we don't
60+
/// need access to the whole graph when allocating per-BCB data. This is
61+
/// only public so that other code can still use exhaustive destructuring.
62+
pub(super) num_bcbs: usize,
5963
pub(super) code_mappings: Vec<CodeMapping>,
6064
pub(super) branch_pairs: Vec<BranchPair>,
6165
pub(super) mcdc_bitmap_bytes: u32,
@@ -106,6 +110,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
106110
);
107111

108112
ExtractedMappings {
113+
num_bcbs: basic_coverage_blocks.num_nodes(),
109114
code_mappings,
110115
branch_pairs,
111116
mcdc_bitmap_bytes,
@@ -115,12 +120,10 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
115120
}
116121

117122
impl ExtractedMappings {
118-
pub(super) fn all_bcbs_with_counter_mappings(
119-
&self,
120-
basic_coverage_blocks: &CoverageGraph, // Only used for allocating a correctly-sized set
121-
) -> BitSet<BasicCoverageBlock> {
123+
pub(super) fn all_bcbs_with_counter_mappings(&self) -> BitSet<BasicCoverageBlock> {
122124
// Fully destructure self to make sure we don't miss any fields that have mappings.
123125
let Self {
126+
num_bcbs,
124127
code_mappings,
125128
branch_pairs,
126129
mcdc_bitmap_bytes: _,
@@ -129,7 +132,7 @@ impl ExtractedMappings {
129132
} = self;
130133

131134
// Identify which BCBs have one or more mappings.
132-
let mut bcbs_with_counter_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes());
135+
let mut bcbs_with_counter_mappings = BitSet::new_empty(*num_bcbs);
133136
let mut insert = |bcb| {
134137
bcbs_with_counter_mappings.insert(bcb);
135138
};
@@ -156,6 +159,15 @@ impl ExtractedMappings {
156159

157160
bcbs_with_counter_mappings
158161
}
162+
163+
/// Returns the set of BCBs that have one or more `Code` mappings.
164+
pub(super) fn bcbs_with_ordinary_code_mappings(&self) -> BitSet<BasicCoverageBlock> {
165+
let mut bcbs = BitSet::new_empty(self.num_bcbs);
166+
for &CodeMapping { span: _, bcb } in &self.code_mappings {
167+
bcbs.insert(bcb);
168+
}
169+
bcbs
170+
}
159171
}
160172

161173
fn resolve_block_markers(

compiler/rustc_mir_transform/src/coverage/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_span::source_map::SourceMap;
2525
use rustc_span::{BytePos, Pos, RelativeBytePos, Span, Symbol};
2626

2727
use crate::coverage::counters::{CounterIncrementSite, CoverageCounters};
28-
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
28+
use crate::coverage::graph::CoverageGraph;
2929
use crate::coverage::mappings::ExtractedMappings;
3030
use crate::MirPass;
3131

@@ -88,8 +88,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
8888
// every coverage span has a `Counter` or `Expression` assigned to its `BasicCoverageBlock`
8989
// and all `Expression` dependencies (operands) are also generated, for any other
9090
// `BasicCoverageBlock`s not already associated with a coverage span.
91-
let bcbs_with_counter_mappings =
92-
extracted_mappings.all_bcbs_with_counter_mappings(&basic_coverage_blocks);
91+
let bcbs_with_counter_mappings = extracted_mappings.all_bcbs_with_counter_mappings();
9392
if bcbs_with_counter_mappings.is_empty() {
9493
// No relevant spans were found in MIR, so skip instrumenting this function.
9594
return;
@@ -109,7 +108,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
109108
inject_coverage_statements(
110109
mir_body,
111110
&basic_coverage_blocks,
112-
bcb_has_counter_mappings,
111+
&extracted_mappings,
113112
&coverage_counters,
114113
);
115114

@@ -163,6 +162,7 @@ fn create_mappings<'tcx>(
163162

164163
// Fully destructure the mappings struct to make sure we don't miss any kinds.
165164
let ExtractedMappings {
165+
num_bcbs: _,
166166
code_mappings,
167167
branch_pairs,
168168
mcdc_bitmap_bytes: _,
@@ -219,7 +219,7 @@ fn create_mappings<'tcx>(
219219
fn inject_coverage_statements<'tcx>(
220220
mir_body: &mut mir::Body<'tcx>,
221221
basic_coverage_blocks: &CoverageGraph,
222-
bcb_has_coverage_spans: impl Fn(BasicCoverageBlock) -> bool,
222+
extracted_mappings: &ExtractedMappings,
223223
coverage_counters: &CoverageCounters,
224224
) {
225225
// Inject counter-increment statements into MIR.
@@ -252,11 +252,16 @@ fn inject_coverage_statements<'tcx>(
252252
// can check whether the injected statement survived MIR optimization.
253253
// (BCB edges can't have spans, so we only need to process BCB nodes here.)
254254
//
255+
// We only do this for ordinary `Code` mappings, because branch and MC/DC
256+
// mappings might have expressions that don't correspond to any single
257+
// point in the control-flow graph.
258+
//
255259
// See the code in `rustc_codegen_llvm::coverageinfo::map_data` that deals
256260
// with "expressions seen" and "zero terms".
261+
let eligible_bcbs = extracted_mappings.bcbs_with_ordinary_code_mappings();
257262
for (bcb, expression_id) in coverage_counters
258263
.bcb_nodes_with_coverage_expressions()
259-
.filter(|&(bcb, _)| bcb_has_coverage_spans(bcb))
264+
.filter(|&(bcb, _)| eligible_bcbs.contains(bcb))
260265
{
261266
inject_statement(
262267
mir_body,

compiler/rustc_parse/messages.ftl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parse_add_paren = try adding parentheses
22
33
parse_ambiguous_range_pattern = the range pattern here has ambiguous interpretation
4-
.suggestion = add parentheses to clarify the precedence
4+
parse_ambiguous_range_pattern_suggestion = add parentheses to clarify the precedence
55
66
parse_array_brackets_instead_of_braces = this is a block expression, not an array
77
.suggestion = to make an array, use square brackets instead of curly braces
@@ -323,10 +323,10 @@ parse_incorrect_semicolon =
323323
.suggestion = remove this semicolon
324324
.help = {$name} declarations are not followed by a semicolon
325325
326-
parse_incorrect_use_of_await =
327-
incorrect use of `await`
326+
parse_incorrect_use_of_await = incorrect use of `await`
328327
.parentheses_suggestion = `await` is not a method call, remove the parentheses
329-
.postfix_suggestion = `await` is a postfix operation
328+
329+
parse_incorrect_use_of_await_postfix_suggestion = `await` is a postfix operation
330330
331331
parse_incorrect_visibility_restriction = incorrect visibility restriction
332332
.help = some possible visibility restrictions are:
@@ -644,7 +644,7 @@ parse_parentheses_with_struct_fields = invalid `struct` delimiters or `fn` call
644644
.suggestion_no_fields_for_fn = if `{$type}` is a function, use the arguments directly
645645
646646
parse_parenthesized_lifetime = parenthesized lifetime bounds are not supported
647-
.suggestion = remove the parentheses
647+
parse_parenthesized_lifetime_suggestion = remove the parentheses
648648
649649
parse_path_single_colon = path separator must be a double colon
650650
.suggestion = use a double colon instead

0 commit comments

Comments
 (0)