mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Fix tests by importing core::ops::Deref
This commit is contained in:
parent
67a9c457e6
commit
1d4d9a1e1a
1 changed files with 18 additions and 10 deletions
|
@ -243,7 +243,9 @@ fn hover_ranged(
|
||||||
})?;
|
})?;
|
||||||
let res = match &expr_or_pat {
|
let res = match &expr_or_pat {
|
||||||
Either::Left(ast::Expr::TryExpr(try_expr)) => hover_try_expr(sema, config, try_expr),
|
Either::Left(ast::Expr::TryExpr(try_expr)) => hover_try_expr(sema, config, try_expr),
|
||||||
Either::Left(ast::Expr::PrefixExpr(prefix_expr)) if prefix_expr.op_kind() == Some(ast::UnaryOp::Deref) => {
|
Either::Left(ast::Expr::PrefixExpr(prefix_expr))
|
||||||
|
if prefix_expr.op_kind() == Some(ast::UnaryOp::Deref) =>
|
||||||
|
{
|
||||||
hover_deref_expr(sema, config, prefix_expr)
|
hover_deref_expr(sema, config, prefix_expr)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -355,7 +357,8 @@ fn hover_deref_expr(
|
||||||
deref_expr: &ast::PrefixExpr,
|
deref_expr: &ast::PrefixExpr,
|
||||||
) -> Option<HoverResult> {
|
) -> Option<HoverResult> {
|
||||||
let inner_ty = sema.type_of_expr(&deref_expr.expr()?)?.original;
|
let inner_ty = sema.type_of_expr(&deref_expr.expr()?)?.original;
|
||||||
let TypeInfo { original, adjusted } = sema.type_of_expr(&ast::Expr::from(deref_expr.clone()))?;
|
let TypeInfo { original, adjusted } =
|
||||||
|
sema.type_of_expr(&ast::Expr::from(deref_expr.clone()))?;
|
||||||
|
|
||||||
let mut res = HoverResult::default();
|
let mut res = HoverResult::default();
|
||||||
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
||||||
|
@ -366,7 +369,7 @@ fn hover_deref_expr(
|
||||||
};
|
};
|
||||||
walk_and_push_ty(sema.db, &inner_ty, &mut push_new_def);
|
walk_and_push_ty(sema.db, &inner_ty, &mut push_new_def);
|
||||||
walk_and_push_ty(sema.db, &original, &mut push_new_def);
|
walk_and_push_ty(sema.db, &original, &mut push_new_def);
|
||||||
|
|
||||||
res.markup = if let Some(adjusted_ty) = adjusted {
|
res.markup = if let Some(adjusted_ty) = adjusted {
|
||||||
walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
|
walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
|
||||||
let original = original.display(sema.db).to_string();
|
let original = original.display(sema.db).to_string();
|
||||||
|
@ -375,7 +378,9 @@ fn hover_deref_expr(
|
||||||
let type_len = "Type: ".len();
|
let type_len = "Type: ".len();
|
||||||
let coerced_len = "Coerced to: ".len();
|
let coerced_len = "Coerced to: ".len();
|
||||||
let deref_len = "Derefenced from: ".len();
|
let deref_len = "Derefenced from: ".len();
|
||||||
let max_len = (original.len() + type_len).max(adjusted.len() + coerced_len).max(inner.len() + deref_len);
|
let max_len = (original.len() + type_len)
|
||||||
|
.max(adjusted.len() + coerced_len)
|
||||||
|
.max(inner.len() + deref_len);
|
||||||
format!(
|
format!(
|
||||||
"{bt_start}Type: {:>apad$}\nCoerced to: {:>opad$}\nDerefenced from: {:>ipad$}\n{bt_end}",
|
"{bt_start}Type: {:>apad$}\nCoerced to: {:>opad$}\nDerefenced from: {:>ipad$}\n{bt_end}",
|
||||||
original,
|
original,
|
||||||
|
@ -4511,12 +4516,13 @@ fn foo() -> Option<()> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_deref_expr() {
|
fn hover_deref_expr() {
|
||||||
check_hover_range(
|
check_hover_range(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: deref
|
//- minicore: deref
|
||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
struct DerefExample<T> {
|
struct DerefExample<T> {
|
||||||
value: T
|
value: T
|
||||||
}
|
}
|
||||||
|
@ -4547,19 +4553,21 @@ fn foo() {
|
||||||
fn hover_deref_expr_with_coercion() {
|
fn hover_deref_expr_with_coercion() {
|
||||||
check_hover_range(
|
check_hover_range(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: deref
|
//- minicore: deref
|
||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
struct DerefExample<T> {
|
struct DerefExample<T> {
|
||||||
value: T
|
value: T
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Deref for DerefExample<T> {
|
impl<T> Deref for DerefExample<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.value
|
&self.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let x = DerefExample { value: &&&&&0 };
|
let x = DerefExample { value: &&&&&0 };
|
||||||
let y: &i32 = $0*x$0;
|
let y: &i32 = $0*x$0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue