File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -237,9 +237,15 @@ pub(super) fn keyword(
237237 if !token. kind ( ) . is_keyword ( ) || !config. documentation . is_some ( ) {
238238 return None ;
239239 }
240- let famous_defs = FamousDefs ( sema, sema. scope ( & token. parent ( ) ?) . krate ( ) ) ;
241- // std exposes {}_keyword modules with docstrings on the root to document keywords
242- let keyword_mod = format ! ( "{}_keyword" , token. text( ) ) ;
240+ let parent = token. parent ( ) ?;
241+ let famous_defs = FamousDefs ( sema, sema. scope ( & parent) . krate ( ) ) ;
242+ let keyword_mod = if token. kind ( ) == T ! [ fn ] && ast:: FnPtrType :: cast ( parent) . is_some ( ) {
243+ // treat fn keyword inside function pointer type as primitive
244+ format ! ( "prim_{}" , token. text( ) )
245+ } else {
246+ // std exposes {}_keyword modules with docstrings on the root to document keywords
247+ format ! ( "{}_keyword" , token. text( ) )
248+ } ;
243249 let doc_owner = find_std_module ( & famous_defs, & keyword_mod) ?;
244250 let docs = doc_owner. attrs ( sema. db ) . docs ( ) ?;
245251 let markup = process_markup (
Original file line number Diff line number Diff line change @@ -3382,6 +3382,30 @@ mod return_keyword {}
33823382 ) ;
33833383}
33843384
3385+ #[ test]
3386+ fn hover_keyword_as_primitive ( ) {
3387+ check (
3388+ r#"
3389+ //- /main.rs crate:main deps:std
3390+ type F = f$0n(i32) -> i32;
3391+ //- /libstd.rs crate:std
3392+ /// Docs for prim_fn
3393+ mod prim_fn {}
3394+ "# ,
3395+ expect ! [ [ r#"
3396+ *fn*
3397+
3398+ ```rust
3399+ fn
3400+ ```
3401+
3402+ ---
3403+
3404+ Docs for prim_fn
3405+ "# ] ] ,
3406+ ) ;
3407+ }
3408+
33853409#[ test]
33863410fn hover_builtin ( ) {
33873411 check (
You can’t perform that action at this time.
0 commit comments