Implement better handling of divergence

Divergence here means that for some reason, the end of a block will not be
reached. We tried to model this just using the never type, but that doesn't work
fully (e.g. in `let x = { loop {}; "foo" };` x should still have type `&str`);
so this introduces a `diverges` flag that the type checker keeps track of, like
rustc does.
This commit is contained in:
Florian Diebold
2020-05-08 17:36:11 +02:00
parent d3eb9d8eaf
commit fe7bf993aa
7 changed files with 200 additions and 23 deletions

View File

@@ -730,6 +730,13 @@ impl Ty {
}
}
pub fn is_never(&self) -> bool {
match self {
Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }) => true,
_ => false,
}
}
/// If this is a `dyn Trait` type, this returns the `Trait` part.
pub fn dyn_trait_ref(&self) -> Option<&TraitRef> {
match self {