1
Fork 0

Auto merge of #96293 - Dylan-DPC:rollup-saipx8c, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #95434 (Only output DepKind in dump-dep-graph.)
 - #96248 (Stop using a string literal as a format argument)
 - #96251 (Update books)
 - #96269 (errors: minor translation-related changes)
 - #96289 (Remove redundant `format!`s)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2022-04-21 21:20:14 +00:00
commit 10baaa6ed2
11 changed files with 57 additions and 44 deletions

View file

@ -1484,7 +1484,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_suggestion_hidden( err.span_suggestion_hidden(
return_span, return_span,
"use `.collect()` to allocate the iterator", "use `.collect()` to allocate the iterator",
format!("{}{}", snippet, ".collect::<Vec<_>>()"), format!("{snippet}.collect::<Vec<_>>()"),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }

View file

@ -241,7 +241,7 @@ fn dump_graph(query: &DepGraphQuery) {
let targets = node_set(&query, &edge_filter.target); let targets = node_set(&query, &edge_filter.target);
filter_nodes(&query, &sources, &targets) filter_nodes(&query, &sources, &targets)
} }
Err(_) => query.nodes().into_iter().collect(), Err(_) => query.nodes().into_iter().map(|n| n.kind).collect(),
}; };
let edges = filter_edges(&query, &nodes); let edges = filter_edges(&query, &nodes);
@ -264,33 +264,33 @@ fn dump_graph(query: &DepGraphQuery) {
} }
#[allow(missing_docs)] #[allow(missing_docs)]
pub struct GraphvizDepGraph<'q>(FxHashSet<&'q DepNode>, Vec<(&'q DepNode, &'q DepNode)>); pub struct GraphvizDepGraph(FxHashSet<DepKind>, Vec<(DepKind, DepKind)>);
impl<'a, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> { impl<'a> dot::GraphWalk<'a> for GraphvizDepGraph {
type Node = &'q DepNode; type Node = DepKind;
type Edge = (&'q DepNode, &'q DepNode); type Edge = (DepKind, DepKind);
fn nodes(&self) -> dot::Nodes<'_, &'q DepNode> { fn nodes(&self) -> dot::Nodes<'_, DepKind> {
let nodes: Vec<_> = self.0.iter().cloned().collect(); let nodes: Vec<_> = self.0.iter().cloned().collect();
nodes.into() nodes.into()
} }
fn edges(&self) -> dot::Edges<'_, (&'q DepNode, &'q DepNode)> { fn edges(&self) -> dot::Edges<'_, (DepKind, DepKind)> {
self.1[..].into() self.1[..].into()
} }
fn source(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode { fn source(&self, edge: &(DepKind, DepKind)) -> DepKind {
edge.0 edge.0
} }
fn target(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode { fn target(&self, edge: &(DepKind, DepKind)) -> DepKind {
edge.1 edge.1
} }
} }
impl<'a, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> { impl<'a> dot::Labeller<'a> for GraphvizDepGraph {
type Node = &'q DepNode; type Node = DepKind;
type Edge = (&'q DepNode, &'q DepNode); type Edge = (DepKind, DepKind);
fn graph_id(&self) -> dot::Id<'_> { fn graph_id(&self) -> dot::Id<'_> {
dot::Id::new("DependencyGraph").unwrap() dot::Id::new("DependencyGraph").unwrap()
} }
fn node_id(&self, n: &&'q DepNode) -> dot::Id<'_> { fn node_id(&self, n: &DepKind) -> dot::Id<'_> {
let s: String = format!("{:?}", n) let s: String = format!("{:?}", n)
.chars() .chars()
.map(|c| if c == '_' || c.is_alphanumeric() { c } else { '_' }) .map(|c| if c == '_' || c.is_alphanumeric() { c } else { '_' })
@ -298,7 +298,7 @@ impl<'a, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> {
debug!("n={:?} s={:?}", n, s); debug!("n={:?} s={:?}", n, s);
dot::Id::new(s).unwrap() dot::Id::new(s).unwrap()
} }
fn node_label(&self, n: &&'q DepNode) -> dot::LabelText<'_> { fn node_label(&self, n: &DepKind) -> dot::LabelText<'_> {
dot::LabelText::label(format!("{:?}", n)) dot::LabelText::label(format!("{:?}", n))
} }
} }
@ -323,7 +323,7 @@ fn filter_nodes<'q>(
query: &'q DepGraphQuery, query: &'q DepGraphQuery,
sources: &Option<FxHashSet<&'q DepNode>>, sources: &Option<FxHashSet<&'q DepNode>>,
targets: &Option<FxHashSet<&'q DepNode>>, targets: &Option<FxHashSet<&'q DepNode>>,
) -> FxHashSet<&'q DepNode> { ) -> FxHashSet<DepKind> {
if let Some(sources) = sources { if let Some(sources) = sources {
if let Some(targets) = targets { if let Some(targets) = targets {
walk_between(query, sources, targets) walk_between(query, sources, targets)
@ -333,7 +333,7 @@ fn filter_nodes<'q>(
} else if let Some(targets) = targets { } else if let Some(targets) = targets {
walk_nodes(query, targets, INCOMING) walk_nodes(query, targets, INCOMING)
} else { } else {
query.nodes().into_iter().collect() query.nodes().into_iter().map(|n| n.kind).collect()
} }
} }
@ -341,17 +341,17 @@ fn walk_nodes<'q>(
query: &'q DepGraphQuery, query: &'q DepGraphQuery,
starts: &FxHashSet<&'q DepNode>, starts: &FxHashSet<&'q DepNode>,
direction: Direction, direction: Direction,
) -> FxHashSet<&'q DepNode> { ) -> FxHashSet<DepKind> {
let mut set = FxHashSet::default(); let mut set = FxHashSet::default();
for &start in starts { for &start in starts {
debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING); debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING);
if set.insert(start) { if set.insert(start.kind) {
let mut stack = vec![query.indices[start]]; let mut stack = vec![query.indices[start]];
while let Some(index) = stack.pop() { while let Some(index) = stack.pop() {
for (_, edge) in query.graph.adjacent_edges(index, direction) { for (_, edge) in query.graph.adjacent_edges(index, direction) {
let neighbor_index = edge.source_or_target(direction); let neighbor_index = edge.source_or_target(direction);
let neighbor = query.graph.node_data(neighbor_index); let neighbor = query.graph.node_data(neighbor_index);
if set.insert(neighbor) { if set.insert(neighbor.kind) {
stack.push(neighbor_index); stack.push(neighbor_index);
} }
} }
@ -365,7 +365,7 @@ fn walk_between<'q>(
query: &'q DepGraphQuery, query: &'q DepGraphQuery,
sources: &FxHashSet<&'q DepNode>, sources: &FxHashSet<&'q DepNode>,
targets: &FxHashSet<&'q DepNode>, targets: &FxHashSet<&'q DepNode>,
) -> FxHashSet<&'q DepNode> { ) -> FxHashSet<DepKind> {
// This is a bit tricky. We want to include a node only if it is: // This is a bit tricky. We want to include a node only if it is:
// (a) reachable from a source and (b) will reach a target. And we // (a) reachable from a source and (b) will reach a target. And we
// have to be careful about cycles etc. Luckily efficiency is not // have to be careful about cycles etc. Luckily efficiency is not
@ -396,6 +396,7 @@ fn walk_between<'q>(
let index = query.indices[n]; let index = query.indices[n];
node_states[index.0] == State::Included node_states[index.0] == State::Included
}) })
.map(|n| n.kind)
.collect(); .collect();
fn recurse(query: &DepGraphQuery, node_states: &mut [State], node: NodeIndex) -> bool { fn recurse(query: &DepGraphQuery, node_states: &mut [State], node: NodeIndex) -> bool {
@ -433,11 +434,13 @@ fn walk_between<'q>(
fn filter_edges<'q>( fn filter_edges<'q>(
query: &'q DepGraphQuery, query: &'q DepGraphQuery,
nodes: &FxHashSet<&'q DepNode>, nodes: &FxHashSet<DepKind>,
) -> Vec<(&'q DepNode, &'q DepNode)> { ) -> Vec<(DepKind, DepKind)> {
query let uniq: FxHashSet<_> = query
.edges() .edges()
.into_iter() .into_iter()
.filter(|&(source, target)| nodes.contains(source) && nodes.contains(target)) .map(|(s, t)| (s.kind, t.kind))
.collect() .filter(|(source, target)| nodes.contains(source) && nodes.contains(target))
.collect();
uniq.into_iter().collect()
} }

View file

@ -16,20 +16,27 @@ use std::collections::{BTreeSet, HashMap};
/// # extern crate rust_middle; /// # extern crate rust_middle;
/// # use rustc_middle::ty::Ty; /// # use rustc_middle::ty::Ty;
/// #[derive(SessionDiagnostic)] /// #[derive(SessionDiagnostic)]
/// #[error(code = "E0505", slug = "move-out-of-borrow-error")] /// #[error(code = "E0505", slug = "borrowck-move-out-of-borrow")]
/// pub struct MoveOutOfBorrowError<'tcx> { /// pub struct MoveOutOfBorrowError<'tcx> {
/// pub name: Ident, /// pub name: Ident,
/// pub ty: Ty<'tcx>, /// pub ty: Ty<'tcx>,
/// #[primary_span] /// #[primary_span]
/// #[label = "cannot move out of borrow"] /// #[label]
/// pub span: Span, /// pub span: Span,
/// #[label = "`{ty}` first borrowed here"] /// #[label = "first-borrow-label"]
/// pub other_span: Span, /// pub first_borrow_span: Span,
/// #[suggestion(message = "consider cloning here", code = "{name}.clone()")] /// #[suggestion(code = "{name}.clone()")]
/// pub opt_sugg: Option<(Span, Applicability)> /// pub clone_sugg: Option<(Span, Applicability)>
/// } /// }
/// ``` /// ```
/// ///
/// ```fluent
/// move-out-of-borrow = cannot move out of {$name} because it is borrowed
/// .label = cannot move out of borrow
/// .first-borrow-label = `{$ty}` first borrowed here
/// .suggestion = consider cloning here
/// ```
///
/// Then, later, to emit the error: /// Then, later, to emit the error:
/// ///
/// ```ignore (pseudo-rust) /// ```ignore (pseudo-rust)
@ -37,10 +44,13 @@ use std::collections::{BTreeSet, HashMap};
/// expected, /// expected,
/// actual, /// actual,
/// span, /// span,
/// other_span, /// first_borrow_span,
/// opt_sugg: Some(suggestion, Applicability::MachineApplicable), /// clone_sugg: Some(suggestion, Applicability::MachineApplicable),
/// }); /// });
/// ``` /// ```
///
/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`:
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html>
pub fn session_diagnostic_derive(s: synstructure::Structure<'_>) -> proc_macro2::TokenStream { pub fn session_diagnostic_derive(s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
// Names for the diagnostic we build and the session we build it from. // Names for the diagnostic we build and the session we build it from.
let diag = format_ident!("diag"); let diag = format_ident!("diag");

View file

@ -1014,7 +1014,7 @@ impl<'a> Resolver<'a> {
} }
ResolutionError::InvalidAsmSym => { ResolutionError::InvalidAsmSym => {
let mut err = self.session.struct_span_err(span, "invalid `sym` operand"); let mut err = self.session.struct_span_err(span, "invalid `sym` operand");
err.span_label(span, &format!("is a local variable")); err.span_label(span, "is a local variable");
err.help("`sym` operands must refer to either a function or a static"); err.help("`sym` operands must refer to either a function or a static");
err err
} }

View file

@ -1696,7 +1696,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
"invalid lifetime parameter name: `{}`", "invalid lifetime parameter name: `{}`",
param.ident, param.ident,
) )
.span_label(param.ident.span, format!("'static is a reserved lifetime name")) .span_label(param.ident.span, "'static is a reserved lifetime name")
.emit(); .emit();
continue; continue;
} }

View file

@ -968,9 +968,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
SuggestionText::Remove(plural) => { SuggestionText::Remove(plural) => {
Some(format!("remove the extra argument{}", if plural { "s" } else { "" })) Some(format!("remove the extra argument{}", if plural { "s" } else { "" }))
} }
SuggestionText::Swap => Some(format!("swap these arguments")), SuggestionText::Swap => Some("swap these arguments".to_string()),
SuggestionText::Reorder => Some(format!("reorder these arguments")), SuggestionText::Reorder => Some("reorder these arguments".to_string()),
SuggestionText::DidYouMean => Some(format!("did you mean")), SuggestionText::DidYouMean => Some("did you mean".to_string()),
}; };
if let Some(suggestion_text) = suggestion_text { if let Some(suggestion_text) = suggestion_text {
let source_map = self.sess().source_map(); let source_map = self.sess().source_map();

View file

@ -134,7 +134,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> {
#[primary_span] #[primary_span]
#[label] #[label]
pub span: Span, pub span: Span,
#[suggestion_verbose(message = "suggestion", code = "{ty}")] #[suggestion_verbose(code = "{ty}")]
pub opt_sugg: Option<(Span, Applicability)>, pub opt_sugg: Option<(Span, Applicability)>,
} }

@ -1 +1 @@
Subproject commit 765318b844569a642ceef7bf1adab9639cbf6af3 Subproject commit de0dbffc5812fd885700874e8d258dd334733ac4

@ -1 +1 @@
Subproject commit a6de8b6e3ea5d4f0de8b7b9a7e5c1405dc2c2ddb Subproject commit f7cefbb995eec8c6148f213235e9e2e03268e775

@ -1 +1 @@
Subproject commit c2a98d9fc5d29c481d42052fbeccfde15ed03116 Subproject commit 44a80e8d8bfc5881c9bd69a2cb3a570776ee4181

@ -1 +1 @@
Subproject commit eeb5a83c15b6ae60df3e4f19207376b22c6fbc4c Subproject commit 043e60f4f191651e9f8bf52fa32df14defbb23d9