mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor(lints): Create emitted_source helper function
This commit is contained in:
parent
01a270f402
commit
5ac9eb0a58
@ -307,6 +307,10 @@ impl Lint {
|
|||||||
.map(|(_, (l, r, _))| (l, r))
|
.map(|(_, (l, r, _))| (l, r))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn emitted_source(&self, lint_level: LintLevel, reason: LintLevelReason) -> String {
|
||||||
|
format!("`cargo::{}` is set to `{lint_level}` {reason}", self.name,)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
@ -449,10 +453,7 @@ pub fn check_im_a_teapot(
|
|||||||
}
|
}
|
||||||
let level = lint_level.to_diagnostic_level();
|
let level = lint_level.to_diagnostic_level();
|
||||||
let manifest_path = rel_cwd_manifest_path(path, gctx);
|
let manifest_path = rel_cwd_manifest_path(path, gctx);
|
||||||
let emitted_reason = format!(
|
let emitted_reason = IM_A_TEAPOT.emitted_source(lint_level, reason);
|
||||||
"`cargo::{}` is set to `{lint_level}` {reason}",
|
|
||||||
IM_A_TEAPOT.name
|
|
||||||
);
|
|
||||||
|
|
||||||
let key_span = get_span(manifest.document(), &["package", "im-a-teapot"], false).unwrap();
|
let key_span = get_span(manifest.document(), &["package", "im-a-teapot"], false).unwrap();
|
||||||
let value_span = get_span(manifest.document(), &["package", "im-a-teapot"], true).unwrap();
|
let value_span = get_span(manifest.document(), &["package", "im-a-teapot"], true).unwrap();
|
||||||
@ -581,10 +582,7 @@ fn output_unknown_lints(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if emitted_source.is_none() {
|
if emitted_source.is_none() {
|
||||||
emitted_source = Some(format!(
|
emitted_source = Some(UNKNOWN_LINTS.emitted_source(lint_level, reason));
|
||||||
"`cargo::{}` is set to `{lint_level}` {reason}",
|
|
||||||
UNKNOWN_LINTS.name
|
|
||||||
));
|
|
||||||
message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap()));
|
message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user