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
|
@ -313,25 +313,24 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
|
|||
// Implement the proposal described in
|
||||
// https://github.com/rust-lang/rust/issues/61733#issuecomment-509626449
|
||||
//
|
||||
// The macro invocation expands to the list of statements.
|
||||
// If the list of statements is empty, then 'parse'
|
||||
// the trailing semicolon on the original invocation
|
||||
// as an empty statement. That is:
|
||||
// The macro invocation expands to the list of statements. If the
|
||||
// list of statements is empty, then 'parse' the trailing semicolon
|
||||
// on the original invocation as an empty statement. That is:
|
||||
//
|
||||
// `empty();` is parsed as a single `StmtKind::Empty`
|
||||
//
|
||||
// If the list of statements is non-empty, see if the
|
||||
// final statement alreayd has a trailing semicolon.
|
||||
// If the list of statements is non-empty, see if the final
|
||||
// statement already has a trailing semicolon.
|
||||
//
|
||||
// If it doesn't have a semicolon, then 'parse' the trailing semicolon
|
||||
// from the invocation as part of the final statement,
|
||||
// If it doesn't have a semicolon, then 'parse' the trailing
|
||||
// semicolon from the invocation as part of the final statement,
|
||||
// using `stmt.add_trailing_semicolon()`
|
||||
//
|
||||
// If it does have a semicolon, then 'parse' the trailing semicolon
|
||||
// from the invocation as a new StmtKind::Empty
|
||||
|
||||
// FIXME: We will need to preserve the original
|
||||
// semicolon token and span as part of #15701
|
||||
// FIXME: We will need to preserve the original semicolon token and
|
||||
// span as part of #15701
|
||||
let empty_stmt = ast::Stmt {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::StmtKind::Empty,
|
||||
|
|
|
@ -16,9 +16,8 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::
|
|||
})
|
||||
});
|
||||
|
||||
let body_visit = s.fold(quote!(), |acc, bind| {
|
||||
let body_visit = s.each(|bind| {
|
||||
quote! {
|
||||
#acc
|
||||
::rustc_middle::ty::fold::TypeFoldable::visit_with(#bind, __folder)?;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -1021,17 +1021,11 @@ impl<'a> Resolver<'a> {
|
|||
("", "")
|
||||
};
|
||||
|
||||
let article = if built_in.is_empty() { res.article() } else { "a" };
|
||||
format!(
|
||||
"{a}{built_in} {thing}{from}",
|
||||
a = article,
|
||||
thing = res.descr(),
|
||||
built_in = built_in,
|
||||
from = from
|
||||
)
|
||||
let a = if built_in.is_empty() { res.article() } else { "a" };
|
||||
format!("{a}{built_in} {thing}{from}", thing = res.descr())
|
||||
} else {
|
||||
let introduced = if b.is_import() { "imported" } else { "defined" };
|
||||
format!("the {thing} {introduced} here", thing = res.descr(), introduced = introduced)
|
||||
format!("the {thing} {introduced} here", thing = res.descr())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1049,19 +1043,13 @@ impl<'a> Resolver<'a> {
|
|||
ident.span,
|
||||
E0659,
|
||||
"`{ident}` is ambiguous ({why})",
|
||||
ident = ident,
|
||||
why = kind.descr()
|
||||
);
|
||||
err.span_label(ident.span, "ambiguous name");
|
||||
|
||||
let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
|
||||
let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
|
||||
let note_msg = format!(
|
||||
"`{ident}` could{also} refer to {what}",
|
||||
ident = ident,
|
||||
also = also,
|
||||
what = what
|
||||
);
|
||||
let note_msg = format!("`{ident}` could{also} refer to {what}");
|
||||
|
||||
let thing = b.res().descr();
|
||||
let mut help_msgs = Vec::new();
|
||||
|
@ -1071,30 +1059,18 @@ impl<'a> Resolver<'a> {
|
|||
|| kind == AmbiguityKind::GlobVsOuter && swapped != also.is_empty())
|
||||
{
|
||||
help_msgs.push(format!(
|
||||
"consider adding an explicit import of \
|
||||
`{ident}` to disambiguate",
|
||||
ident = ident
|
||||
"consider adding an explicit import of `{ident}` to disambiguate"
|
||||
))
|
||||
}
|
||||
if b.is_extern_crate() && ident.span.rust_2018() {
|
||||
help_msgs.push(format!(
|
||||
"use `::{ident}` to refer to this {thing} unambiguously",
|
||||
ident = ident,
|
||||
thing = thing,
|
||||
))
|
||||
help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
|
||||
}
|
||||
if misc == AmbiguityErrorMisc::SuggestCrate {
|
||||
help_msgs.push(format!(
|
||||
"use `crate::{ident}` to refer to this {thing} unambiguously",
|
||||
ident = ident,
|
||||
thing = thing,
|
||||
))
|
||||
help_msgs
|
||||
.push(format!("use `crate::{ident}` to refer to this {thing} unambiguously"))
|
||||
} else if misc == AmbiguityErrorMisc::SuggestSelf {
|
||||
help_msgs.push(format!(
|
||||
"use `self::{ident}` to refer to this {thing} unambiguously",
|
||||
ident = ident,
|
||||
thing = thing,
|
||||
))
|
||||
help_msgs
|
||||
.push(format!("use `self::{ident}` to refer to this {thing} unambiguously"))
|
||||
}
|
||||
|
||||
err.span_note(b.span, ¬e_msg);
|
||||
|
@ -1167,12 +1143,10 @@ impl<'a> Resolver<'a> {
|
|||
};
|
||||
|
||||
let first = ptr::eq(binding, first_binding);
|
||||
let descr = get_descr(binding);
|
||||
let msg = format!(
|
||||
"{and_refers_to}the {item} `{name}`{which} is defined here{dots}",
|
||||
and_refers_to = if first { "" } else { "...and refers to " },
|
||||
item = descr,
|
||||
name = name,
|
||||
item = get_descr(binding),
|
||||
which = if first { "" } else { " which" },
|
||||
dots = if next_binding.is_some() { "..." } else { "" },
|
||||
);
|
||||
|
|
|
@ -865,7 +865,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
err.span_suggestion(
|
||||
span,
|
||||
&format!("use struct {} syntax instead", descr),
|
||||
format!("{} {{{pad}{}{pad}}}", path_str, fields, pad = pad),
|
||||
format!("{path_str} {{{pad}{fields}{pad}}}"),
|
||||
applicability,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(format_args_capture)]
|
||||
#![feature(nll)]
|
||||
#![feature(or_patterns)]
|
||||
#![recursion_limit = "256"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue