Skip to content

Rollup of 7 pull requests #106472

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

Merged
merged 18 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
48 changes: 11 additions & 37 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,6 @@ enum WriteKind {
/// local place can be mutated.
//
// FIXME: @nikomatsakis suggested that this flag could be removed with the following modifications:
// - Merge `check_access_permissions()` and `check_if_reassignment_to_immutable_state()`.
// - Split `is_mutable()` into `is_assignable()` (can be directly assigned) and
// `is_declared_mutable()`.
// - Take flow state into consideration in `is_assignable()` for local variables.
Expand Down Expand Up @@ -1132,20 +1131,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// Write of P[i] or *P requires P init'd.
self.check_if_assigned_path_is_moved(location, place_span, flow_state);

// Special case: you can assign an immutable local variable
// (e.g., `x = ...`) so long as it has never been initialized
// before (at this point in the flow).
if let Some(local) = place_span.0.as_local() {
if let Mutability::Not = self.body.local_decls[local].mutability {
// check for reassignments to immutable local variables
self.check_if_reassignment_to_immutable_state(
location, local, place_span, flow_state,
);
return;
}
}

// Otherwise, use the normal access permission rules.
self.access_place(
location,
place_span,
Expand Down Expand Up @@ -1554,24 +1539,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

fn check_if_reassignment_to_immutable_state(
&mut self,
location: Location,
local: Local,
place_span: (Place<'tcx>, Span),
flow_state: &Flows<'cx, 'tcx>,
) {
debug!("check_if_reassignment_to_immutable_state({:?})", local);

// Check if any of the initializations of `local` have happened yet:
if let Some(init_index) = self.is_local_ever_initialized(local, flow_state) {
// And, if so, report an error.
let init = &self.move_data.inits[init_index];
let span = init.span(&self.body);
self.report_illegal_reassignment(location, place_span, span, place_span.0);
}
}

fn check_if_full_path_is_moved(
&mut self,
location: Location,
Expand Down Expand Up @@ -2037,12 +2004,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// partial initialization, do not complain about mutability
// errors except for actual mutation (as opposed to an attempt
// to do a partial initialization).
let previously_initialized =
self.is_local_ever_initialized(place.local, flow_state).is_some();
let previously_initialized = self.is_local_ever_initialized(place.local, flow_state);

// at this point, we have set up the error reporting state.
if previously_initialized {
self.report_mutability_error(place, span, the_place_err, error_access, location);
if let Some(init_index) = previously_initialized {
if let (AccessKind::Mutate, Some(_)) = (error_access, place.as_local()) {
// If this is a mutate access to an immutable local variable with no projections
// report the error as an illegal reassignment
let init = &self.move_data.inits[init_index];
let assigned_span = init.span(&self.body);
self.report_illegal_reassignment(location, (place, span), assigned_span, place);
} else {
self.report_mutability_error(place, span, the_place_err, error_access, location)
}
true
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! # How to read this documentation
//!
//! If you already know the name of what you are looking for, the fastest way to
//! find it is to use the <a href="#" onclick="focusSearchBar();">search
//! find it is to use the <a href="#" onclick="window.searchState.focus();">search
//! bar</a> at the top of the page.
//!
//! Otherwise, you may want to jump to one of these useful sections:
Expand Down
6 changes: 3 additions & 3 deletions library/test/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
let mut ntest = 0;
let mut nbench = 0;

for test in filter_tests(&opts, tests).into_iter() {
for test in filter_tests(opts, tests).into_iter() {
use crate::TestFn::*;

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

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

let max_name_len = tests
.iter()
.max_by_key(|t| len_if_padded(*t))
.max_by_key(|t| len_if_padded(t))
.map(|t| t.desc.name.as_slice().len())
.unwrap_or(0);

Expand Down
18 changes: 9 additions & 9 deletions library/test/src/formatters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ impl<T: Write> JsonFormatter<T> {
extra: Option<&str>,
) -> io::Result<()> {
// A doc test's name includes a filename which must be escaped for correct json.
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "{}", "name": "{}", "event": "{}""#,
ty,
EscapedString(name),
evt
))?;
if let Some(exec_time) = exec_time {
self.write_message(&*format!(r#", "exec_time": {}"#, exec_time.0.as_secs_f64()))?;
self.write_message(&format!(r#", "exec_time": {}"#, exec_time.0.as_secs_f64()))?;
}
if let Some(stdout) = stdout {
self.write_message(&*format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
self.write_message(&format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
}
if let Some(extra) = extra {
self.write_message(&*format!(r#", {extra}"#))?;
self.write_message(&format!(r#", {extra}"#))?;
}
self.writeln_message(" }")
}
Expand All @@ -66,13 +66,13 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
} else {
String::new()
};
self.writeln_message(&*format!(
self.writeln_message(&format!(
r#"{{ "type": "suite", "event": "started", "test_count": {test_count}{shuffle_seed_json} }}"#
))
}

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

self.writeln_message(&*line)
self.writeln_message(&line)
}
}
}

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

fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
self.write_message(&*format!(
self.write_message(&format!(
"{{ \"type\": \"suite\", \
\"event\": \"{}\", \
\"passed\": {}, \
Expand Down
16 changes: 8 additions & 8 deletions library/test/src/formatters/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
self.write_message("<testsuites>")?;

self.write_message(&*format!(
self.write_message(&format!(
"<testsuite name=\"test\" package=\"test\" id=\"0\" \
errors=\"0\" \
failures=\"{}\" \
Expand All @@ -73,12 +73,12 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
>",
state.failed, state.total, state.ignored
))?;
for (desc, result, duration) in std::mem::replace(&mut self.results, Vec::new()) {
for (desc, result, duration) in std::mem::take(&mut self.results) {
let (class_name, test_name) = parse_class_name(&desc);
match result {
TestResult::TrIgnored => { /* no-op */ }
TestResult::TrFailed => {
self.write_message(&*format!(
self.write_message(&format!(
"<testcase classname=\"{}\" \
name=\"{}\" time=\"{}\">",
class_name,
Expand All @@ -90,19 +90,19 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
}

TestResult::TrFailedMsg(ref m) => {
self.write_message(&*format!(
self.write_message(&format!(
"<testcase classname=\"{}\" \
name=\"{}\" time=\"{}\">",
class_name,
test_name,
duration.as_secs_f64()
))?;
self.write_message(&*format!("<failure message=\"{m}\" type=\"assert\"/>"))?;
self.write_message(&format!("<failure message=\"{m}\" type=\"assert\"/>"))?;
self.write_message("</testcase>")?;
}

TestResult::TrTimedFail => {
self.write_message(&*format!(
self.write_message(&format!(
"<testcase classname=\"{}\" \
name=\"{}\" time=\"{}\">",
class_name,
Expand All @@ -114,15 +114,15 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
}

TestResult::TrBench(ref b) => {
self.write_message(&*format!(
self.write_message(&format!(
"<testcase classname=\"benchmark::{}\" \
name=\"{}\" time=\"{}\" />",
class_name, test_name, b.ns_iter_summ.sum
))?;
}

TestResult::TrOk => {
self.write_message(&*format!(
self.write_message(&format!(
"<testcase classname=\"{}\" \
name=\"{}\" time=\"{}\"/>",
class_name,
Expand Down
16 changes: 8 additions & 8 deletions library/test/src/formatters/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl<T: Write> PrettyFormatter<T> {

let mut results = Vec::new();
let mut stdouts = String::new();
for &(ref f, ref stdout) in inputs {
for (f, stdout) in inputs {
results.push(f.name.to_string());
if !stdout.is_empty() {
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
Expand Down Expand Up @@ -171,9 +171,9 @@ impl<T: Write> PrettyFormatter<T> {
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
let name = desc.padded_name(self.max_name_len, desc.name.padding());
if let Some(test_mode) = desc.test_mode() {
self.write_plain(&format!("test {name} - {test_mode} ... "))?;
self.write_plain(format!("test {name} - {test_mode} ... "))?;
} else {
self.write_plain(&format!("test {name} ... "))?;
self.write_plain(format!("test {name} ... "))?;
}

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

fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
TestResult::TrIgnored => self.write_ignored(desc.ignore_message)?,
TestResult::TrBench(ref bs) => {
self.write_bench()?;
self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;
self.write_plain(format!(": {}", fmt_bench_samples(bs)))?;
}
TestResult::TrTimedFail => self.write_time_failed()?,
}
Expand All @@ -231,7 +231,7 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
}

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

self.write_plain(&s)?;
self.write_plain(s)?;

if let Some(ref exec_time) = state.exec_time {
let time_str = format!("; finished in {exec_time}");
self.write_plain(&time_str)?;
self.write_plain(time_str)?;
}

self.write_plain("\n\n")?;
Expand Down
20 changes: 10 additions & 10 deletions library/test/src/formatters/terse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<T: Write> TerseFormatter<T> {
// screen when dealing with line-buffered output (e.g., piping to
// `stamp` in the rust CI).
let out = format!(" {}/{}\n", self.test_count + 1, self.total_test_count);
self.write_plain(&out)?;
self.write_plain(out)?;
}

self.test_count += 1;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl<T: Write> TerseFormatter<T> {
self.write_plain("\nsuccesses:\n")?;
let mut successes = Vec::new();
let mut stdouts = String::new();
for &(ref f, ref stdout) in &state.not_failures {
for (f, stdout) in &state.not_failures {
successes.push(f.name.to_string());
if !stdout.is_empty() {
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
Expand All @@ -132,7 +132,7 @@ impl<T: Write> TerseFormatter<T> {
self.write_plain("\nfailures:\n")?;
let mut failures = Vec::new();
let mut fail_out = String::new();
for &(ref f, ref stdout) in &state.failures {
for (f, stdout) in &state.failures {
failures.push(f.name.to_string());
if !stdout.is_empty() {
fail_out.push_str(&format!("---- {} stdout ----\n", f.name));
Expand All @@ -157,9 +157,9 @@ impl<T: Write> TerseFormatter<T> {
fn write_test_name(&mut self, desc: &TestDesc) -> io::Result<()> {
let name = desc.padded_name(self.max_name_len, desc.name.padding());
if let Some(test_mode) = desc.test_mode() {
self.write_plain(&format!("test {name} - {test_mode} ... "))?;
self.write_plain(format!("test {name} - {test_mode} ... "))?;
} else {
self.write_plain(&format!("test {name} ... "))?;
self.write_plain(format!("test {name} ... "))?;
}

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

fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
Expand Down Expand Up @@ -209,13 +209,13 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
self.write_test_name(desc)?;
}
self.write_bench()?;
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
self.write_plain(format!(": {}\n", fmt_bench_samples(bs)))
}
}
}

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

self.write_plain(&s)?;
self.write_plain(s)?;

if let Some(ref exec_time) = state.exec_time {
let time_str = format!("; finished in {exec_time}");
self.write_plain(&time_str)?;
self.write_plain(time_str)?;
}

self.write_plain("\n\n")?;
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fn run_test_in_spawned_subprocess(
}
});
let record_result2 = record_result.clone();
panic::set_hook(Box::new(move |info| record_result2(Some(&info))));
panic::set_hook(Box::new(move |info| record_result2(Some(info))));
if let Err(message) = testfn() {
panic!("{}", message);
}
Expand Down
Loading