Skip to content

Commit

Permalink
Auto merge of #13225 - lowr:fix/hir-proj-normalization, r=Veykril
Browse files Browse the repository at this point in the history
fixup: remove unnecessary `Option`

Fixup for #13223, two things:

- `normalize_projection_query()` (and consequently `HirDatabase::normalize_projection()`) never returns `None` (well, it used to when I first wrote it...), so just return `Ty` instead of `Option<Ty>`
- When chalk cannot normalize projection uniquely, `normalize_trait_assoc_type()` used to return `None` before #13223, but not anymore because of the first point. I restored the behavior so its callers work as before.
  • Loading branch information
bors committed Sep 13, 2022
2 parents 125d43c + d223c28 commit ba15f75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
&self,
projection: crate::ProjectionTy,
env: Arc<crate::TraitEnvironment>,
) -> Option<crate::Ty>;
) -> Ty;

#[salsa::invoke(trait_solve_wait)]
#[salsa::transparent]
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ pub(crate) fn normalize_projection_query(
db: &dyn HirDatabase,
projection: ProjectionTy,
env: Arc<TraitEnvironment>,
) -> Option<Ty> {
let mut table = InferenceTable::new(db, env.clone());
) -> Ty {
let mut table = InferenceTable::new(db, env);
let ty = table.normalize_projection_ty(projection);
Some(table.resolve_completely(ty))
table.resolve_completely(ty)
}

/// Solve a trait goal using Chalk.
Expand Down
7 changes: 6 additions & 1 deletion crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,12 @@ impl Type {
})
.build();

db.normalize_projection(projection, self.env.clone()).map(|ty| self.derived(ty))
let ty = db.normalize_projection(projection, self.env.clone());
if ty.is_unknown() {
None
} else {
Some(self.derived(ty))
}
}

pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {
Expand Down

0 comments on commit ba15f75

Please sign in to comment.