Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7aec84d
resolve: Merge `ExternPreludeEntry::introduced_by_item` into `item_bi…
petrochenkov Aug 29, 2025
f0dbfad
resolve: Merge `ExternPreludeEntry::only_item` into `flag_binding`
petrochenkov Aug 29, 2025
1112274
add `Bound::copied`
connortsui20 Aug 28, 2025
9c1255f
add feature gate in doc test
connortsui20 Aug 28, 2025
114c0c2
Add `#[must_use] and update `cloned` documentation
connortsui20 Aug 30, 2025
18a36bc
Detect negative literal inferred to unsigned integer
estebank Aug 30, 2025
263766b
suggest method name with maybe ty mismatch
chenyukang Aug 31, 2025
cfba491
fix
LorrensP-2158466 Aug 31, 2025
ea2daa3
Split `ObligationCauseCode::BinOp` for unops to `UnOp`
estebank Aug 31, 2025
7ea882d
Inline and remove `dump_matched_mir_node`.
nnethercote Aug 14, 2025
3a0d0be
Inline and remove `dump_mir_for_pass`.
nnethercote Aug 14, 2025
d7faa56
Avoid unnecessary `mut`-ness for various closures.
nnethercote Aug 14, 2025
d3e2c93
Use trait object references for closures.
nnethercote Aug 15, 2025
2d21c13
Indent some functions.
nnethercote Aug 15, 2025
5ce3797
Introduce `MirDumper` and `MirWriter`.
nnethercote Aug 15, 2025
d17b3fb
Rollup merge of #145421 - nnethercote:dump_mir-cleanups, r=davidtwco
Zalathar Sep 1, 2025
0fa8265
Rollup merge of #145968 - connortsui20:bound-copied, r=joboet
Zalathar Sep 1, 2025
5adc0fe
Rollup merge of #146004 - petrochenkov:epentry, r=nnethercote
Zalathar Sep 1, 2025
142ad69
Rollup merge of #146042 - estebank:issue-83413, r=lcnr
Zalathar Sep 1, 2025
eed5259
Rollup merge of #146046 - chenyukang:yukang-fix-method-exists-for-ret…
Zalathar Sep 1, 2025
0dbd8e6
Rollup merge of #146051 - LorrensP-2158466:miri-libstd-fix, r=RalfJung
Zalathar Sep 1, 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
35 changes: 16 additions & 19 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::str::FromStr;
use polonius_engine::{Algorithm, AllFacts, Output};
use rustc_data_structures::frozen::Frozen;
use rustc_index::IndexSlice;
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
use rustc_middle::mir::{Body, PassWhere, Promoted, create_dump_file, dump_enabled, dump_mir};
use rustc_middle::mir::pretty::PrettyPrintMirOptions;
use rustc_middle::mir::{Body, MirDumper, PassWhere, Promoted};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_dataflow::move_paths::MoveData;
Expand Down Expand Up @@ -68,7 +68,9 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
// Replace all remaining regions with fresh inference variables.
renumber::renumber_mir(infcx, body, promoted);

dump_mir(infcx.tcx, false, "renumber", &0, body, |_, _| Ok(()));
if let Some(dumper) = MirDumper::new(infcx.tcx, "renumber", body) {
dumper.dump_mir(body);
}

universal_regions
}
Expand Down Expand Up @@ -175,9 +177,7 @@ pub(super) fn dump_nll_mir<'tcx>(
borrow_set: &BorrowSet<'tcx>,
) {
let tcx = infcx.tcx;
if !dump_enabled(tcx, "nll", body.source.def_id()) {
return;
}
let Some(dumper) = MirDumper::new(tcx, "nll", body) else { return };

// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
Expand All @@ -188,27 +188,24 @@ pub(super) fn dump_nll_mir<'tcx>(
MirIncludeSpans::On | MirIncludeSpans::Nll
),
};
dump_mir_with_options(
tcx,
false,
"nll",
&0,
body,
|pass_where, out| {
emit_nll_mir(tcx, regioncx, closure_region_requirements, borrow_set, pass_where, out)
},
options,
);

let extra_data = &|pass_where, out: &mut dyn std::io::Write| {
emit_nll_mir(tcx, regioncx, closure_region_requirements, borrow_set, pass_where, out)
};

let dumper = dumper.set_extra_data(extra_data).set_options(options);

