Skip to content

Commit

Permalink
Remove duplicate method from hir::Type
Browse files Browse the repository at this point in the history
I added it by mistake in #18927.

I chose to keep the method as not static, because it's more comfortable, and keep the name `add_reference()` and not `reference()`, because it is clearer and better matches `strip_reference[s]()`.
  • Loading branch information
ChayimFriedman2 committed Jan 27, 2025
1 parent ad0aea4 commit 78feee8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
11 changes: 0 additions & 11 deletions src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4698,17 +4698,6 @@ impl Type {
Type { env: TraitEnvironment::empty(krate), ty }
}

pub fn reference(inner: &Type, m: Mutability) -> Type {
inner.derived(
TyKind::Ref(
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
hir_ty::error_lifetime(),
inner.ty.clone(),
)
.intern(Interner),
)
}

fn new(db: &dyn HirDatabase, lexical_env: impl HasResolver, ty: Ty) -> Type {
let resolver = lexical_env.resolver(db.upcast());
let environment = resolver
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir/src/term_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl LookupTable {
self.data
.iter()
.find(|(t, _)| {
Type::reference(t, Mutability::Shared).could_unify_with_deeply(db, ty)
t.add_reference(Mutability::Shared).could_unify_with_deeply(db, ty)
})
.map(|(t, it)| {
it.exprs(t)
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/ide-assists/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ pub(crate) fn convert_reference_type(
}

fn could_deref_to_target(ty: &hir::Type, target: &hir::Type, db: &dyn HirDatabase) -> bool {
let ty_ref = hir::Type::reference(ty, hir::Mutability::Shared);
let target_ref = hir::Type::reference(target, hir::Mutability::Shared);
let ty_ref = ty.add_reference(hir::Mutability::Shared);
let target_ref = target.add_reference(hir::Mutability::Shared);
ty_ref.could_coerce_to(db, &target_ref)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use either::Either;
use hir::{db::ExpandDatabase, CallableKind, ClosureStyle, HirDisplay, HirFileIdExt, InFile, Type};
use hir::{db::ExpandDatabase, CallableKind, ClosureStyle, HirDisplay, HirFileIdExt, InFile};
use ide_db::{
famous_defs::FamousDefs,
source_change::{SourceChange, SourceChangeBuilder},
Expand Down Expand Up @@ -88,7 +88,7 @@ fn add_reference(
let range = ctx.sema.diagnostics_display_range((*expr_ptr).map(|it| it.into()));

let (_, mutability) = d.expected.as_reference()?;
let actual_with_ref = Type::reference(&d.actual, mutability);
let actual_with_ref = d.actual.add_reference(mutability);
if !actual_with_ref.could_coerce_to(ctx.sema.db, &d.expected) {
return None;
}
Expand Down

0 comments on commit 78feee8

Please sign in to comment.