Skip to content

Commit 10baaa6

Browse files
committed
Auto merge of rust-lang#96293 - Dylan-DPC:rollup-saipx8c, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#95434 (Only output DepKind in dump-dep-graph.) - rust-lang#96248 (Stop using a string literal as a format argument) - rust-lang#96251 (Update books) - rust-lang#96269 (errors: minor translation-related changes) - rust-lang#96289 (Remove redundant `format!`s) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents de1bc00 + 5ebb8b0 commit 10baaa6

File tree

11 files changed

+57
-44
lines changed

11 files changed

+57
-44
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14841484
err.span_suggestion_hidden(
14851485
return_span,
14861486
"use `.collect()` to allocate the iterator",
1487-
format!("{}{}", snippet, ".collect::<Vec<_>>()"),
1487+
format!("{snippet}.collect::<Vec<_>>()"),
14881488
Applicability::MaybeIncorrect,
14891489
);
14901490
}

compiler/rustc_incremental/src/assert_dep_graph.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn dump_graph(query: &DepGraphQuery) {
241241
let targets = node_set(&query, &edge_filter.target);
242242
filter_nodes(&query, &sources, &targets)
243243
}
244-
Err(_) => query.nodes().into_iter().collect(),
244+
Err(_) => query.nodes().into_iter().map(|n| n.kind).collect(),
245245
};
246246
let edges = filter_edges(&query, &nodes);
247247

@@ -264,41 +264,41 @@ fn dump_graph(query: &DepGraphQuery) {
264264
}
265265

266266
#[allow(missing_docs)]
267-
pub struct GraphvizDepGraph<'q>(FxHashSet<&'q DepNode>, Vec<(&'q DepNode, &'q DepNode)>);
267+
pub struct GraphvizDepGraph(FxHashSet<DepKind>, Vec<(DepKind, DepKind)>);
268268

