Skip to content

Commit

Permalink
Rollup merge of rust-lang#66754 - estebank:rustdoc-capitalization, r=…
Browse files Browse the repository at this point in the history
…Dylan-DPC

Various tweaks to diagnostic output
  • Loading branch information
tmandry authored Nov 26, 2019
2 parents 0b3d4a1 + 5ea922a commit bb6236c
Show file tree
Hide file tree
Showing 35 changed files with 115 additions and 300 deletions.
15 changes: 5 additions & 10 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&self,
err: &mut DiagnosticBuilder<'_>,
terr: &TypeError<'tcx>,
sp: Span,
) {
use hir::def_id::CrateNum;
use hir::map::DisambiguatedDefPathData;
Expand Down Expand Up @@ -577,14 +576,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
if same_path().unwrap_or(false) {
let crate_name = self.tcx.crate_name(did1.krate);
err.span_note(
sp,
&format!(
"Perhaps two different versions \
of crate `{}` are being used?",
crate_name
),
);
err.note(&format!(
"perhaps two different versions of crate `{}` are being used?",
crate_name
));
}
}
};
Expand Down Expand Up @@ -1434,7 +1429,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.unwrap_or_else(|| {
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
});
self.check_and_note_conflicting_crates(diag, terr, span);
self.check_and_note_conflicting_crates(diag, terr);
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);

// It reads better to have the error origin as the final
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ impl<'a> CrateLoader<'a> {
let has_global_allocator = match &*global_allocator_spans(krate) {
[span1, span2, ..] => {
self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
.span_note(*span1, "the previous global allocator is defined here").emit();
.span_label(*span2, "cannot define a new global allocator")
.span_label(*span1, "previous global allocator is defined here")
.emit();
true
}
spans => !spans.is_empty()
Expand Down
18 changes: 6 additions & 12 deletions src/librustc_mir/borrow_check/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,23 +1264,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MachineApplicable,
);

match category {
ConstraintCategory::Return => {
err.span_note(constraint_span, "closure is returned here");
}
ConstraintCategory::OpaqueType => {
err.span_note(constraint_span, "generator is returned here");
}
let msg = match category {
ConstraintCategory::Return => "closure is returned here".to_string(),
ConstraintCategory::OpaqueType => "generator is returned here".to_string(),
ConstraintCategory::CallArgument => {
fr_name.highlight_region_name(&mut err);
err.span_note(
constraint_span,
&format!("function requires argument type to outlive `{}`", fr_name),
);
format!("function requires argument type to outlive `{}`", fr_name)
}
_ => bug!("report_escaping_closure_capture called with unexpected constraint \
category: `{:?}`", category),
}
};
err.span_note(constraint_span, &msg);
err
}

Expand Down
9 changes: 2 additions & 7 deletions src/librustc_mir/borrow_check/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'a>,
binds_to: &[Local],
) {
let mut noncopy_var_spans = Vec::new();
for (j, local) in binds_to.into_iter().enumerate() {
let bind_to = &self.body.local_decls[*local];
let binding_span = bind_to.source_info.span;
Expand All @@ -576,16 +575,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
bind_to.ty,
Some(binding_span)
);
} else {
noncopy_var_spans.push(binding_span);
}
}

if binds_to.len() > 1 {
err.span_note(
noncopy_var_spans,
"move occurs because these variables have types that \
don't implement the `Copy` trait",
err.note("move occurs because these variables have types that \
don't implement the `Copy` trait",
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,12 @@ impl<'a> Parser<'a> {
}

/// Parses a macro invocation inside a `trait`, `impl` or `extern` block.
fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
at_end: &mut bool) -> PResult<'a, Option<Mac>>
{
fn parse_assoc_macro_invoc(
&mut self,
item_kind: &str,
vis: Option<&Visibility>,
at_end: &mut bool,
) -> PResult<'a, Option<Mac>> {
if self.token.is_path_start() &&
!(self.is_async_fn() && self.token.span.rust_2015()) {
let prev_span = self.prev_span;
Expand Down Expand Up @@ -532,9 +535,11 @@ impl<'a> Parser<'a> {
}
}

fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span)
-> DiagnosticBuilder<'a>
{
fn missing_assoc_item_kind_err(
&self,
item_type: &str,
prev_span: Span,
) -> DiagnosticBuilder<'a> {
let expected_kinds = if item_type == "extern" {
"missing `fn`, `type`, or `static`"
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
"`continue` pointing to a labeled block")
.span_label(e.span,
"labeled blocks cannot be `continue`'d")
.span_note(block.span,
"labeled block the continue points to")
.span_label(block.span,
"labeled block the `continue` points to")
.emit();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
.emit();
} else {
let msg = format!("`{}` is private, and cannot be re-exported", ident);
let note_msg =
format!("consider marking `{}` as `pub` in the imported module", ident);
let note_msg = format!(
"consider marking `{}` as `pub` in the imported module",
ident,
);
struct_span_err!(self.r.session, directive.span, E0364, "{}", &msg)
.span_note(directive.span, &note_msg)
.emit();
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub fn look_for_tests<'tcx>(
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
hir_id,
sp,
"Missing code example in this documentation");
"missing code example in this documentation");
diag.emit();
} else if check_missing_code == false &&
tests.found_tests > 0 &&
Expand All @@ -353,7 +353,7 @@ pub fn look_for_tests<'tcx>(
lint::builtin::PRIVATE_DOC_TESTS,
hir_id,
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
"Documentation test in private item");
"documentation test in private item");
diag.emit();
}
}
Expand All @@ -367,7 +367,7 @@ crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> {
if start == DUMMY_SP {
return None;
}
let end = attrs.doc_strings.last().expect("No doc strings provided").span();
let end = attrs.doc_strings.last().expect("no doc strings provided").span();
Some(start.to(end))
}

Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
crate_edition: Edition, allow_features: &Option<Vec<String>>) -> Features {
fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed");
err.span_label(span, "feature has been removed");
if let Some(reason) = reason {
err.span_note(span, reason);
} else {
err.span_label(span, "feature has been removed");
err.note(reason);
}
err.emit();
}
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax_expand/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ fn check_binders(
// for nested macro definitions.
sess.span_diagnostic
.struct_span_err(span, "duplicate matcher binding")
.span_note(prev_info.span, "previous declaration was here")
.span_label(span, "duplicate binding")
.span_label(prev_info.span, "previous binding")
.emit();
*valid = false;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ fn parse_args<'a>(
let e = p.parse_expr()?;
if let Some(prev) = names.get(&name) {
ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name))
.span_note(args[*prev].span, "previously here")
.span_label(args[*prev].span, "previously here")
.span_label(e.span, "duplicate argument")
.emit();
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
};

