@@ -257,26 +257,20 @@ 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
- let callable = sema. type_of_expr ( & ast:: Expr :: PathExpr ( expr) ) ?. original . as_callable ( sema. db ) ;
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 ( || ( ) ) ;
275
- }
276
- }
277
-
278
- // otherwise use the qualifying segment as the constructor name
279
- let qual_seg = path. qualifier ( ) ?. segment ( ) ?;
268
+ // If it exists, use qualifying segment as the constructor name.
269
+ // If not, use the last segment.
270
+ let qual_seg = match path. qualifier ( ) {
271
+ Some ( qual) => qual. segment ( ) ,
272
+ None => path. segment ( ) ,
273
+ } ?;
280
274
let ctor_name = match qual_seg. kind ( ) ? {
281
275
ast:: PathSegmentKind :: Name ( name_ref) => {
282
276
match qual_seg. generic_arg_list ( ) . map ( |it| it. generic_args ( ) ) {
@@ -1341,7 +1335,7 @@ fn main() {
1341
1335
}
1342
1336
1343
1337
#[ test]
1344
- fn skip_constructor_type_hints ( ) {
1338
+ fn skip_constructor_and_enum_type_hints ( ) {
1345
1339
check_with_config (
1346
1340
InlayHintsConfig {
1347
1341
type_hints : true ,
@@ -1351,7 +1345,7 @@ fn main() {
1351
1345
max_length : None ,
1352
1346
} ,
1353
1347
r#"
1354
- //- minicore: try
1348
+ //- minicore: try, option
1355
1349
use core::ops::ControlFlow;
1356
1350
1357
1351
struct Struct;
@@ -1373,13 +1367,37 @@ impl Generic<i32> {
1373
1367
}
1374
1368
}
1375
1369
1370
+ enum Enum {
1371
+ Variant(u32)
1372
+ }
1373
+
1374
+ fn times2(value: i32) -> i32 {
1375
+ 2 * value
1376
+ }
1377
+
1376
1378
fn main() {
1379
+ let enumb = Enum::Variant(0);
1380
+
1381
+ let strukt = Struct;
1377
1382
let strukt = Struct::new();
1383
+
1378
1384
let tuple_struct = TupleStruct();
1385
+
1379
1386
let generic0 = Generic::new();
1380
- // ^^^^^^^^ Generic<i32>
1381
- let generic1 = Generic::<i32>::new();
1382
- let generic2 = <Generic<i32>>::new();
1387
+ // ^^^^^^^^ Generic<i32>
1388
+ let generic1 = Generic(0);
1389
+ // ^^^^^^^^ Generic<i32>
1390
+ let generic2 = Generic::<i32>::new();
1391
+ let generic3 = <Generic<i32>>::new();
1392
+ let generic4 = Generic::<i32>(0);
1393
+
1394
+
1395
+ let option = Some(0);
1396
+ // ^^^^^^ Option<i32>
1397
+ let func = times2;
1398
+ // ^^^^ fn times2(i32) -> i32
1399
+ let closure = |x: i32| x * 2;
1400
+ // ^^^^^^^ |i32| -> i32
1383
1401
}
1384
1402
1385
1403
fn fallible() -> ControlFlow<()> {
0 commit comments