Skip to content

Commit 8c0b4f6

Browse files
committed
Auto merge of rust-lang#120660 - matthiaskrgr:rollup-zuqljul, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#119481 (Clarify ambiguity in select_nth_unstable docs) - rust-lang#119600 (Remove outdated references to librustc_middle) - rust-lang#120458 (Document `&CStr` to `CString` conversion) - rust-lang#120569 (coverage: Improve handling of function/closure spans) - rust-lang#120572 (Update libc to 0.2.153) - rust-lang#120587 (miri: normalize struct tail in ABI compat check) - rust-lang#120607 (fix rust-lang#120603 by adding a check in default_read_buf) - rust-lang#120636 (Subtree update of `rust-analyzer`) - rust-lang#120641 (rustdoc: trait.impl, type.impl: sort impls to make it not depend on serialization order) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0984bec + a2d3eed commit 8c0b4f6

File tree

228 files changed

+3480
-2121
lines changed

Some content is hidden

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

228 files changed

+3480
-2121
lines changed

Diff for: Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2169,9 +2169,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21692169

21702170
[[package]]
21712171
name = "libc"
2172-
version = "0.2.150"
2172+
version = "0.2.153"
21732173
source = "registry+https://github.com/rust-lang/crates.io-index"
2174-
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
2174+
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
21752175
dependencies = [
21762176
"rustc-std-workspace-core",
21772177
]

Diff for: compiler/rustc_const_eval/src/const_eval/error.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ impl MachineStopType for ConstEvalErrKind {
4949
}
5050
}
5151

52-
// The errors become `MachineStop` with plain strings when being raised.
53-
// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
54-
// handle these.
52+
/// The errors become [`InterpError::MachineStop`] when being raised.
5553
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
5654
fn into(self) -> InterpErrorInfo<'tcx> {
5755
err_machine_stop!(self).into()

Diff for: compiler/rustc_const_eval/src/interpret/terminator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
373373
if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
374374
// This is okay if they have the same metadata type.
375375
let meta_ty = |ty: Ty<'tcx>| {
376-
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, |ty| ty);
376+
// Even if `ty` is normalized, the search for the unsized tail will project
377+
// to fields, which can yield non-normalized types. So we need to provide a
378+
// normalization function.
379+
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
380+
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
377381
assert!(
378382
!only_if_sized,
379383
"there should be no more 'maybe has that metadata' types during interpretation"

Diff for: compiler/rustc_data_structures/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl
148148
Printer { f }
149149
}
150150

151-
// See comments in src/librustc_middle/lib.rs
151+
// See comments in compiler/rustc_middle/src/tests.rs
152152
#[doc(hidden)]
153153
pub fn __noop_fix_for_27438() {}
154154

Diff for: compiler/rustc_error_codes/src/error_codes/E0264.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
```
1414

1515
A list of available external lang items is available in
16-
`src/librustc_middle/middle/weak_lang_items.rs`. Example:
16+
`compiler/rustc_hir/src/weak_lang_items.rs`. Example:
1717

1818
```
1919
#![feature(lang_items)]

Diff for: compiler/rustc_errors/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ impl DiagCtxt {
645645
}
646646

647647
// This is here to not allow mutation of flags;
648-
// as of this writing it's only used in tests in librustc_middle.
648+
// as of this writing it's used in Session::consider_optimizing and
649+
// in tests in rustc_interface.
649650
pub fn can_emit_warnings(&self) -> bool {
650651
self.inner.borrow_mut().flags.can_emit_warnings
651652
}

Diff for: compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use crate::nonstandard_style::{method_context, MethodLateContext};
7272

7373
use std::fmt::Write;
7474

75-
// hardwired lints from librustc_middle
75+
// hardwired lints from rustc_lint_defs
7676
pub use rustc_session::lint::builtin::*;
7777

