Skip to content
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

Rollup of 9 pull requests #120660

Merged
merged 115 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
7ac4515
Clarify ambiguity in select_nth_unstable docs
romanows Dec 31, 2023
16e117c
Remove outdated references to `librustc_middle`.
aDotInTheVoid Jan 5, 2024
e15f40e
feat: add conflict ext (panicbit.cargo) detect
Young-Flash Jan 22, 2024
56f54c8
fix lint and fmt
Young-Flash Jan 22, 2024
85d56ee
Fix copy/paste error.
nnethercote Jan 24, 2024
5651407
Rework `CStrUnit`.
nnethercote Jan 23, 2024
858f4ac
Rename the unescaping functions.
nnethercote Jan 24, 2024
96ebad0
minor: update conflict extension detect logic
Young-Flash Jan 26, 2024
da798bc
make `ast::UseTree::wrap_in_tree_list` more robust
davidsemakula Jan 20, 2024
57934ac
Add postfix completion for let else
Alainx277 Oct 8, 2023
51d57b9
Make return a snippet
Alainx277 Oct 9, 2023
7ec32d0
Remove letelse control flow snippets
Alainx277 Jan 27, 2024
b22e772
feat: Support for GOTO def from *inside* files included with include!…
wasd96040501 Jan 27, 2024
8fab92f
normalize use trees when merging imports
davidsemakula Jan 20, 2024
81d713e
remove ordered insert logic from recursive merge function
davidsemakula Jan 20, 2024
a8a18f3
add normalize import assist
davidsemakula Jan 20, 2024
b241593
merge imports assist always applies to covering use item except for n…
davidsemakula Jan 21, 2024
fc00602
merge imports assist avoids adding unnecessary braces when merging ne…
davidsemakula Jan 21, 2024
84e1314
add more tests for normalize import assist
davidsemakula Jan 22, 2024
6f303f4
feat: enable excluding refs search results in test
Young-Flash Jan 28, 2024
1bd21e9
test: add test for excluding refs
Young-Flash Jan 28, 2024
f43cea0
Merge commit '7219414e81810fd4d967136c4a0650523892c157' into sync-fro…
lnicola Jan 28, 2024
6aec11a
Document From<&CStr> for CString
rytheo Jan 28, 2024
6181102
fix: use Semantics to judge whether a func is marked as #[test]
Young-Flash Jan 29, 2024
2b71aca
test: add full path ref exclude test case
Young-Flash Jan 29, 2024
d13951f
Auto merge of #15730 - Alainx277:let-else-postfix, r=Veykril
bors Jan 29, 2024
20c0167
Bump scip
lnicola Jan 30, 2024
5860763
Cleanup error variants in MIR code slightly
Veykril Jan 30, 2024
22b6f96
Auto merge of #16439 - wasd96040501:feat/gotodef3, r=Veykril
bors Jan 30, 2024
11b401d
Auto merge of #16447 - Veykril:mir-errors, r=Veykril
bors Jan 30, 2024
4facb62
minor: update warning msg
Young-Flash Jan 30, 2024
dba3fc4
style: remove unnecessary macro
davidsemakula Jan 30, 2024
db9fd37
minor: correct typos
Young-Flash Jan 30, 2024
75a42f1
collapsible_if
Urhengulas Jan 21, 2024
73c7c72
CI: add clippy
Urhengulas Jan 21, 2024
628f701
CI: Don't deny clippy warnings
Urhengulas Jan 30, 2024
43b1ae0
`cargo clippy --fix`
Urhengulas Jan 30, 2024
da4d5f8
Auto merge of #16413 - Urhengulas:clippy-ci, r=Veykril
bors Jan 30, 2024
63123ab
Auto merge of #16417 - davidsemakula:normalize-use-trees, r=Veykril
bors Jan 30, 2024
e1ea7c8
internal: switch to `tracing` from `log`
davidbarsky Jan 18, 2024
d923d62
Auto merge of #16394 - davidbarsky:david/add-more-tracing-spans, r=Ve…
bors Jan 30, 2024
17d2e8d
internal: remove `tracing/mod.rs`
davidbarsky Jan 30, 2024
8f1a253
internal: Undo special bracket classification for attributes in vscod…
Veykril Jan 30, 2024
9a832c4
Auto merge of #16453 - Veykril:brackets, r=Veykril
bors Jan 30, 2024
e4146af
Auto merge of #16441 - Young-Flash:exclude_tests_refs, r=Veykril
bors Jan 31, 2024
604479c
internal: Use improved adjusted_display_range for all diagnostics
Veykril Jan 31, 2024
e48bc04
Auto merge of #16459 - Veykril:diagnostics, r=Veykril
bors Jan 31, 2024
d252247
internal: Remove unnecessary usages of ExpansionInfo
Veykril Jan 31, 2024
2661c27
Auto merge of #16461 - Veykril:expansion-info, r=Veykril
bors Jan 31, 2024
9d837a6
Auto merge of #16445 - lnicola:bump-scip, r=lnicola
bors Jan 31, 2024
62ff8f3
minor: correct `close` to `closure`
Young-Flash Jan 31, 2024
355c944
Auto merge of #16448 - Young-Flash:typos, r=lnicola
bors Jan 31, 2024
251b14f
internal: don't panic in `debug_pat`
davidbarsky Jan 30, 2024
579e98c
internal: record Event kind in `handle_event`
davidbarsky Jan 30, 2024
386d438
skip_while_next
Urhengulas Jan 21, 2024
daa2072
toplevel_ref_arg
Urhengulas Jan 22, 2024
de6f956
unnecessary_cast
Urhengulas Jan 22, 2024
f15ee8a
unnecessary_filter_map
Urhengulas Jan 22, 2024
c4302ea
unnecessary_lazy_evaluations
Urhengulas Jan 22, 2024
f191b80
Refactor
Urhengulas Jan 22, 2024
e7d0dea
unnecessary_mut_passed
Urhengulas Jan 22, 2024
b73ee2f
useless_conversion
Urhengulas Jan 22, 2024
b176cf2
useless_format
Urhengulas Jan 22, 2024
0adb4d1
wildcard_in_or_patterns
Urhengulas Jan 22, 2024
c468834
derivable_impls
Urhengulas Jan 22, 2024
dd9f27b
borrow_deref_ref
Urhengulas Jan 22, 2024
04ccef8
field_reassign_with_default
Urhengulas Jan 22, 2024
e7e09e7
large_enum_variant
Urhengulas Jan 22, 2024
d37f4e0
new_without_default
Urhengulas Jan 30, 2024
771c6c9
format_collect
Urhengulas Jan 30, 2024
df2c7a6
`cargo clippy --fix`
Urhengulas Jan 31, 2024
44494e2
internal: teach hprof to record `tracing` fields
davidbarsky Jan 30, 2024
0396811
Auto merge of #16456 - davidbarsky:david/tracing-followups, r=Veykril
bors Jan 31, 2024
a1fdb87
Remove `abi_amdgpu_kernel` references
clubby789 Jan 31, 2024
1ab1a25
Auto merge of #16463 - clubby789:remove-abi_amdgpu_kernel, r=lnicola
bors Jan 31, 2024
23f4b7f
Remove stdx::eprintln overwrite
Veykril Jan 31, 2024
42cb1a2
Auto merge of #16465 - Veykril:eprintln, r=Veykril
bors Jan 31, 2024
671c776
minor: Recommend maintained Neovim plugin in documentation
ThomasFrans Feb 1, 2024
3afa6b1
Auto merge of #16468 - ThomasFrans:docs-update-plugin-url, r=lnicola
bors Feb 1, 2024
135a8d9
Auto merge of #16416 - Young-Flash:cargo_ext_detect, r=lnicola
bors Feb 1, 2024
36cb518
internal: add typos.toml as typo white list
Young-Flash Feb 1, 2024
b0be296
internal: add typos CI check
Young-Flash Feb 1, 2024
850ba2f
Auto merge of #16451 - Urhengulas:satisfy-clippy, r=Veykril
bors Feb 1, 2024
ee87033
Update libc to 0.2.153
pheki Feb 2, 2024
8ba31cc
Merge remote-tracking branch 'upstream/release' into sync-from-rust
lnicola Feb 2, 2024
4f09335
Merge remote-tracking branch 'upstream/master' into sync-from-rust
lnicola Feb 2, 2024
ef07b05
Bump rustc_lexer and rustc_parse_format
lnicola Feb 2, 2024
7a0b887
Bump rustc_index and rustc_abi
lnicola Feb 2, 2024
980d348
Auto merge of #16476 - lnicola:sync-from-rust, r=lnicola
bors Feb 2, 2024
ba2910a
minor: correct some typos
Young-Flash Feb 2, 2024
70d6141
internal: update .typos.tmol
Young-Flash Feb 2, 2024
a52a4d9
internal: update typo-check CI setting
Young-Flash Feb 2, 2024
8f6a728
Auto merge of #16469 - Young-Flash:ci_typos, r=lnicola
bors Feb 2, 2024
30e7b87
miri: normalize struct tail in ABI compat check
Feb 2, 2024
a27e45a
fix #120603 by adding a check in default_read_buf
conradludgate Feb 3, 2024
4c694db
add another test to make sure it still works with full reads
conradludgate Feb 3, 2024
a605b96
Bump release runners to MacOS 12
lnicola Feb 3, 2024
0113bc9
Auto merge of #16479 - lnicola:macos-12, r=lnicola
bors Feb 3, 2024
468f400
Merge commit '0113bc9388b480fa42c632f57f4f0f7af5813ec1' into sync-fro…
lnicola Feb 4, 2024
98ad126
Try to fix in-tree build
lnicola Feb 4, 2024
cb4e69a
rustdoc: trait.impl, type.impl: sort impls to make it not depend on s…
klensy Feb 4, 2024
fe420dc
coverage: Test for closure body that is a single bang-macro
Zalathar Jan 22, 2024
8dd2b37
coverage: Add a test for `#[coverage(..)]` on closures
Zalathar Jan 20, 2024
dd6d7f2
coverage: Make unexpansion of closure bodies more precise
Zalathar Jan 22, 2024
fde1702
coverage: Hoist special handling of async function spans
Zalathar Jan 16, 2024
a246b6b
coverage: Make `fn_sig_span` optional, and note its quirks
Zalathar Jan 22, 2024
7158b3d
Rollup merge of #119481 - romanows:fix-doc-select-nth-unstable, r=Mar…
matthiaskrgr Feb 5, 2024
ca36ed2
Rollup merge of #119600 - aDotInTheVoid:comment-fix, r=compiler-errors
matthiaskrgr Feb 5, 2024
9838e94
Rollup merge of #120458 - rytheo:cstr-conversion-doc, r=Mark-Simulacrum
matthiaskrgr Feb 5, 2024
7294c15
Rollup merge of #120569 - Zalathar:fn-sig, r=oli-obk
matthiaskrgr Feb 5, 2024
16200db
Rollup merge of #120572 - pheki:update-libc, r=Mark-Simulacrum
matthiaskrgr Feb 5, 2024
e348f07
Rollup merge of #120587 - lukas-code:miri-tail-normalize, r=RalfJung
matthiaskrgr Feb 5, 2024
d8e9ddc
Rollup merge of #120607 - conradludgate:fix-120603, r=dtolnay
matthiaskrgr Feb 5, 2024
bc98f57
Rollup merge of #120636 - lnicola:sync-from-ra, r=lnicola
matthiaskrgr Feb 5, 2024
a2d3eed
Rollup merge of #120641 - klensy:copypaste-me, r=notriddle
matthiaskrgr Feb 5, 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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2169,9 +2169,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"