self.handler.struct_span_err(attr.span, &msg)
.span_note(prev_attr.span, "previous attribute here")
.span_label(prev_attr.span, "previous attribute here")
.emit();

return;
Expand Down
8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/doc-without-codeblock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![deny(missing_doc_code_examples)] //~ ERROR Missing code example in this documentation
#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation

/// Some docs.
//~^ ERROR Missing code example in this documentation
//~^ ERROR missing code example in this documentation
pub struct Foo;

/// And then, the princess died.
//~^ ERROR Missing code example in this documentation
//~^ ERROR missing code example in this documentation
pub mod foo {
/// Or maybe not because she saved herself!
//~^ ERROR Missing code example in this documentation
//~^ ERROR missing code example in this documentation
pub fn bar() {}
}
8 changes: 4 additions & 4 deletions src/test/rustdoc-ui/doc-without-codeblock.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:1:1
|
LL | / #![deny(missing_doc_code_examples)]
Expand All @@ -16,19 +16,19 @@ note: lint level defined here
LL | #![deny(missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:3:1
|
LL | /// Some docs.
| ^^^^^^^^^^^^^^

error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:7:1
|
LL | /// And then, the princess died.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:10:5
|
LL | /// Or maybe not because she saved herself!
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/lint-group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it

/// wait, this doesn't have a doctest?
pub fn no_doctest() {} //~^ ERROR Missing code example in this documentation
pub fn no_doctest() {} //~^ ERROR missing code example in this documentation

/// wait, this *does* have a doctest?
///
/// ```
/// println!("sup");
/// ```
fn private_doctest() {} //~^^^^^ ERROR Documentation test in private item
fn private_doctest() {} //~^^^^^ ERROR documentation test in private item
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/lint-group.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Documentation test in private item
error: documentation test in private item
--> $DIR/lint-group.rs:19:1
|
LL | / /// wait, this *does* have a doctest?
Expand Down Expand Up @@ -29,7 +29,7 @@ LL | #![deny(rustdoc)]
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`

error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/lint-group.rs:16:1
|
LL | /// wait, this doesn't have a doctest?
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/lint-missing-doc-code-example.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/lint-missing-doc-code-example.rs:19:1
|
LL | / mod module1 {
Expand All @@ -11,7 +11,7 @@ note: lint level defined here
LL | #![deny(missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: Missing code example in this documentation
error: missing code example in this documentation
--> $DIR/lint-missing-doc-code-example.rs:37:3
|
LL | /// doc
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/private-item-doc-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ mod foo {
/// ```
/// assert!(false);
/// ```
//~^^^^^ ERROR Documentation test in private item
//~^^^^^ ERROR documentation test in private item
fn bar() {}
}
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/private-item-doc-test.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: Documentation test in private item
error: documentation test in private item
--> $DIR/private-item-doc-test.rs:4:5
|
LL | / /// private doc test
Expand Down
11 changes: 4 additions & 7 deletions src/test/ui/allocator/two-allocators.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
error: cannot define multiple global allocators
--> $DIR/two-allocators.rs:6:1
|
LL | static B: System = System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the previous global allocator is defined here
--> $DIR/two-allocators.rs:4:1
|
LL | static A: System = System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| -------------------------- previous global allocator is defined here
LL | #[global_allocator]
LL | static B: System = System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator

error: aborting due to previous error

18 changes: 2 additions & 16 deletions src/test/ui/borrowck/borrowck-move-error-with-note.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ LL | num2) => (),
LL | Foo::Foo2(num) => (),
| --- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-error-with-note.rs:12:19
|
LL | Foo::Foo1(num1,
| ^^^^
LL | num2) => (),
| ^^^^
LL | Foo::Foo2(num) => (),
| ^^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
--> $DIR/borrowck-move-error-with-note.rs:28:11
Expand All @@ -31,13 +23,7 @@ LL | f: _s,
LL | g: _t
| -- ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-error-with-note.rs:31:16
|
LL | f: _s,
| ^^
LL | g: _t
| ^^
= note: move occurs because these variables have types that don't implement the `Copy` trait

error[E0507]: cannot move out of `a.a` which is behind a shared reference
--> $DIR/borrowck-move-error-with-note.rs:46:11
Expand Down
8 changes: 1 addition & 7 deletions src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ LL | &[Foo { string: a },
LL | Foo { string: b }] => {
| - ...and here
|
note: move occurs because these variables have types that don't implement the `Copy` trait
--> $DIR/borrowck-move-out-of-vec-tail.rs:21:33
|
LL | &[Foo { string: a },
| ^
LL | Foo { string: b }] => {
| ^
= note: move occurs because these variables have types that don't implement the `Copy` trait
help: consider removing the `&`
|
LL | [Foo { string: a },
Expand Down
Loading

0 comments on commit bb6236c

Please sign in to comment.