Skip to content

Commit 5ac9eb0

Browse files
committed
refactor(lints): Create emitted_source helper function
1 parent 01a270f commit 5ac9eb0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/cargo/util/lints.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ impl Lint {
307307
.map(|(_, (l, r, _))| (l, r))
308308
.unwrap()
309309
}
310+
311+
fn emitted_source(&self, lint_level: LintLevel, reason: LintLevelReason) -> String {
312+
format!("`cargo::{}` is set to `{lint_level}` {reason}", self.name,)
313+
}
310314
}
311315

312316
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -449,10 +453,7 @@ pub fn check_im_a_teapot(
449453
}
450454
let level = lint_level.to_diagnostic_level();
451455
let manifest_path = rel_cwd_manifest_path(path, gctx);
452-
let emitted_reason = format!(
453-
"`cargo::{}` is set to `{lint_level}` {reason}",
454-
IM_A_TEAPOT.name
455-
);
456+
let emitted_reason = IM_A_TEAPOT.emitted_source(lint_level, reason);
456457

457458
let key_span = get_span(manifest.document(), &["package", "im-a-teapot"], false).unwrap();
458459
let value_span = get_span(manifest.document(), &["package", "im-a-teapot"], true).unwrap();
@@ -581,10 +582,7 @@ fn output_unknown_lints(
581582
};
582583

583584
if emitted_source.is_none() {
584-
emitted_source = Some(format!(
585-
"`cargo::{}` is set to `{lint_level}` {reason}",
586-
UNKNOWN_LINTS.name
587-
));
585+
emitted_source = Some(UNKNOWN_LINTS.emitted_source(lint_level, reason));
588586
message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap()));
589587
}
590588

0 commit comments

Comments
 (0)