7878
declare_lint! {

Diff for: compiler/rustc_middle/src/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ macro_rules! arena_types {
9494

9595
// Note that this deliberately duplicates items in the `rustc_hir::arena`,
9696
// since we need to allocate this type on both the `rustc_hir` arena
97-
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
97+
// (during lowering) and the `rustc_middle` arena (for decoding MIR)
9898
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
9999
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
100100
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,

Diff for: compiler/rustc_middle/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22

3-
// FIXME(#27438): right now the unit tests of librustc_middle don't refer to any actual
4-
// functions generated in librustc_data_structures (all
3+
// FIXME(#27438): right now the unit tests of rustc_middle don't refer to any actual
4+
// functions generated in rustc_data_structures (all
55
// references are through generic functions), but statics are
66
// referenced from time to time. Due to this bug we won't
77
// actually correctly link in the statics unless we also

Diff for: compiler/rustc_mir_transform/src/coverage/mod.rs

+21-26
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
394394
struct ExtractedHirInfo {
395395
function_source_hash: u64,
396396
is_async_fn: bool,
397-
fn_sig_span: Span,
397+
/// The span of the function's signature, extended to the start of `body_span`.
398+
/// Must have the same context and filename as the body span.
399+
fn_sig_span_extended: Option<Span>,
398400
body_span: Span,
399401
}
400402

@@ -407,13 +409,25 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
407409
hir::map::associated_body(hir_node).expect("HIR node is a function with body");
408410
let hir_body = tcx.hir().body(fn_body_id);
409411

410-
let is_async_fn = hir_node.fn_sig().is_some_and(|fn_sig| fn_sig.header.is_async());
411-
let body_span = get_body_span(tcx, hir_body, def_id);
412+
let maybe_fn_sig = hir_node.fn_sig();
413+
let is_async_fn = maybe_fn_sig.is_some_and(|fn_sig| fn_sig.header.is_async());
414+
415+
let mut body_span = hir_body.value.span;
416+
417+
use rustc_hir::{Closure, Expr, ExprKind, Node};
418+
// Unexpand a closure's body span back to the context of its declaration.
419+
// This helps with closure bodies that consist of just a single bang-macro,
420+
// and also with closure bodies produced by async desugaring.
421+
if let Node::Expr(&Expr { kind: ExprKind::Closure(&Closure { fn_decl_span, .. }), .. }) =
422+
hir_node
423+
{
424+
body_span = body_span.find_ancestor_in_same_ctxt(fn_decl_span).unwrap_or(body_span);
425+
}
412426

413427
// The actual signature span is only used if it has the same context and
414428
// filename as the body, and precedes the body.
415-
let maybe_fn_sig_span = hir_node.fn_sig().map(|fn_sig| fn_sig.span);
416-
let fn_sig_span = maybe_fn_sig_span
429+
let fn_sig_span_extended = maybe_fn_sig
430+
.map(|fn_sig| fn_sig.span)
417431
.filter(|&fn_sig_span| {
418432
let source_map = tcx.sess.source_map();
419433
let file_idx = |span: Span| source_map.lookup_source_file_idx(span.lo());
@@ -423,30 +437,11 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
423437
&& file_idx(fn_sig_span) == file_idx(body_span)
424438
})
425439
// If so, extend it to the start of the body span.
426-
.map(|fn_sig_span| fn_sig_span.with_hi(body_span.lo()))
427-
// Otherwise, create a dummy signature span at the start of the body.
428-
.unwrap_or_else(|| body_span.shrink_to_lo());
440+
.map(|fn_sig_span| fn_sig_span.with_hi(body_span.lo()));
429441

430442
let function_source_hash = hash_mir_source(tcx, hir_body);
431443

432-
ExtractedHirInfo { function_source_hash, is_async_fn, fn_sig_span, body_span }
433-
}
434-
435-
fn get_body_span<'tcx>(
436-
tcx: TyCtxt<'tcx>,
437-
hir_body: &rustc_hir::Body<'tcx>,
438-
def_id: LocalDefId,
439-
) -> Span {
440-
let mut body_span = hir_body.value.span;
441-
442-
if tcx.is_closure_or_coroutine(def_id.to_def_id()) {
443-
// If the current function is a closure, and its "body" span was created
444-
// by macro expansion or compiler desugaring, try to walk backwards to
445-
// the pre-expansion call site or body.
446-
body_span = body_span.source_callsite();
447-
}
448-
449-
body_span
444+
ExtractedHirInfo { function_source_hash, is_async_fn, fn_sig_span_extended, body_span }
450445
}
451446

452447
fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx rustc_hir::Body<'tcx>) -> u64 {

Diff for: compiler/rustc_mir_transform/src/coverage/spans.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_index::bit_set::BitSet;
33
use rustc_middle::mir;
44
use rustc_span::{BytePos, Span, DUMMY_SP};
55

6-
use super::graph::{BasicCoverageBlock, CoverageGraph};
6+
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
77
use crate::coverage::ExtractedHirInfo;
88

