2 use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo};
4 base_db::{FileRange, SourceDatabase},
5 defs::{Definition, NameClass, NameRefClass},
7 generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES},
8 pick_best_token, try_resolve_derive_input_at, FamousDefs,
12 use itertools::Itertools;
15 algo, ast, display::fn_as_proc_macro_label, match_ast, AstNode, Direction, SyntaxKind::*,
16 SyntaxNode, SyntaxToken, T,
20 display::{macro_label, TryToNav},
22 doc_attributes, extract_definitions_from_docs, remove_links, resolve_doc_path_for_def,
25 markdown_remove::remove_markdown,
27 runnables::{runnable_fn, runnable_mod},
28 FileId, FilePosition, NavigationTarget, RangeInfo, Runnable,
31 #[derive(Clone, Debug, PartialEq, Eq)]
32 pub struct HoverConfig {
33 pub links_in_hover: bool,
34 pub documentation: Option<HoverDocFormat>,
38 fn markdown(&self) -> bool {
39 matches!(self.documentation, Some(HoverDocFormat::Markdown))
43 #[derive(Clone, Debug, PartialEq, Eq)]
44 pub enum HoverDocFormat {
49 #[derive(Debug, Clone)]
50 pub enum HoverAction {
52 Implementation(FilePosition),
53 Reference(FilePosition),
54 GoToType(Vec<HoverGotoTypeData>),
58 fn goto_type_from_targets(db: &RootDatabase, targets: Vec<hir::ModuleDef>) -> Self {
62 Some(HoverGotoTypeData {
63 mod_path: render_path(
66 it.name(db).map(|name| name.to_string()),
68 nav: it.try_to_nav(db)?,
72 HoverAction::GoToType(targets)
76 #[derive(Debug, Clone, Eq, PartialEq)]
77 pub struct HoverGotoTypeData {
79 pub nav: NavigationTarget,
82 /// Contains the results when hovering over an item
83 #[derive(Debug, Default)]
84 pub struct HoverResult {
86 pub actions: Vec<HoverAction>,
91 // Shows additional information, like the type of an expression or the documentation for a definition when "focusing" code.
92 // Focusing is usually hovering with a mouse, but can also be triggered with a shortcut.
94 // image::https://user-images.githubusercontent.com/48062697/113020658-b5f98b80-917a-11eb-9f88-3dbc27320c95.gif[]
97 FileRange { file_id, range }: FileRange,
99 ) -> Option<RangeInfo<HoverResult>> {
100 let sema = hir::Semantics::new(db);
101 let file = sema.parse(file_id).syntax().clone();
103 if !range.is_empty() {
104 return hover_ranged(&file, range, &sema, config);
106 let offset = range.start();
108 let token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
109 IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
110 T!['('] | T![')'] => 2,
111 kind if kind.is_trivia() => 0,
114 let token = sema.descend_into_macros(token);
115 let node = token.parent()?;
116 let mut range_override = None;
117 let definition = match_ast! {
119 ast::Name(name) => NameClass::classify(&sema, &name).map(|class| match class {
120 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
121 NameClass::PatFieldShorthand { local_def, field_ref: _ } => Definition::Local(local_def),
123 ast::NameRef(name_ref) => NameRefClass::classify(&sema, &name_ref).map(|class| match class {
124 NameRefClass::Definition(def) => def,
125 NameRefClass::FieldShorthand { local_ref: _, field_ref } => {
126 Definition::Field(field_ref)
129 ast::Lifetime(lifetime) => NameClass::classify_lifetime(&sema, &lifetime).map_or_else(
131 NameRefClass::classify_lifetime(&sema, &lifetime).and_then(|class| match class {
132 NameRefClass::Definition(it) => Some(it),
140 if token.kind() == COMMENT {
141 cov_mark::hit!(no_highlight_on_comment_hover);
142 let (attributes, def) = doc_attributes(&sema, &node)?;
143 let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
144 let (idl_range, link, ns) =
145 extract_definitions_from_docs(&docs).into_iter().find_map(|(range, link, ns)| {
146 let mapped = doc_mapping.map(range)?;
147 (mapped.file_id == file_id.into() && mapped.value.contains(offset)).then(||(mapped.value, link, ns))
149 range_override = Some(idl_range);
150 Some(match resolve_doc_path_for_def(db,def, &link,ns)? {
151 Either::Left(it) => Definition::ModuleDef(it),
152 Either::Right(it) => Definition::Macro(it),
154 // attributes, require special machinery as they are mere ident tokens
155 } else if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
157 if let res@Some(_) = try_hover_for_lint(&attr, &token) {
161 range_override = Some(token.text_range());
162 try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro)
171 if let Some(definition) = definition {
172 let famous_defs = match &definition {
173 Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) => {
174 Some(FamousDefs(&sema, sema.scope(&node).krate()))
178 if let Some(markup) = hover_for_definition(db, definition, famous_defs.as_ref(), config) {
179 let mut res = HoverResult::default();
180 res.markup = process_markup(sema.db, definition, &markup, config);
181 if let Some(action) = show_implementations_action(db, definition) {
182 res.actions.push(action);
185 if let Some(action) = show_fn_references_action(db, definition) {
186 res.actions.push(action);
189 if let Some(action) = runnable_action(&sema, definition, file_id) {
190 res.actions.push(action);
193 if let Some(action) = goto_type_action_for_def(db, definition) {
194 res.actions.push(action);
197 let range = range_override.unwrap_or_else(|| sema.original_range(&node).range);
198 return Some(RangeInfo::new(range, res));
202 if let res @ Some(_) = hover_for_keyword(&sema, config, &token) {
206 // No definition below cursor, fall back to showing type hovers.
210 .take_while(|it| !ast::Item::can_cast(it.kind()))
211 .find(|n| ast::Expr::can_cast(n.kind()) || ast::Pat::can_cast(n.kind()))?;
213 let expr_or_pat = match_ast! {
215 ast::Expr(it) => Either::Left(it),
216 ast::Pat(it) => Either::Right(it),
217 // If this node is a MACRO_CALL, it means that `descend_into_macros` failed to resolve.
218 // (e.g expanding a builtin macro). So we give up here.
219 ast::MacroCall(_it) => return None,
224 let res = hover_type_info(&sema, config, &expr_or_pat)?;
225 let range = sema.original_range(&node).range;
226 Some(RangeInfo::new(range, res))
231 range: syntax::TextRange,
232 sema: &Semantics<RootDatabase>,
233 config: &HoverConfig,
234 ) -> Option<RangeInfo<HoverResult>> {
235 let expr_or_pat = file.covering_element(range).ancestors().find_map(|it| {
238 ast::Expr(expr) => Some(Either::Left(expr)),
239 ast::Pat(pat) => Some(Either::Right(pat)),
244 let res = match &expr_or_pat {
245 Either::Left(ast::Expr::TryExpr(try_expr)) => hover_try_expr(sema, config, try_expr),
248 let res = res.or_else(|| hover_type_info(sema, config, &expr_or_pat));
250 let range = match expr_or_pat {
251 Either::Left(it) => it.syntax().text_range(),
252 Either::Right(it) => it.syntax().text_range(),
254 RangeInfo::new(range, it)
259 sema: &Semantics<RootDatabase>,
260 config: &HoverConfig,
261 try_expr: &ast::TryExpr,
262 ) -> Option<HoverResult> {
263 let inner_ty = sema.type_of_expr(&try_expr.expr()?)?.original;
264 let mut ancestors = try_expr.syntax().ancestors();
265 let mut body_ty = loop {
266 let next = ancestors.next()?;
269 ast::Fn(fn_) => sema.to_def(&fn_)?.ret_type(sema.db),
270 ast::Item(__) => return None,
271 ast::ClosureExpr(closure) => sema.type_of_expr(&closure.body()?)?.original,
272 ast::EffectExpr(effect) => if matches!(effect.effect(), ast::Effect::Async(_) | ast::Effect::Try(_)| ast::Effect::Const(_)) {
273 sema.type_of_expr(&effect.block_expr()?.into())?.original
282 if inner_ty == body_ty {
286 let mut inner_ty = inner_ty;
287 let mut s = "Try Target".to_owned();
289 let adts = inner_ty.as_adt().zip(body_ty.as_adt());
290 if let Some((hir::Adt::Enum(inner), hir::Adt::Enum(body))) = adts {
291 let famous_defs = FamousDefs(sema, sema.scope(&try_expr.syntax()).krate());
292 // special case for two options, there is no value in showing them
293 if let Some(option_enum) = famous_defs.core_option_Option() {
294 if inner == option_enum && body == option_enum {
295 cov_mark::hit!(hover_try_expr_opt_opt);
300 // special case two results to show the error variants only
301 if let Some(result_enum) = famous_defs.core_result_Result() {
302 if inner == result_enum && body == result_enum {
303 let error_type_args =
304 inner_ty.type_arguments().nth(1).zip(body_ty.type_arguments().nth(1));
305 if let Some((inner, body)) = error_type_args {
308 s = "Try Error".to_owned();
314 let mut res = HoverResult::default();
316 let mut targets: Vec<hir::ModuleDef> = Vec::new();
317 let mut push_new_def = |item: hir::ModuleDef| {
318 if !targets.contains(&item) {
322 walk_and_push_ty(sema.db, &inner_ty, &mut push_new_def);
323 walk_and_push_ty(sema.db, &body_ty, &mut push_new_def);
324 res.actions.push(HoverAction::goto_type_from_targets(sema.db, targets));
326 let inner_ty = inner_ty.display(sema.db).to_string();
327 let body_ty = body_ty.display(sema.db).to_string();
328 let ty_len_max = inner_ty.len().max(body_ty.len());
330 let l = "Propagated as: ".len() - " Type: ".len();
331 let static_text_len_diff = l as isize - s.len() as isize;
332 let tpad = static_text_len_diff.max(0) as usize;
333 let ppad = static_text_len_diff.min(0).abs() as usize;
335 res.markup = format!(
336 "{bt_start}{} Type: {:>pad0$}\nPropagated as: {:>pad1$}\n{bt_end}",
340 pad0 = ty_len_max + tpad,
341 pad1 = ty_len_max + ppad,
342 bt_start = if config.markdown() { "```text\n" } else { "" },
343 bt_end = if config.markdown() { "```\n" } else { "" }
350 sema: &Semantics<RootDatabase>,
351 config: &HoverConfig,
352 expr_or_pat: &Either<ast::Expr, ast::Pat>,
353 ) -> Option<HoverResult> {
354 let TypeInfo { original, adjusted } = match expr_or_pat {
355 Either::Left(expr) => sema.type_of_expr(expr)?,
356 Either::Right(pat) => sema.type_of_pat(pat)?,
359 let mut res = HoverResult::default();
360 let mut targets: Vec<hir::ModuleDef> = Vec::new();
361 let mut push_new_def = |item: hir::ModuleDef| {
362 if !targets.contains(&item) {
366 walk_and_push_ty(sema.db, &original, &mut push_new_def);
368 res.markup = if let Some(adjusted_ty) = adjusted {
369 walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
370 let original = original.display(sema.db).to_string();
371 let adjusted = adjusted_ty.display(sema.db).to_string();
372 let static_text_diff_len = "Coerced to: ".len() - "Type: ".len();
374 "{bt_start}Type: {:>apad$}\nCoerced to: {:>opad$}\n{bt_end}",
377 apad = static_text_diff_len + adjusted.len().max(original.len()),
378 opad = original.len(),
379 bt_start = if config.markdown() { "```text\n" } else { "" },
380 bt_end = if config.markdown() { "```\n" } else { "" }
384 if config.markdown() {
385 Markup::fenced_block(&original.display(sema.db))
387 original.display(sema.db).to_string().into()
390 res.actions.push(HoverAction::goto_type_from_targets(sema.db, targets));
394 fn try_hover_for_lint(attr: &ast::Attr, token: &SyntaxToken) -> Option<RangeInfo<HoverResult>> {
395 let (path, tt) = attr.as_simple_call()?;
396 if !tt.syntax().text_range().contains(token.text_range().start()) {
399 let (is_clippy, lints) = match &*path {
400 "feature" => (false, FEATURES),
401 "allow" | "deny" | "forbid" | "warn" => {
402 let is_clippy = algo::non_trivia_sibling(token.clone().into(), Direction::Prev)
403 .filter(|t| t.kind() == T![:])
404 .and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
405 .filter(|t| t.kind() == T![:])
406 .and_then(|t| algo::non_trivia_sibling(t, Direction::Prev))
408 t.kind() == T![ident] && t.into_token().map_or(false, |t| t.text() == "clippy")
413 (false, DEFAULT_LINTS)
420 let needle = if is_clippy {
421 tmp = format!("clippy::{}", token.text());
428 lints.binary_search_by_key(&needle, |lint| lint.label).ok().map(|idx| &lints[idx])?;
432 markup: Markup::from(format!("```\n{}\n```\n___\n\n{}", lint.label, lint.description)),
438 fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
439 fn to_action(nav_target: NavigationTarget) -> HoverAction {
440 HoverAction::Implementation(FilePosition {
441 file_id: nav_target.file_id,
442 offset: nav_target.focus_or_full_range().start(),
446 let adt = match def {
447 Definition::ModuleDef(hir::ModuleDef::Trait(it)) => {
448 return it.try_to_nav(db).map(to_action)
450 Definition::ModuleDef(hir::ModuleDef::Adt(it)) => Some(it),
451 Definition::SelfType(it) => it.self_ty(db).as_adt(),
454 adt.try_to_nav(db).map(to_action)
457 fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
459 Definition::ModuleDef(hir::ModuleDef::Function(it)) => {
460 it.try_to_nav(db).map(|nav_target| {
461 HoverAction::Reference(FilePosition {
462 file_id: nav_target.file_id,
463 offset: nav_target.focus_or_full_range().start(),
472 sema: &hir::Semantics<RootDatabase>,
475 ) -> Option<HoverAction> {
477 Definition::ModuleDef(it) => match it {
478 hir::ModuleDef::Module(it) => runnable_mod(sema, it).map(HoverAction::Runnable),
479 hir::ModuleDef::Function(func) => {
480 let src = func.source(sema.db)?;
481 if src.file_id != file_id.into() {
482 cov_mark::hit!(hover_macro_generated_struct_fn_doc_comment);
483 cov_mark::hit!(hover_macro_generated_struct_fn_doc_attr);
487 runnable_fn(sema, func).map(HoverAction::Runnable)
495 fn goto_type_action_for_def(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
496 let mut targets: Vec<hir::ModuleDef> = Vec::new();
497 let mut push_new_def = |item: hir::ModuleDef| {
498 if !targets.contains(&item) {
503 if let Definition::GenericParam(hir::GenericParam::TypeParam(it)) = def {
504 it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
507 Definition::Local(it) => it.ty(db),
508 Definition::GenericParam(hir::GenericParam::ConstParam(it)) => it.ty(db),
509 Definition::Field(field) => field.ty(db),
513 walk_and_push_ty(db, &ty, &mut push_new_def);
516 Some(HoverAction::goto_type_from_targets(db, targets))
522 push_new_def: &mut dyn FnMut(hir::ModuleDef),
525 if let Some(adt) = t.as_adt() {
526 push_new_def(adt.into());
527 } else if let Some(trait_) = t.as_dyn_trait() {
528 push_new_def(trait_.into());
529 } else if let Some(traits) = t.as_impl_traits(db) {
530 traits.into_iter().for_each(|it| push_new_def(it.into()));
531 } else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
532 push_new_def(trait_.into());
537 fn hover_markup(docs: Option<String>, desc: String, mod_path: Option<String>) -> Option<Markup> {
538 let mut buf = String::new();
540 if let Some(mod_path) = mod_path {
541 if !mod_path.is_empty() {
542 format_to!(buf, "```rust\n{}\n```\n\n", mod_path);
545 format_to!(buf, "```rust\n{}\n```", desc);
547 if let Some(doc) = docs {
548 format_to!(buf, "\n___\n\n{}", doc);
557 config: &HoverConfig,
559 let markup = markup.as_str();
560 let markup = if !config.markdown() {
561 remove_markdown(markup)
562 } else if config.links_in_hover {
563 rewrite_links(db, markup, def)
570 fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String> {
572 Definition::Field(f) => Some(f.parent_def(db).name(db)),
573 Definition::Local(l) => l.parent(db).name(db),
574 Definition::ModuleDef(md) => match md {
575 hir::ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) {
576 hir::AssocItemContainer::Trait(t) => Some(t.name(db)),
577 hir::AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)),
579 hir::ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)),
584 .map(|name| name.to_string())
587 fn render_path(db: &RootDatabase, module: hir::Module, item_name: Option<String>) -> String {
589 db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string());
590 let module_path = module
594 .flat_map(|it| it.name(db).map(|name| name.to_string()));
595 crate_name.into_iter().chain(module_path).chain(item_name).join("::")
598 fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
599 if let Definition::GenericParam(_) = def {
602 def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def)))
605 fn hover_for_definition(
608 famous_defs: Option<&FamousDefs>,
609 config: &HoverConfig,
610 ) -> Option<Markup> {
611 let mod_path = definition_mod_path(db, &def);
612 let (label, docs) = match def {
613 Definition::Macro(it) => (
614 match &it.source(db)?.value {
615 Either::Left(mac) => macro_label(mac),
616 Either::Right(mac_fn) => fn_as_proc_macro_label(mac_fn),
620 Definition::Field(def) => label_and_docs(db, def),
621 Definition::ModuleDef(it) => match it {
622 hir::ModuleDef::Module(it) => label_and_docs(db, it),
623 hir::ModuleDef::Function(it) => label_and_docs(db, it),
624 hir::ModuleDef::Adt(it) => label_and_docs(db, it),
625 hir::ModuleDef::Variant(it) => label_and_docs(db, it),
626 hir::ModuleDef::Const(it) => label_and_docs(db, it),
627 hir::ModuleDef::Static(it) => label_and_docs(db, it),
628 hir::ModuleDef::Trait(it) => label_and_docs(db, it),
629 hir::ModuleDef::TypeAlias(it) => label_and_docs(db, it),
630 hir::ModuleDef::BuiltinType(it) => {
632 .and_then(|fd| hover_for_builtin(fd, it))
633 .or_else(|| Some(Markup::fenced_block(&it.name())))
636 Definition::Local(it) => return hover_for_local(it, db),
637 Definition::SelfType(impl_def) => {
638 impl_def.self_ty(db).as_adt().map(|adt| label_and_docs(db, adt))?
640 Definition::GenericParam(it) => label_and_docs(db, it),
641 Definition::Label(it) => return Some(Markup::fenced_block(&it.name(db))),
645 docs.filter(|_| config.documentation.is_some()).map(Into::into),
650 fn label_and_docs<D>(db: &RootDatabase, def: D) -> (String, Option<hir::Documentation>)
652 D: HasAttrs + HirDisplay,
654 let label = def.display(db).to_string();
655 let docs = def.attrs(db).docs();
660 fn hover_for_local(it: hir::Local, db: &RootDatabase) -> Option<Markup> {
662 let ty = ty.display(db);
663 let is_mut = if it.is_mut(db) { "mut " } else { "" };
664 let desc = match it.source(db).value {
665 Either::Left(ident) => {
666 let name = it.name(db).unwrap();
667 let let_kw = if ident
670 .map_or(false, |p| p.kind() == LET_STMT || p.kind() == CONDITION)
676 format!("{}{}{}: {}", let_kw, is_mut, name, ty)
678 Either::Right(_) => format!("{}self: {}", is_mut, ty),
680 hover_markup(None, desc, None)
683 fn hover_for_keyword(
684 sema: &Semantics<RootDatabase>,
685 config: &HoverConfig,
687 ) -> Option<RangeInfo<HoverResult>> {
688 if !token.kind().is_keyword() || !config.documentation.is_some() {
691 let famous_defs = FamousDefs(sema, sema.scope(&token.parent()?).krate());
692 // std exposes {}_keyword modules with docstrings on the root to document keywords
693 let keyword_mod = format!("{}_keyword", token.text());
694 let doc_owner = find_std_module(&famous_defs, &keyword_mod)?;
695 let docs = doc_owner.attrs(sema.db).docs()?;
696 let markup = process_markup(
698 Definition::ModuleDef(doc_owner.into()),
699 &hover_markup(Some(docs.into()), token.text().into(), None)?,
702 Some(RangeInfo::new(token.text_range(), HoverResult { markup, actions: Default::default() }))
705 fn hover_for_builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Option<Markup> {
706 // std exposes prim_{} modules with docstrings on the root to document the builtins
707 let primitive_mod = format!("prim_{}", builtin.name());
708 let doc_owner = find_std_module(famous_defs, &primitive_mod)?;
709 let docs = doc_owner.attrs(famous_defs.0.db).docs()?;
710 hover_markup(Some(docs.into()), builtin.name().to_string(), None)
713 fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module> {
714 let db = famous_defs.0.db;
715 let std_crate = famous_defs.std()?;
716 let std_root_module = std_crate.root_module(db);
719 .find(|module| module.name(db).map_or(false, |module| module.to_string() == name))
724 use expect_test::{expect, Expect};
725 use ide_db::base_db::{FileLoader, FileRange};
726 use syntax::TextRange;
728 use crate::{fixture, hover::HoverDocFormat, HoverConfig};
730 fn check_hover_no_result(ra_fixture: &str) {
731 let (analysis, position) = fixture::position(ra_fixture);
735 links_in_hover: true,
736 documentation: Some(HoverDocFormat::Markdown),
738 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
741 assert!(hover.is_none());
744 fn check(ra_fixture: &str, expect: Expect) {
745 let (analysis, position) = fixture::position(ra_fixture);
749 links_in_hover: true,
750 documentation: Some(HoverDocFormat::Markdown),
752 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
757 let content = analysis.db.file_text(position.file_id);
758 let hovered_element = &content[hover.range];
760 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
761 expect.assert_eq(&actual)
764 fn check_hover_no_links(ra_fixture: &str, expect: Expect) {
765 let (analysis, position) = fixture::position(ra_fixture);
769 links_in_hover: false,
770 documentation: Some(HoverDocFormat::Markdown),
772 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
777 let content = analysis.db.file_text(position.file_id);
778 let hovered_element = &content[hover.range];
780 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
781 expect.assert_eq(&actual)
784 fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) {
785 let (analysis, position) = fixture::position(ra_fixture);
789 links_in_hover: true,
790 documentation: Some(HoverDocFormat::PlainText),
792 FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
797 let content = analysis.db.file_text(position.file_id);
798 let hovered_element = &content[hover.range];
800 let actual = format!("*{}*\n{}\n", hovered_element, hover.info.markup);
801 expect.assert_eq(&actual)
804 fn check_actions(ra_fixture: &str, expect: Expect) {
805 let (analysis, file_id, position) = fixture::range_or_position(ra_fixture);
809 links_in_hover: true,
810 documentation: Some(HoverDocFormat::Markdown),
812 FileRange { file_id, range: position.range_or_empty() },
816 expect.assert_debug_eq(&hover.info.actions)
819 fn check_hover_range(ra_fixture: &str, expect: Expect) {
820 let (analysis, range) = fixture::range(ra_fixture);
824 links_in_hover: false,
825 documentation: Some(HoverDocFormat::Markdown),
831 expect.assert_eq(hover.info.markup.as_str())
834 fn check_hover_range_no_results(ra_fixture: &str) {
835 let (analysis, range) = fixture::range(ra_fixture);
839 links_in_hover: false,
840 documentation: Some(HoverDocFormat::Markdown),
845 assert!(hover.is_none());
849 fn hover_shows_type_of_an_expression() {
852 pub fn foo() -> u32 { 1 }
855 let foo_test = foo()$0;
868 fn hover_remove_markdown_if_configured() {
869 check_hover_no_markdown(
871 pub fn foo() -> u32 { 1 }
874 let foo_test = foo()$0;
885 fn hover_shows_long_type_of_an_expression() {
888 struct Scan<A, B, C> { a: A, b: B, c: C }
889 struct Iter<I> { inner: I }
890 enum Option<T> { Some(T), None }
892 struct OtherStruct<T> { i: T }
894 fn scan<A, B, C>(a: A, b: B, c: C) -> Iter<Scan<OtherStruct<A>, B, C>> {
895 Iter { inner: Scan { a, b, c } }
900 let closure = |memo: &mut u32, value: &u32, _another: &mut u32| -> Option<u32> {
901 Option::Some(*memo + value)
904 let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
911 let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
918 fn hover_shows_fn_signature() {
919 // Single file with result
922 pub fn foo() -> u32 { 1 }
924 fn main() { let foo_test = fo$0o(); }
939 // Multiple candidates but results are ambiguous.
943 pub fn foo() -> u32 { 1 }
946 pub fn foo() -> &str { "" }
949 pub fn foo(a: u32, b: u32) {}
956 fn main() { let foo_test = fo$0o(); }
968 fn hover_shows_fn_signature_with_type_params() {
971 pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
973 fn main() { let foo_test = fo$0o(); }
983 pub fn foo<'a, T>(b: &'a T) -> &'a str
992 fn hover_shows_fn_signature_on_fn_name() {
995 pub fn foo$0(a: u32, b: u32) -> u32 {}
1007 pub fn foo(a: u32, b: u32) -> u32
1014 fn hover_shows_fn_doc() {
1019 /// # use std::path::Path;
1021 /// foo(Path::new("hello, world!"))
1023 pub fn foo$0(_: &Path) {}
1035 pub fn foo(_: &Path)
1043 # use std::path::Path;
1045 foo(Path::new("hello, world!"))
1052 fn hover_shows_fn_doc_attr_raw_string() {
1055 #[doc = r#"Raw string doc attr"#]
1056 pub fn foo$0(_: &Path) {}
1068 pub fn foo(_: &Path)
1079 fn hover_shows_struct_field_info() {
1080 // Hovering over the field when instantiating
1083 struct Foo { field_a: u32 }
1086 let foo = Foo { field_a$0: 0, };
1102 // Hovering over the field in the definition
1105 struct Foo { field_a$0: u32 }
1108 let foo = Foo { field_a: 0 };
1126 fn hover_const_static() {
1128 r#"const foo$0: u32 = 123;"#,
1142 r#"static foo$0: u32 = 456;"#,
1158 fn hover_default_generic_types() {
1161 struct Test<K, T = u8> { k: K, t: T }
1164 let zz$0 = Test { t: 23u8, k: 33 };
1170 let zz: Test<i32, u8>
1180 enum Option<T> { Some(T) }
1183 fn main() { So$0me(12); }
1200 enum Option<T> { Some(T) }
1203 fn main() { let b$0ar = Some(12); }
1209 let bar: Option<i32>
1216 fn hover_enum_variant() {
1220 /// The None variant
1244 /// The Some variant
1248 let s = Option::Som$0e(12);
1270 fn hover_for_local_variable() {
1272 r#"fn func(foo: i32) { fo$0o; }"#,
1284 fn hover_for_local_variable_pat() {
1286 r#"fn func(fo$0o: i32) {}"#,
1298 fn hover_local_var_edge() {
1300 r#"fn func(foo: i32) { if true { $0foo; }; }"#,
1312 fn hover_for_param_edge() {
1314 r#"fn func($0foo: i32) {}"#,
1326 fn hover_for_param_with_multiple_traits() {
1331 type Target: ?Sized;
1334 type Target: ?Sized;
1336 fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
1341 _x: impl Deref<Target = u8> + DerefMut<Target = u8>
1348 fn test_hover_infer_associated_method_result() {
1351 struct Thing { x: u32 }
1354 fn new() -> Thing { Thing { x: 0 } }
1357 fn main() { let foo_$0test = Thing::new(); }
1370 fn test_hover_infer_associated_method_exact() {
1374 struct Thing { x: u32 }
1377 fn new() -> Thing { Thing { x: 0 } }
1381 fn main() { let foo_test = wrapper::Thing::new$0(); }
1387 test::wrapper::Thing
1398 fn test_hover_infer_associated_const_in_pattern() {
1429 fn test_hover_self() {
1432 struct Thing { x: u32 }
1434 fn new() -> Self { Self$0 { x: 0 } }
1451 struct Thing { x: u32 }
1453 fn new() -> Self$0 { Self { x: 0 } }
1472 pub fn new() -> Self$0 { Thing::A }
1491 pub fn thing(a: Self$0) {}
1509 fn test_hover_shadowing_pat() {
1530 fn test_hover_macro_invocation() {
1533 macro_rules! foo { () => {} }
1535 fn f() { fo$0o!(); }
1552 fn test_hover_macro2_invocation() {
1560 fn f() { fo$0o!(); }
1583 fn test_hover_tuple_field() {
1585 r#"struct TS(String, i32$0);"#,
1597 fn test_hover_through_macro() {
1600 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1603 fn bar() { fo$0o(); }
1621 fn test_hover_through_expr_in_macro() {
1624 macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1625 fn foo(bar:u32) { let a = id!(ba$0r); }
1638 fn test_hover_through_expr_in_macro_recursive() {
1641 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1642 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1643 fn foo(bar:u32) { let a = id!(ba$0r); }
1656 fn test_hover_through_func_in_macro_recursive() {
1659 macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
1660 macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
1661 fn bar() -> u32 { 0 }
1662 fn foo() { let a = id!([0u32, bar($0)] ); }
1674 fn test_hover_through_literal_string_in_macro() {
1677 macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
1679 let mastered_for_itunes = "";
1680 let _ = arr!("Tr$0acks", &mastered_for_itunes);
1693 fn test_hover_through_assert_macro() {
1696 #[rustc_builtin_macro]
1697 macro_rules! assert {}
1699 fn bar() -> bool { true }
1719 fn test_hover_through_literal_string_in_builtin_macro() {
1720 check_hover_no_result(
1722 #[rustc_builtin_macro]
1723 macro_rules! format {}
1726 format!("hel$0lo {}", 0);
1733 fn test_hover_non_ascii_space_doc() {
1736 /// <- `\u{3000}` here
1739 fn bar() { fo$0o(); }
1760 fn test_hover_function_show_qualifiers() {
1762 r#"async fn foo$0() {}"#,
1776 r#"pub const unsafe fn foo$0() {}"#,
1785 pub const unsafe fn foo()
1789 // Top level `pub(crate)` will be displayed as no visibility.
1791 r#"mod m { pub(crate) async unsafe extern "C" fn foo$0() {} }"#,
1800 pub(crate) async unsafe extern "C" fn foo()
1807 fn test_hover_trait_show_qualifiers() {
1809 r"unsafe trait foo$0() {}",
1826 fn test_hover_extern_crate() {
1829 //- /main.rs crate:main deps:std
1831 //- /std/lib.rs crate:std
1832 //! Standard library for this test
1846 Standard library for this test
1854 //- /main.rs crate:main deps:std
1855 extern crate std as ab$0c;
1856 //- /std/lib.rs crate:std
1857 //! Standard library for this test
1871 Standard library for this test
1880 fn test_hover_mod_with_same_name_as_function() {
1883 use self::m$0y::Bar;
1884 mod my { pub struct Bar; }
1903 fn test_hover_struct_doc_comment() {
1906 /// This is an example
1914 /// assert_eq!(6, my_crate::add_one(5));
1918 fn foo() { let bar = Ba$0r; }
1941 assert_eq!(6, my_crate::add_one(5));
1948 fn test_hover_struct_doc_attr() {
1954 fn foo() { let bar = Ba$0r; }
1975 fn test_hover_struct_doc_attr_multiple_and_mixed() {
1979 #[doc = "bar docs 1"]
1980 #[doc = "bar docs 2"]
1983 fn foo() { let bar = Ba$0r; }
2006 fn test_hover_external_url() {
2010 /// [external](https://www.google.com)
2026 [external](https://www.google.com)
2031 // Check that we don't rewrite links which we can't identify
2033 fn test_hover_unknown_target() {
2059 fn test_hover_no_links() {
2060 check_hover_no_links(
2063 /// case 1. bare URL: https://www.example.com/
2064 /// case 2. inline URL with title: [example](https://www.example.com/)
2065 /// case 3. code reference: [`Result`]
2066 /// case 4. code reference but miss footnote: [`String`]
2067 /// case 5. autolink: <http://www.example.com/>
2068 /// case 6. email address: <test@example.com>
2069 /// case 7. reference: [example][example]
2070 /// case 8. collapsed link: [example][]
2071 /// case 9. shortcut link: [example]
2072 /// case 10. inline without URL: [example]()
2073 /// case 11. reference: [foo][foo]
2074 /// case 12. reference: [foo][bar]
2075 /// case 13. collapsed link: [foo][]
2076 /// case 14. shortcut link: [foo]
2077 /// case 15. inline without URL: [foo]()
2078 /// case 16. just escaped text: \[foo]
2079 /// case 17. inline link: [Foo](foo::Foo)
2081 /// [`Result`]: ../../std/result/enum.Result.html
2082 /// [^example]: https://www.example.com/
2099 case 1. bare URL: https://www.example.com/
2100 case 2. inline URL with title: [example](https://www.example.com/)
2101 case 3. code reference: `Result`
2102 case 4. code reference but miss footnote: `String`
2103 case 5. autolink: http://www.example.com/
2104 case 6. email address: test@example.com
2105 case 7. reference: example
2106 case 8. collapsed link: example
2107 case 9. shortcut link: example
2108 case 10. inline without URL: example
2109 case 11. reference: foo
2110 case 12. reference: foo
2111 case 13. collapsed link: foo
2112 case 14. shortcut link: foo
2113 case 15. inline without URL: foo
2114 case 16. just escaped text: \[foo\]
2115 case 17. inline link: Foo
2117 [^example]: https://www.example.com/
2123 fn test_hover_macro_generated_struct_fn_doc_comment() {
2124 cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
2140 fn foo() { let bar = Bar; bar.fo$0o(); }
2161 fn test_hover_macro_generated_struct_fn_doc_attr() {
2162 cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
2170 #[doc = "Do the foo"]
2178 fn foo() { let bar = Bar; bar.fo$0o(); }
2199 fn test_hover_trait_has_impl_action() {
2201 r#"trait foo$0() {}"#,
2218 fn test_hover_struct_has_impl_action() {
2220 r"struct foo$0() {}",
2237 fn test_hover_union_has_impl_action() {
2239 r#"union foo$0() {}"#,
2256 fn test_hover_enum_has_impl_action() {
2258 r"enum foo$0() { A, B }",
2275 fn test_hover_self_has_impl_action() {
2277 r#"struct foo where Self$0:;"#,
2294 fn test_hover_test_has_action() {
2312 use_name_in_title: false,
2313 nav: NavigationTarget {
2318 focus_range: 11..19,
2339 fn test_hover_test_mod_has_action() {
2351 use_name_in_title: false,
2352 nav: NavigationTarget {
2360 description: "mod tests",
2374 fn test_hover_struct_has_goto_type_action() {
2379 fn main() { let s$0t = S{ f1:0 }; }
2386 mod_path: "test::S",
2387 nav: NavigationTarget {
2395 description: "struct S",
2406 fn test_hover_generic_struct_has_goto_type_actions() {
2410 struct S<T>{ f1: T }
2412 fn main() { let s$0t = S{ f1:Arg(0) }; }
2419 mod_path: "test::S",
2420 nav: NavigationTarget {
2425 focus_range: 24..25,
2428 description: "struct S<T>",
2432 mod_path: "test::Arg",
2433 nav: NavigationTarget {
2441 description: "struct Arg",
2452 fn test_hover_generic_struct_has_flattened_goto_type_actions() {
2456 struct S<T>{ f1: T }
2458 fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
2465 mod_path: "test::S",
2466 nav: NavigationTarget {
2471 focus_range: 24..25,
2474 description: "struct S<T>",
2478 mod_path: "test::Arg",
2479 nav: NavigationTarget {
2487 description: "struct Arg",
2498 fn test_hover_tuple_has_goto_type_actions() {
2507 fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
2514 mod_path: "test::A",
2515 nav: NavigationTarget {
2523 description: "struct A",
2527 mod_path: "test::B",
2528 nav: NavigationTarget {
2533 focus_range: 22..23,
2536 description: "struct B",
2540 mod_path: "test::M::C",
2541 nav: NavigationTarget {
2546 focus_range: 53..54,
2549 description: "pub struct C",
2560 fn test_hover_return_impl_trait_has_goto_type_action() {
2564 fn foo() -> impl Foo {}
2566 fn main() { let s$0t = foo(); }
2573 mod_path: "test::Foo",
2574 nav: NavigationTarget {
2582 description: "trait Foo",
2593 fn test_hover_generic_return_impl_trait_has_goto_type_action() {
2598 fn foo() -> impl Foo<S> {}
2600 fn main() { let s$0t = foo(); }
2607 mod_path: "test::Foo",
2608 nav: NavigationTarget {
2616 description: "trait Foo<T>",
2620 mod_path: "test::S",
2621 nav: NavigationTarget {
2626 focus_range: 23..24,
2629 description: "struct S",
2640 fn test_hover_return_impl_traits_has_goto_type_action() {
2645 fn foo() -> impl Foo + Bar {}
2647 fn main() { let s$0t = foo(); }
2654 mod_path: "test::Foo",
2655 nav: NavigationTarget {
2663 description: "trait Foo",
2667 mod_path: "test::Bar",
2668 nav: NavigationTarget {
2673 focus_range: 19..22,
2676 description: "trait Bar",
2687 fn test_hover_generic_return_impl_traits_has_goto_type_action() {
2695 fn foo() -> impl Foo<S1> + Bar<S2> {}
2697 fn main() { let s$0t = foo(); }
2704 mod_path: "test::Foo",
2705 nav: NavigationTarget {
2713 description: "trait Foo<T>",
2717 mod_path: "test::Bar",
2718 nav: NavigationTarget {
2723 focus_range: 22..25,
2726 description: "trait Bar<T>",
2730 mod_path: "test::S1",
2731 nav: NavigationTarget {
2736 focus_range: 39..41,
2739 description: "struct S1",
2743 mod_path: "test::S2",
2744 nav: NavigationTarget {
2749 focus_range: 52..54,
2752 description: "struct S2",
2763 fn test_hover_arg_impl_trait_has_goto_type_action() {
2767 fn foo(ar$0g: &impl Foo) {}
2774 mod_path: "test::Foo",
2775 nav: NavigationTarget {
2783 description: "trait Foo",
2794 fn test_hover_arg_impl_traits_has_goto_type_action() {
2801 fn foo(ar$0g: &impl Foo + Bar<S>) {}
2808 mod_path: "test::Foo",
2809 nav: NavigationTarget {
2817 description: "trait Foo",
2821 mod_path: "test::Bar",
2822 nav: NavigationTarget {
2827 focus_range: 19..22,
2830 description: "trait Bar<T>",
2834 mod_path: "test::S",
2835 nav: NavigationTarget {
2840 focus_range: 36..37,
2843 description: "struct S",
2854 fn test_hover_async_block_impl_trait_has_goto_type_action() {
2857 //- minicore: future
2860 let fo$0o = async { S };
2868 mod_path: "core::future::Future",
2869 nav: NavigationTarget {
2873 full_range: 254..436,
2874 focus_range: 293..299,
2877 description: "pub trait Future",
2881 mod_path: "test::S",
2882 nav: NavigationTarget {
2890 description: "struct S",
2901 fn test_hover_arg_generic_impl_trait_has_goto_type_action() {
2906 fn foo(ar$0g: &impl Foo<S>) {}
2913 mod_path: "test::Foo",
2914 nav: NavigationTarget {
2922 description: "trait Foo<T>",
2926 mod_path: "test::S",
2927 nav: NavigationTarget {
2932 focus_range: 23..24,
2935 description: "struct S",
2946 fn test_hover_dyn_return_has_goto_type_action() {
2954 fn foo() -> B<dyn Foo> {}
2956 fn main() { let s$0t = foo(); }
2963 mod_path: "test::B",
2964 nav: NavigationTarget {
2969 focus_range: 49..50,
2972 description: "struct B<T>",
2976 mod_path: "test::Foo",
2977 nav: NavigationTarget {
2985 description: "trait Foo",
2996 fn test_hover_dyn_arg_has_goto_type_action() {
3000 fn foo(ar$0g: &dyn Foo) {}
3007 mod_path: "test::Foo",
3008 nav: NavigationTarget {
3016 description: "trait Foo",
3027 fn test_hover_generic_dyn_arg_has_goto_type_action() {
3032 fn foo(ar$0g: &dyn Foo<S>) {}
3039 mod_path: "test::Foo",
3040 nav: NavigationTarget {
3048 description: "trait Foo<T>",
3052 mod_path: "test::S",
3053 nav: NavigationTarget {
3058 focus_range: 23..24,
3061 description: "struct S",
3072 fn test_hover_goto_type_action_links_order() {
3075 trait ImplTrait<T> {}
3076 trait DynTrait<T> {}
3080 fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
3087 mod_path: "test::ImplTrait",
3088 nav: NavigationTarget {
3096 description: "trait ImplTrait<T>",
3100 mod_path: "test::B",
3101 nav: NavigationTarget {
3106 focus_range: 50..51,
3109 description: "struct B<T>",
3113 mod_path: "test::DynTrait",
3114 nav: NavigationTarget {
3119 focus_range: 28..36,
3122 description: "trait DynTrait<T>",
3126 mod_path: "test::S",
3127 nav: NavigationTarget {
3132 focus_range: 65..66,
3135 description: "struct S",
3146 fn test_hover_associated_type_has_goto_type_action() {
3151 fn get(self) -> Self::Item {}
3157 impl Foo for S { type Item = Bar; }
3159 fn test() -> impl Foo { S {} }
3161 fn main() { let s$0t = test().get(); }
3168 mod_path: "test::Foo",
3169 nav: NavigationTarget {
3177 description: "trait Foo",
3188 fn test_hover_const_param_has_goto_type_action() {
3192 struct Foo<const BAR: Bar>;
3194 impl<const BAR: Bar> Foo<BAR$0> {}
3201 mod_path: "test::Bar",
3202 nav: NavigationTarget {
3210 description: "struct Bar",
3221 fn test_hover_type_param_has_goto_type_action() {
3226 fn foo<T: Foo>(t: T$0){}
3233 mod_path: "test::Foo",
3234 nav: NavigationTarget {
3242 description: "trait Foo",
3253 fn test_hover_self_has_go_to_type() {
3266 mod_path: "test::Foo",
3267 nav: NavigationTarget {
3275 description: "struct Foo",
3286 fn hover_displays_normalized_crate_names() {
3289 //- /lib.rs crate:name-with-dashes
3291 pub struct Thing { x: u32 }
3294 pub fn new() -> Thing { Thing { x: 0 } }
3298 //- /main.rs crate:main deps:name-with-dashes
3299 fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
3305 name_with_dashes::wrapper::Thing
3309 pub fn new() -> Thing
3316 fn hover_field_pat_shorthand_ref_match_ergonomics() {
3339 fn hover_self_param_shows_type() {
3358 fn hover_self_param_shows_type_for_arbitrary_self_type() {
3364 fn bar(sel$0f: Arc<Foo>) {}
3378 fn hover_doc_outer_inner() {
3385 /// This comment belongs to the function
3409 fn hover_doc_outer_inner_attribue() {
3412 #[doc = "Be quick;"]
3414 #![doc = "time is mana"]
3416 #[doc = "This comment belongs to the function"]
3440 fn hover_doc_block_style_indentend() {
3474 fn hover_comments_dont_highlight_parent() {
3475 cov_mark::check!(no_highlight_on_comment_hover);
3476 check_hover_no_result(
3504 fn hover_lifetime() {
3506 r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
3518 fn hover_type_param() {
3525 impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
3549 // lifetimes bounds arent being tracked yet
3554 impl<T: 'static> Foo<T$0> {}
3567 fn hover_type_param_sized_bounds() {
3568 // implicit `: Sized` bound
3574 impl<T: Trait> Foo<T$0> {}
3589 impl<T: Trait + ?Sized> Foo<T$0> {}
3601 mod type_param_sized_bounds {
3605 fn single_implicit() {
3622 fn single_explicit() {
3626 fn foo<T$0: Sized>() {}
3639 fn single_relaxed() {
3643 fn foo<T$0: ?Sized>() {}
3656 fn multiple_implicit() {
3661 fn foo<T$0: Trait>() {}
3674 fn multiple_explicit() {
3679 fn foo<T$0: Trait + Sized>() {}
3692 fn multiple_relaxed() {
3697 fn foo<T$0: Trait + ?Sized>() {}
3714 fn foo<T$0: ?Sized + Sized + Sized>() {}
3728 fn foo<T$0: Sized + ?Sized + Sized + Trait>() {}
3742 fn hover_const_param() {
3745 struct Foo<const LEN: usize>;
3746 impl<const LEN: usize> Foo<LEN$0> {}
3759 fn hover_const_pat() {
3763 const FOO: usize = 3;
3790 fn hover_mod_def() {
3817 fn hover_self_in_use() {
3820 //! This should not appear
3822 /// But this should appear
3825 use foo::bar::{self$0};
3840 But this should appear
3846 fn hover_keyword() {
3849 //- /main.rs crate:main deps:std
3850 fn f() { retur$0n; }
3851 //- /libstd.rs crate:std
3852 /// Docs for return_keyword
3853 mod return_keyword {}
3864 Docs for return_keyword
3870 fn hover_builtin() {
3873 //- /main.rs crate:main deps:std
3874 cosnt _: &str$0 = ""; }
3876 //- /libstd.rs crate:std
3877 /// Docs for prim_str
3895 fn hover_macro_expanded_function() {
3898 struct S<'a, T>(&'a T);
3902 fn bar<'t, T: Clone + 't>(s: &mut S<'t, T>, t: u32) -> *mut u32 where
3904 for<'a> T: Clone + 'a
3923 fn bar<'t, T>(s: &mut S<'t, T>, t: u32) -> *mut u32
3927 for<'a> T: Clone + 'a,
3934 fn hover_intra_doc_links() {
3939 /// This is the item. Cool!
3943 /// Gives you a [`TheItem$0`].
3945 /// [`TheItem`]: theitem::TheItem
3946 pub fn gimme() -> theitem::TheItem {
3963 This is the item. Cool!
3969 fn hover_generic_assoc() {
3972 fn foo<T: A>() where T::Assoc$0: {}
3992 let _: <T>::Assoc$0;
4032 fn string_shadowed_with_inner_items() {
4035 //- /main.rs crate:main deps:alloc
4037 /// Custom `String` type.
4046 //- /alloc.rs crate:alloc
4051 /// This is `alloc::String`.
4068 Custom `String` type.
4074 fn function_doesnt_shadow_crate_in_use_tree() {
4077 //- /main.rs crate:main deps:foo
4080 //- /foo.rs crate:foo
4094 fn hover_feature() {
4096 r#"#![feature(box_syntax$0)]"#,
4106 The tracking issue for this feature is: [#49733]
4108 [#49733]: https://github.com/rust-lang/rust/issues/49733
4110 See also [`box_patterns`](box-patterns.md)
4112 ------------------------
4114 Currently the only stable way to create a `Box` is via the `Box::new` method.
4115 Also it is not possible in stable Rust to destructure a `Box` in a match
4116 pattern. The unstable `box` keyword can be used to create a `Box`. An example
4120 #![feature(box_syntax)]
4134 r#"#![allow(arithmetic_overflow$0)]"#,
4136 *arithmetic_overflow*
4142 arithmetic operation overflows
4148 fn hover_clippy_lint() {
4150 r#"#![allow(clippy::almost_swapped$0)]"#,
4154 clippy::almost_swapped
4158 Checks for `foo = bar; bar = foo` sequences.
4164 fn hover_attr_path_qualifier() {
4165 cov_mark::check!(name_ref_classify_attr_path_qualifier);
4168 //- /foo.rs crate:foo
4170 //- /lib.rs crate:main.rs deps:foo
4201 use bar::{self as foo$0};
4244 fn hover_derive_input() {
4247 #[rustc_builtin_macro]
4267 #[rustc_builtin_macro]
4270 #[derive(foo::Copy$0)]
4288 fn hover_range_math() {
4291 fn f() { let expr = $01 + 2 * 3$0 }
4301 fn f() { let expr = 1 $0+ 2 * $03 }
4311 fn f() { let expr = 1 + $02 * 3$0 }
4321 fn hover_range_arrays() {
4324 fn f() { let expr = $0[1, 2, 3, 4]$0 }
4334 fn f() { let expr = [1, 2, $03, 4]$0 }
4344 fn f() { let expr = [1, 2, $03$0, 4] }
4354 fn hover_range_functions() {
4357 fn f<T>(a: &[T]) { }
4358 fn b() { $0f$0(&[1, 2, 3, 4, 5]); }
4368 fn f<T>(a: &[T]) { }
4369 fn b() { f($0&[1, 2, 3, 4, 5]$0); }
4379 fn hover_range_shows_nothing_when_invalid() {
4380 check_hover_range_no_results(
4382 fn f<T>(a: &[T]) { }
4383 fn b()$0 { f(&[1, 2, 3, 4, 5]); }$0
4387 check_hover_range_no_results(
4389 fn f<T>$0(a: &[T]) { }
4390 fn b() { f(&[1, 2, 3,$0 4, 5]); }
4394 check_hover_range_no_results(
4396 fn $0f() { let expr = [1, 2, 3, 4]$0 }
4402 fn hover_range_shows_unit_for_statements() {
4405 fn f<T>(a: &[T]) { }
4406 fn b() { $0f(&[1, 2, 3, 4, 5]); }$0
4416 fn f() { let expr$0 = $0[1, 2, 3, 4] }
4426 fn hover_range_for_pat() {
4453 fn hover_range_shows_coercions_if_applicable_expr() {
4457 let x: &u32 = $0&&&&&0$0;
4470 let x: *const u32 = $0&0$0;
4476 Coerced to: *const u32
4483 fn hover_range_shows_type_actions() {
4488 let x: &Foo = $0&&&&&Foo$0;
4496 mod_path: "test::Foo",
4497 nav: NavigationTarget {
4505 description: "struct Foo",
4516 fn hover_try_expr_res() {
4522 fn foo() -> Result<(), FooError> {
4523 Ok($0Result::<(), FooError>::Ok(())?$0)
4537 fn foo() -> Result<(), FooError> {
4538 Ok($0Result::<(), BarError>::Ok(())?$0)
4543 Try Error Type: BarError
4544 Propagated as: FooError
4551 fn hover_try_expr() {
4554 struct NotResult<T, U>(T, U);
4558 fn foo() -> NotResult<(), Looooong> {
4559 $0NotResult((), Short)?$0;
4564 Try Target Type: NotResult<(), Short>
4565 Propagated as: NotResult<(), Looooong>
4571 struct NotResult<T, U>(T, U);
4575 fn foo() -> NotResult<(), Short> {
4576 $0NotResult((), Looooong)?$0;
4581 Try Target Type: NotResult<(), Looooong>
4582 Propagated as: NotResult<(), Short>
4589 fn hover_try_expr_option() {
4590 cov_mark::check!(hover_try_expr_opt_opt);
4593 //- minicore: option, try
4595 fn foo() -> Option<()> {
4602 <Option<i32> as Try>::Output