dumper.dump_mir(body);

// Also dump the region constraint graph as a graphviz file.
let _: io::Result<()> = try {
let mut file = create_dump_file(tcx, "regioncx.all.dot", false, "nll", &0, body)?;
let mut file = dumper.create_dump_file("regioncx.all.dot", body)?;
regioncx.dump_graphviz_raw_constraints(tcx, &mut file)?;
};

// Also dump the region constraint SCC graph as a graphviz file.
let _: io::Result<()> = try {
let mut file = create_dump_file(tcx, "regioncx.scc.dot", false, "nll", &0, body)?;
let mut file = dumper.create_dump_file("regioncx.scc.dot", body)?;
regioncx.dump_graphviz_scc_constraints(tcx, &mut file)?;
};
}
Expand Down
87 changes: 32 additions & 55 deletions compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::io;

use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_index::IndexVec;
use rustc_middle::mir::pretty::{
PassWhere, PrettyPrintMirOptions, create_dump_file, dump_enabled, dump_mir_to_writer,
};
use rustc_middle::mir::pretty::{MirDumper, PassWhere, PrettyPrintMirOptions};
use rustc_middle::mir::{Body, Location};
use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::points::PointIndex;
Expand Down Expand Up @@ -33,22 +31,41 @@ pub(crate) fn dump_polonius_mir<'tcx>(
return;
}

if !dump_enabled(tcx, "polonius", body.source.def_id()) {
return;
}
let Some(dumper) = MirDumper::new(tcx, "polonius", body) else { return };

let polonius_diagnostics =
polonius_diagnostics.expect("missing diagnostics context with `-Zpolonius=next`");

let extra_data = &|pass_where, out: &mut dyn io::Write| {
emit_polonius_mir(
tcx,
regioncx,
closure_region_requirements,
borrow_set,
&polonius_diagnostics.localized_outlives_constraints,
pass_where,
out,
)
};
// We want the NLL extra comments printed by default in NLL MIR dumps. Specifying `-Z
// mir-include-spans` on the CLI still has priority.
let options = PrettyPrintMirOptions {
include_extra_comments: matches!(
tcx.sess.opts.unstable_opts.mir_include_spans,
MirIncludeSpans::On | MirIncludeSpans::Nll
),
};

let dumper = dumper.set_extra_data(extra_data).set_options(options);

