diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index b479a20beb..509b158184 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -257,26 +257,20 @@ fn is_named_constructor( }?; let expr = match expr { ast::Expr::CallExpr(call) => match call.expr()? { - ast::Expr::PathExpr(p) => p, + ast::Expr::PathExpr(path) => path, _ => return None, }, + ast::Expr::PathExpr(path) => path, _ => return None, }; let path = expr.path()?; - // Check for tuple-struct or tuple-variant in which case we can check the last segment - let callable = sema.type_of_expr(&ast::Expr::PathExpr(expr))?.original.as_callable(sema.db); - let callable_kind = callable.map(|it| it.kind()); - if let Some(hir::CallableKind::TupleStruct(_) | hir::CallableKind::TupleEnumVariant(_)) = - callable_kind - { - if let Some(ctor) = path.segment() { - return (ctor.to_string() == ty_name).then(|| ()); - } - } - - // otherwise use the qualifying segment as the constructor name - let qual_seg = path.qualifier()?.segment()?; + // If it exists, use qualifying segment as the constructor name. + // If not, use the last segment. + let qual_seg = match path.qualifier() { + Some(qual) => qual.segment(), + None => path.segment(), + }?; let ctor_name = match qual_seg.kind()? { ast::PathSegmentKind::Name(name_ref) => { match qual_seg.generic_arg_list().map(|it| it.generic_args()) { @@ -1341,7 +1335,7 @@ fn main() { } #[test] - fn skip_constructor_type_hints() { + fn skip_constructor_and_enum_type_hints() { check_with_config( InlayHintsConfig { type_hints: true, @@ -1351,7 +1345,7 @@ fn main() { max_length: None, }, r#" -//- minicore: try +//- minicore: try, option use core::ops::ControlFlow; struct Struct; @@ -1373,13 +1367,37 @@ impl Generic { } } +enum Enum { + Variant(u32) +} + +fn times2(value: i32) -> i32 { + 2 * value +} + fn main() { + let enumb = Enum::Variant(0); + + let strukt = Struct; let strukt = Struct::new(); + let tuple_struct = TupleStruct(); + let generic0 = Generic::new(); - // ^^^^^^^^ Generic - let generic1 = Generic::::new(); - let generic2 = >::new(); + // ^^^^^^^^ Generic + let generic1 = Generic(0); + // ^^^^^^^^ Generic + let generic2 = Generic::::new(); + let generic3 = >::new(); + let generic4 = Generic::(0); + + + let option = Some(0); + // ^^^^^^ Option + let func = times2; + // ^^^^ fn times2(i32) -> i32 + let closure = |x: i32| x * 2; + // ^^^^^^^ |i32| -> i32 } fn fallible() -> ControlFlow<()> {