Auto merge of #78874 - m-ou-se:rollup-3jp1ijj, r=m-ou-se
Rollup of 19 pull requests Successful merges: - #76097 (Stabilize hint::spin_loop) - #76227 (Stabilize `Poll::is_ready` and `is_pending` as const) - #78065 (make concurrency helper more pleasant to read) - #78570 (Remove FIXME comment in print_type_sizes ui test suite) - #78572 (Use SOCK_CLOEXEC and accept4() on more platforms.) - #78658 (Add a tool to run `x.py` from any subdirectory) - #78706 (Fix run-make tests running when LLVM is disabled) - #78728 (Constantify `UnsafeCell::into_inner` and related) - #78775 (Bump Rustfmt and RLS) - #78788 (Correct unsigned equivalent of isize to be usize) - #78811 (Make some std::io functions `const`) - #78828 (use single char patterns for split() (clippy::single_char_pattern)) - #78841 (Small cleanup in `TypeFoldable` derive macro) - #78842 (Honor the rustfmt setting in config.toml) - #78843 (Less verbose debug logging from inlining integrator) - #78852 (Convert a bunch of intra-doc links) - #78860 (rustc_resolve: Use `#![feature(format_args_capture)]`) - #78861 (typo and formatting) - #78865 (Don't fire `CONST_ITEM_MUTATION` lint when borrowing a deref) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
b1277d04db
63 changed files with 516 additions and 314 deletions
|
@ -61,22 +61,35 @@ impl<'a, 'tcx> ConstMutationChecker<'a, 'tcx> {
|
|||
|
||||
fn lint_const_item_usage(
|
||||
&self,
|
||||
place: &Place<'tcx>,
|
||||
const_item: DefId,
|
||||
location: Location,
|
||||
decorate: impl for<'b> FnOnce(LintDiagnosticBuilder<'b>) -> DiagnosticBuilder<'b>,
|
||||
) {
|
||||
let source_info = self.body.source_info(location);
|
||||
let lint_root = self.body.source_scopes[source_info.scope]
|
||||
.local_data
|
||||
.as_ref()
|
||||
.assert_crate_local()
|
||||
.lint_root;
|
||||
// Don't lint on borrowing/assigning to a dereference
|
||||
// e.g:
|
||||
//
|
||||
// `unsafe { *FOO = 0; *BAR.field = 1; }`
|
||||
// `unsafe { &mut *FOO }`
|
||||
if !matches!(place.projection.last(), Some(PlaceElem::Deref)) {
|
||||
let source_info = self.body.source_info(location);
|
||||
let lint_root = self.body.source_scopes[source_info.scope]
|
||||
.local_data
|
||||
.as_ref()
|
||||
.assert_crate_local()
|
||||
.lint_root;
|
||||
|
||||
self.tcx.struct_span_lint_hir(CONST_ITEM_MUTATION, lint_root, source_info.span, |lint| {
|
||||
decorate(lint)
|
||||
.span_note(self.tcx.def_span(const_item), "`const` item defined here")
|
||||
.emit()
|
||||
});
|
||||
self.tcx.struct_span_lint_hir(
|
||||
CONST_ITEM_MUTATION,
|
||||
lint_root,
|
||||
source_info.span,
|
||||
|lint| {
|
||||
decorate(lint)
|
||||
.span_note(self.tcx.def_span(const_item), "`const` item defined here")
|
||||
.emit()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,15 +101,11 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
|
|||
// so emitting a lint would be redundant.
|
||||
if !lhs.projection.is_empty() {
|
||||
if let Some(def_id) = self.is_const_item_without_destructor(lhs.local) {
|
||||
// Don't lint on writes through a pointer
|
||||
// (e.g. `unsafe { *FOO = 0; *BAR.field = 1; }`)
|
||||
if !matches!(lhs.projection.last(), Some(PlaceElem::Deref)) {
|
||||
self.lint_const_item_usage(def_id, loc, |lint| {
|
||||
let mut lint = lint.build("attempting to modify a `const` item");
|
||||
lint.note("each usage of a `const` item creates a new temporary - the original `const` item will not be modified");
|
||||
lint
|
||||
})
|
||||
}
|
||||
self.lint_const_item_usage(&lhs, def_id, loc, |lint| {
|
||||
let mut lint = lint.build("attempting to modify a `const` item");
|
||||
lint.note("each usage of a `const` item creates a new temporary; the original `const` item will not be modified");
|
||||
lint
|
||||
})
|
||||
}
|
||||
}
|
||||
// We are looking for MIR of the form:
|
||||
|
@ -127,7 +136,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ConstMutationChecker<'a, 'tcx> {
|
|||
});
|
||||
let lint_loc =
|
||||
if method_did.is_some() { self.body.terminator_loc(loc.block) } else { loc };
|
||||
self.lint_const_item_usage(def_id, lint_loc, |lint| {
|
||||
self.lint_const_item_usage(place, def_id, lint_loc, |lint| {
|
||||
let mut lint = lint.build("taking a mutable reference to a `const` item");
|
||||
lint
|
||||
.note("each usage of a `const` item creates a new temporary")
|
||||
|
|
|
@ -147,8 +147,8 @@ impl DebugOptions {
|
|||
let mut counter_format = ExpressionFormat::default();
|
||||
|
||||
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
|
||||
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(",") {
|
||||
let mut setting = setting_str.splitn(2, "=");
|
||||
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
|
||||
let mut setting = setting_str.splitn(2, '=');
|
||||
match setting.next() {
|
||||
Some(option) if option == "allow_unused_expressions" => {
|
||||
allow_unused_expressions = bool_option_val(option, setting.next());
|
||||
|
@ -210,7 +210,7 @@ fn bool_option_val(option: &str, some_strval: Option<&str>) -> bool {
|
|||
|
||||
fn counter_format_option_val(strval: &str) -> ExpressionFormat {
|
||||
let mut counter_format = ExpressionFormat { id: false, block: false, operation: false };
|
||||
let components = strval.splitn(3, "+");
|
||||
let components = strval.splitn(3, '+');
|
||||
for component in components {
|
||||
match component {
|
||||
"id" => counter_format.id = true,
|
||||
|
@ -695,7 +695,7 @@ pub(crate) fn dump_coverage_graphviz(
|
|||
let from_bcb_data = &basic_coverage_blocks[from_bcb];
|
||||
let from_terminator = from_bcb_data.terminator(mir_body);
|
||||
let mut edge_labels = from_terminator.kind.fmt_successor_labels();
|
||||
edge_labels.retain(|label| label.to_string() != "unreachable");
|
||||
edge_labels.retain(|label| label != "unreachable");
|
||||
let edge_counters = from_terminator
|
||||
.successors()
|
||||
.map(|&successor_bb| graphviz_data.get_edge_counter(from_bcb, successor_bb));
|
||||
|
|
|
@ -425,7 +425,7 @@ impl Inliner<'tcx> {
|
|||
}
|
||||
|
||||
let dest = if dest_needs_borrow(destination.0) {
|
||||
debug!("creating temp for return destination");
|
||||
trace!("creating temp for return destination");
|
||||
let dest = Rvalue::Ref(
|
||||
self.tcx.lifetimes.re_erased,
|
||||
BorrowKind::Mut { allow_two_phase_borrow: false },
|
||||
|
@ -633,7 +633,7 @@ impl Inliner<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
debug!("creating temp for argument {:?}", arg);
|
||||
trace!("creating temp for argument {:?}", arg);
|
||||
// Otherwise, create a temporary for the arg
|
||||
let arg = Rvalue::Use(arg);
|
||||
|
||||
|
@ -703,19 +703,19 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {
|
|||
Local::new(self.new_locals.start.index() + (idx - self.args.len()))
|
||||
}
|
||||
};
|
||||
debug!("mapping local `{:?}` to `{:?}`", local, new);
|
||||
trace!("mapping local `{:?}` to `{:?}`", local, new);
|
||||
new
|
||||
}
|
||||
|
||||
fn map_scope(&self, scope: SourceScope) -> SourceScope {
|
||||
let new = SourceScope::new(self.new_scopes.start.index() + scope.index());
|
||||
debug!("mapping scope `{:?}` to `{:?}`", scope, new);
|
||||
trace!("mapping scope `{:?}` to `{:?}`", scope, new);
|
||||
new
|
||||
}
|
||||
|
||||
fn map_block(&self, block: BasicBlock) -> BasicBlock {
|
||||
let new = BasicBlock::new(self.new_blocks.start.index() + block.index());
|
||||
debug!("mapping block `{:?}` to `{:?}`", block, new);
|
||||
trace!("mapping block `{:?}` to `{:?}`", block, new);
|
||||
new
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ impl<
|
|||
where
|
||||
W: Write,
|
||||
{
|
||||
let lines = label.split("\n").map(|s| dot::escape_html(s)).collect::<Vec<_>>();
|
||||
let lines = label.split('\n').map(|s| dot::escape_html(s)).collect::<Vec<_>>();
|
||||
let escaped_label = lines.join(r#"<br align="left"/>"#);
|
||||
writeln!(w, r#" label=<<br/><br/>{}<br align="left"/><br/><br/><br/>>;"#, escaped_label)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue