Skip to content

Commit ac2f041

Browse files
committed
Auto merge of #6787 - matthiaskrgr:lint_msgs, r=llogiq
tests: add test that roughly ensures that our lint messages conform with the diagnostics convention of the rustc dev guide lint message should not start with uppercase letters lint messages should not have punctuation at the end of the last line https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure The test reads through all the .stderr files in the testsuit and checks lint messages that start with "help: ", "error: " etc. There is also an exception list for special messages that are deemed acceptable. changelog: make sure lint messages conform with the rustc dev guide and add test
2 parents abd2c7e + ebc5c8f commit ac2f041

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+490
-397
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tester = "0.9"
4242
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
4343
serde = { version = "1.0", features = ["derive"] }
4444
derive-new = "0.5"
45+
regex = "1.4"
4546

4647
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
4748
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

clippy_lints/src/assign_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn lint_misrefactored_assign_op(
209209
diag.span_suggestion(
210210
expr.span,
211211
&format!(
212-
"Did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
212+
"did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
213213
snip_a,
214214
snip_a,
215215
op.node.as_str(),

clippy_lints/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
639639
diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);
640640

641641
if !unix_suggested && is_unix(os) {
642-
diag.help("Did you mean `unix`?");
642+
diag.help("did you mean `unix`?");
643643
unix_suggested = true;
644644
}
645645
}

clippy_lints/src/await_holding_invalid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
116116
cx,
117117
AWAIT_HOLDING_LOCK,
118118
ty_cause.span,
119-
"this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await.",
119+
"this MutexGuard is held across an 'await' point. Consider using an async-aware Mutex type or ensuring the MutexGuard is dropped before calling await",
120120
ty_cause.scope_span.or(Some(span)),
121121
"these are all the await points this lock is held through",
122122
);
@@ -126,7 +126,7 @@ fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorType
126126
cx,
127127
AWAIT_HOLDING_REFCELL_REF,
128128
ty_cause.span,
129-
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await.",
129+
"this RefCell Ref is held across an 'await' point. Consider ensuring the Ref is dropped before calling await",
130130
ty_cause.scope_span.or(Some(span)),
131131
"these are all the await points this ref is held through",
132132
);

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
117117
expr.span,
118118
"`if` chain can be rewritten with `match`",
119119
None,
120-
"Consider rewriting the `if` chain to use `cmp` and `match`.",
120+
"consider rewriting the `if` chain to use `cmp` and `match`",
121121
)
122122
}
123123
}

clippy_lints/src/drop_forget_ref.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ declare_clippy_lint! {
9898
}
9999

100100
const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \
101-
Dropping a reference does nothing.";
101+
Dropping a reference does nothing";
102102
const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \
103-
Forgetting a reference does nothing.";
103+
Forgetting a reference does nothing";
104104
const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \
105-
Dropping a copy leaves the original intact.";
105+
Dropping a copy leaves the original intact";
106106
const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \
107-
Forgetting a copy leaves the original intact.";
107+
Forgetting a copy leaves the original intact";
108108

109109
declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
110110

clippy_lints/src/fallible_impl_from.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
133133
move |diag| {
134134
diag.help(
135135
"`From` is intended for infallible conversions only. \
136-
Use `TryFrom` if there's a possibility for the conversion to fail.");
136+
Use `TryFrom` if there's a possibility for the conversion to fail");
137137
diag.span_note(fpu.result, "potential failure(s)");
138138
});
139139
}

clippy_lints/src/indexing_slicing.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
132132
}
133133

134134
let help_msg = match (range.start, range.end) {
135-
(None, Some(_)) => "Consider using `.get(..n)`or `.get_mut(..n)` instead",
136-
(Some(_), None) => "Consider using `.get(n..)` or .get_mut(n..)` instead",
137-
(Some(_), Some(_)) => "Consider using `.get(n..m)` or `.get_mut(n..m)` instead",
135+
(None, Some(_)) => "consider using `.get(..n)`or `.get_mut(..n)` instead",
136+
(Some(_), None) => "consider using `.get(n..)` or .get_mut(n..)` instead",
137+
(Some(_), Some(_)) => "consider using `.get(n..m)` or `.get_mut(n..m)` instead",
138138
(None, None) => return, // [..] is ok.
139139
};
140140

141-
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", None, help_msg);
141+
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic", None, help_msg);
142142
} else {
143143
// Catchall non-range index, i.e., [n] or [n << m]
144144
if let ty::Array(..) = ty.kind() {
@@ -153,9 +153,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
153153
cx,
154154
INDEXING_SLICING,
155155
expr.span,
156-
"indexing may panic.",
156+
"indexing may panic",
157157
None,
158-
"Consider using `.get(n)` or `.get_mut(n)` instead",
158+
"consider using `.get(n)` or `.get_mut(n)` instead",
159159
);
160160
}
161161
}

