Skip to content

Commit 6963ecd

Browse files
authored
Merge pull request rust-lang#4157 from RalfJung/rustup
Rustup
2 parents 396691a + 051829e commit 6963ecd

File tree

519 files changed

+3383
-5406
lines changed

Some content is hidden

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

519 files changed

+3383
-5406
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct Path {
100100
impl PartialEq<Symbol> for Path {
101101
#[inline]
102102
fn eq(&self, symbol: &Symbol) -> bool {
103-
self.segments.len() == 1 && { self.segments[0].ident.name == *symbol }
103+
matches!(&self.segments[..], [segment] if segment.ident.name == *symbol)
104104
}
105105
}
106106

@@ -121,13 +121,13 @@ impl Path {
121121
}
122122

123123
pub fn is_global(&self) -> bool {
124-
!self.segments.is_empty() && self.segments[0].ident.name == kw::PathRoot
124+
self.segments.first().is_some_and(|segment| segment.ident.name == kw::PathRoot)
125125
}
126126

127127
/// If this path is a single identifier with no arguments, does not ensure
128128
/// that the path resolves to a const param, the caller should check this.
129129
pub fn is_potential_trivial_const_arg(&self) -> bool {
130-
self.segments.len() == 1 && self.segments[0].args.is_none()
130+
matches!(self.segments[..], [PathSegment { args: None, .. }])
131131
}
132132
}
133133

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl AttrItem {
302302
impl MetaItem {
303303
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
304304
pub fn ident(&self) -> Option<Ident> {
305-
if self.path.segments.len() == 1 { Some(self.path.segments[0].ident) } else { None }
305+
if let [PathSegment { ident, .. }] = self.path.segments[..] { Some(ident) } else { None }
306306
}
307307

308308
pub fn name_or_empty(&self) -> Symbol {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,10 @@ pub fn walk_flat_map_stmt<T: MutVisitor>(
18131813
.into_iter()
18141814
.map(|kind| Stmt { id, kind, span })
18151815
.collect();
1816-
match stmts.len() {
1817-
0 => {}
1818-
1 => vis.visit_span(&mut stmts[0].span),
1819-
2.. => panic!(
1816+
match &mut stmts[..] {
1817+
[] => {}
1818+
[stmt] => vis.visit_span(&mut stmt.span),
1819+
_ => panic!(
18201820
"cloning statement `NodeId`s is prohibited by default, \
18211821
the visitor should implement custom statement visiting"
18221822
),

compiler/rustc_ast/src/util/comments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
3939
let mut i = 0;
4040
let mut j = lines.len();
4141
// first line of all-stars should be omitted
42-
if !lines.is_empty() && lines[0].chars().all(|c| c == '*') {
42+
if lines.first().is_some_and(|line| line.chars().all(|c| c == '*')) {
4343
i += 1;
4444
}
4545

@@ -97,7 +97,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
9797
return None;
9898
}
9999
}
100-
if lines.is_empty() { None } else { Some(lines[0][..i].into()) }
100+
Some(lines.first()?[..i].to_string())
101101
}
102102

103103
let data_s = data.as_str();

compiler/rustc_borrowck/src/polonius/dump.rs

Lines changed: 170 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::io;
22

3-
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
4-
use rustc_middle::mir::{Body, ClosureRegionRequirements, PassWhere};
3+
use rustc_middle::mir::pretty::{
4+
PassWhere, PrettyPrintMirOptions, create_dump_file, dump_enabled, dump_mir_to_writer,
5+
};
6+
use rustc_middle::mir::{Body, ClosureRegionRequirements};
57
use rustc_middle::ty::TyCtxt;
68
use rustc_session::config::MirIncludeSpans;
79

@@ -10,9 +12,6 @@ use crate::polonius::{LocalizedOutlivesConstraint, LocalizedOutlivesConstraintSe
1012
use crate::{BorrowckInferCtxt, RegionInferenceContext};
1113

1214
/// `-Zdump-mir=polonius` dumps MIR annotated with NLL and polonius specific information.
13-
// Note: this currently duplicates most of NLL MIR, with some additions for the localized outlives
14-
// constraints. This is ok for now as this dump will change in the near future to an HTML file to
15-
// become more useful.
1615
pub(crate) fn dump_polonius_mir<'tcx>(
1716
infcx: &BorrowckInferCtxt<'tcx>,
1817
body: &Body<'tcx>,
@@ -26,25 +25,113 @@ pub(crate) fn dump_polonius_mir<'tcx>(
2625
return;
2726
}
2827

28+
if !dump_enabled(tcx, "polonius", body.source.def_id()) {
29+
return;
30+
}
31+
2932
let localized_outlives_constraints = localized_outlives_constraints
3033
.expect("missing localized constraints with `-Zpolonius=next`");
3134

32-
// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
33-
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
34-
// they're always disabled in mir-opt tests to make working with blessed dumps easier.
35+
let _: io::Result<()> = try {
36+
let mut file = create_dump_file(tcx, "html", false, "polonius", &0, body)?;
37+
emit_polonius_dump(
38+
tcx,
39+
body,
40+
regioncx,
41+
borrow_set,
42+
localized_outlives_constraints,
43+
closure_region_requirements,
44+
&mut file,
45+
)?;
46+
};
47+
}
48+
49+
/// The polonius dump consists of:
50+
/// - the NLL MIR
51+
/// - the list of polonius localized constraints
52+
/// - a mermaid graph of the CFG
53+
fn emit_polonius_dump<'tcx>(
54+
tcx: TyCtxt<'tcx>,
55+
body: &Body<'tcx>,
56+
regioncx: &RegionInferenceContext<'tcx>,
57+
borrow_set: &BorrowSet<'tcx>,
58+
localized_outlives_constraints: LocalizedOutlivesConstraintSet,
59+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
60+
out: &mut dyn io::Write,
61+
) -> io::Result<()> {
62+
// Prepare the HTML dump file prologue.
63+
writeln!(out, "<!DOCTYPE html>")?;
64+
writeln!(out, "<html>")?;
65+
writeln!(out, "<head><title>Polonius MIR dump</title></head>")?;
66+
writeln!(out, "<body>")?;
67+
68+
// Section 1: the NLL + Polonius MIR.
69+
writeln!(out, "<div>")?;
70+
writeln!(out, "Raw MIR dump")?;
71+
writeln!(out, "<code><pre>")?;
72+
emit_html_mir(
73+
tcx,
74+
body,
75+
regioncx,
76+
borrow_set,
77+
localized_outlives_constraints,
78+
closure_region_requirements,
79+
out,
80+
)?;
81+
writeln!(out, "</pre></code>")?;
82+
writeln!(out, "</div>")?;
83+
84+
// Section 2: mermaid visualization of the CFG.
85+
writeln!(out, "<div>")?;
86+
writeln!(out, "Control-flow graph")?;
87+
writeln!(out, "<code><pre class='mermaid'>")?;
88+
emit_mermaid_cfg(body, out)?;
89+
writeln!(out, "</pre></code>")?;
90+
writeln!(out, "</div>")?;
91+
92+
// Finalize the dump with the HTML epilogue.
93+
writeln!(
94+
out,
95+
"<script src='https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js'></script>"
96+
)?;
97+
writeln!(out, "<script>")?;
98+
writeln!(out, "mermaid.initialize({{ startOnLoad: false, maxEdges: 100 }});")?;
99+
writeln!(out, "mermaid.run({{ querySelector: '.mermaid' }})")?;
100+
writeln!(out, "</script>")?;
101+
writeln!(out, "</body>")?;
102+
writeln!(out, "</html>")?;
103+
104+
Ok(())
105+
}
106+
107+
/// Emits the polonius MIR, as escaped HTML.
108+
fn emit_html_mir<'tcx>(
109+
tcx: TyCtxt<'tcx>,
110+
body: &Body<'tcx>,
111+
regioncx: &RegionInferenceContext<'tcx>,
112+
borrow_set: &BorrowSet<'tcx>,
113+
localized_outlives_constraints: LocalizedOutlivesConstraintSet,
114+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
115+
out: &mut dyn io::Write,
116+
) -> io::Result<()> {
117+
// Buffer the regular MIR dump to be able to escape it.
118+
let mut buffer = Vec::new();
119+
120+
// We want the NLL extra comments printed by default in NLL MIR dumps. Specifying `-Z
121+
// mir-include-spans` on the CLI still has priority.
35122
let options = PrettyPrintMirOptions {
36123
include_extra_comments: matches!(
37124
tcx.sess.opts.unstable_opts.mir_include_spans,
38125
MirIncludeSpans::On | MirIncludeSpans::Nll
39126
),
40127
};
41128

42-
dump_mir_with_options(
129+
dump_mir_to_writer(
43130
tcx,
44-
false,
45131
"polonius",
46132
&0,
47133
body,
134+
&mut buffer,
48135
|pass_where, out| {
49136
emit_polonius_mir(
50137
tcx,
@@ -57,7 +144,27 @@ pub(crate) fn dump_polonius_mir<'tcx>(
57144
)
58145
},
59146
options,
60-
);
147+
)?;
148+
149+
// Escape the handful of characters that need it. We don't need to be particularly efficient:
150+
// we're actually writing into a buffered writer already. Note that MIR dumps are valid UTF-8.
151+
let buffer = String::from_utf8_lossy(&buffer);
152+
for ch in buffer.chars() {
153+
let escaped = match ch {
154+
'>' => "&gt;",
155+
'<' => "&lt;",
156+
'&' => "&amp;",
157+
'\'' => "&#39;",
158+
'"' => "&quot;",
159+
_ => {
160+
// The common case, no escaping needed.
161+
write!(out, "{}", ch)?;
162+
continue;
163+
}
164+
};
165+
write!(out, "{}", escaped)?;
166+
}
167+
Ok(())
61168
}
62169

63170
/// Produces the actual NLL + Polonius MIR sections to emit during the dumping process.
@@ -102,3 +209,55 @@ fn emit_polonius_mir<'tcx>(
102209

103210
Ok(())
104211
}
212+
213+
/// Emits a mermaid flowchart of the CFG blocks and edges, similar to the graphviz version.
214+
fn emit_mermaid_cfg(body: &Body<'_>, out: &mut dyn io::Write) -> io::Result<()> {
215+
use rustc_middle::mir::{TerminatorEdges, TerminatorKind};
216+
217+
// The mermaid chart type: a top-down flowchart.
218+
writeln!(out, "flowchart TD")?;
219+
220+
// Emit the block nodes.
221+
for (block_idx, block) in body.basic_blocks.iter_enumerated() {
222+
let block_idx = block_idx.as_usize();
223+
let cleanup = if block.is_cleanup { " (cleanup)" } else { "" };
224+
writeln!(out, "{block_idx}[\"bb{block_idx}{cleanup}\"]")?;
225+
}
226+
227+
// Emit the edges between blocks, from the terminator edges.
228+
for (block_idx, block) in body.basic_blocks.iter_enumerated() {
229+
let block_idx = block_idx.as_usize();
230+
let terminator = block.terminator();
231+
match terminator.edges() {
232+
TerminatorEdges::None => {}
233+
TerminatorEdges::Single(bb) => {
234+
writeln!(out, "{block_idx} --> {}", bb.as_usize())?;
235+
}
236+
TerminatorEdges::Double(bb1, bb2) => {
237+
if matches!(terminator.kind, TerminatorKind::FalseEdge { .. }) {
238+
writeln!(out, "{block_idx} --> {}", bb1.as_usize())?;
239+
writeln!(out, "{block_idx} -- imaginary --> {}", bb2.as_usize())?;
240+
} else {
241+
writeln!(out, "{block_idx} --> {}", bb1.as_usize())?;
242+
writeln!(out, "{block_idx} -- unwind --> {}", bb2.as_usize())?;
243+
}
244+
}
245+
TerminatorEdges::AssignOnReturn { return_, cleanup, .. } => {
246+
for to_idx in return_ {
247+
writeln!(out, "{block_idx} --> {}", to_idx.as_usize())?;
248+
}
249+
250+
if let Some(to_idx) = cleanup {
251+
writeln!(out, "{block_idx} -- unwind --> {}", to_idx.as_usize())?;
252+
}
253+
}
254+
TerminatorEdges::SwitchInt { targets, .. } => {
255+
for to_idx in targets.all_targets() {
256+
writeln!(out, "{block_idx} --> {}", to_idx.as_usize())?;
257+
}
258+
}
259+
}
260+
}
261+
262+
Ok(())
263+
}

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
157157
{
158158
cx.dcx().emit_err(RequiresMaybeSized {
159159
span: pointee_ty_ident.span,
160-
name: pointee_ty_ident.name.to_ident_string(),
160+
name: pointee_ty_ident,
161161
});
162162
return;
163163
}
@@ -471,5 +471,5 @@ struct TooManyPointees {
471471
struct RequiresMaybeSized {
472472
#[primary_span]
473473
span: Span,
474-
name: String,
474+
name: Ident,
475475
}

compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
151151
apply_patches(
152152
&runner.dirs,
153153
"coretests",
154-
&runner.stdlib_source.join("library/core/tests"),
154+
&runner.stdlib_source.join("library/coretests"),
155155
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
156156
);
157157

compiler/rustc_codegen_cranelift/patches/0022-coretests-Disable-not-compiling-tests.patch

Lines changed: 0 additions & 44 deletions
This file was deleted.

compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ Cranelift doesn't support them yet
1010
library/core/tests/atomic.rs | 4 ---
1111
4 files changed, 4 insertions(+), 50 deletions(-)
1212

13-
diff --git a/lib.rs b/lib.rs
13+
diff --git a/tests/lib.rs b/tests/lib.rs
1414
index 1e336bf..35e6f54 100644
15-
--- a/lib.rs
16-
+++ b/lib.rs
17-
@@ -2,6 +2,5 @@
18-
#![cfg(test)]
15+
--- a/tests/lib.rs
16+
+++ b/tests/lib.rs
17+
@@ -2,5 +2,4 @@
1918
// tidy-alphabetical-start
2019
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2120
#![cfg_attr(test, feature(cfg_match))]
2221
#![feature(alloc_layout_extra)]
2322
#![feature(array_chunks)]
24-
diff --git a/atomic.rs b/atomic.rs
23+
diff --git a/tests/atomic.rs b/tests/atomic.rs
2524
index b735957..ea728b6 100644
26-
--- a/atomic.rs
27-
+++ b/atomic.rs
25+
--- a/tests/atomic.rs
26+
+++ b/tests/atomic.rs
2827
@@ -185,10 +185,6 @@ fn atomic_alignment() {
2928
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
3029
#[cfg(target_has_atomic = "64")]

0 commit comments

Comments
 (0)