[[package]]
name = "libc"
version = "0.2.150"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ impl MachineStopType for ConstEvalErrKind {
}
}

// The errors become `MachineStop` with plain strings when being raised.
// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
// handle these.
/// The errors become [`InterpError::MachineStop`] when being raised.
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind {
fn into(self) -> InterpErrorInfo<'tcx> {
err_machine_stop!(self).into()
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_const_eval/src/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
// This is okay if they have the same metadata type.
let meta_ty = |ty: Ty<'tcx>| {
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, |ty| ty);
// Even if `ty` is normalized, the search for the unsized tail will project
// to fields, which can yield non-normalized types. So we need to provide a
// normalization function.
let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
assert!(
!only_if_sized,
"there should be no more 'maybe has that metadata' types during interpretation"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl
Printer { f }
}

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0264.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {
```

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

```
#![feature(lang_items)]
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ impl DiagCtxt {
}

// This is here to not allow mutation of flags;
// as of this writing it's only used in tests in librustc_middle.
// as of this writing it's used in Session::consider_optimizing and
// in tests in rustc_interface.
pub fn can_emit_warnings(&self) -> bool {
self.inner.borrow_mut().flags.can_emit_warnings
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use crate::nonstandard_style::{method_context, MethodLateContext};

use std::fmt::Write;

// hardwired lints from librustc_middle
// hardwired lints from rustc_lint_defs
pub use rustc_session::lint::builtin::*;

declare_lint! {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ macro_rules! arena_types {

// Note that this deliberately duplicates items in the `rustc_hir::arena`,
// since we need to allocate this type on both the `rustc_hir` arena
// (during lowering) and the `librustc_middle` arena (for decoding MIR)
// (during lowering) and the `rustc_middle` arena (for decoding MIR)
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet<rustc_hir::def_id::LocalDefId>,
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet<rustc_hir::ItemLocalId>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

// FIXME(#27438): right now the unit tests of librustc_middle don't refer to any actual
// functions generated in librustc_data_structures (all
// FIXME(#27438): right now the unit tests of rustc_middle don't refer to any actual
// functions generated in rustc_data_structures (all
// references are through generic functions), but statics are
// referenced from time to time. Due to this bug we won't
// actually correctly link in the statics unless we also
Expand Down
47 changes: 21 additions & 26 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
struct ExtractedHirInfo {
function_source_hash: u64,
is_async_fn: bool,
fn_sig_span: Span,
/// The span of the function's signature, extended to the start of `body_span`.
/// Must have the same context and filename as the body span.
fn_sig_span_extended: Option<Span>,
body_span: Span,
}

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

let is_async_fn = hir_node.fn_sig().is_some_and(|fn_sig| fn_sig.header.is_async());
let body_span = get_body_span(tcx, hir_body, def_id);
let maybe_fn_sig = hir_node.fn_sig();
let is_async_fn = maybe_fn_sig.is_some_and(|fn_sig| fn_sig.header.is_async());

let mut body_span = hir_body.value.span;

use rustc_hir::{Closure, Expr, ExprKind, Node};
// Unexpand a closure's body span back to the context of its declaration.
// This helps with closure bodies that consist of just a single bang-macro,
// and also with closure bodies produced by async desugaring.
if let Node::Expr(&Expr { kind: ExprKind::Closure(&Closure { fn_decl_span, .. }), .. }) =
hir_node
{
body_span = body_span.find_ancestor_in_same_ctxt(fn_decl_span).unwrap_or(body_span);
}

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

let function_source_hash = hash_mir_source(tcx, hir_body);

ExtractedHirInfo { function_source_hash, is_async_fn, fn_sig_span, body_span }
}

fn get_body_span<'tcx>(
tcx: TyCtxt<'tcx>,
hir_body: &rustc_hir::Body<'tcx>,
def_id: LocalDefId,
) -> Span {
let mut body_span = hir_body.value.span;

if tcx.is_closure_or_coroutine(def_id.to_def_id()) {
// If the current function is a closure, and its "body" span was created
// by macro expansion or compiler desugaring, try to walk backwards to
// the pre-expansion call site or body.
body_span = body_span.source_callsite();
}

body_span
ExtractedHirInfo { function_source_hash, is_async_fn, fn_sig_span_extended, body_span }
}

fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx rustc_hir::Body<'tcx>) -> u64 {
Expand Down
29 changes: 21 additions & 8 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::mir;
use rustc_span::{BytePos, Span, DUMMY_SP};

use super::graph::{BasicCoverageBlock, CoverageGraph};
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
use crate::coverage::ExtractedHirInfo;

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

let sorted_spans =
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
let coverage_spans = SpansRefiner::refine_sorted_spans(basic_coverage_blocks, sorted_spans);
mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
}));
if hir_info.is_async_fn {
// An async function desugars into a function that returns a future,
// with the user code wrapped in a closure. Any spans in the desugared
// outer function will be unhelpful, so just keep the signature span
// and ignore all of the spans in the MIR body.
if let Some(span) = hir_info.fn_sig_span_extended {
mappings.push(BcbMapping { kind: BcbMappingKind::Code(START_BCB), span });
}
} else {
let sorted_spans = from_mir::mir_to_initial_sorted_coverage_spans(
mir_body,
hir_info,
basic_coverage_blocks,
);
let coverage_spans = SpansRefiner::refine_sorted_spans(basic_coverage_blocks, sorted_spans);
mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
}));
}

