1 //! Diagnostics related methods for `TyS`.
3 use crate::ty::sty::InferTy;
4 use crate::ty::TyKind::*;
8 /// Similar to `TyS::is_primitive`, but also considers inferred numeric values to be primitive.
9 pub fn is_primitive_ty(&self) -> bool {
17 | Infer(InferTy::IntVar(_))
18 | Infer(InferTy::FloatVar(_))
19 | Infer(InferTy::FreshIntTy(_))
20 | Infer(InferTy::FreshFloatTy(_)) => true,
25 /// Whether the type is succinctly representable as a type instead of just referred to with a
26 /// description in error messages. This is used in the main error message.
27 pub fn is_simple_ty(&self) -> bool {
35 | Infer(InferTy::IntVar(_))
36 | Infer(InferTy::FloatVar(_))
37 | Infer(InferTy::FreshIntTy(_))
38 | Infer(InferTy::FreshFloatTy(_)) => true,
39 Ref(_, x, _) | Array(x, _) | Slice(x) => x.peel_refs().is_simple_ty(),
40 Tuple(tys) if tys.is_empty() => true,
45 /// Whether the type is succinctly representable as a type instead of just referred to with a
46 /// description in error messages. This is used in the primary span label. Beyond what
47 /// `is_simple_ty` includes, it also accepts ADTs with no type arguments and references to
48 /// ADTs with no type arguments.
49 pub fn is_simple_text(&self) -> bool {
51 Adt(_, substs) => substs.types().next().is_none(),
52 Ref(_, ty, _) => ty.is_simple_text(),
53 _ => self.is_simple_ty(),
57 /// Whether the type can be safely suggested during error recovery.
58 pub fn is_suggestable(&self) -> bool {
60 Opaque(..) | FnDef(..) | FnPtr(..) | Dynamic(..) | Closure(..) | Infer(..)
61 | Projection(..) => false,