Skip to content

Commit f0f4ac8

Browse files
committed
more fixes for clippy
1 parent b116b92 commit f0f4ac8

File tree

20 files changed

+138
-122
lines changed

20 files changed

+138
-122
lines changed

crates/common/src/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
22
use std::panic;
33

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

1818
eprintln!();

crates/hir-analysis/src/ty/adt_def.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ impl<'db> AdtDef<'db> {
3939
self.adt_ref(db).name(db)
4040
}
4141

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

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

@@ -202,7 +202,7 @@ impl<'db> AdtRefId<'db> {
202202
pub(crate) fn generic_owner_id(
203203
self,
204204
db: &'db dyn HirAnalysisDb,
205-
) -> Option<GenericParamOwnerId> {
205+
) -> Option<GenericParamOwnerId<'db>> {
206206
match self.data(db) {
207207
AdtRef::Enum(e) => Some(GenericParamOwnerId::new(db, e.into())),
208208
AdtRef::Struct(s) => Some(GenericParamOwnerId::new(db, s.into())),

crates/hir-analysis/src/ty/def_analysis.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ enum DefKind<'db> {
989989
}
990990

991991
impl<'db> DefKind<'db> {
992-
fn original_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
992+
fn original_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
993993
match self {
994994
Self::Adt(def) => def.original_params(db),
995995
Self::Trait(def) => def.original_params(db),
@@ -1009,7 +1009,10 @@ impl<'db> DefKind<'db> {
10091009
}
10101010
}
10111011

1012-
fn collect_super_trait_cycle(self, db: &'db dyn HirAnalysisDb) -> Option<&SuperTraitCycle> {
1012+
fn collect_super_trait_cycle(
1013+
self,
1014+
db: &'db dyn HirAnalysisDb,
1015+
) -> Option<&'db SuperTraitCycle<'db>> {
10131016
if let Self::Trait(def) = self {
10141017
collect_super_traits(db, def).as_ref().err()
10151018
} else {

crates/hir-analysis/src/ty/func_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ impl<'db> FuncDef<'db> {
8383
self.hir_def(db).scope()
8484
}
8585

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

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

crates/hir-analysis/src/ty/trait_def.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'db> Implementor<'db> {
191191
self.trait_(db).def(db)
192192
}
193193

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

@@ -209,7 +209,7 @@ impl<'db> Implementor<'db> {
209209
pub(super) fn methods(
210210
self,
211211
db: &'db dyn HirAnalysisDb,
212-
) -> &IndexMap<IdentId<'db>, FuncDef<'db>> {
212+
) -> &'db IndexMap<IdentId<'db>, FuncDef<'db>> {
213213
collect_implementor_methods(db, self)
214214
}
215215
}
@@ -299,15 +299,15 @@ pub struct TraitDef<'db> {
299299
}
300300

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

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

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

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

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

340-
pub(super) fn super_traits(self, db: &'db dyn HirAnalysisDb) -> &IndexSet<Binder<TraitInstId>> {
340+
pub(super) fn super_traits(
341+
self,
342+
db: &'db dyn HirAnalysisDb,
343+
) -> &'db IndexSet<Binder<TraitInstId<'db>>> {
341344
use std::sync::OnceLock;
342345
static EMPTY: OnceLock<IndexSet<Binder<TraitInstId>>> = OnceLock::new();
343346

crates/hir-analysis/src/ty/ty_check/mod.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,58 @@ struct TyCheckerFinalizer<'db> {
286286
diags: Vec<FuncBodyDiag<'db>>,
287287
}
288288

289+
impl<'db> Visitor<'db> for TyCheckerFinalizer<'db> {
290+
fn visit_pat(
291+
&mut self,
292+
ctxt: &mut VisitorCtxt<'db, LazyPatSpan<'db>>,
293+
pat: PatId,
294+
_: &Pat<'db>,
295+
) {
296+
let ty = self.body.pat_ty(self.db, pat);
297+
let span = ctxt.span().unwrap();
298+
self.check_unknown(ty, span.clone().into());
299+
300+
walk_pat(self, ctxt, pat)
301+
}
302+
303+
fn visit_expr(
304+
&mut self,
305+
ctxt: &mut VisitorCtxt<'db, LazyExprSpan<'db>>,
306+
expr: ExprId,
307+
expr_data: &Expr<'db>,
308+
) {
309+
// Skip the check if the expr is block.
310+
if !matches!(expr_data, Expr::Block(..)) {
311+
let prop = self.body.expr_prop(self.db, expr);
312+
let span = ctxt.span().unwrap();
313+
self.check_unknown(prop.ty, span.clone().into());
314+
if prop.binding.is_none() {
315+
self.check_wf(prop.ty, span.into());
316+
}
317+
}
318+
319+
// We need this additional check for method call because the callable type is
320+
// not tied to the expression type.
321+
if let Expr::MethodCall(..) = expr_data {
322+
if let Some(callable) = self.body.callable_expr(expr) {
323+
let callable_ty = callable.ty(self.db);
324+
let span = ctxt.span().unwrap().into_method_call_expr().method_name();
325+
self.check_unknown(callable_ty, span.clone().into());
326+
self.check_wf(callable_ty, span.into())
327+
}
328+
}
329+
330+
walk_expr(self, ctxt, expr);
331+
}
332+
333+
fn visit_item(
334+
&mut self,
335+
_: &mut VisitorCtxt<'db, hir::visitor::prelude::LazyItemSpan<'db>>,
336+
_: hir::hir_def::ItemKind<'db>,
337+
) {
338+
}
339+
}
340+
289341
impl<'db> TyCheckerFinalizer<'db> {
290342
fn new(mut checker: TyChecker<'db>) -> Self {
291343
let assumptions = checker.env.assumptions();
@@ -306,58 +358,6 @@ impl<'db> TyCheckerFinalizer<'db> {
306358
}
307359

308360
fn check_unknown_types(&mut self) {
309-
impl<'db> Visitor<'db> for TyCheckerFinalizer<'db> {
310-
fn visit_pat(
311-
&mut self,
312-
ctxt: &mut VisitorCtxt<'db, LazyPatSpan<'db>>,
313-
pat: PatId,
314-
_: &Pat<'db>,
315-
) {
316-
let ty = self.body.pat_ty(self.db, pat);
317-
let span = ctxt.span().unwrap();
318-
self.check_unknown(ty, span.clone().into());
319-
320-
walk_pat(self, ctxt, pat)
321-
}
322-
323-
fn visit_expr(
324-
&mut self,
325-
ctxt: &mut VisitorCtxt<'db, LazyExprSpan<'db>>,
326-
expr: ExprId,
327-
expr_data: &Expr<'db>,
328-
) {
329-
// Skip the check if the expr is block.
330-
if !matches!(expr_data, Expr::Block(..)) {
331-
let prop = self.body.expr_prop(self.db, expr);
332-
let span = ctxt.span().unwrap();
333-
self.check_unknown(prop.ty, span.clone().into());
334-
if prop.binding.is_none() {
335-
self.check_wf(prop.ty, span.into());
336-
}
337-
}
338-
339-
// We need this additional check for method call because the callable type is
340-
// not tied to the expression type.
341-
if let Expr::MethodCall(..) = expr_data {
342-
if let Some(callable) = self.body.callable_expr(expr) {
343-
let callable_ty = callable.ty(self.db);
344-
let span = ctxt.span().unwrap().into_method_call_expr().method_name();
345-
self.check_unknown(callable_ty, span.clone().into());
346-
self.check_wf(callable_ty, span.into())
347-
}
348-
}
349-
350-
walk_expr(self, ctxt, expr);
351-
}
352-
353-
fn visit_item(
354-
&mut self,
355-
_: &mut VisitorCtxt<'db, hir::visitor::prelude::LazyItemSpan<'db>>,
356-
_: hir::hir_def::ItemKind<'db>,
357-
) {
358-
}
359-
}
360-
361361
if let Some(body) = self.body.body {
362362
let mut ctxt = VisitorCtxt::with_body(self.db.as_hir_db(), body);
363363
self.visit_body(&mut ctxt, body);

crates/hir-analysis/src/ty/ty_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'db> TyId<'db> {
127127
!matches!(self.kind(db), Kind::Abs(_, _))
128128
}
129129

130-
pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> &str {
130+
pub fn pretty_print(self, db: &'db dyn HirAnalysisDb) -> &'db str {
131131
pretty_print_ty(db, self)
132132
}
133133

@@ -477,7 +477,7 @@ impl<'db> TyId<'db> {
477477
}
478478

479479
/// Returns the property of the type that can be applied to the `self`.
480-
pub fn applicable_ty(self, db: &'db dyn HirAnalysisDb) -> Option<ApplicableTyProp> {
480+
pub fn applicable_ty(self, db: &'db dyn HirAnalysisDb) -> Option<ApplicableTyProp<'db>> {
481481
let applicable_kind = match self.kind(db) {
482482
Kind::Star => return None,
483483
Kind::Abs(arg, _) => *arg.clone(),

crates/hir-analysis/src/ty/ty_lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ pub struct GenericParamTypeSet<'db> {
428428
}
429429

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

435-
pub(crate) fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &[TyId<'db>] {
435+
pub(crate) fn explicit_params(self, db: &'db dyn HirAnalysisDb) -> &'db [TyId<'db>] {
436436
let offset = self.offset_to_explicit(db);
437437
&self.params(db)[offset..]
438438
}

crates/hir-analysis/tests/test_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl HirAnalysisTestDb {
7373
&'db self,
7474
prop_formatter: &mut HirPropertyFormatter<'db>,
7575
input_file: InputFile,
76-
) -> TopLevelMod {
76+
) -> TopLevelMod<'db> {
7777
let top_mod = lower::map_file_to_mod(self, input_file);
7878
let path = input_file.path(self);
7979
let text = input_file.text(self);

0 commit comments

Comments
 (0)