Skip to content

Rollup of 10 pull requests #137019

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

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a710e1f
account for `c_enum_min_bits` in `multiple-reprs` UI test
japaric Jan 20, 2025
b691e9f
Correct comment for FreeBSD and DragonFly BSD in unix/thread
no1wudi Jan 25, 2025
8c24c0a
Remove the common prelude module
ehuss Feb 11, 2025
142d107
remove : from stack-protector-heuristics-effect.rs filecheck
mustartt Feb 12, 2025
51b105d
ignore vendor directory in `git status`
jyn514 Feb 13, 2025
1a3efd2
Use `slice::fill` in `io::Repeat` implementation
DaniPopes Feb 13, 2025
2f27236
alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr
jedbrown Feb 13, 2025
fb3a363
Emit MIR for each bit with on `dont_reset_cast_kind_without_updating_…
pvdrz Feb 14, 2025
46c7236
Move drop elaboration infrastructure.
nnethercote Feb 14, 2025
28b75a3
Move `MirPatch` from `rustc_middle` to `rustc_mir_transform`.
nnethercote Feb 14, 2025
b480a92
Use underline suggestions for purely 'additive' replacements
compiler-errors Feb 13, 2025
f6406df
Consider add-prefix replacements too
compiler-errors Feb 13, 2025
6d71251
Trim suggestion parts to the subset that is purely additive
compiler-errors Feb 13, 2025
a28ed1e
Rollup merge of #135778 - ferrocene:ja-gh135777, r=workingjubilee
workingjubilee Feb 14, 2025
f980164
Rollup merge of #136052 - no1wudi:fix, r=workingjubilee
workingjubilee Feb 14, 2025
fc45dde
Rollup merge of #136886 - ehuss:remove-prelude-common, r=jhpratt
workingjubilee Feb 14, 2025
93a7b06
Rollup merge of #136938 - mustartt:fix-stack-protector-filecheck, r=w…
workingjubilee Feb 14, 2025
334e535
Rollup merge of #136956 - jyn514:ignore-vendor, r=Noratrieb
workingjubilee Feb 14, 2025
c4effdb
Rollup merge of #136958 - compiler-errors:additive-replacmeent, r=est…
workingjubilee Feb 14, 2025
2013078
Rollup merge of #136967 - DaniPopes:io-repeat-fill, r=joboet
workingjubilee Feb 14, 2025
3c28284
Rollup merge of #136976 - jedbrown:jed/doc-boxed-deferred-init, r=tgr…
workingjubilee Feb 14, 2025
fdf824c
Rollup merge of #137007 - pvdrz:fix-aarch64-alloc-layout, r=compiler-…
workingjubilee Feb 14, 2025
3aa627e
Rollup merge of #137008 - nnethercote:mv-code-into-rustc_mir_transfor…
workingjubilee Feb 14, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ no_llvm_build
/library/target
/src/bootstrap/target
/src/tools/x/target
# Created by `x vendor`
/vendor
# Created by default with `src/ci/docker/run.sh`
/obj/
# Created by nix dev shell / .envrc
Expand Down
25 changes: 18 additions & 7 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1976,13 +1976,16 @@ impl HumanEmitter {
Some(Style::HeaderMsg),
);

let other_suggestions = suggestions.len().saturating_sub(MAX_SUGGESTIONS);

let mut row_num = 2;
for (i, (complete, parts, highlights, _)) in
suggestions.iter().enumerate().take(MAX_SUGGESTIONS)
suggestions.into_iter().enumerate().take(MAX_SUGGESTIONS)
{
debug!(?complete, ?parts, ?highlights);

let has_deletion = parts.iter().any(|p| p.is_deletion(sm) || p.is_replacement(sm));
let has_deletion =
parts.iter().any(|p| p.is_deletion(sm) || p.is_destructive_replacement(sm));
let is_multiline = complete.lines().count() > 1;

if i == 0 {
Expand Down Expand Up @@ -2167,7 +2170,7 @@ impl HumanEmitter {
self.draw_code_line(
&mut buffer,
&mut row_num,
highlight_parts,
&highlight_parts,
line_pos + line_start,
line,
show_code_change,
Expand Down Expand Up @@ -2213,7 +2216,12 @@ impl HumanEmitter {
if let DisplaySuggestion::Diff | DisplaySuggestion::Underline | DisplaySuggestion::Add =
show_code_change
{
for part in parts {
for mut part in parts {
// If this is a replacement of, e.g. `"a"` into `"ab"`, adjust the
// suggestion and snippet to look as if we just suggested to add
// `"b"`, which is typically much easier for the user to understand.
part.trim_trivial_replacements(sm);

let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) {
snippet
} else {
Expand Down Expand Up @@ -2376,9 +2384,12 @@ impl HumanEmitter {
row_num = row + 1;
}
}
if suggestions.len() > MAX_SUGGESTIONS {
let others = suggestions.len() - MAX_SUGGESTIONS;
let msg = format!("and {} other candidate{}", others, pluralize!(others));
if other_suggestions > 0 {
let msg = format!(
"and {} other candidate{}",
other_suggestions,
pluralize!(other_suggestions)
);
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
}

Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,40 @@ impl SubstitutionPart {
!self.snippet.is_empty() && self.replaces_meaningful_content(sm)
}

/// Whether this is a replacement that overwrites source with a snippet
/// in a way that isn't a superset of the original string. For example,
/// replacing "abc" with "abcde" is not destructive, but replacing it
/// it with "abx" is, since the "c" character is lost.
pub fn is_destructive_replacement(&self, sm: &SourceMap) -> bool {
self.is_replacement(sm)
&& !sm.span_to_snippet(self.span).is_ok_and(|snippet| {
self.snippet.trim_start().starts_with(snippet.trim_start())
|| self.snippet.trim_end().ends_with(snippet.trim_end())
})
}

fn replaces_meaningful_content(&self, sm: &SourceMap) -> bool {
sm.span_to_snippet(self.span)
.map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty())
}

/// Try to turn a replacement into an addition when the span that is being
/// overwritten matches either the prefix or suffix of the replacement.
fn trim_trivial_replacements(&mut self, sm: &SourceMap) {
if self.snippet.is_empty() {
return;
}
let Ok(snippet) = sm.span_to_snippet(self.span) else {
return;
};
if self.snippet.starts_with(&snippet) {
self.span = self.span.shrink_to_hi();
self.snippet = self.snippet[snippet.len()..].to_string();
} else if self.snippet.ends_with(&snippet) {
self.span = self.span.shrink_to_lo();
self.snippet = self.snippet[..self.snippet.len() - snippet.len()].to_string();
}
}
}

impl CodeSuggestion {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub mod generic_graphviz;
pub mod graphviz;
pub mod interpret;
pub mod mono;
pub mod patch;
pub mod pretty;
mod query;
mod statement;
Expand Down
21 changes: 20 additions & 1 deletion compiler/rustc_mir_dataflow/src/drop_flag_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@ use rustc_middle::mir::{self, Body, Location, Terminator, TerminatorKind};
use tracing::debug;

use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex};
use crate::elaborate_drops::DropFlagState;

/// The value of an inserted drop flag.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum DropFlagState {
/// The tracked value is initialized and needs to be dropped when leaving its scope.
Present,

/// The tracked value is uninitialized or was moved out of and does not need to be dropped when
/// leaving its scope.
Absent,
}

impl DropFlagState {
pub fn value(self) -> bool {
match self {
DropFlagState::Present => true,
DropFlagState::Absent => false,
}
}
}

pub fn move_path_children_matching<'tcx, F>(
move_data: &MoveData<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty::util::Discr;
use rustc_middle::ty::{self, TyCtxt};
use tracing::{debug, instrument};

use crate::elaborate_drops::DropFlagState;
use crate::drop_flag_effects::DropFlagState;
use crate::framework::SwitchIntTarget;
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
use crate::{
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_dataflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty;
// Please change the public `use` directives cautiously, as they might be used by external tools.
// See issue #120130.
pub use self::drop_flag_effects::{
drop_flag_effects_for_function_entry, drop_flag_effects_for_location,
DropFlagState, drop_flag_effects_for_function_entry, drop_flag_effects_for_location,
move_path_children_matching, on_all_children_bits, on_lookup_result_bits,
};
pub use self::framework::{
Expand All @@ -26,7 +26,6 @@ use self::move_paths::MoveData;

pub mod debuginfo;
mod drop_flag_effects;
pub mod elaborate_drops;
mod errors;
mod framework;
pub mod impls;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
use tracing::debug;

use crate::patch::MirPatch;
use crate::util;

/// This pass moves values being dropped that are within a packed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;

use crate::patch::MirPatch;

pub(super) struct Subtyper;

struct SubTypeChecker<'a, 'tcx> {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,9 +1061,8 @@ fn insert_switch<'tcx>(
}

fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
use rustc_middle::mir::patch::MirPatch;
use rustc_mir_dataflow::elaborate_drops::{Unwind, elaborate_drop};

use crate::elaborate_drop::{Unwind, elaborate_drop};
use crate::patch::MirPatch;
use crate::shim::DropShimElaborator;

// Note that `elaborate_drops` only drops the upvars of a coroutine, and
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/deref_separator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::visit::NonUseContext::VarDebugInfo;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext};
use rustc_middle::mir::*;
use rustc_middle::ty::TyCtxt;

use crate::patch::MirPatch;

pub(super) struct Derefer;

struct DerefChecker<'a, 'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/early_otherwise_branch.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::fmt::Debug;

use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::{Ty, TyCtxt};
use tracing::trace;

use super::simplify::simplify_cfg;
use crate::patch::MirPatch;

/// This pass optimizes something like
/// ```ignore (syntax-highlighting-only)
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/elaborate_box_derefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use rustc_abi::FieldIdx;
use rustc_hir::def_id::DefId;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::visit::MutVisitor;
use rustc_middle::mir::*;
use rustc_middle::span_bug;
use rustc_middle::ty::{Ty, TyCtxt};

