1 //! Diagnostics related methods for `TyS`.
4 use crate::ty::TyKind::*;
5 use crate::ty::sty::InferTy;
8 /// Similar to `TyS::is_primitive`, but also considers inferred numeric values to be primitive.
9 pub fn is_primitive_ty(&self) -> bool {
11 Bool | Char | Str | Int(_) | Uint(_) | Float(_) |
12 Infer(InferTy::IntVar(_)) | Infer(InferTy::FloatVar(_)) |
13 Infer(InferTy::FreshIntTy(_)) | Infer(InferTy::FreshFloatTy(_)) => true,
18 /// Whether the type is succinctly representable as a type instead of just referred to with a
19 /// description in error messages. This is used in the main error message.
20 pub fn is_simple_ty(&self) -> bool {
22 Bool | Char | Str | Int(_) | Uint(_) | Float(_) |
23 Infer(InferTy::IntVar(_)) | Infer(InferTy::FloatVar(_)) |
24 Infer(InferTy::FreshIntTy(_)) | Infer(InferTy::FreshFloatTy(_)) => true,
25 Ref(_, x, _) | Array(x, _) | Slice(x) => x.peel_refs().is_simple_ty(),
26 Tuple(tys) if tys.is_empty() => true,
31 /// Whether the type is succinctly representable as a type instead of just referred to with a
32 /// description in error messages. This is used in the primary span label. Beyond what
33 /// `is_simple_ty` includes, it also accepts ADTs with no type arguments and references to
34 /// ADTs with no type arguments.
35 pub fn is_simple_text(&self) -> bool {
37 Adt(_, substs) => substs.types().next().is_none(),
38 Ref(_, ty, _) => ty.is_simple_text(),
39 _ => self.is_simple_ty(),
43 /// Whether the type can be safely suggested during error recovery.
44 pub fn is_suggestable(&self) -> bool {
52 Projection(..) => false,