if mappings.is_empty() {
return None;
Expand Down
32 changes: 14 additions & 18 deletions compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,21 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
hir_info: &ExtractedHirInfo,
basic_coverage_blocks: &CoverageGraph,
) -> Vec<CoverageSpan> {
let &ExtractedHirInfo { is_async_fn, fn_sig_span, body_span, .. } = hir_info;

let mut initial_spans = vec![SpanFromMir::for_fn_sig(fn_sig_span)];

if is_async_fn {
// An async function desugars into a function that returns a future,
// with the user code wrapped in a closure. Any spans in the desugared
// outer function will be unhelpful, so just keep the signature span
// and ignore all of the spans in the MIR body.
} else {
for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() {
initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data));
}
let &ExtractedHirInfo { body_span, .. } = hir_info;

// If no spans were extracted from the body, discard the signature span.
// FIXME: This preserves existing behavior; consider getting rid of it.
if initial_spans.len() == 1 {
initial_spans.clear();
}
let mut initial_spans = vec![];

for (bcb, bcb_data) in basic_coverage_blocks.iter_enumerated() {
initial_spans.extend(bcb_to_initial_coverage_spans(mir_body, body_span, bcb, bcb_data));
}

// Only add the signature span if we found at least one span in the body.
if !initial_spans.is_empty() {
// If there is no usable signature span, add a fake one (before refinement)
// to avoid an ugly gap between the body start and the first real span.
// FIXME: Find a more principled way to solve this problem.
let fn_sig_span = hir_info.fn_sig_span_extended.unwrap_or_else(|| body_span.shrink_to_lo());
initial_spans.push(SpanFromMir::for_fn_sig(fn_sig_span));
}