99
mod from_mir;
@@ -46,13 +46,26 @@ pub(super) fn generate_coverage_spans(
4646
) -> Option<CoverageSpans> {
4747
let mut mappings = vec![];
4848

49-
let sorted_spans =
50-
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
51-
let coverage_spans = SpansRefiner::refine_sorted_spans(basic_coverage_blocks, sorted_spans);
52-
mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| {
53-
// Each span produced by the generator represents an ordinary code region.
54-
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
55-
}));
49+
if hir_info.is_async_fn {
50+
// An async function desugars into a function that returns a future,
51+
// with the user code wrapped in a closure. Any spans in the desugared
52+
// outer function will be unhelpful, so just keep the signature span
53+
// and ignore all of the spans in the MIR body.
54+
if let Some(span) = hir_info.fn_sig_span_extended {
55+
mappings.push(BcbMapping { kind: BcbMappingKind::Code(START_BCB), span });
56+
}
57+
} else {
58+
let sorted_spans = from_mir::mir_to_initial_sorted_coverage_spans(
59+
mir_body,
60+
hir_info,
61+
basic_coverage_blocks,
62+
);
63+
let coverage_spans = SpansRefiner::refine_sorted_spans(basic_coverage_blocks, sorted_spans);
64+
mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| {
65+
// Each span produced by the generator represents an ordinary code region.
66+
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
67+
}));
68+
}
5669

5770
if mappings.is_empty() {
5871
return None;

Diff for: compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,21 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
2323
hir_info: &ExtractedHirInfo,
2424
basic_coverage_blocks: &CoverageGraph,
2525
) -> Vec<CoverageSpan> {
26-
let &ExtractedHirInfo { is_async_fn, fn_sig_span, body_span, .. } = hir_info;
27-
28-
let mut initial_spans = vec![SpanFromMir::for_fn_sig(fn_sig_span)];
29-
30-
if is_async_fn {
31-
// An async function desugars into a function that returns a future,
32-
// with the user code wrapped in a closure. Any spans in the desugared
33-
// outer function will be unhelpful, so just keep the signature span
34-
// and ignore all of the spans in the MIR body.
35-
} else {
36-
for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() {
37-
initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data));
38-
}
26+
let &ExtractedHirInfo { body_span, .. } = hir_info;
3927

40-
// If no spans were extracted from the body, discard the signature span.
41-
// FIXME: This preserves existing behavior; consider getting rid of it.
42-
if initial_spans.len() == 1 {
43-
initial_spans.clear();
44-
}
28+
let mut initial_spans = vec![];
29+
30+
for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() {
31+
initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data));
32+
}
33+
34+
// Only add the signature span if we found at least one span in the body.
35+
if !initial_spans.is_empty() {
36+
// If there is no usable signature span, add a fake one (before refinement)
37+
// to avoid an ugly gap between the body start and the first real span.
38+
// FIXME: Find a more principled way to solve this problem.
39+
let fn_sig_span = hir_info.fn_sig_span_extended.unwrap_or_else(|| body_span.shrink_to_lo());
40+
initial_spans.push(SpanFromMir::for_fn_sig(fn_sig_span));
4541
}
4642

4743
initial_spans.sort_by(|a, b| basic_coverage_blocks.cmp_in_dominator_order(a.bcb, b.bcb));

