Skip to content

Commit

Permalink
distinguish no_std code
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Jan 6, 2025
1 parent c5a2ba5 commit ae5b740
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions clippy_lints/src/too_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::symbol::sym;

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -71,11 +71,19 @@ fn replacement(cx: &LateContext<'_>, cty: &hir::Ty<'_>) -> Option<(Span, String)
None
};
}
for (diag, repl) in [
(sym::cstring_type, "std::ffi::CStr"),
(sym::OsString, "std::ffi::OsStr"),
(sym::PathBuf, "std::path::Path"),
] {
if clippy_utils::is_path_diagnostic_item(cx, cty, sym::cstring_type) {
return Some((
cty.span,
(if clippy_utils::is_no_std_crate(cx) {
"core::ffi::CStr"
} else {
"std::ffi::CStr"
})
.into(),
));
}
// Neither OsString nor PathBuf are available outside std
for (diag, repl) in [(sym::OsString, "std::ffi::OsStr"), (sym::PathBuf, "std::path::Path")] {
if clippy_utils::is_path_diagnostic_item(cx, cty, diag) {
return Some((cty.span, repl.into()));
}
Expand Down

0 comments on commit ae5b740

Please sign in to comment.