Skip to content

Commit

Permalink
Rollup merge of rust-lang#68096 - varkor:diagnostic-cleanup, r=Centril
Browse files Browse the repository at this point in the history
Clean up some diagnostics by making them more consistent

In general:

- Diagnostic should start with a lowercase letter.
- Diagnostics should not end with a full stop.
- Ellipses contain three dots.
- Backticks should encode Rust code.

I also reworded a couple of messages to make them read more clearly.

It might be sensible to create a style guide for diagnostics, so these informal conventions are written down somewhere, after which we could audit the existing diagnostics.

r? @Centril
  • Loading branch information
Dylan-DPC authored Jan 12, 2020
2 parents b33b791 + 1faa05d commit 3794082
Show file tree
Hide file tree
Showing 95 changed files with 294 additions and 292 deletions.
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
// this, both the generated test artifact and the linked libtest (which
// transitively includes libcore) will both define the same set of lang items,
// and this will cause the E0152 "duplicate lang item found" error. See
// and this will cause the E0152 "found duplicate lang item" error. See
// discussion in #50466 for details.
//
// This cfg won't affect doc tests.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl LanguageItemCollector<'tcx> {
self.tcx.sess,
span,
E0152,
"duplicate lang item found: `{}`.",
"found duplicate lang item `{}`",
name
),
None => {
Expand All @@ -206,12 +206,12 @@ impl LanguageItemCollector<'tcx> {
},
};
if let Some(span) = self.tcx.hir().span_if_local(original_def_id) {
err.span_note(span, "first defined here.");
err.span_note(span, "first defined here");
} else {
match self.tcx.extern_crate(original_def_id) {
Some(ExternCrate {dependency_of, ..}) => {
err.note(&format!(
"first defined in crate `{}` (which `{}` depends on).",
"first defined in crate `{}` (which `{}` depends on)",
self.tcx.crate_name(original_def_id.krate),
self.tcx.crate_name(*dependency_of)));
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.span_help(impl_span, "trait impl with same name found");
let trait_crate = self.tcx.crate_name(trait_with_same_path.krate);
let crate_msg = format!(
"Perhaps two different versions of crate `{}` are being used?",
"perhaps two different versions of crate `{}` are being used?",
trait_crate
);
err.note(&crate_msg);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
self.check_extern(bare_fn_ty.ext);
}
ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span, "The `!` type is experimental");
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
}
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
`expected = \"error message\"`",
)
.note(
"Errors in this attribute were erroneously \
"errors in this attribute were erroneously \
allowed and will become a hard error in a \
future release.",
)
Expand Down
23 changes: 13 additions & 10 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl EarlyLintPass for AnonymousParameters {
)
.span_suggestion(
arg.pat.span,
"Try naming the parameter or explicitly \
"try naming the parameter or explicitly \
ignoring it",
format!("_: {}", ty_snip),
appl,
Expand Down Expand Up @@ -1934,21 +1934,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
use rustc::ty::TyKind::*;
match ty.kind {
// Primitive types that don't like 0 as a value.
Ref(..) => Some((format!("References must be non-null"), None)),
Ref(..) => Some((format!("references must be non-null"), None)),
Adt(..) if ty.is_box() => Some((format!("`Box` must be non-null"), None)),
FnPtr(..) => Some((format!("Function pointers must be non-null"), None)),
Never => Some((format!("The never type (`!`) has no valid value"), None)),
FnPtr(..) => Some((format!("function pointers must be non-null"), None)),
Never => Some((format!("the `!` type has no valid value"), None)),
RawPtr(tm) if matches!(tm.ty.kind, Dynamic(..)) =>
// raw ptr to dyn Trait
{
Some((format!("The vtable of a wide raw pointer must be non-null"), None))
Some((format!("the vtable of a wide raw pointer must be non-null"), None))
}
// Primitive types with other constraints.
Bool if init == InitKind::Uninit => {
Some((format!("Booleans must be `true` or `false`"), None))
Some((format!("booleans must be either `true` or `false`"), None))
}
Char if init == InitKind::Uninit => {
Some((format!("Characters must be a valid unicode codepoint"), None))
Some((format!("characters must be a valid Unicode codepoint"), None))
}
// Recurse and checks for some compound types.
Adt(adt_def, substs) if !adt_def.is_union() => {
Expand All @@ -1959,21 +1959,24 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
// return `Bound::Excluded`. (And we have tests checking that we
// handle the attribute correctly.)
(Bound::Included(lo), _) if lo > 0 => {
return Some((format!("{} must be non-null", ty), None));
return Some((format!("`{}` must be non-null", ty), None));
}
(Bound::Included(_), _) | (_, Bound::Included(_))
if init == InitKind::Uninit =>
{
return Some((
format!("{} must be initialized inside its custom valid range", ty),
format!(
"`{}` must be initialized inside its custom valid range",
ty,
),
None,
));
}
_ => {}
}
// Now, recurse.
match adt_def.variants.len() {
0 => Some((format!("0-variant enums have no valid value"), None)),
0 => Some((format!("enums with no variants have no valid value"), None)),
1 => {
// Struct, or enum with exactly one variant.
// Proceed recursively, check all fields.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/borrow_check/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
// better.

if let Some(closure_region_requirements) = closure_region_requirements {
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "External requirements");
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "external requirements");

regioncx.annotate(tcx, &mut err);

Expand All @@ -379,7 +379,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(

err.buffer(errors_buffer);
} else {
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "No external requirements");
let mut err = tcx.sess.diagnostic().span_note_diag(body.span, "no external requirements");
regioncx.annotate(tcx, &mut err);

err.buffer(errors_buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_parse/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ impl<'a> Parser<'a> {
self.struct_span_err(lit.span, msg)
.help(
"instead of using a suffixed literal \
(1u8, 1.0f32, etc.), use an unsuffixed version \
(1, 1.0, etc.).",
(`1u8`, `1.0f32`, etc.), use an unsuffixed version \
(`1`, `1.0`, etc.)",
)
.emit()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_parse/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ impl<'a> Parser<'a> {
if let Ok(seq_snippet) = self.span_to_snippet(seq_span) {
err.span_suggestion(
seq_span,
"try adding parentheses to match on a tuple..",
"try adding parentheses to match on a tuple...",
format!("({})", seq_snippet),
Applicability::MachineApplicable,
)
.span_suggestion(
seq_span,
"..or a vertical bar to match on multiple alternatives",
"...or a vertical bar to match on multiple alternatives",
format!("{}", seq_snippet.replace(",", " |")),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/diagnostic_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn collect_item(
)),
};
if let Some(span) = tcx.hir().span_if_local(original_def_id) {
err.span_note(span, "first defined here.");
err.span_note(span, "first defined here");
} else {
err.note(&format!(
"first defined in crate `{}`.",
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
.session
.struct_span_err(
attr.span,
"`macro_use` is not supported on `extern crate self`",
"`#[macro_use]` is not supported on `extern crate self`",
)
.emit();
}
Expand Down Expand Up @@ -1054,10 +1054,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
for attr in attrs {
if attr.check_name(sym::macro_escape) {
let msg = "macro_escape is a deprecated synonym for macro_use";
let msg = "`#[macro_escape]` is a deprecated synonym for `#[macro_use]`";
let mut err = self.r.session.struct_span_warn(attr.span, msg);
if let ast::AttrStyle::Inner = attr.style {
err.help("consider an outer attribute, `#[macro_use]` mod ...").emit();
err.help("try an outer attribute: `#[macro_use]`").emit();
} else {
err.emit();
}
Expand All @@ -1066,7 +1066,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}

if !attr.is_word() {
self.r.session.span_err(attr.span, "arguments to macro_use are not allowed here");
self.r.session.span_err(attr.span, "arguments to `macro_use` are not allowed here");
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ impl<'a> Resolver<'a> {
continue;
}
}
let msg = "there are too many initial `super`s.".to_string();
let msg = "there are too many leading `super` keywords".to_string();
return PathResult::Failed {
span: ident.span,
label: msg,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
if unknown_cast_to { "to" } else { "from" }
);
err.note(
"The type information given here is insufficient to check whether \
"the type information given here is insufficient to check whether \
the pointer cast is valid",
);
if unknown_cast_to {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
macro_rules! report_function {
($span:expr, $name:expr) => {
err.note(&format!(
"{} is a function, perhaps you wish to call it",
"`{}` is a function, perhaps you wish to call it",
$name
));
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ fn check_opaque_for_cycles<'tcx>(
if let hir::OpaqueTyOrigin::AsyncFn = origin {
struct_span_err!(tcx.sess, span, E0733, "recursion in an `async fn` requires boxing",)
.span_label(span, "recursive `async fn`")
.note("a recursive `async fn` must be rewritten to return a boxed `dyn Future`.")
.note("a recursive `async fn` must be rewritten to return a boxed `dyn Future`")
.emit();
} else {
let mut err =
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn default_hook(info: &PanicInfo<'_>) {
let _ = writeln!(
err,
"note: run with `RUST_BACKTRACE=1` \
environment variable to display a backtrace."
environment variable to display a backtrace"
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/panic-handler-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::panic::PanicInfo;

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
//~^ error duplicate lang item found: `panic_impl`
//~^ ERROR found duplicate lang item `panic_impl`
loop {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{ "type": "test", "event": "started", "name": "a" }
{ "type": "test", "name": "a", "event": "ok" }
{ "type": "test", "event": "started", "name": "b" }
{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.\n" }
{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
{ "type": "test", "event": "started", "name": "c" }
{ "type": "test", "name": "c", "event": "ok" }
{ "type": "test", "event": "started", "name": "d" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{ "type": "test", "event": "started", "name": "a" }
{ "type": "test", "name": "a", "event": "ok", "stdout": "print from successful test\n" }
{ "type": "test", "event": "started", "name": "b" }
{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.\n" }
{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
{ "type": "test", "event": "started", "name": "c" }
{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:15:5\n" }
{ "type": "test", "event": "started", "name": "d" }
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/failed-doctest-output.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stderr:
stderr 1
stderr 2
thread 'main' panicked at 'oh no', $DIR/failed-doctest-output.rs:7:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/anon-params-deprecated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
--> $DIR/anon-params-deprecated.rs:9:12
|
LL | fn foo(i32);
| ^^^ help: Try naming the parameter or explicitly ignoring it: `_: i32`
| ^^^ help: try naming the parameter or explicitly ignoring it: `_: i32`
|
note: lint level defined here
--> $DIR/anon-params-deprecated.rs:1:9
Expand All @@ -16,7 +16,7 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
--> $DIR/anon-params-deprecated.rs:12:30
|
LL | fn bar_with_default_impl(String, String) {}
| ^^^^^^ help: Try naming the parameter or explicitly ignoring it: `_: String`
| ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
Expand All @@ -25,7 +25,7 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
--> $DIR/anon-params-deprecated.rs:12:38
|
LL | fn bar_with_default_impl(String, String) {}
| ^^^^^^ help: Try naming the parameter or explicitly ignoring it: `_: String`
| ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ error[E0733]: recursion in an `async fn` requires boxing
LL | async fn rec_1() {
| ^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`.
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`

error[E0733]: recursion in an `async fn` requires boxing
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18
|
LL | async fn rec_2() {
| ^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`.
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0733]: recursion in an `async fn` requires boxing
LL | async fn recursive_async_function() -> () {
| ^^ recursive `async fn`
|
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`.
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LL | unsafe { std::mem::transmute(()) }
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
= note: `#[warn(invalid_value)]` on by default
= note: The never type (`!`) has no valid value
= note: the `!` type has no valid value

warning: the type `Empty` does not permit zero-initialization
--> $DIR/validate_uninhabited_zsts.rs:17:35
Expand All @@ -45,7 +45,7 @@ LL | const BAR: [Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
= note: 0-variant enums have no valid value
= note: enums with no variants have no valid value

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/miri_unleashed/mutable_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *m
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:346:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

Expand Down
Loading

0 comments on commit 3794082

Please sign in to comment.