Skip to content

Commit cdb2c3c

Browse files
committed
use static strs
1 parent 1661a0a commit cdb2c3c

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/librustc_lint/builtin.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ impl MissingDoc {
349349
id: Option<hir::HirId>,
350350
attrs: &[ast::Attribute],
351351
sp: Span,
352-
desc: &str,
352+
article: &'static str,
353+
desc: &'static str,
353354
) {
354355
// If we're building a test harness, then warning about
355356
// documentation is probably not really relevant right now.
@@ -374,7 +375,7 @@ impl MissingDoc {
374375
let has_doc = attrs.iter().any(|a| has_doc(a));
375376
if !has_doc {
376377
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
377-
lint.build(&format!("missing documentation for {}", desc)).emit()
378+
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
378379
});
379380
}
380381
}
@@ -398,7 +399,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
398399
}
399400

400401
fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate<'_>) {
401-
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "crate");
402+
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "a", "crate");
402403

403404
for macro_def in krate.exported_macros {
404405
let has_doc = macro_def.attrs.iter().any(|a| has_doc(a));
@@ -455,13 +456,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
455456
let def_id = cx.tcx.hir().local_def_id(it.hir_id);
456457
let (article, desc) = cx.tcx.article_and_description(def_id);
457458

458-
self.check_missing_docs_attrs(
459-
cx,
460-
Some(it.hir_id),
461-
&it.attrs,
462-
it.span,
463-
&format!("{} {}", article, desc),
464-
);
459+
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, article, desc);
465460
}
466461

467462
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
@@ -477,7 +472,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
477472
Some(trait_item.hir_id),
478473
&trait_item.attrs,
479474
trait_item.span,
480-
&format!("{} {}", article, desc),
475+
article,
476+
desc,
481477
);
482478
}
483479

@@ -494,18 +490,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
494490
Some(impl_item.hir_id),
495491
&impl_item.attrs,
496492
impl_item.span,
497-
&format!("{} {}", article, desc),
493+
article,
494+
desc,
498495
);
499496
}
500497

501498
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField<'_>) {
502499
if !sf.is_positional() {
503-
self.check_missing_docs_attrs(cx, Some(sf.hir_id), &sf.attrs, sf.span, "a struct field")
500+
self.check_missing_docs_attrs(
501+
cx,
502+
Some(sf.hir_id),
503+
&sf.attrs,
504+
sf.span,
505+
"a",
506+
"struct field",
507+
)
504508
}
505509
}
506510

507511
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant<'_>) {
508-
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a variant");
512+
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant");
509513
}
510514
}
511515

0 commit comments

Comments
 (0)