clippy_lints/src/integer_division.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'tcx> LateLintPass<'tcx> for IntegerDivision {
3939
expr.span,
4040
"integer division",
4141
None,
42-
"division of integers may cause loss of precision. consider using floats.",
42+
"division of integers may cause loss of precision. consider using floats",
4343
);
4444
}
4545
}

clippy_lints/src/loops.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,7 @@ fn check_for_loop_range<'tcx>(
16251625
cx,
16261626
NEEDLESS_RANGE_LOOP,
16271627
expr.span,
1628-
&format!(
1629-
"the loop variable `{}` is only used to index `{}`.",
1630-
ident.name, indexed
1631-
),
1628+
&format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
16321629
|diag| {
16331630
multispan_sugg(
16341631
diag,
@@ -1763,7 +1760,7 @@ fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
17631760
arg.span,
17641761
&format!(
17651762
"for loop over `{0}`, which is an `Option`. This is more readably written as an \
1766-
`if let` statement.",
1763+
`if let` statement",
17671764
snippet(cx, arg.span, "_")
17681765
),
17691766
None,
@@ -1780,7 +1777,7 @@ fn check_arg_type(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
17801777
arg.span,
17811778
&format!(
17821779
"for loop over `{0}`, which is a `Result`. This is more readably written as an \
1783-
`if let` statement.",
1780+
`if let` statement",
17841781
snippet(cx, arg.span, "_")
17851782
),
17861783
None,
@@ -1826,7 +1823,7 @@ fn check_for_loop_explicit_counter<'tcx>(
18261823
cx,
18271824
EXPLICIT_COUNTER_LOOP,
18281825
for_span.with_hi(arg.span.hi()),
1829-
&format!("the variable `{}` is used as a loop counter.", name),
1826+
&format!("the variable `{}` is used as a loop counter", name),
18301827
"consider using",
18311828
format!(
18321829
"for ({}, {}) in {}.enumerate()",
@@ -3055,16 +3052,16 @@ impl IterFunction {
30553052
fn get_suggestion_text(&self) -> &'static str {
30563053
match &self.func {
30573054
IterFunctionKind::IntoIter => {
3058-
"Use the original Iterator instead of collecting it and then producing a new one"
3055+
"use the original Iterator instead of collecting it and then producing a new one"
30593056
},
30603057
IterFunctionKind::Len => {
3061-
"Take the original Iterator's count instead of collecting it and finding the length"
3058+
"take the original Iterator's count instead of collecting it and finding the length"
30623059
},
30633060
IterFunctionKind::IsEmpty => {
3064-
"Check if the original Iterator has anything instead of collecting it and seeing if it's empty"
3061+
"check if the original Iterator has anything instead of collecting it and seeing if it's empty"
30653062
},
30663063
IterFunctionKind::Contains(_) => {
3067-
"Check if the original Iterator contains an element instead of collecting then checking"
3064+
"check if the original Iterator contains an element instead of collecting then checking"
30683065
},
30693066
}
30703067
}

clippy_lints/src/matches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,9 +1173,9 @@ fn check_wild_in_or_pats(cx: &LateContext<'_>, arms: &[Arm<'_>]) {
11731173
cx,
11741174
WILDCARD_IN_OR_PATTERNS,
11751175
arm.pat.span,
1176-
"wildcard pattern covers any other pattern as it will match anyway.",
1176+
"wildcard pattern covers any other pattern as it will match anyway",
11771177
None,
1178-
"Consider handling `_` separately.",
1178+
"consider handling `_` separately",
11791179
);
11801180
}
11811181
}

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,7 @@ fn lint_step_by<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, args: &'tcx
25692569
cx,
25702570
ITERATOR_STEP_BY_ZERO,
25712571
expr.span,
2572-
"Iterator::step_by(0) will panic at runtime",
2572+
"`Iterator::step_by(0)` will panic at runtime",
25732573
);
25742574
}
25752575
}
@@ -3081,7 +3081,7 @@ fn lint_filter_next<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, fil
30813081
// lint if caller of `.filter().next()` is an Iterator
30823082
if match_trait_method(cx, expr, &paths::ITERATOR) {
30833083
let msg = "called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
3084-
`.find(..)` instead.";
3084+
`.find(..)` instead";
30853085
let filter_snippet = snippet(cx, filter_args[1].span, "..");
30863086
if filter_snippet.lines().count() <= 1 {
30873087
let iter_snippet = snippet(cx, filter_args[0].span, "..");
@@ -3209,7 +3209,7 @@ fn lint_filter_map_next<'tcx>(
32093209
}
32103210

32113211
let msg = "called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling \
3212-
`.find_map(..)` instead.";
3212+
`.find_map(..)` instead";
32133213
let filter_snippet = snippet(cx, filter_args[1].span, "..");
32143214
if filter_snippet.lines().count() <= 1 {
32153215
let iter_snippet = snippet(cx, filter_args[0].span, "..");

clippy_lints/src/methods/unnecessary_lazy_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(super) fn lint<'tcx>(
5050
UNNECESSARY_LAZY_EVALUATIONS,
5151
expr.span,
5252
msg,
53-
&format!("Use `{}` instead", simplify_using),
53+
&format!("use `{}` instead", simplify_using),
5454
format!(
5555
"{0}.{1}({2})",
5656
snippet(cx, args[0].span, ".."),

clippy_lints/src/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
292292
TOPLEVEL_REF_ARG,
293293
arg.pat.span,
294294
"`ref` directly on a function argument is ignored. \
295-
Consider using a reference type instead.",
295+
Consider using a reference type instead",
296296
);
297297
}
298298
}
@@ -422,7 +422,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
422422
expr.span,
423423
&format!(
424424
"used binding `{}` which is prefixed with an underscore. A leading \
425-
underscore signals that a binding will not be used.",
425+
underscore signals that a binding will not be used",
426426
binding
427427
),
428428
);

