Skip to content

Commit bb6236c

Browse files
authored
Rollup merge of #66754 - estebank:rustdoc-capitalization, r=Dylan-DPC
Various tweaks to diagnostic output
2 parents 0b3d4a1 + 5ea922a commit bb6236c

35 files changed

+115
-300
lines changed

src/librustc/infer/error_reporting/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
463463
&self,
464464
err: &mut DiagnosticBuilder<'_>,
465465
terr: &TypeError<'tcx>,
466-
sp: Span,
467466
) {
468467
use hir::def_id::CrateNum;
469468
use hir::map::DisambiguatedDefPathData;
@@ -577,14 +576,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
577576
};
578577
if same_path().unwrap_or(false) {
579578
let crate_name = self.tcx.crate_name(did1.krate);
580-
err.span_note(
581-
sp,
582-
&format!(
583-
"Perhaps two different versions \
584-
of crate `{}` are being used?",
585-
crate_name
586-
),
587-
);
579+
err.note(&format!(
580+
"perhaps two different versions of crate `{}` are being used?",
581+
crate_name
582+
));
588583
}
589584
}
590585
};
@@ -1434,7 +1429,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14341429
.unwrap_or_else(|| {
14351430
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
14361431
});
1437-
self.check_and_note_conflicting_crates(diag, terr, span);
1432+
self.check_and_note_conflicting_crates(diag, terr);
14381433
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);
14391434

14401435
// It reads better to have the error origin as the final

src/librustc_metadata/creader.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,9 @@ impl<'a> CrateLoader<'a> {
698698
let has_global_allocator = match &*global_allocator_spans(krate) {
699699
[span1, span2, ..] => {
700700
self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
701-
.span_note(*span1, "the previous global allocator is defined here").emit();
701+
.span_label(*span2, "cannot define a new global allocator")
702+
.span_label(*span1, "previous global allocator is defined here")
703+
.emit();
702704
true
703705
}
704706
spans => !spans.is_empty()

src/librustc_mir/borrow_check/conflict_errors.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1264,23 +1264,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12641264
Applicability::MachineApplicable,
12651265
);
12661266

1267-
match category {
1268-
ConstraintCategory::Return => {
1269-
err.span_note(constraint_span, "closure is returned here");
1270-
}
1271-
ConstraintCategory::OpaqueType => {
1272-
err.span_note(constraint_span, "generator is returned here");
1273-
}
1267+
let msg = match category {
1268+
ConstraintCategory::Return => "closure is returned here".to_string(),
1269+
ConstraintCategory::OpaqueType => "generator is returned here".to_string(),
12741270
ConstraintCategory::CallArgument => {
12751271
fr_name.highlight_region_name(&mut err);
1276-
err.span_note(
1277-
constraint_span,
1278-
&format!("function requires argument type to outlive `{}`", fr_name),
1279-
);
1272+
format!("function requires argument type to outlive `{}`", fr_name)
12801273
}
12811274
_ => bug!("report_escaping_closure_capture called with unexpected constraint \
12821275
category: `{:?}`", category),
1283-
}
1276+
};
1277+
err.span_note(constraint_span, &msg);
12841278
err
12851279
}
12861280

src/librustc_mir/borrow_check/move_errors.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
558558
err: &mut DiagnosticBuilder<'a>,
559559
binds_to: &[Local],
560560
) {
561-
let mut noncopy_var_spans = Vec::new();
562561
for (j, local) in binds_to.into_iter().enumerate() {
563562
let bind_to = &self.body.local_decls[*local];
564563
let binding_span = bind_to.source_info.span;
@@ -576,16 +575,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
576575
bind_to.ty,
577576
Some(binding_span)
578577
);
579-
} else {
580-
noncopy_var_spans.push(binding_span);
581578
}
582579
}
583580

584581
if binds_to.len() > 1 {
585-
err.span_note(
586-
noncopy_var_spans,
587-
"move occurs because these variables have types that \
588-
don't implement the `Copy` trait",
582+
err.note("move occurs because these variables have types that \
583+
don't implement the `Copy` trait",
589584
);
590585
}
591586
}

src/librustc_parse/parser/item.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,12 @@ impl<'a> Parser<'a> {
491491
}
492492

