Fix tests by importing core::ops::Deref

This commit is contained in:
Teddy_Wang 2021-09-11 11:40:16 -04:00
parent 67a9c457e6
commit 1d4d9a1e1a

View file

@ -243,7 +243,9 @@ fn hover_ranged(
})?;
let res = match &expr_or_pat {
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)
}
_ => None,
@ -355,7 +357,8 @@ fn hover_deref_expr(
deref_expr: &ast::PrefixExpr,
) -> Option<HoverResult> {
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 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, &original, &mut push_new_def);
res.markup = if let Some(adjusted_ty) = adjusted {
walk_and_push_ty(sema.db, &adjusted_ty, &mut push_new_def);
let original = original.display(sema.db).to_string();
@ -375,7 +378,9 @@ fn hover_deref_expr(
let type_len = "Type: ".len();
let coerced_len = "Coerced to: ".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!(
"{bt_start}Type: {:>apad$}\nCoerced to: {:>opad$}\nDerefenced from: {:>ipad$}\n{bt_end}",
original,
@ -4511,12 +4516,13 @@ fn foo() -> Option<()> {
);
}
#[test]
fn hover_deref_expr() {
check_hover_range(
r#"
//- minicore: deref
//- minicore: deref
use core::ops::Deref;
struct DerefExample<T> {
value: T
}
@ -4547,19 +4553,21 @@ fn foo() {
fn hover_deref_expr_with_coercion() {
check_hover_range(
r#"
//- minicore: deref
//- minicore: deref
use core::ops::Deref;
struct DerefExample<T> {
value: T
}
impl<T> Deref for DerefExample<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.value
}
}
fn foo() {
let x = DerefExample { value: &&&&&0 };
let y: &i32 = $0*x$0;