Skip to content

Commit

Permalink
Add an additional empty line between the suggested use and the next…
Browse files Browse the repository at this point in the history
… item
  • Loading branch information
oli-obk committed Aug 18, 2017
1 parent e0ba29c commit 8f56322
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ impl CodeSuggestion {
if !buf.ends_with('\n') {
push_trailing(buf, prev_line.as_ref(), &prev_hi, None);
}
// remove trailing newline
buf.pop();
// remove trailing newlines
while buf.ends_with('\n') {
buf.pop();
}
}
bufs
}
Expand Down
17 changes: 14 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
struct UsePlacementFinder {
target_module: NodeId,
span: Option<Span>,
found_use: bool,
}

impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
Expand Down Expand Up @@ -611,6 +612,7 @@ impl<'tcx> Visitor<'tcx> for UsePlacementFinder {
let mut span = item.span;
span.hi = span.lo;
self.span = Some(span);
self.found_use = true;
return;
}
},
Expand Down Expand Up @@ -3576,11 +3578,12 @@ impl<'a> Resolver<'a> {
let mut finder = UsePlacementFinder {
target_module: node_id,
span: None,
found_use: false,
};
visit::walk_crate(&mut finder, krate);
if !candidates.is_empty() {
let span = finder.span.expect("did not find module");
show_candidates(&mut err, span, &candidates, better);
show_candidates(&mut err, span, &candidates, better, finder.found_use);
}
err.emit();
}
Expand Down Expand Up @@ -3776,7 +3779,8 @@ fn import_candidate_to_paths(suggestion: &ImportSuggestion) -> (Span, String, St
fn show_candidates(err: &mut DiagnosticBuilder,
span: Span,
candidates: &[ImportSuggestion],
better: bool) {
better: bool,
found_use: bool) {

// we want consistent results across executions, but candidates are produced
// by iterating through a hash map, so make sure they are ordered:
Expand All @@ -3792,7 +3796,14 @@ fn show_candidates(err: &mut DiagnosticBuilder,
let msg = format!("possible {}candidate{} into scope", better, msg_diff);

for candidate in &mut path_strings {
*candidate = format!("use {};\n", candidate);
// produce an additional newline to separate the new use statement
// from the directly following item.
let additional_newline = if found_use {
""
} else {
"\n"
};
*candidate = format!("use {};\n{}", candidate, additional_newline);
}

err.span_suggestions(span, &msg, path_strings);
Expand Down

0 comments on commit 8f56322

Please sign in to comment.