493493
/// Parses a macro invocation inside a `trait`, `impl` or `extern` block.
494-
fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
495-
at_end: &mut bool) -> PResult<'a, Option<Mac>>
496-
{
494+
fn parse_assoc_macro_invoc(
495+
&mut self,
496+
item_kind: &str,
497+
vis: Option<&Visibility>,
498+
at_end: &mut bool,
499+
) -> PResult<'a, Option<Mac>> {
497500
if self.token.is_path_start() &&
498501
!(self.is_async_fn() && self.token.span.rust_2015()) {
499502
let prev_span = self.prev_span;
@@ -532,9 +535,11 @@ impl<'a> Parser<'a> {
532535
}
533536
}
534537

535-
fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span)
536-
-> DiagnosticBuilder<'a>
537-
{
538+
fn missing_assoc_item_kind_err(
539+
&self,
540+
item_type: &str,
541+
prev_span: Span,
542+
) -> DiagnosticBuilder<'a> {
538543
let expected_kinds = if item_type == "extern" {
539544
"missing `fn`, `type`, or `static`"
540545
} else {

src/librustc_passes/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
144144
"`continue` pointing to a labeled block")
145145
.span_label(e.span,
146146
"labeled blocks cannot be `continue`'d")
147-
.span_note(block.span,
148-
"labeled block the continue points to")
147+
.span_label(block.span,
148+
"labeled block the `continue` points to")
149149
.emit();
150150
}
151151
}

src/librustc_resolve/resolve_imports.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11601160
.emit();
11611161
} else {
11621162
let msg = format!("`{}` is private, and cannot be re-exported", ident);
1163-
let note_msg =
1164-
format!("consider marking `{}` as `pub` in the imported module", ident);
1163+
let note_msg = format!(
1164+
"consider marking `{}` as `pub` in the imported module",
1165+
ident,
1166+
);
11651167
struct_span_err!(self.r.session, directive.span, E0364, "{}", &msg)
11661168
.span_note(directive.span, &note_msg)
11671169
.emit();

src/librustdoc/passes/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub fn look_for_tests<'tcx>(
344344
lint::builtin::MISSING_DOC_CODE_EXAMPLES,
345345
hir_id,
346346
sp,
347-
"Missing code example in this documentation");
347+
"missing code example in this documentation");
348348
diag.emit();
349349
} else if check_missing_code == false &&
350350
tests.found_tests > 0 &&
@@ -353,7 +353,7 @@ pub fn look_for_tests<'tcx>(
353353
lint::builtin::PRIVATE_DOC_TESTS,
354354
hir_id,
355355
span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
356-
"Documentation test in private item");
356+
"documentation test in private item");
357357
diag.emit();
358358
}
359359
}
@@ -367,7 +367,7 @@ crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> {
367367
if start == DUMMY_SP {
368368
return None;
369369
}
370-
let end = attrs.doc_strings.last().expect("No doc strings provided").span();
370+
let end = attrs.doc_strings.last().expect("no doc strings provided").span();
371371
Some(start.to(end))
372372
}
373373

src/libsyntax/feature_gate/check.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
688688
crate_edition: Edition, allow_features: &Option<Vec<String>>) -> Features {
689689
fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
690690
let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed");
691+
err.span_label(span, "feature has been removed");
691692
if let Some(reason) = reason {
692-
err.span_note(span, reason);
693-
} else {
694-
err.span_label(span, "feature has been removed");
693+
err.note(reason);
695694
}
696695
err.emit();
697696
}

src/libsyntax_expand/mbe/macro_check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ fn check_binders(
269269
// for nested macro definitions.
270270
sess.span_diagnostic
271271
.struct_span_err(span, "duplicate matcher binding")
272-
.span_note(prev_info.span, "previous declaration was here")
272+
.span_label(span, "duplicate binding")
273+
.span_label(prev_info.span, "previous binding")
273274
.emit();
274275
*valid = false;
275276
} else {

src/libsyntax_ext/format.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ fn parse_args<'a>(
172172
let e = p.parse_expr()?;
173173
if let Some(prev) = names.get(&name) {
174174
ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name))
175-
.span_note(args[*prev].span, "previously here")
175+
.span_label(args[*prev].span, "previously here")
176+
.span_label(e.span, "duplicate argument")
176177
.emit();
177178
continue;
178179
}

src/libsyntax_ext/proc_macro_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
270270
};
271271

272272
self.handler.struct_span_err(attr.span, &msg)
273-
.span_note(prev_attr.span, "previous attribute here")
273+
.span_label(prev_attr.span, "previous attribute here")
274274
.emit();
275275

276276
return;
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#![deny(missing_doc_code_examples)] //~ ERROR Missing code example in this documentation
1+
#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation
22

33
/// Some docs.
4-
//~^ ERROR Missing code example in this documentation
4+
//~^ ERROR missing code example in this documentation
55
pub struct Foo;
66

77
/// And then, the princess died.
8-
//~^ ERROR Missing code example in this documentation
8+
//~^ ERROR missing code example in this documentation
99
pub mod foo {
1010
/// Or maybe not because she saved herself!
11-
//~^ ERROR Missing code example in this documentation
11+
//~^ ERROR missing code example in this documentation
1212
pub fn bar() {}
1313
}

src/test/rustdoc-ui/doc-without-codeblock.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Missing code example in this documentation
1+
error: missing code example in this documentation
22
--> $DIR/doc-without-codeblock.rs:1:1
33
|
44
LL | / #![deny(missing_doc_code_examples)]
@@ -16,19 +16,19 @@ note: lint level defined here
1616
LL | #![deny(missing_doc_code_examples)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: Missing code example in this documentation
19+
error: missing code example in this documentation
2020
--> $DIR/doc-without-codeblock.rs:3:1
2121
|
2222
LL | /// Some docs.
2323
| ^^^^^^^^^^^^^^
2424

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