clippy_lints/src/needless_question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn emit_lint(cx: &LateContext<'_>, expr: &SomeOkCall<'_>) {
142142
cx,
143143
NEEDLESS_QUESTION_MARK,
144144
entire_expr.span,
145-
"Question mark operator is useless here",
145+
"question mark operator is useless here",
146146
"try",
147147
format!("{}", utils::snippet(cx, inner_expr.span, r#""...""#)),
148148
Applicability::MachineApplicable,

clippy_lints/src/ptr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
188188
PTR_ARG,
189189
arg.span,
190190
"writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used \
191-
with non-Vec-based slices.",
191+
with non-Vec-based slices",
192192
|diag| {
193193
if let Some(ref snippet) = get_only_generic_arg_snippet(cx, arg) {
194194
diag.span_suggestion(
@@ -217,7 +217,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
217217
cx,
218218
PTR_ARG,
219219
arg.span,
220-
"writing `&String` instead of `&str` involves a new object where a slice will do.",
220+
"writing `&String` instead of `&str` involves a new object where a slice will do",
221221
|diag| {
222222
diag.span_suggestion(arg.span, "change this to", "&str".into(), Applicability::Unspecified);
223223
for (clonespan, suggestion) in spans {
@@ -239,7 +239,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
239239
cx,
240240
PTR_ARG,
241241
arg.span,
242-
"writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.",
242+
"writing `&PathBuf` instead of `&Path` involves a new object where a slice will do",
243243
|diag| {
244244
diag.span_suggestion(
245245
arg.span,
@@ -278,7 +278,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id:
278278
cx,
279279
PTR_ARG,
280280
arg.span,
281-
"using a reference to `Cow` is not recommended.",
281+
"using a reference to `Cow` is not recommended",
282282
"change this to",
283283
"&".to_owned() + &r,
284284
Applicability::Unspecified,

clippy_lints/src/suspicious_operation_groupings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ fn emit_suggestion(cx: &EarlyContext<'_>, span: Span, sugg: String, applicabilit
261261
cx,
262262
SUSPICIOUS_OPERATION_GROUPINGS,
263263
span,
264-
"This sequence of operators looks suspiciously like a bug.",
265-
"I think you meant",
264+
"this sequence of operators looks suspiciously like a bug",
265+
"did you mean",
266266
sugg,
267267
applicability,
268268
)

clippy_lints/src/transmuting_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare_clippy_lint! {
2727

2828
declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]);
2929

30-
const LINT_MSG: &str = "transmuting a known null pointer into a reference.";
30+
const LINT_MSG: &str = "transmuting a known null pointer into a reference";
3131

3232
impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
3333
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {

clippy_lints/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl Types {
388388
hir_ty.span,
389389
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
390390
None,
391-
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.",
391+
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation",
392392
);
393393
return; // don't recurse into the type
394394
}
@@ -554,7 +554,7 @@ impl Types {
554554
cx,
555555
VEC_BOX,
556556
hir_ty.span,
557-
"`Vec<T>` is already on the heap, the boxing is unnecessary.",
557+
"`Vec<T>` is already on the heap, the boxing is unnecessary",
558558
"try",
559559
format!("Vec<{}>", snippet(cx, boxed_ty.span, "..")),
560560
Applicability::MachineApplicable,
@@ -578,7 +578,7 @@ impl Types {
578578
cx,
579579
LINKEDLIST,
580580
hir_ty.span,
581-
"I see you're using a LinkedList! Perhaps you meant some other data structure?",
581+
"you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
582582
None,
583583
"a `VecDeque` might work",
584584
);

clippy_lints/src/zero_div_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for ZeroDiv {
5555
"constant division of `0.0` with `0.0` will always result in NaN",
5656
None,
5757
&format!(
58-
"Consider using `{}::NAN` if you would like a constant representing NaN",
58+
"consider using `{}::NAN` if you would like a constant representing NaN",
5959
float_type,
6060
),
6161
);

0 commit comments

Comments
 (0)