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 <59022059+BD103@users.noreply.github.com>
  • Loading branch information
MrGVSV and BD103 committed Nov 2, 2024
1 parent 27f9c87 commit 0b28a95
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions bevy_lint/src/lints/borrow_of_reborrowable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,17 @@ impl<'tcx> LateLintPass<'tcx> for BorrowOfReborrowable {
fn check_fn(
&mut self,
cx: &LateContext<'tcx>,
_: FnKind<'tcx>,
kind: FnKind<'tcx>,
decl: &'tcx FnDecl<'tcx>,
_: &'tcx Body<'tcx>,
_: 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 @@ -137,7 +142,7 @@ impl<'tcx> LateLintPass<'tcx> for BorrowOfReborrowable {
}
}

#[derive(Debug)]
#[derive(Debug, Copy, Clone)]
enum Reborrowable {
Commands,
// Deferred,
Expand All @@ -158,19 +163,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 0b28a95

Please sign in to comment.