let _: io::Result<()> = try {
let mut file = create_dump_file(tcx, "html", false, "polonius", &0, body)?;
let mut file = dumper.create_dump_file("html", body)?;
emit_polonius_dump(
tcx,
&dumper,
body,
regioncx,
borrow_set,
&polonius_diagnostics.localized_outlives_constraints,
closure_region_requirements,
&mut file,
)?;
};
Expand All @@ -61,12 +78,11 @@ pub(crate) fn dump_polonius_mir<'tcx>(
/// - a mermaid graph of the NLL regions and the constraints between them
/// - a mermaid graph of the NLL SCCs and the constraints between them
fn emit_polonius_dump<'tcx>(
tcx: TyCtxt<'tcx>,
dumper: &MirDumper<'_, '_, 'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
borrow_set: &BorrowSet<'tcx>,
localized_outlives_constraints: &LocalizedOutlivesConstraintSet,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
out: &mut dyn io::Write,
) -> io::Result<()> {
// Prepare the HTML dump file prologue.
Expand All @@ -79,15 +95,7 @@ fn emit_polonius_dump<'tcx>(
writeln!(out, "<div>")?;
writeln!(out, "Raw MIR dump")?;
writeln!(out, "<pre><code>")?;
emit_html_mir(
tcx,
body,
regioncx,
borrow_set,
&localized_outlives_constraints,
closure_region_requirements,
out,
)?;
emit_html_mir(dumper, body, out)?;
writeln!(out, "</code></pre>")?;
writeln!(out, "</div>")?;

Expand Down Expand Up @@ -116,15 +124,15 @@ fn emit_polonius_dump<'tcx>(
writeln!(out, "<div>")?;
writeln!(out, "NLL regions")?;
writeln!(out, "<pre class='mermaid'>")?;
emit_mermaid_nll_regions(tcx, regioncx, out)?;
emit_mermaid_nll_regions(dumper.tcx(), regioncx, out)?;
writeln!(out, "</pre>")?;
writeln!(out, "</div>")?;

// Section 5: mermaid visualization of the NLL SCC graph.
writeln!(out, "<div>")?;
writeln!(out, "NLL SCCs")?;
writeln!(out, "<pre class='mermaid'>")?;
emit_mermaid_nll_sccs(tcx, regioncx, out)?;
emit_mermaid_nll_sccs(dumper.tcx(), regioncx, out)?;
writeln!(out, "</pre>")?;
writeln!(out, "</div>")?;

Expand All @@ -149,45 +157,14 @@ fn emit_polonius_dump<'tcx>(

/// Emits the polonius MIR, as escaped HTML.
fn emit_html_mir<'tcx>(
tcx: TyCtxt<'tcx>,
dumper: &MirDumper<'_, '_, 'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
borrow_set: &BorrowSet<'tcx>,
localized_outlives_constraints: &LocalizedOutlivesConstraintSet,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
out: &mut dyn io::Write,
) -> io::Result<()> {
// Buffer the regular MIR dump to be able to escape it.
let mut buffer = Vec::new();

// We want the NLL extra comments printed by default in NLL MIR dumps. Specifying `-Z
// mir-include-spans` on the CLI still has priority.
let options = PrettyPrintMirOptions {
include_extra_comments: matches!(
tcx.sess.opts.unstable_opts.mir_include_spans,
MirIncludeSpans::On | MirIncludeSpans::Nll
),
};

dump_mir_to_writer(
tcx,
"polonius",
&0,
body,
&mut buffer,
|pass_where, out| {
emit_polonius_mir(
tcx,
regioncx,
closure_region_requirements,
borrow_set,
localized_outlives_constraints,
pass_where,
out,
)
},
options,
)?;
dumper.dump_mir_to_writer(body, &mut buffer)?;

// Escape the handful of characters that need it. We don't need to be particularly efficient:
// we're actually writing into a buffered writer already. Note that MIR dumps are valid UTF-8.
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ pub(crate) fn codegen_fn<'tcx>(
let _mir_guard = crate::PrintOnPanic(|| {
let mut buf = Vec::new();
with_no_trimmed_paths!({
use rustc_middle::mir::pretty;
let options = pretty::PrettyPrintMirOptions::from_cli(tcx);
pretty::write_mir_fn(tcx, mir, &mut |_, _| Ok(()), &mut buf, options).unwrap();
let writer = pretty::MirWriter::new(tcx);
writer.write_mir_fn(mir, &mut buf).unwrap();
});
String::from_utf8_lossy(&buf).into_owned()
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(Ambiguity(..)) => true,
Err(PrivateMatch(..)) => false,
Err(IllegalSizedBound { .. }) => true,
Err(BadReturnType) => false,
Err(BadReturnType) => true,
Err(ErrorReported(_)) => false,
}
}
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,13 +962,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (opt_rhs_expr, opt_rhs_ty) = opt_rhs.unzip();
let cause = self.cause(
span,
ObligationCauseCode::BinOp {
lhs_hir_id: lhs_expr.hir_id,
rhs_hir_id: opt_rhs_expr.map(|expr| expr.hir_id),
rhs_span: opt_rhs_expr.map(|expr| expr.span),
rhs_is_lit: opt_rhs_expr
.is_some_and(|expr| matches!(expr.kind, hir::ExprKind::Lit(_))),
output_ty: expected.only_has_type(self),
match opt_rhs_expr {
Some(rhs) => ObligationCauseCode::BinOp {
lhs_hir_id: lhs_expr.hir_id,
rhs_hir_id: rhs.hir_id,
rhs_span: rhs.span,
rhs_is_lit: matches!(rhs.kind, hir::ExprKind::Lit(_)),
output_ty: expected.only_has_type(self),
},
None => ObligationCauseCode::UnOp { hir_id: lhs_expr.hir_id },
},
);

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ pub use terminator::*;

pub use self::generic_graph::graphviz_safe_def_name;
pub use self::graphviz::write_mir_graphviz;
pub use self::pretty::{
PassWhere, create_dump_file, display_allocation, dump_enabled, dump_mir, write_mir_pretty,
};
pub use self::pretty::{MirDumper, PassWhere, display_allocation, write_mir_pretty};

/// Types for locals
pub type LocalDecls<'tcx> = IndexSlice<Local, LocalDecl<'tcx>>;
Expand Down
Loading
Loading