use crate::patch::MirPatch;

/// Constructs the types used when accessing a Box's pointer
fn build_ptr_tys<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{fmt, iter, mem};
use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_hir::lang_items::LangItem;
use rustc_index::Idx;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::span_bug;
use rustc_middle::ty::adjustment::PointerCoercion;
Expand All @@ -13,29 +12,11 @@ use rustc_span::DUMMY_SP;
use rustc_span::source_map::Spanned;
use tracing::{debug, instrument};

/// The value of an inserted drop flag.
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum DropFlagState {
/// The tracked value is initialized and needs to be dropped when leaving its scope.
Present,

/// The tracked value is uninitialized or was moved out of and does not need to be dropped when
/// leaving its scope.
Absent,
}

impl DropFlagState {
pub fn value(self) -> bool {
match self {
DropFlagState::Present => true,
DropFlagState::Absent => false,
}
}
}
use crate::patch::MirPatch;

/// Describes how/if a value should be dropped.
#[derive(Debug)]
pub enum DropStyle {
pub(crate) enum DropStyle {
/// The value is already dead at the drop location, no drop will be executed.
Dead,

Expand All @@ -56,7 +37,7 @@ pub enum DropStyle {

/// Which drop flags to affect/check with an operation.
#[derive(Debug)]
pub enum DropFlagMode {
pub(crate) enum DropFlagMode {
/// Only affect the top-level drop flag, not that of any contained fields.
Shallow,
/// Affect all nested drop flags in addition to the top-level one.
Expand All @@ -65,7 +46,7 @@ pub enum DropFlagMode {

/// Describes if unwinding is necessary and where to unwind to if a panic occurs.
#[derive(Copy, Clone, Debug)]
pub enum Unwind {
pub(crate) enum Unwind {
/// Unwind to this block.
To(BasicBlock),
/// Already in an unwind path, any panic will cause an abort.
Expand Down Expand Up @@ -98,7 +79,7 @@ impl Unwind {
}
}

pub trait DropElaborator<'a, 'tcx>: fmt::Debug {
pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {
/// The type representing paths that can be moved out of.
///
/// Users can move out of individual fields of a struct, such as `a.b.c`. This type is used to
Expand Down Expand Up @@ -177,7 +158,7 @@ where
/// value.
///
/// When this returns, the MIR patch in the `elaborator` contains the necessary changes.
pub fn elaborate_drop<'b, 'tcx, D>(
pub(crate) fn elaborate_drop<'b, 'tcx, D>(
elaborator: &mut D,
source_info: SourceInfo,
place: Place<'tcx>,
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_mir_transform/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ use std::fmt;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_index::IndexVec;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_dataflow::elaborate_drops::{
DropElaborator, DropFlagMode, DropFlagState, DropStyle, Unwind, elaborate_drop,
};
use rustc_mir_dataflow::impls::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use rustc_mir_dataflow::move_paths::{LookupResult, MoveData, MovePathIndex};
use rustc_mir_dataflow::{
Analysis, MoveDataTypingEnv, ResultsCursor, on_all_children_bits, on_lookup_result_bits,
Analysis, DropFlagState, MoveDataTypingEnv, ResultsCursor, on_all_children_bits,
on_lookup_result_bits,
};
use rustc_span::Span;
use tracing::{debug, instrument};

use crate::deref_separator::deref_finder;
use crate::elaborate_drop::{DropElaborator, DropFlagMode, DropStyle, Unwind, elaborate_drop};
use crate::patch::MirPatch;

/// During MIR building, Drop terminators are inserted in every place where a drop may occur.
/// However, in this phase, the presence of these terminators does not guarantee that a destructor
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ mod check_pointers;
mod cost_checker;
mod cross_crate_inline;
mod deduce_param_attrs;
mod elaborate_drop;
mod errors;
mod ffi_unwind_calls;
mod lint;
mod lint_tail_expr_drop_order;
mod patch;
mod shim;
mod ssa;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/match_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::iter;

use rustc_abi::Integer;
use rustc_index::IndexSlice;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
use rustc_type_ir::TyKind::*;
use tracing::instrument;

use super::simplify::simplify_cfg;
use crate::patch::MirPatch;

pub(super) struct MatchBranchSimplification;

Expand Down
Loading
Loading