Skip to content

Commit d8b1ec6

Browse files
committed
Remove unnecessary option wrapping
1 parent 27fad2a commit d8b1ec6

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

crates/hir-ty/src/infer/path.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ impl<'a> InferenceContext<'a> {
3535
let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1);
3636
let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver);
3737
let (ty, _) = ctx.lower_ty_relative_path(ty, None, remaining_segments_for_ty);
38-
self.resolve_ty_assoc_item(ty, last.name, id)?
38+
self.resolve_ty_assoc_item(ty, last.name, id).map(|(it, substs)| (it, Some(substs)))?
3939
} else {
4040
// FIXME: report error, unresolved first path segment
4141
let value_or_partial =
4242
self.resolver.resolve_path_in_value_ns(self.db.upcast(), path.mod_path())?;
4343

4444
match value_or_partial {
4545
ResolveValueResult::ValueNs(it) => (it, None),
46-
ResolveValueResult::Partial(def, remaining_index) => {
47-
self.resolve_assoc_item(def, path, remaining_index, id)?
48-
}
46+
ResolveValueResult::Partial(def, remaining_index) => self
47+
.resolve_assoc_item(def, path, remaining_index, id)
48+
.map(|(it, substs)| (it, Some(substs)))?,
4949
}
5050
};
5151

@@ -113,7 +113,7 @@ impl<'a> InferenceContext<'a> {
113113
path: &Path,
114114
remaining_index: usize,
115115
id: ExprOrPatId,
116-
) -> Option<(ValueNs, Option<Substitution>)> {
116+
) -> Option<(ValueNs, Substitution)> {
117117
assert!(remaining_index < path.segments().len());
118118
// there may be more intermediate segments between the resolved one and
119119
// the end. Only the last segment needs to be resolved to a value; from
@@ -166,7 +166,7 @@ impl<'a> InferenceContext<'a> {
166166
trait_ref: TraitRef,
167167
segment: PathSegment<'_>,
168168
id: ExprOrPatId,
169-
) -> Option<(ValueNs, Option<Substitution>)> {
169+
) -> Option<(ValueNs, Substitution)> {
170170
let trait_ = trait_ref.hir_trait_id();
171171
let item =
172172
self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| {
@@ -202,16 +202,15 @@ impl<'a> InferenceContext<'a> {
202202
};
203203

204204
self.write_assoc_resolution(id, item, trait_ref.substitution.clone());
205-
Some((def, Some(trait_ref.substitution)))
205+
Some((def, trait_ref.substitution))
206206
}
207207

208-
// FIXME: Change sig to -> Option<(ValueNs, Substitution)>, subs aren't optional from here anymore
209208
fn resolve_ty_assoc_item(
210209
&mut self,
211210
ty: Ty,
212211
name: &Name,
213212
id: ExprOrPatId,
214-
) -> Option<(ValueNs, Option<Substitution>)> {
213+
) -> Option<(ValueNs, Substitution)> {
215214
if let TyKind::Error = ty.kind(Interner) {
216215
return None;
217216
}
@@ -280,15 +279,15 @@ impl<'a> InferenceContext<'a> {
280279
if !visible {
281280
self.push_diagnostic(InferenceDiagnostic::PrivateAssocItem { id, item });
282281
}
283-
Some((def, Some(substs)))
282+
Some((def, substs))
284283
}
285284

286285
fn resolve_enum_variant_on_ty(
287286
&mut self,
288287
ty: &Ty,
289288
name: &Name,
290289
id: ExprOrPatId,
291-
) -> Option<(ValueNs, Option<Substitution>)> {
290+
) -> Option<(ValueNs, Substitution)> {
292291
let ty = self.resolve_ty_shallow(ty);
293292
let (enum_id, subst) = match ty.as_adt() {
294293
Some((AdtId::EnumId(e), subst)) => (e, subst),
@@ -298,6 +297,6 @@ impl<'a> InferenceContext<'a> {
298297
let local_id = enum_data.variant(name)?;
299298
let variant = EnumVariantId { parent: enum_id, local_id };
300299
self.write_variant_resolution(id, variant.into());
301-
Some((ValueNs::EnumVariantId(variant), Some(subst.clone())))
300+
Some((ValueNs::EnumVariantId(variant), subst.clone()))
302301
}
303302
}

0 commit comments

Comments
 (0)