Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: BD103 <[email protected]>
  • Loading branch information
MrGVSV and BD103 authored Nov 2, 2024
1 parent 1205c38 commit 428c708
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions bevy_lint/src/lints/borrow_of_reborrowable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl<'tcx> LateLintPass<'tcx> for BorrowOfReborrowable {
_: Span,
def_id: LocalDefId,
) {
// Closures are not currently supported, as `tcx.fn_sig()` crashes for them.
if let FnKind::Closure = kind {
return;
}
// We are already inside of the function item,
// so we can use `instantiate_identity` to discharge the binder
let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity();
Expand Down Expand Up @@ -158,19 +162,21 @@ enum Reborrowable {

impl Reborrowable {
fn try_from_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Self> {
if match_type(cx, ty, &crate::paths::COMMANDS) {
Some(Self::Commands)
} else if match_type(cx, ty, &crate::paths::ENTITY_COMMANDS) {
Some(Self::EntityCommands)
} else if match_type(cx, ty, &crate::paths::QUERY) {
Some(Self::Query)
} else if match_type(cx, ty, &crate::paths::RES_MUT) {
Some(Self::ResMut)
} else if match_type(cx, ty, &crate::paths::NON_SEND_MUT) {
Some(Self::NonSendMut)
} else {
None
const PATH_MAP: &[(&[&str], Reborrowable)] = &[
(&crate::paths::COMMANDS, Reborrowable::Commands),
(&crate::paths::ENTITY_COMMANDS, Reborrowable::EntityCommands),
(&crate::paths::QUERY, Reborrowable::Query),
(&crate::paths::RES_MUT, Reborrowable::ResMut),
(&crate::paths::NON_SEND_MUT, Reborrowable::NonSendMut),
];

for &(path, reborrowable) in PATH_MAP {
if match_type(cx, ty, path) {
return Some(reborrowable);
}
}

None
}

fn lint(&self) -> &'static Lint {
Expand Down

0 comments on commit 428c708

Please sign in to comment.