Skip to content

Commit d26242d

Browse files
committed
Auto merge of #106472 - matthiaskrgr:rollup-4w4v50e, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #106391 (rustdoc: allow popover child links to work) - #106398 (Fix a few clippy lints in libtest) - #106412 (Fix link generation for local primitive types in rustdoc JSON output) - #106437 (rustdoc: fix buggy JS check for absolute URL) - #106451 (Merge borrowck permission checks) - #106460 (Move tests) - #106461 (docs: fix broken link "search bar") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d9e317a + 06b2df4 commit d26242d

Some content is hidden

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

52 files changed

+150
-104
lines changed

compiler/rustc_borrowck/src/lib.rs

+11-37
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ enum WriteKind {
863863
/// local place can be mutated.
864864
//
865865
// FIXME: @nikomatsakis suggested that this flag could be removed with the following modifications:
866-
// - Merge `check_access_permissions()` and `check_if_reassignment_to_immutable_state()`.
867866
// - Split `is_mutable()` into `is_assignable()` (can be directly assigned) and
868867
// `is_declared_mutable()`.
869868
// - Take flow state into consideration in `is_assignable()` for local variables.
@@ -1132,20 +1131,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11321131
// Write of P[i] or *P requires P init'd.
11331132
self.check_if_assigned_path_is_moved(location, place_span, flow_state);
11341133

1135-
// Special case: you can assign an immutable local variable
1136-
// (e.g., `x = ...`) so long as it has never been initialized
1137-
// before (at this point in the flow).
1138-
if let Some(local) = place_span.0.as_local() {
1139-
if let Mutability::Not = self.body.local_decls[local].mutability {
1140-
// check for reassignments to immutable local variables
1141-
self.check_if_reassignment_to_immutable_state(
1142-
location, local, place_span, flow_state,
1143-
);
1144-
return;
1145-
}
1146-
}
1147-
1148-
// Otherwise, use the normal access permission rules.
11491134
self.access_place(
11501135
location,
11511136
place_span,
@@ -1554,24 +1539,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15541539
}
15551540
}
15561541

