Skip to content

Commit 0689fdb

Browse files
committed
Add "add missing Ok/Some" fix
1 parent ab3313b commit 0689fdb

File tree

3 files changed

+252
-227
lines changed

3 files changed

+252
-227
lines changed

crates/hir/src/lib.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,26 @@ impl Adt {
10041004
Type::from_def(db, id.module(db.upcast()).krate(), id)
10051005
}
10061006

1007+
/// Turns this ADT into a type with the given type parameters. This isn't
1008+
/// the greatest API, FIXME find a better one.
1009+
pub fn ty_with_args(self, db: &dyn HirDatabase, args: &[Type]) -> Type {
1010+
let id = AdtId::from(self);
1011+
let mut it = args.iter().map(|t| t.ty.clone());
1012+
let ty = TyBuilder::def_ty(db, id.into())
1013+
.fill(|x| {
1014+
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
1015+
match x {
1016+
ParamKind::Type => GenericArgData::Ty(r).intern(Interner),
1017+
ParamKind::Const(ty) => {
1018+
unknown_const_as_generic(ty.clone())
1019+
}
1020+
}
1021+
})
1022+
.build();
1023+
let krate = id.module(db.upcast()).krate();
1024+
Type::new(db, krate, id, ty)
1025+
}
1026+
10071027
pub fn module(self, db: &dyn HirDatabase) -> Module {
10081028
match self {
10091029
Adt::Struct(s) => s.module(db),
@@ -1019,6 +1039,14 @@ impl Adt {
10191039
Adt::Enum(e) => e.name(db),
10201040
}
10211041
}
1042+
1043+
pub fn as_enum(&self) -> Option<Enum> {
1044+
if let Self::Enum(v) = self {
1045+
Some(*v)
1046+
} else {
1047+
None
1048+
}
1049+
}
10221050
}
10231051

10241052
impl HasVisibility for Adt {

crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs

Lines changed: 0 additions & 223 deletions
This file was deleted.

0 commit comments

Comments
 (0)