initial_spans.sort_by(|a, b| basic_coverage_blocks.cmp_in_dominator_order(a.bcb, b.bcb));
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ impl ToOwned for CStr {

#[stable(feature = "cstring_asref", since = "1.7.0")]
impl From<&CStr> for CString {
/// Converts a <code>&[CStr]</code> into a [`CString`]
/// by copying the contents into a new allocation.
fn from(s: &CStr) -> CString {
s.to_owned()
}
Expand Down
14 changes: 7 additions & 7 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2989,7 +2989,7 @@ impl<T> [T] {
sort::quicksort(self, |a, b| f(a).lt(&f(b)));
}

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

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

/// Reorder the slice with a key extraction function such that the element at `index` is at its
/// final sorted position.
/// Reorder the slice with a key extraction function such that the element at `index` after the reordering is
/// at its final sorted position.
///
/// This reordering has the additional property that any value at position `i < index` will be
/// less than or equal to any value at a position `j > index` using the key extraction function.
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
libc = { version = "0.2.150", default-features = false, features = ['rustc-dep-of-std'], public = true }
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
compiler_builtins = { version = "0.1.105" }
profiler_builtins = { path = "../profiler_builtins", optional = true }
unwind = { path = "../unwind" }
Expand Down
7 changes: 6 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,13 @@ where
F: FnOnce(&mut [u8]) -> Result<usize>,
{
let n = read(cursor.ensure_init().init_mut())?;
assert!(
n <= cursor.capacity(),
"read should not return more bytes than there is capacity for in the read buffer"
);
unsafe {
// SAFETY: we initialised using `ensure_init` so there is no uninit data to advance to.
// SAFETY: we initialised using `ensure_init` so there is no uninit data to advance to
// and we have checked that the read amount is not over capacity (see #120603)
cursor.advance(n);
}
Ok(())
Expand Down
31 changes: 30 additions & 1 deletion library/std/src/io/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{repeat, BorrowedBuf, Cursor, SeekFrom};
use crate::cmp::{self, min};
use crate::io::{self, IoSlice, IoSliceMut};
use crate::io::{self, IoSlice, IoSliceMut, DEFAULT_BUF_SIZE};
use crate::io::{BufRead, BufReader, Read, Seek, Write};
use crate::mem::MaybeUninit;
use crate::ops::Deref;
Expand Down Expand Up @@ -652,3 +652,32 @@ fn bench_take_read_buf(b: &mut test::Bencher) {
[255; 128].take(64).read_buf(buf.unfilled()).unwrap();
});
}

// Issue #120603
#[test]
#[should_panic = "read should not return more bytes than there is capacity for in the read buffer"]
fn read_buf_broken_read() {
struct MalformedRead;

impl Read for MalformedRead {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// broken length calculation
Ok(buf.len() + 1)
}
}

let _ = BufReader::new(MalformedRead).fill_buf();
}

#[test]
fn read_buf_full_read() {
struct FullRead;

impl Read for FullRead {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
Ok(buf.len())
}
}

assert_eq!(BufReader::new(FullRead).fill_buf().unwrap().len(), DEFAULT_BUF_SIZE);
}
Loading
Loading