Diff for: library/alloc/src/ffi/c_str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ impl ToOwned for CStr {
10241024

10251025
#[stable(feature = "cstring_asref", since = "1.7.0")]
10261026
impl From<&CStr> for CString {
1027+
/// Converts a <code>&[CStr]</code> into a [`CString`]
1028+
/// by copying the contents into a new allocation.
10271029
fn from(s: &CStr) -> CString {
10281030
s.to_owned()
10291031
}

Diff for: library/core/src/slice/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2989,7 +2989,7 @@ impl<T> [T] {
29892989
sort::quicksort(self, |a, b| f(a).lt(&f(b)));
29902990
}
29912991

2992-
/// Reorder the slice such that the element at `index` is at its final sorted position.
2992+
/// Reorder the slice such that the element at `index` after the reordering is at its final sorted position.
29932993
///
29942994
/// This reordering has the additional property that any value at position `i < index` will be
29952995
/// less than or equal to any value at a position `j > index`. Additionally, this reordering is
@@ -3017,7 +3017,7 @@ impl<T> [T] {
30173017
/// # Examples
30183018
///
30193019
/// ```
3020-
/// let mut v = [-5i32, 4, 1, -3, 2];
3020+
/// let mut v = [-5i32, 4, 2, -3, 1];
30213021
///
30223022
/// // Find the median
30233023
/// v.select_nth_unstable(2);
@@ -3038,8 +3038,8 @@ impl<T> [T] {
30383038
select::partition_at_index(self, index, T::lt)
30393039
}
30403040

3041-
/// Reorder the slice with a comparator function such that the element at `index` is at its
3042-
/// final sorted position.
3041+
/// Reorder the slice with a comparator function such that the element at `index` after the reordering is at
3042+
/// its final sorted position.
30433043
///
30443044
/// This reordering has the additional property that any value at position `i < index` will be
30453045
/// less than or equal to any value at a position `j > index` using the comparator function.
@@ -3068,7 +3068,7 @@ impl<T> [T] {
30683068
/// # Examples
30693069
///
30703070
/// ```
3071-
/// let mut v = [-5i32, 4, 1, -3, 2];
3071+
/// let mut v = [-5i32, 4, 2, -3, 1];
30723072
///
30733073
/// // Find the median as if the slice were sorted in descending order.
30743074
/// v.select_nth_unstable_by(2, |a, b| b.cmp(a));
@@ -3093,8 +3093,8 @@ impl<T> [T] {
30933093
select::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less)
30943094
}
30953095

3096-
/// Reorder the slice with a key extraction function such that the element at `index` is at its
3097-
/// final sorted position.
3096+
/// Reorder the slice with a key extraction function such that the element at `index` after the reordering is
3097+
/// at its final sorted position.
30983098
///
30993099
/// This reordering has the additional property that any value at position `i < index` will be
31003100
/// less than or equal to any value at a position `j > index` using the key extraction function.

Diff for: 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-
libc = { version = "0.2.150", default-features = false, features = ['rustc-dep-of-std'], public = true }
20+
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
2121
compiler_builtins = { version = "0.1.105" }
2222
profiler_builtins = { path = "../profiler_builtins", optional = true }
2323
unwind = { path = "../unwind" }

Diff for: library/std/src/io/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,13 @@ where
578578
F: FnOnce(&mut [u8]) -> Result<usize>,
579579
{
580580
let n = read(cursor.ensure_init().init_mut())?;
581+
assert!(
582+
n <= cursor.capacity(),
583+
"read should not return more bytes than there is capacity for in the read buffer"
584+
);
581585
unsafe {
582-
// SAFETY: we initialised using `ensure_init` so there is no uninit data to advance to.
586+
// SAFETY: we initialised using `ensure_init` so there is no uninit data to advance to
587+
// and we have checked that the read amount is not over capacity (see #120603)
583588
cursor.advance(n);
584589
}
585590
Ok(())

Diff for: library/std/src/io/tests.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{repeat, BorrowedBuf, Cursor, SeekFrom};
22
use crate::cmp::{self, min};
3-
use crate::io::{self, IoSlice, IoSliceMut};
3+
use crate::io::{self, IoSlice, IoSliceMut, DEFAULT_BUF_SIZE};
44
use crate::io::{BufRead, BufReader, Read, Seek, Write};
55
use crate::mem::MaybeUninit;
66
use crate::ops::Deref;
@@ -652,3 +652,32 @@ fn bench_take_read_buf(b: &mut test::Bencher) {
652652
[255; 128].take(64).read_buf(buf.unfilled()).unwrap();
653653
});
654654
}
655+
656+
// Issue #120603
657+
#[test]
658+
#[should_panic = "read should not return more bytes than there is capacity for in the read buffer"]
659+
fn read_buf_broken_read() {
660+
struct MalformedRead;
661+
662+
impl Read for MalformedRead {
663+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
664+
// broken length calculation
665+
Ok(buf.len() + 1)
666+
}
667+
}
668+
669+
let _ = BufReader::new(MalformedRead).fill_buf();
670+
}
671+
672+
#[test]
673+
fn read_buf_full_read() {
674+
struct FullRead;
675+
676+
impl Read for FullRead {
677+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
678+
Ok(buf.len())
679+
}
680+
}
681+
682+
assert_eq!(BufReader::new(FullRead).fill_buf().unwrap().len(), DEFAULT_BUF_SIZE);
683+
}

0 commit comments

Comments
 (0)