@@ -257,26 +257,23 @@ fn is_named_constructor(
257
257
} ?;
258
258
let expr = match expr {
259
259
ast:: Expr :: CallExpr ( call) => match call. expr ( ) ? {
260
- ast:: Expr :: PathExpr ( p ) => p ,
260
+ ast:: Expr :: PathExpr ( path ) => path ,
261
261
_ => return None ,
262
262
} ,
263
+ ast:: Expr :: PathExpr ( path) => path,
263
264
_ => return None ,
264
265
} ;
265
266
let path = expr. path ( ) ?;
266
267
267
- // Check for tuple-struct or tuple-variant in which case we can check the last segment
268
268
let callable = sema. type_of_expr ( & ast:: Expr :: PathExpr ( expr) ) ?. original . as_callable ( sema. db ) ;
269
269
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 ( )
275
273
}
276
- }
274
+ _ => path. segment ( ) ,
275
+ } ?;
277
276
278
- // otherwise use the qualifying segment as the constructor name
279
- let qual_seg = path. qualifier ( ) ?. segment ( ) ?;
280
277
let ctor_name = match qual_seg. kind ( ) ? {
281
278
ast:: PathSegmentKind :: Name ( name_ref) => {
282
279
match qual_seg. generic_arg_list ( ) . map ( |it| it. generic_args ( ) ) {
@@ -1341,7 +1338,7 @@ fn main() {
1341
1338
}
1342
1339
1343
1340
#[ test]
1344
- fn skip_constructor_type_hints ( ) {
1341
+ fn skip_constructor_and_enum_type_hints ( ) {
1345
1342
check_with_config (
1346
1343
InlayHintsConfig {
1347
1344
type_hints : true ,
@@ -1351,9 +1348,16 @@ fn main() {
1351
1348
max_length : None ,
1352
1349
} ,
1353
1350
r#"
1354
- //- minicore: try
1351
+ //- minicore: try, option
1355
1352
use core::ops::ControlFlow;
1356
1353
1354
+ mod x {
1355
+ pub mod y { pub struct Foo; }
1356
+ pub struct Foo;
1357
+ pub enum AnotherEnum {
1358
+ Variant()
1359
+ };
1360
+ }
1357
1361
struct Struct;
1358
1362
struct TupleStruct();
1359
1363
@@ -1373,13 +1377,39 @@ impl Generic<i32> {
1373
1377
}
1374
1378
}
1375
1379
1380
+ enum Enum {
1381
+ Variant(u32)
1382
+ }
1383
+
1384
+ fn times2(value: i32) -> i32 {
1385
+ 2 * value
1386
+ }
1387
+
1376
1388
fn main() {
1389
+ let enumb = Enum::Variant(0);
1390
+
1391
+ let strukt = x::Foo;
1392
+ let strukt = x::y::Foo;
1393
+ let strukt = Struct;
1377
1394
let strukt = Struct::new();
1395
+
1378
1396
let tuple_struct = TupleStruct();
1397
+
1379
1398
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
1383
1413
}
1384
1414
1385
1415
fn fallible() -> ControlFlow<()> {
0 commit comments