Skip to content

Commit 8afa272

Browse files
committed
Revise TypeInfo::ty usage
1 parent 25ff717 commit 8afa272

18 files changed

+30
-29
lines changed

crates/hir/src/semantics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ impl TypeInfo {
100100
self.ty
101101
}
102102

103-
pub fn coerced(self) -> Option<Type> {
104-
self.coerced
103+
pub fn has_coercion(&self) -> bool {
104+
self.coerced.is_some()
105105
}
106106

107-
pub fn coerced_or_original(self) -> Type {
107+
pub fn coerced(self) -> Type {
108108
self.coerced.unwrap_or(self.ty)
109109
}
110110
}

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn highlight_method_call(
555555
if let Some(receiver_ty) =
556556
method_call.receiver().and_then(|it| sema.type_of_expr(&it))
557557
{
558-
if !receiver_ty.ty.is_copy(sema.db) {
558+
if !receiver_ty.coerced().is_copy(sema.db) {
559559
h |= HlMod::Consuming
560560
}
561561
}

crates/ide_assists/src/handlers/add_explicit_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
5757
(ast::Pat::IdentPat(_), Some(expr)) => ctx.sema.type_of_expr(&expr)?,
5858
(pat, _) => ctx.sema.type_of_pat(&pat)?,
5959
}
60-
.coerced_or_original();
60+
.coerced();
6161

6262
// Unresolved or unnameable types can't be annotated
6363
if ty.contains_unknown() || ty.is_closure() {

crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn validate_method_call_expr(
8686
let receiver = expr.receiver()?;
8787
let expr = ast::Expr::MethodCallExpr(expr);
8888

89-
let it_type = sema.type_of_expr(&receiver)?.ty;
89+
let it_type = sema.type_of_expr(&receiver)?.coerced();
9090
let module = sema.scope(receiver.syntax()).module()?;
9191
let krate = module.krate();
9292

crates/ide_assists/src/handlers/extract_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl FlowKind {
345345
FlowKind::Return(Some(expr))
346346
| FlowKind::Break(Some(expr))
347347
| FlowKind::TryReturn { expr, .. } => {
348-
ctx.sema.type_of_expr(expr).map(TypeInfo::coerced_or_original)
348+
ctx.sema.type_of_expr(expr).map(TypeInfo::coerced)
349349
}
350350
FlowKind::Try { .. } => {
351351
stdx::never!("try does not have defined expr_ty");

crates/ide_assists/src/handlers/extract_variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
4040
.take_while(|it| it.text_range().contains_range(ctx.frange.range))
4141
.find_map(valid_target_expr)?;
4242
if let Some(ty_info) = ctx.sema.type_of_expr(&to_extract) {
43-
if ty_info.ty.is_unit() {
43+
if ty_info.coerced().is_unit() {
4444
return None;
4545
}
4646
}

crates/ide_assists/src/handlers/fill_match_arms.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl ExtendedEnum {
223223
}
224224

225225
fn resolve_enum_def(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<ExtendedEnum> {
226-
sema.type_of_expr(expr)?.ty.autoderef(sema.db).find_map(|ty| match ty.as_adt() {
226+
sema.type_of_expr(expr)?.coerced().autoderef(sema.db).find_map(|ty| match ty.as_adt() {
227227
Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)),
228228
_ => ty.is_bool().then(|| ExtendedEnum::Bool),
229229
})
@@ -234,7 +234,7 @@ fn resolve_tuple_of_enum_def(
234234
expr: &ast::Expr,
235235
) -> Option<Vec<ExtendedEnum>> {
236236
sema.type_of_expr(expr)?
237-
.ty
237+
.coerced()
238238
.tuple_fields(sema.db)
239239
.iter()
240240
.map(|ty| {

crates/ide_assists/src/handlers/generate_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn fn_arg_type(
331331
target_module: hir::Module,
332332
fn_arg: &ast::Expr,
333333
) -> Option<String> {
334-
let ty = ctx.sema.type_of_expr(fn_arg)?.ty;
334+
let ty = ctx.sema.type_of_expr(fn_arg)?.coerced();
335335
if ty.is_unknown() {
336336
return None;
337337
}

crates/ide_assists/src/handlers/infer_function_return_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
1818
pub(crate) fn infer_function_return_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
1919
let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?;
2020
let module = ctx.sema.scope(tail_expr.syntax()).module()?;
21-
let ty = ctx.sema.type_of_expr(&tail_expr)?.ty;
21+
let ty = ctx.sema.type_of_expr(&tail_expr)?.coerced();
2222
if ty.is_unit() {
2323
return None;
2424
}

crates/ide_assists/src/handlers/inline_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub(crate) fn inline_(
190190
let ty = ctx
191191
.sema
192192
.type_of_expr(&expr)
193-
.and_then(TypeInfo::coerced)
193+
.filter(TypeInfo::has_coercion)
194194
.and_then(|_| param_ty);
195195
body.push_front(
196196
make::let_stmt(pat, ty, Some(expr)).clone_for_update().into(),

0 commit comments

Comments
 (0)