269-
impl<'a, 'q> dot::GraphWalk<'a> for GraphvizDepGraph<'q> {
270-
type Node = &'q DepNode;
271-
type Edge = (&'q DepNode, &'q DepNode);
272-
fn nodes(&self) -> dot::Nodes<'_, &'q DepNode> {
269+
impl<'a> dot::GraphWalk<'a> for GraphvizDepGraph {
270+
type Node = DepKind;
271+
type Edge = (DepKind, DepKind);
272+
fn nodes(&self) -> dot::Nodes<'_, DepKind> {
273273
let nodes: Vec<_> = self.0.iter().cloned().collect();
274274
nodes.into()
275275
}
276-
fn edges(&self) -> dot::Edges<'_, (&'q DepNode, &'q DepNode)> {
276+
fn edges(&self) -> dot::Edges<'_, (DepKind, DepKind)> {
277277
self.1[..].into()
278278
}
279-
fn source(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode {
279+
fn source(&self, edge: &(DepKind, DepKind)) -> DepKind {
280280
edge.0
281281
}
282-
fn target(&self, edge: &(&'q DepNode, &'q DepNode)) -> &'q DepNode {
282+
fn target(&self, edge: &(DepKind, DepKind)) -> DepKind {
283283
edge.1
284284
}
285285
}
286286

287-
impl<'a, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> {
288-
type Node = &'q DepNode;
289-
type Edge = (&'q DepNode, &'q DepNode);
287+
impl<'a> dot::Labeller<'a> for GraphvizDepGraph {
288+
type Node = DepKind;
289+
type Edge = (DepKind, DepKind);
290290
fn graph_id(&self) -> dot::Id<'_> {
291291
dot::Id::new("DependencyGraph").unwrap()
292292
}
293-
fn node_id(&self, n: &&'q DepNode) -> dot::Id<'_> {
293+
fn node_id(&self, n: &DepKind) -> dot::Id<'_> {
294294
let s: String = format!("{:?}", n)
295295
.chars()
296296
.map(|c| if c == '_' || c.is_alphanumeric() { c } else { '_' })
297297
.collect();
298298
debug!("n={:?} s={:?}", n, s);
299299
dot::Id::new(s).unwrap()
300300
}
301-
fn node_label(&self, n: &&'q DepNode) -> dot::LabelText<'_> {
301+
fn node_label(&self, n: &DepKind) -> dot::LabelText<'_> {
302302
dot::LabelText::label(format!("{:?}", n))
303303
}
304304
}
@@ -323,7 +323,7 @@ fn filter_nodes<'q>(
323323
query: &'q DepGraphQuery,
324324
sources: &Option<FxHashSet<&'q DepNode>>,
325325
targets: &Option<FxHashSet<&'q DepNode>>,
326-
) -> FxHashSet<&'q DepNode> {
326+
) -> FxHashSet<DepKind> {
327327
if let Some(sources) = sources {
328328
if let Some(targets) = targets {
329329
walk_between(query, sources, targets)
@@ -333,25 +333,25 @@ fn filter_nodes<'q>(
333333
} else if let Some(targets) = targets {
334334
walk_nodes(query, targets, INCOMING)
335335
} else {
336-
query.nodes().into_iter().collect()
336+
query.nodes().into_iter().map(|n| n.kind).collect()
337337
}
338338
}
339339

340340
fn walk_nodes<'q>(
341341
query: &'q DepGraphQuery,
342342
starts: &FxHashSet<&'q DepNode>,
343343
direction: Direction,
344-
) -> FxHashSet<&'q DepNode> {
344+
) -> FxHashSet<DepKind> {
345345
let mut set = FxHashSet::default();
346346
for &start in starts {
347347
debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING);
348-
if set.insert(start) {
348+
if set.insert(start.kind) {
349349
let mut stack = vec![query.indices[start]];
350350
while let Some(index) = stack.pop() {
351351
for (_, edge) in query.graph.adjacent_edges(index, direction) {
352352
let neighbor_index = edge.source_or_target(direction);
353353
let neighbor = query.graph.node_data(neighbor_index);
354-
if set.insert(neighbor) {
354+
if set.insert(neighbor.kind) {
355355
stack.push(neighbor_index);
356356
}
357357
}
@@ -365,7 +365,7 @@ fn walk_between<'q>(
365365
query: &'q DepGraphQuery,
366366
sources: &FxHashSet<&'q DepNode>,
367367
targets: &FxHashSet<&'q DepNode>,
368-
) -> FxHashSet<&'q DepNode> {
368+
) -> FxHashSet<DepKind> {
369369
// This is a bit tricky. We want to include a node only if it is:
370370
// (a) reachable from a source and (b) will reach a target. And we
371371
// have to be careful about cycles etc. Luckily efficiency is not
@@ -396,6 +396,7 @@ fn walk_between<'q>(
396396
let index = query.indices[n];
397397
node_states[index.0] == State::Included
398398
})
399+
.map(|n| n.kind)
399400
.collect();
400401

401402
fn recurse(query: &DepGraphQuery, node_states: &mut [State], node: NodeIndex) -> bool {
@@ -433,11 +434,13 @@ fn walk_between<'q>(
433434

434435
fn filter_edges<'q>(
435436
query: &'q DepGraphQuery,
436-
nodes: &FxHashSet<&'q DepNode>,
437-
) -> Vec<(&'q DepNode, &'q DepNode)> {
438-
query
437+
nodes: &FxHashSet<DepKind>,
438+
) -> Vec<(DepKind, DepKind)> {
439+
let uniq: FxHashSet<_> = query
439440
.edges()
440441
.into_iter()
441-
.filter(|&(source, target)| nodes.contains(source) && nodes.contains(target))
442-
.collect()
442+
.map(|(s, t)| (s.kind, t.kind))
443+
.filter(|(source, target)| nodes.contains(source) && nodes.contains(target))
444+
.collect();
445+
uniq.into_iter().collect()
443446
}

compiler/rustc_macros/src/session_diagnostic.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,41 @@ use std::collections::{BTreeSet, HashMap};
1616
/// # extern crate rust_middle;
1717
/// # use rustc_middle::ty::Ty;
1818
/// #[derive(SessionDiagnostic)]
19-
/// #[error(code = "E0505", slug = "move-out-of-borrow-error")]
19+
/// #[error(code = "E0505", slug = "borrowck-move-out-of-borrow")]
2020
/// pub struct MoveOutOfBorrowError<'tcx> {
2121
/// pub name: Ident,
2222
/// pub ty: Ty<'tcx>,
2323
/// #[primary_span]
24-
/// #[label = "cannot move out of borrow"]
24+
/// #[label]
2525
/// pub span: Span,
26-
/// #[label = "`{ty}` first borrowed here"]
27-
/// pub other_span: Span,
28-
/// #[suggestion(message = "consider cloning here", code = "{name}.clone()")]
29-
/// pub opt_sugg: Option<(Span, Applicability)>
26+
/// #[label = "first-borrow-label"]
27+
/// pub first_borrow_span: Span,
28+
/// #[suggestion(code = "{name}.clone()")]
29+
/// pub clone_sugg: Option<(Span, Applicability)>
3030
/// }
3131
/// ```
3232
///
33+
/// ```fluent
34+
/// move-out-of-borrow = cannot move out of {$name} because it is borrowed
35+
/// .label = cannot move out of borrow
36+
/// .first-borrow-label = `{$ty}` first borrowed here
37+
/// .suggestion = consider cloning here
38+
/// ```
39+
///
3340
/// Then, later, to emit the error:
3441
///
3542
/// ```ignore (pseudo-rust)
3643
/// sess.emit_err(MoveOutOfBorrowError {
3744
/// expected,
3845
/// actual,
3946
/// span,
40-
/// other_span,
41-
/// opt_sugg: Some(suggestion, Applicability::MachineApplicable),
47+
/// first_borrow_span,
48+
/// clone_sugg: Some(suggestion, Applicability::MachineApplicable),
4249
/// });
4350
/// ```
51+
///
52+
/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`:
53+
/// <https://rustc-dev-guide.rust-lang.org/diagnostics/sessiondiagnostic.html>
4454
pub fn session_diagnostic_derive(s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4555
// Names for the diagnostic we build and the session we build it from.
4656
let diag = format_ident!("diag");

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ impl<'a> Resolver<'a> {
10141014
}
10151015
ResolutionError::InvalidAsmSym => {
10161016
let mut err = self.session.struct_span_err(span, "invalid `sym` operand");
1017-
err.span_label(span, &format!("is a local variable"));
1017+
err.span_label(span, "is a local variable");
10181018
err.help("`sym` operands must refer to either a function or a static");
10191019
err
10201020
}

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16961696
"invalid lifetime parameter name: `{}`",
16971697
param.ident,
16981698
)
1699-
.span_label(param.ident.span, format!("'static is a reserved lifetime name"))
1699+
.span_label(param.ident.span, "'static is a reserved lifetime name")
17001700
.emit();
17011701
continue;
17021702
}

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
968968
SuggestionText::Remove(plural) => {
969969
Some(format!("remove the extra argument{}", if plural { "s" } else { "" }))
970970
}
971-
SuggestionText::Swap => Some(format!("swap these arguments")),
972-
SuggestionText::Reorder => Some(format!("reorder these arguments")),
973-
SuggestionText::DidYouMean => Some(format!("did you mean")),
971+
SuggestionText::Swap => Some("swap these arguments".to_string()),
972+
SuggestionText::Reorder => Some("reorder these arguments".to_string()),
973+
SuggestionText::DidYouMean => Some("did you mean".to_string()),
974974
};
975975
if let Some(suggestion_text) = suggestion_text {
976976
let source_map = self.sess().source_map();

compiler/rustc_typeck/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> {
134134
#[primary_span]
135135
#[label]
136136
pub span: Span,
137-
#[suggestion_verbose(message = "suggestion", code = "{ty}")]
137+
#[suggestion_verbose(code = "{ty}")]
138138
pub opt_sugg: Option<(Span, Applicability)>,
139139
}
140140

src/doc/rust-by-example

0 commit comments

Comments
 (0)