@@ -257,26 +257,23 @@ fn is_named_constructor(
257257 } ?;
258258 let expr = match expr {
259259 ast:: Expr :: CallExpr ( call) => match call. expr ( ) ? {
260- ast:: Expr :: PathExpr ( p ) => p ,
260+ ast:: Expr :: PathExpr ( path ) => path ,
261261 _ => return None ,
262262 } ,
263+ ast:: Expr :: PathExpr ( path) => path,
263264 _ => return None ,
264265 } ;
265266 let path = expr. path ( ) ?;
266267
267- // Check for tuple-struct or tuple-variant in which case we can check the last segment
268268 let callable = sema. type_of_expr ( & ast:: Expr :: PathExpr ( expr) ) ?. original . as_callable ( sema. db ) ;
269269 let callable_kind = callable. map ( |it| it. kind ( ) ) ;
270- if let Some ( hir:: CallableKind :: TupleStruct ( _) | hir:: CallableKind :: TupleEnumVariant ( _) ) =
271- callable_kind
272- {
273- if let Some ( ctor) = path. segment ( ) {
274- return ( ctor. to_string ( ) == ty_name) . then ( || ( ) ) ;
270+ let qual_seg = match callable_kind {
271+ Some ( hir:: CallableKind :: Function ( _) | hir:: CallableKind :: TupleEnumVariant ( _) ) => {
272+ path. qualifier ( ) ?. segment ( )
275273 }
276- }
274+ _ => path. segment ( ) ,
275+ } ?;
277276
278- // otherwise use the qualifying segment as the constructor name
279- let qual_seg = path. qualifier ( ) ?. segment ( ) ?;
280277 let ctor_name = match qual_seg. kind ( ) ? {
281278 ast:: PathSegmentKind :: Name ( name_ref) => {
282279 match qual_seg. generic_arg_list ( ) . map ( |it| it. generic_args ( ) ) {
@@ -1341,7 +1338,7 @@ fn main() {
13411338 }
13421339
13431340 #[ test]
1344- fn skip_constructor_type_hints ( ) {
1341+ fn skip_constructor_and_enum_type_hints ( ) {
13451342 check_with_config (
13461343 InlayHintsConfig {
13471344 type_hints : true ,
@@ -1351,9 +1348,16 @@ fn main() {
13511348 max_length : None ,
13521349 } ,
13531350 r#"
1354- //- minicore: try
1351+ //- minicore: try, option
13551352use core::ops::ControlFlow;
13561353
1354+ mod x {
1355+ pub mod y { pub struct Foo; }
1356+ pub struct Foo;
1357+ pub enum AnotherEnum {
1358+ Variant()
1359+ };
1360+ }
13571361struct Struct;
13581362struct TupleStruct();
13591363
@@ -1373,13 +1377,39 @@ impl Generic<i32> {
13731377 }
13741378}
13751379
1380+ enum Enum {
1381+ Variant(u32)
1382+ }
1383+
1384+ fn times2(value: i32) -> i32 {
1385+ 2 * value
1386+ }
1387+
13761388fn main() {
1389+ let enumb = Enum::Variant(0);
1390+
1391+ let strukt = x::Foo;
1392+ let strukt = x::y::Foo;
1393+ let strukt = Struct;
13771394 let strukt = Struct::new();
1395+
13781396 let tuple_struct = TupleStruct();
1397+
13791398 let generic0 = Generic::new();
1380- // ^^^^^^^^ Generic<i32>
1381- let generic1 = Generic::<i32>::new();
1382- let generic2 = <Generic<i32>>::new();
1399+ // ^^^^^^^^ Generic<i32>
1400+ let generic1 = Generic(0);
1401+ // ^^^^^^^^ Generic<i32>
1402+ let generic2 = Generic::<i32>::new();
1403+ let generic3 = <Generic<i32>>::new();
1404+ let generic4 = Generic::<i32>(0);
1405+
1406+
1407+ let option = Some(0);
1408+ // ^^^^^^ Option<i32>
1409+ let func = times2;
1410+ // ^^^^ fn times2(i32) -> i32
1411+ let closure = |x: i32| x * 2;
1412+ // ^^^^^^^ |i32| -> i32
13831413}
13841414
13851415fn fallible() -> ControlFlow<()> {
0 commit comments