Skip to content

Commit

Permalink
more fixes for clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
micahscopes committed Nov 30, 2024
1 parent b116b92 commit d400186
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 125 deletions.
4 changes: 2 additions & 2 deletions crates/common/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use std::panic;

const BUG_REPORT_URL: &str = "https://github.com/ethereum/fe/issues/new";
type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static;
type PanicCallback = dyn Fn(&panic::PanicHookInfo<'_>) + Sync + Send + 'static;
static DEFAULT_PANIC_HOOK: Lazy<Box<PanicCallback>> = Lazy::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(report_ice));
Expand All @@ -12,7 +12,7 @@ static DEFAULT_PANIC_HOOK: Lazy<Box<PanicCallback>> = Lazy::new(|| {
pub fn install_panic_hook() {
Lazy::force(&DEFAULT_PANIC_HOOK);
}
fn report_ice(info: &panic::PanicInfo) {
fn report_ice(info: &panic::PanicHookInfo) {
(*DEFAULT_PANIC_HOOK)(info);

eprintln!();
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-analysis/src/ty/adt_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ impl<'db> AdtDef<'db> {
self.adt_ref(db).name(db)
}

pub(crate) fn params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub(crate) fn params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.param_set(db).params(db)
}

pub(crate) fn original_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId] {
pub(crate) fn original_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.param_set(db).explicit_params(db)
}

Expand Down Expand Up @@ -202,7 +202,7 @@ impl<'db> AdtRefId<'db> {
pub(crate) fn generic_owner_id(
self,
db: &'db dyn HirAnalysisDb,
) -> Option<GenericParamOwnerId> {
) -> Option<GenericParamOwnerId<'db>> {
match self.data(db) {
AdtRef::Enum(e) => Some(GenericParamOwnerId::new(db, e.into())),
AdtRef::Struct(s) => Some(GenericParamOwnerId::new(db, s.into())),
Expand Down
7 changes: 5 additions & 2 deletions crates/hir-analysis/src/ty/def_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ enum DefKind<'db> {
}

impl<'db> DefKind<'db> {
fn original_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
fn original_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
match self {
Self::Adt(def) => def.original_params(db),
Self::Trait(def) => def.original_params(db),
Expand All @@ -1009,7 +1009,10 @@ impl<'db> DefKind<'db> {
}
}

fn collect_super_trait_cycle(self, db: &'db dyn HirAnalysisDb) -> Option<&SuperTraitCycle> {
fn collect_super_trait_cycle(
self,
db: &'db dyn HirAnalysisDb,
) -> Option<&'db SuperTraitCycle<'db>> {
if let Self::Trait(def) = self {
collect_super_traits(db, def).as_ref().err()
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-analysis/src/ty/func_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ impl<'db> FuncDef<'db> {
self.hir_def(db).scope()
}

pub fn params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub fn params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.params_set(db).params(db)
}

pub fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.params_set(db).explicit_params(db)
}

Expand Down
17 changes: 10 additions & 7 deletions crates/hir-analysis/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'db> Implementor<'db> {
self.trait_(db).def(db)
}

pub(crate) fn original_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub(crate) fn original_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.params(db)
}

Expand All @@ -209,7 +209,7 @@ impl<'db> Implementor<'db> {
pub(super) fn methods(
self,
db: &'db dyn HirAnalysisDb,
) -> &IndexMap<IdentId<'db>, FuncDef<'db>> {
) -> &'db IndexMap<IdentId<'db>, FuncDef<'db>> {
collect_implementor_methods(db, self)
}
}
Expand Down Expand Up @@ -299,15 +299,15 @@ pub struct TraitDef<'db> {
}

impl<'db> TraitDef<'db> {
pub fn params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub fn params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.param_set(db).params(db)
}

pub fn self_param(self, db: &'db dyn HirAnalysisDb) -> TyId<'db> {
self.param_set(db).trait_self(db).unwrap()
}

pub fn original_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub fn original_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
self.param_set(db).explicit_params(db)
}
}
Expand All @@ -327,17 +327,20 @@ impl TraitMethod<'_> {

impl<'db> TraitDef<'db> {
/// Returns the type kind that implementor type must have.
pub(crate) fn expected_implementor_kind(self, db: &'db dyn HirAnalysisDb) -> &Kind {
pub(crate) fn expected_implementor_kind(self, db: &'db dyn HirAnalysisDb) -> &'db Kind {
self.self_param(db).kind(db)
}

/// Returns `ingot` in which this trait is defined.
pub(crate) fn ingot(self, db: &'db dyn HirAnalysisDb) -> IngotId {
pub(crate) fn ingot(self, db: &'db dyn HirAnalysisDb) -> IngotId<'db> {
let hir_db = db.as_hir_db();
self.trait_(db).top_mod(hir_db).ingot(hir_db)
}

pub(super) fn super_traits(self, db: &'db dyn HirAnalysisDb) -> &IndexSet<Binder<TraitInstId>> {
pub(super) fn super_traits(
self,
db: &'db dyn HirAnalysisDb,
) -> &'db IndexSet<Binder<TraitInstId<'db>>> {
use std::sync::OnceLock;
static EMPTY: OnceLock<IndexSet<Binder<TraitInstId>>> = OnceLock::new();

Expand Down
104 changes: 52 additions & 52 deletions crates/hir-analysis/src/ty/ty_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,58 @@ struct TyCheckerFinalizer<'db> {
diags: Vec<FuncBodyDiag<'db>>,
}

impl<'db> Visitor<'db> for TyCheckerFinalizer<'db> {
fn visit_pat(
&mut self,
ctxt: &mut VisitorCtxt<'db, LazyPatSpan<'db>>,
pat: PatId,
_: &Pat<'db>,
) {
let ty = self.body.pat_ty(self.db, pat);
let span = ctxt.span().unwrap();
self.check_unknown(ty, span.clone().into());

walk_pat(self, ctxt, pat)
}

fn visit_expr(
&mut self,
ctxt: &mut VisitorCtxt<'db, LazyExprSpan<'db>>,
expr: ExprId,
expr_data: &Expr<'db>,
) {
// Skip the check if the expr is block.
if !matches!(expr_data, Expr::Block(..)) {
let prop = self.body.expr_prop(self.db, expr);
let span = ctxt.span().unwrap();
self.check_unknown(prop.ty, span.clone().into());
if prop.binding.is_none() {
self.check_wf(prop.ty, span.into());
}
}

// We need this additional check for method call because the callable type is
// not tied to the expression type.
if let Expr::MethodCall(..) = expr_data {
if let Some(callable) = self.body.callable_expr(expr) {
let callable_ty = callable.ty(self.db);
let span = ctxt.span().unwrap().into_method_call_expr().method_name();
self.check_unknown(callable_ty, span.clone().into());
self.check_wf(callable_ty, span.into())
}
}

walk_expr(self, ctxt, expr);
}

fn visit_item(
&mut self,
_: &mut VisitorCtxt<'db, hir::visitor::prelude::LazyItemSpan<'db>>,
_: hir::hir_def::ItemKind<'db>,
) {
}
}

impl<'db> TyCheckerFinalizer<'db> {
fn new(mut checker: TyChecker<'db>) -> Self {
let assumptions = checker.env.assumptions();
Expand All @@ -306,58 +358,6 @@ impl<'db> TyCheckerFinalizer<'db> {
}

fn check_unknown_types(&mut self) {
impl<'db> Visitor<'db> for TyCheckerFinalizer<'db> {
fn visit_pat(
&mut self,
ctxt: &mut VisitorCtxt<'db, LazyPatSpan<'db>>,
pat: PatId,
_: &Pat<'db>,
) {
let ty = self.body.pat_ty(self.db, pat);
let span = ctxt.span().unwrap();
self.check_unknown(ty, span.clone().into());

walk_pat(self, ctxt, pat)
}

fn visit_expr(
&mut self,
ctxt: &mut VisitorCtxt<'db, LazyExprSpan<'db>>,
expr: ExprId,
expr_data: &Expr<'db>,
) {
// Skip the check if the expr is block.
if !matches!(expr_data, Expr::Block(..)) {
let prop = self.body.expr_prop(self.db, expr);
let span = ctxt.span().unwrap();
self.check_unknown(prop.ty, span.clone().into());
if prop.binding.is_none() {
self.check_wf(prop.ty, span.into());
}
}

// We need this additional check for method call because the callable type is
// not tied to the expression type.
if let Expr::MethodCall(..) = expr_data {
if let Some(callable) = self.body.callable_expr(expr) {
let callable_ty = callable.ty(self.db);
let span = ctxt.span().unwrap().into_method_call_expr().method_name();
self.check_unknown(callable_ty, span.clone().into());
self.check_wf(callable_ty, span.into())
}
}

walk_expr(self, ctxt, expr);
}

fn visit_item(
&mut self,
_: &mut VisitorCtxt<'db, hir::visitor::prelude::LazyItemSpan<'db>>,
_: hir::hir_def::ItemKind<'db>,
) {
}
}

if let Some(body) = self.body.body {
let mut ctxt = VisitorCtxt::with_body(self.db.as_hir_db(), body);
self.visit_body(&mut ctxt, body);
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-analysis/src/ty/ty_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<'db> TyId<'db> {
!matches!(self.kind(db), Kind::Abs(_, _))
}

pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> &str {
pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> &'db str {
pretty_print_ty(db, self)
}

Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'db> TyId<'db> {
}

/// Returns the property of the type that can be applied to the `self`.
pub fn applicable_ty(self, db: &'db dyn HirAnalysisDb) -> Option<ApplicableTyProp> {
pub fn applicable_ty(self, db: &'db dyn HirAnalysisDb) -> Option<ApplicableTyProp<'db>> {
let applicable_kind = match self.kind(db) {
Kind::Star => return None,
Kind::Abs(arg, _) => *arg.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-analysis/src/ty/ty_lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ pub struct GenericParamTypeSet<'db> {
}

impl<'db> GenericParamTypeSet<'db> {
pub(crate) fn params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub(crate) fn params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
evaluate_params_precursor(db, self)
}

pub(crate) fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
pub(crate) fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
let offset = self.offset_to_explicit(db);
&self.params(db)[offset..]
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-analysis/tests/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl HirAnalysisTestDb {
&'db self,
prop_formatter: &mut HirPropertyFormatter<'db>,
input_file: InputFile,
) -> TopLevelMod {
) -> TopLevelMod<'db> {
let top_mod = lower::map_file_to_mod(self, input_file);
let path = input_file.path(self);
let text = input_file.text(self);
Expand Down
Loading

0 comments on commit d400186

Please sign in to comment.