Skip to content

Commit b48a1ae

Browse files
committed
Auto merge of rust-lang#13822 - WaffleLapkin:famous, r=Veykril
internal: Pass `FamousDefs` around in inlay hints Bind after at go brrrrr
2 parents eb3963b + ef4c816 commit b48a1ae

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ impl InlayHintLabelBuilder<'_> {
232232
}
233233

234234
fn label_of_ty(
235-
sema: &Semantics<'_, RootDatabase>,
236-
desc_pat: &impl AstNode,
235+
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
237236
config: &InlayHintsConfig,
238237
ty: hir::Type,
239238
) -> Option<InlayHintLabel> {
@@ -263,8 +262,6 @@ fn label_of_ty(
263262
};
264263
}
265264

266-
let krate = sema.scope(desc_pat.syntax())?.krate();
267-
let famous_defs = FamousDefs(sema, krate);
268265
let mut label_builder = InlayHintLabelBuilder {
269266
db: sema.db,
270267
last_part: String::new(),
@@ -329,7 +326,7 @@ pub(crate) fn inlay_hints(
329326

330327
fn hints(
331328
hints: &mut Vec<InlayHint>,
332-
FamousDefs(sema, _): &FamousDefs<'_, '_>,
329+
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
333330
config: &InlayHintsConfig,
334331
file_id: FileId,
335332
node: SyntaxNode,
@@ -338,14 +335,14 @@ fn hints(
338335
match_ast! {
339336
match node {
340337
ast::Expr(expr) => {
341-
chaining::hints(hints, sema, config, file_id, &expr);
338+
chaining::hints(hints, famous_defs, config, file_id, &expr);
342339
adjustment::hints(hints, sema, config, &expr);
343340
match expr {
344341
ast::Expr::CallExpr(it) => param_name::hints(hints, sema, config, ast::Expr::from(it)),
345342
ast::Expr::MethodCallExpr(it) => {
346343
param_name::hints(hints, sema, config, ast::Expr::from(it))
347344
}
348-
ast::Expr::ClosureExpr(it) => closure_ret::hints(hints, sema, config, file_id, it),
345+
ast::Expr::ClosureExpr(it) => closure_ret::hints(hints, famous_defs, config, file_id, it),
349346
// We could show reborrows for all expressions, but usually that is just noise to the user
350347
// and the main point here is to show why "moving" a mutable reference doesn't necessarily move it
351348
// ast::Expr::PathExpr(_) => reborrow_hints(hints, sema, config, &expr),
@@ -355,7 +352,7 @@ fn hints(
355352
ast::Pat(it) => {
356353
binding_mode::hints(hints, sema, config, &it);
357354
if let ast::Pat::IdentPat(it) = it {
358-
bind_pat::hints(hints, sema, config, file_id, &it);
355+
bind_pat::hints(hints, famous_defs, config, file_id, &it);
359356
}
360357
Some(())
361358
},

crates/ide/src/inlay_hints/bind_pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! let _x /* i32 */= f(4, 4);
55
//! ```
66
use hir::{Semantics, TypeInfo};
7-
use ide_db::{base_db::FileId, RootDatabase};
7+
use ide_db::{base_db::FileId, famous_defs::FamousDefs, RootDatabase};
88

99
use itertools::Itertools;
1010
use syntax::{
@@ -20,7 +20,7 @@ use super::label_of_ty;
2020

2121
pub(super) fn hints(
2222
acc: &mut Vec<InlayHint>,
23-
sema: &Semantics<'_, RootDatabase>,
23+
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
2424
config: &InlayHintsConfig,
2525
file_id: FileId,
2626
pat: &ast::IdentPat,
@@ -37,7 +37,7 @@ pub(super) fn hints(
3737
return None;
3838
}
3939

40-
let label = label_of_ty(sema, desc_pat, config, ty)?;
40+
let label = label_of_ty(famous_defs, config, ty)?;
4141

4242
if config.hide_named_constructor_hints
4343
&& is_named_constructor(sema, pat, &label.to_string()).is_some()

crates/ide/src/inlay_hints/chaining.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Implementation of "chaining" inlay hints.
2-
use hir::Semantics;
3-
use ide_db::RootDatabase;
2+
use ide_db::famous_defs::FamousDefs;
43
use syntax::{
54
ast::{self, AstNode},
65
Direction, NodeOrToken, SyntaxKind, T,
@@ -12,7 +11,7 @@ use super::label_of_ty;
1211

1312
pub(super) fn hints(
1413
acc: &mut Vec<InlayHint>,
15-
sema: &Semantics<'_, RootDatabase>,
14+
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
1615
config: &InlayHintsConfig,
1716
file_id: FileId,
1817
expr: &ast::Expr,
@@ -61,7 +60,7 @@ pub(super) fn hints(
6160
acc.push(InlayHint {
6261
range: expr.syntax().text_range(),
6362
kind: InlayKind::ChainingHint,
64-
label: label_of_ty(sema, desc_expr, config, ty)?,
63+
label: label_of_ty(famous_defs, config, ty)?,
6564
tooltip: Some(InlayTooltip::HoverRanged(file_id, expr.syntax().text_range())),
6665
});
6766
}

crates/ide/src/inlay_hints/closure_ret.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Implementation of "closure return type" inlay hints.
2-
use hir::Semantics;
3-
use ide_db::{base_db::FileId, RootDatabase};
2+
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
43
use syntax::ast::{self, AstNode};
54

65
use crate::{
@@ -12,7 +11,7 @@ use super::label_of_ty;
1211

1312
pub(super) fn hints(
1413
acc: &mut Vec<InlayHint>,
15-
sema: &Semantics<'_, RootDatabase>,
14+
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
1615
config: &InlayHintsConfig,
1716
file_id: FileId,
1817
closure: ast::ClosureExpr,
@@ -43,7 +42,7 @@ pub(super) fn hints(
4342
acc.push(InlayHint {
4443
range: param_list.syntax().text_range(),
4544
kind: InlayKind::ClosureReturnTypeHint,
46-
label: label_of_ty(sema, &param_list, config, ty)?,
45+
label: label_of_ty(famous_defs, config, ty)?,
4746
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
4847
});
4948
Some(())

0 commit comments

Comments
 (0)