1
Fork 0

Change ty_with_args to return Ty instead of Result

Although, we would like to avoid crashes whenever
possible, and that's why I wanted to make this API fallible. It's
looking pretty hard to do proper validation.

I think many of our APIs will unfortunately depend on the user doing
the correct thing since at the MIR level we are working on,
we expect types to have been checked already.
This commit is contained in:
Celina G. Val 2023-12-05 12:01:09 -08:00
parent 1720b108f7
commit 326fea0fb8
8 changed files with 148 additions and 33 deletions

View file

@ -382,7 +382,9 @@ impl AdtDef {
}
/// Retrieve the type of this Adt instantiating the type with the given arguments.
pub fn ty_with_args(&self, args: &GenericArgs) -> Result<Ty, Error> {
///
/// This will assume the type can be instantiated with these arguments.
pub fn ty_with_args(&self, args: &GenericArgs) -> Ty {
with(|cx| cx.def_ty_with_args(self.0, args))
}
@ -441,6 +443,7 @@ impl VariantDef {
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FieldDef {
/// The field definition.
///
@ -454,7 +457,9 @@ pub struct FieldDef {
impl FieldDef {
/// Retrieve the type of this field instantiating the type with the given arguments.
pub fn ty_with_args(&self, args: &GenericArgs) -> Result<Ty, Error> {
///
/// This will assume the type can be instantiated with these arguments.
pub fn ty_with_args(&self, args: &GenericArgs) -> Ty {
with(|cx| cx.def_ty_with_args(self.def, args))
}