31-
error: Missing code example in this documentation
31+
error: missing code example in this documentation
3232
--> $DIR/doc-without-codeblock.rs:10:5
3333
|
3434
LL | /// Or maybe not because she saved herself!

src/test/rustdoc-ui/lint-group.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it
1515

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

1919
/// wait, this *does* have a doctest?
2020
///
2121
/// ```
2222
/// println!("sup");
2323
/// ```
24-
fn private_doctest() {} //~^^^^^ ERROR Documentation test in private item
24+
fn private_doctest() {} //~^^^^^ ERROR documentation test in private item

src/test/rustdoc-ui/lint-group.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Documentation test in private item
1+
error: documentation test in private item
22
--> $DIR/lint-group.rs:19:1
33
|
44
LL | / /// wait, this *does* have a doctest?
@@ -29,7 +29,7 @@ LL | #![deny(rustdoc)]
2929
= note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
3030
= help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
3131

32-
error: Missing code example in this documentation
32+
error: missing code example in this documentation
3333
--> $DIR/lint-group.rs:16:1
3434
|
3535
LL | /// wait, this doesn't have a doctest?

src/test/rustdoc-ui/lint-missing-doc-code-example.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Missing code example in this documentation
1+
error: missing code example in this documentation
22
--> $DIR/lint-missing-doc-code-example.rs:19:1
33
|
44
LL | / mod module1 {
@@ -11,7 +11,7 @@ note: lint level defined here
1111
LL | #![deny(missing_doc_code_examples)]
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1313

14-
error: Missing code example in this documentation
14+
error: missing code example in this documentation
1515
--> $DIR/lint-missing-doc-code-example.rs:37:3
1616
|
1717
LL | /// doc

src/test/rustdoc-ui/private-item-doc-test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ mod foo {
66
/// ```
77
/// assert!(false);
88
/// ```
9-
//~^^^^^ ERROR Documentation test in private item
9+
//~^^^^^ ERROR documentation test in private item
1010
fn bar() {}
1111
}

src/test/rustdoc-ui/private-item-doc-test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Documentation test in private item
1+
error: documentation test in private item
22
--> $DIR/private-item-doc-test.rs:4:5
33
|
44
LL | / /// private doc test
+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error: cannot define multiple global allocators
22
--> $DIR/two-allocators.rs:6:1
33
|
4-
LL | static B: System = System;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
note: the previous global allocator is defined here
8-
--> $DIR/two-allocators.rs:4:1
9-
|
104
LL | static A: System = System;
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| -------------------------- previous global allocator is defined here
6+
LL | #[global_allocator]
7+
LL | static B: System = System;
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
129

1310
error: aborting due to previous error
1411

src/test/ui/borrowck/borrowck-move-error-with-note.stderr

+2-16
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ LL | num2) => (),
1010
LL | Foo::Foo2(num) => (),
1111
| --- ...and here
1212
|
13-
note: move occurs because these variables have types that don't implement the `Copy` trait
14-
--> $DIR/borrowck-move-error-with-note.rs:12:19
15-
|
16-
LL | Foo::Foo1(num1,
17-
| ^^^^
18-
LL | num2) => (),
19-
| ^^^^
20-
LL | Foo::Foo2(num) => (),
21-
| ^^^
13+
= note: move occurs because these variables have types that don't implement the `Copy` trait
2214

2315
error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
2416
--> $DIR/borrowck-move-error-with-note.rs:28:11
@@ -31,13 +23,7 @@ LL | f: _s,
3123
LL | g: _t
3224
| -- ...and here
3325
|
34-
note: move occurs because these variables have types that don't implement the `Copy` trait
35-
--> $DIR/borrowck-move-error-with-note.rs:31:16
36-
|
37-
LL | f: _s,
38-
| ^^
39-
LL | g: _t
40-
| ^^
26+
= note: move occurs because these variables have types that don't implement the `Copy` trait
4127

4228
error[E0507]: cannot move out of `a.a` which is behind a shared reference
4329
--> $DIR/borrowck-move-error-with-note.rs:46:11

src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ LL | &[Foo { string: a },
99
LL | Foo { string: b }] => {
1010
| - ...and here
1111
|
12-
note: move occurs because these variables have types that don't implement the `Copy` trait
13-
--> $DIR/borrowck-move-out-of-vec-tail.rs:21:33
14-
|
15-
LL | &[Foo { string: a },
16-
| ^
17-
LL | Foo { string: b }] => {
18-
| ^
12+
= note: move occurs because these variables have types that don't implement the `Copy` trait
1913
help: consider removing the `&`
2014
|
2115
LL | [Foo { string: a },

0 commit comments

Comments
 (0)