1557-
fn check_if_reassignment_to_immutable_state(
1558-
&mut self,
1559-
location: Location,
1560-
local: Local,
1561-
place_span: (Place<'tcx>, Span),
1562-
flow_state: &Flows<'cx, 'tcx>,
1563-
) {
1564-
debug!("check_if_reassignment_to_immutable_state({:?})", local);
1565-
1566-
// Check if any of the initializations of `local` have happened yet:
1567-
if let Some(init_index) = self.is_local_ever_initialized(local, flow_state) {
1568-
// And, if so, report an error.
1569-
let init = &self.move_data.inits[init_index];
1570-
let span = init.span(&self.body);
1571-
self.report_illegal_reassignment(location, place_span, span, place_span.0);
1572-
}
1573-
}
1574-
15751542
fn check_if_full_path_is_moved(
15761543
&mut self,
15771544
location: Location,
@@ -2037,12 +2004,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20372004
// partial initialization, do not complain about mutability
20382005
// errors except for actual mutation (as opposed to an attempt
20392006
// to do a partial initialization).
2040-
let previously_initialized =
2041-
self.is_local_ever_initialized(place.local, flow_state).is_some();
2007+
let previously_initialized = self.is_local_ever_initialized(place.local, flow_state);
20422008

20432009
// at this point, we have set up the error reporting state.
2044-
if previously_initialized {
2045-
self.report_mutability_error(place, span, the_place_err, error_access, location);
2010+
if let Some(init_index) = previously_initialized {
2011+
if let (AccessKind::Mutate, Some(_)) = (error_access, place.as_local()) {
2012+
// If this is a mutate access to an immutable local variable with no projections
2013+
// report the error as an illegal reassignment
2014+
let init = &self.move_data.inits[init_index];
2015+
let assigned_span = init.span(&self.body);
2016+
self.report_illegal_reassignment(location, (place, span), assigned_span, place);
2017+
} else {
2018+
self.report_mutability_error(place, span, the_place_err, error_access, location)
2019+
}
20462020
true
20472021
} else {
20482022
false

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! # How to read this documentation
1515
//!
1616
//! If you already know the name of what you are looking for, the fastest way to
17-
//! find it is to use the <a href="#" onclick="focusSearchBar();">search
17+
//! find it is to use the <a href="#" onclick="window.searchState.focus();">search
1818
//! bar</a> at the top of the page.
1919
//!
2020
//! Otherwise, you may want to jump to one of these useful sections:

library/test/src/console.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
147147
let mut ntest = 0;
148148
let mut nbench = 0;
149149

150-
for test in filter_tests(&opts, tests).into_iter() {
150+
for test in filter_tests(opts, tests).into_iter() {
151151
use crate::TestFn::*;
152152

153153
let TestDescAndFn { desc: TestDesc { name, .. }, testfn } = test;
@@ -244,7 +244,7 @@ fn on_test_event(
244244
let stdout = &completed_test.stdout;
245245

246246
st.write_log_result(test, result, exec_time.as_ref())?;
247-
out.write_result(test, result, exec_time.as_ref(), &*stdout, st)?;
247+
out.write_result(test, result, exec_time.as_ref(), stdout, st)?;
248248
handle_test_result(st, completed_test);
249249
}
250250
}
@@ -262,7 +262,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
262262

263263
let max_name_len = tests
264264
.iter()
265-
.max_by_key(|t| len_if_padded(*t))
265+
.max_by_key(|t| len_if_padded(t))
266266
.map(|t| t.desc.name.as_slice().len())
267267
.unwrap_or(0);
268268

library/test/src/formatters/json.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ impl<T: Write> JsonFormatter<T> {
4040
extra: Option<&str>,
4141
) -> io::Result<()> {
4242
// A doc test's name includes a filename which must be escaped for correct json.
43-
self.write_message(&*format!(
43+
self.write_message(&format!(
4444
r#"{{ "type": "{}", "name": "{}", "event": "{}""#,
4545
ty,
4646
EscapedString(name),
4747
evt
4848
))?;
4949
if let Some(exec_time) = exec_time {
50-
self.write_message(&*format!(r#", "exec_time": {}"#, exec_time.0.as_secs_f64()))?;
50+
self.write_message(&format!(r#", "exec_time": {}"#, exec_time.0.as_secs_f64()))?;
5151
}
5252
if let Some(stdout) = stdout {
53-
self.write_message(&*format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
53+
self.write_message(&format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
5454
}
5555
if let Some(extra) = extra {
56-
self.write_message(&*format!(r#", {extra}"#))?;
56+
self.write_message(&format!(r#", {extra}"#))?;
5757
}
5858
self.writeln_message(" }")
5959
}
@@ -66,13 +66,13 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
6666
} else {
6767
String::new()
6868
};
69-
self.writeln_message(&*format!(
69+
self.writeln_message(&format!(
7070
r#"{{ "type": "suite", "event": "started", "test_count": {test_count}{shuffle_seed_json} }}"#
7171
))
7272
}
7373

7474
fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
75-
self.writeln_message(&*format!(
75+
self.writeln_message(&format!(
7676
r#"{{ "type": "test", "event": "started", "name": "{}" }}"#,
7777
EscapedString(desc.name.as_slice())
7878
))
@@ -151,20 +151,20 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
151151
mbps
152152
);
153153

154-
self.writeln_message(&*line)
154+
self.writeln_message(&line)
155155
}
156156
}
157157
}
158158

159159
fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
160-
self.writeln_message(&*format!(
160+
self.writeln_message(&format!(
161161
r#"{{ "type": "test", "event": "timeout", "name": "{}" }}"#,
162162
EscapedString(desc.name.as_slice())
163163
))
164164
}
165165

166166
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
167-
self.write_message(&*format!(
167+
self.write_message(&format!(
168168
"{{ \"type\": \"suite\", \
169169
\"event\": \"{}\", \
170170
\"passed\": {}, \

library/test/src/formatters/junit.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
6464
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
6565
self.write_message("<testsuites>")?;
6666

67-
self.write_message(&*format!(
67+
self.write_message(&format!(
6868
"<testsuite name=\"test\" package=\"test\" id=\"0\" \
6969
errors=\"0\" \
7070
failures=\"{}\" \
@@ -73,12 +73,12 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
7373
>",
7474
state.failed, state.total, state.ignored
7575
))?;
76-
for (desc, result, duration) in std::mem::replace(&mut self.results, Vec::new()) {
76+
for (desc, result, duration) in std::mem::take(&mut self.results) {
7777
let (class_name, test_name) = parse_class_name(&desc);
7878
match result {
7979
TestResult::TrIgnored => { /* no-op */ }
8080
TestResult::TrFailed => {
81-
self.write_message(&*format!(
81+
self.write_message(&format!(
8282
"<testcase classname=\"{}\" \
8383
name=\"{}\" time=\"{}\">",
8484
class_name,
@@ -90,19 +90,19 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
9090
}
9191

9292
TestResult::TrFailedMsg(ref m) => {
93-
self.write_message(&*format!(
93+
self.write_message(&format!(
9494
"<testcase classname=\"{}\" \
9595
name=\"{}\" time=\"{}\">",
9696
class_name,
9797
test_name,
9898
duration.as_secs_f64()
9999
))?;
100-
self.write_message(&*format!("<failure message=\"{m}\" type=\"assert\"/>"))?;
100+
self.write_message(&format!("<failure message=\"{m}\" type=\"assert\"/>"))?;
101101
self.write_message("</testcase>")?;
102102
}
103103

104104
TestResult::TrTimedFail => {
105-
self.write_message(&*format!(
105+
self.write_message(&format!(
106106
"<testcase classname=\"{}\" \
107107
name=\"{}\" time=\"{}\">",
108108
class_name,
@@ -114,15 +114,15 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
114114
}
115115

116116
TestResult::TrBench(ref b) => {
117-
self.write_message(&*format!(
117+
self.write_message(&format!(
118118
"<testcase classname=\"benchmark::{}\" \
119119
name=\"{}\" time=\"{}\" />",
120120
class_name, test_name, b.ns_iter_summ.sum
121121
))?;
122122
}
123123

124124
TestResult::TrOk => {
125-
self.write_message(&*format!(
125+
self.write_message(&format!(
126126
"<testcase classname=\"{}\" \
127127
name=\"{}\" time=\"{}\"/>",
128128
class_name,

library/test/src/formatters/pretty.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<T: Write> PrettyFormatter<T> {
134134

135135
let mut results = Vec::new();
136136
let mut stdouts = String::new();
137-
for &(ref f, ref stdout) in inputs {
137+
for (f, stdout) in inputs {
138138
results.push(f.name.to_string());
139139
if !stdout.is_empty() {
140140
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
@@ -171,9 +171,9 @@ impl<T: Write> PrettyFormatter<T> {
171171
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
172172
let name = desc.padded_name(self.max_name_len, desc.name.padding());
173173
if let Some(test_mode) = desc.test_mode() {
174-
self.write_plain(&format!("test {name} - {test_mode} ... "))?;
174+
self.write_plain(format!("test {name} - {test_mode} ... "))?;
175175
} else {
176-
self.write_plain(&format!("test {name} ... "))?;
176+
self.write_plain(format!("test {name} ... "))?;
177177
}
178178

179179
Ok(())
@@ -188,7 +188,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
188188
} else {
189189
String::new()
190190
};
191-
self.write_plain(&format!("\nrunning {test_count} {noun}{shuffle_seed_msg}\n"))
191+
self.write_plain(format!("\nrunning {test_count} {noun}{shuffle_seed_msg}\n"))
192192
}
193193

194194
fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
@@ -221,7 +221,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
221221
TestResult::TrIgnored => self.write_ignored(desc.ignore_message)?,
222222
TestResult::TrBench(ref bs) => {
223223
self.write_bench()?;
224-
self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;
224+
self.write_plain(format!(": {}", fmt_bench_samples(bs)))?;
225225
}
226226
TestResult::TrTimedFail => self.write_time_failed()?,
227227
}
@@ -231,7 +231,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
231231
}
232232

233233
fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
234-
self.write_plain(&format!(
234+
self.write_plain(format!(
235235
"test {} has been running for over {} seconds\n",
236236
desc.name,
237237
time::TEST_WARN_TIMEOUT_S
@@ -267,11 +267,11 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
267267
state.passed, state.failed, state.ignored, state.measured, state.filtered_out
268268
);
269269

270-
self.write_plain(&s)?;
270+
self.write_plain(s)?;
271271

272272
if let Some(ref exec_time) = state.exec_time {
273273
let time_str = format!("; finished in {exec_time}");
274-
self.write_plain(&time_str)?;
274+
self.write_plain(time_str)?;
275275
}
276276

277277
self.write_plain("\n\n")?;

library/test/src/formatters/terse.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<T: Write> TerseFormatter<T> {
7070
// screen when dealing with line-buffered output (e.g., piping to
7171
// `stamp` in the rust CI).
7272
let out = format!(" {}/{}\n", self.test_count + 1, self.total_test_count);
73-
self.write_plain(&out)?;
73+
self.write_plain(out)?;
7474
}
7575

7676
self.test_count += 1;
@@ -106,7 +106,7 @@ impl<T: Write> TerseFormatter<T> {
106106
self.write_plain("\nsuccesses:\n")?;
107107
let mut successes = Vec::new();
108108
let mut stdouts = String::new();
109-
for &(ref f, ref stdout) in &state.not_failures {
109+
for (f, stdout) in &state.not_failures {
110110
successes.push(f.name.to_string());
111111
if !stdout.is_empty() {
112112
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
@@ -132,7 +132,7 @@ impl<T: Write> TerseFormatter<T> {
132132
self.write_plain("\nfailures:\n")?;
133133
let mut failures = Vec::new();
134134
let mut fail_out = String::new();
135-
for &(ref f, ref stdout) in &state.failures {
135+
for (f, stdout) in &state.failures {
136136
failures.push(f.name.to_string());
137137
if !stdout.is_empty() {
138138
fail_out.push_str(&format!("---- {} stdout ----\n", f.name));
@@ -157,9 +157,9 @@ impl<T: Write> TerseFormatter<T> {
157157
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
158158
let name = desc.padded_name(self.max_name_len, desc.name.padding());
159159
if let Some(test_mode) = desc.test_mode() {
160-
self.write_plain(&format!("test {name} - {test_mode} ... "))?;
160+
self.write_plain(format!("test {name} - {test_mode} ... "))?;
161161
} else {
162-
self.write_plain(&format!("test {name} ... "))?;
162+
self.write_plain(format!("test {name} ... "))?;
163163
}
164164

165165
Ok(())
@@ -175,7 +175,7 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
175175
} else {
176176
String::new()
177177
};
178-
self.write_plain(&format!("\nrunning {test_count} {noun}{shuffle_seed_msg}\n"))
178+
self.write_plain(format!("\nrunning {test_count} {noun}{shuffle_seed_msg}\n"))
179179
}
180180

181181
fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
@@ -209,13 +209,13 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
209209
self.write_test_name(desc)?;
210210
}
211211
self.write_bench()?;
212-
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
212+
self.write_plain(format!(": {}\n", fmt_bench_samples(bs)))
213213
}
214214
}
215215
}
216216

217217
fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
218-
self.write_plain(&format!(
218+
self.write_plain(format!(
219219
"test {} has been running for over {} seconds\n",
220220
desc.name,
221221
time::TEST_WARN_TIMEOUT_S
@@ -245,11 +245,11 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
245245
state.passed, state.failed, state.ignored, state.measured, state.filtered_out
246246
);
247247

248-
self.write_plain(&s)?;
248+
self.write_plain(s)?;
249249

250250
if let Some(ref exec_time) = state.exec_time {
251251
let time_str = format!("; finished in {exec_time}");
252-
self.write_plain(&time_str)?;
252+
self.write_plain(time_str)?;
253253
}
254254

255255
self.write_plain("\n\n")?;

library/test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ fn run_test_in_spawned_subprocess(
789789
}
790790
});
791791
let record_result2 = record_result.clone();
792-
panic::set_hook(Box::new(move |info| record_result2(Some(&info))));
792+
panic::set_hook(Box::new(move |info| record_result2(Some(info))));
793793
if let Err(message) = testfn() {
794794
panic!("{}", message);
795795
}

0 commit comments

Comments
 (0)