pub fn to_diagnostic(&self) -> Diagnostic {
        match *self {
            TypeError::Internal(ref err) => err.to_diagnostic(),
            TypeError::ArgAppliedToNonFunction {
                fn_span,
                arg_span,
                ref found,
            } => Diagnostic::new_error(format!(
                "applied an argument to a term that was not a function - found type `{}`",
                found,
            ))
            .with_label(Label::new_primary(fn_span).with_message("the term"))
            .with_label(Label::new_secondary(arg_span).with_message("the applied argument")),
            TypeError::FunctionParamNeedsAnnotation {
                param_span,
                var_span: _, // TODO
                ref name,
            } => Diagnostic::new_error(format!(
                "type annotation needed for the function parameter `{}`",
                name
            ))
            .with_label(
                Label::new_primary(param_span)
                    .with_message("the parameter that requires an annotation"),
            ),
            TypeError::BinderNeedsAnnotation { span, ref binder } => Diagnostic::new_error(
                format!("type annotation needed for the binder `{}`", binder),
            )
            .with_label(
                Label::new_primary(span).with_message("the binder that requires an annotation"),
            ),
            TypeError::LiteralMismatch {
                literal_span,
                ref found,
                ref expected,
            } => {
                let found_text = match *found {
                    raw::Literal::String(_, _) => "string",
                    raw::Literal::Char(_, _) => "character",
                    raw::Literal::Int(_, _, _) => "numeric",
                    raw::Literal::Float(_, _, _) => "floating point",
                };

                Diagnostic::new_error(format!(
                    "found a {} literal, but expected a type `{}`",
                    found_text, expected,
                ))
                .with_label(Label::new_primary(literal_span).with_message("the literal"))
            },
            TypeError::AmbiguousStringLiteral { span } => Diagnostic::new_error(
                "ambiguous string literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousIntLiteral { span } => Diagnostic::new_error(
                "ambiguous integer literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousFloatLiteral { span } => Diagnostic::new_error(
                "ambiguous floating point literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousExtern { span } => Diagnostic::new_error(
                "ambiguous extern definition",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousEmptyMatch { span } => Diagnostic::new_error(
                "empty match expressions need type annotations",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::UnableToElaborateHole {
                span,
                expected: None,
                ..
            } => Diagnostic::new_error("unable to elaborate hole")
                .with_label(Label::new_primary(span).with_message("the hole")),
            TypeError::UnableToElaborateHole {
                span,
                expected: Some(ref expected),
                ..
            } => Diagnostic::new_error(format!(
                "unable to elaborate hole - expected: `{}`",
                expected,
            ))
            .with_label(Label::new_primary(span).with_message("the hole")),
            TypeError::UnexpectedFunction {
                span, ref expected, ..
            } => Diagnostic::new_error(format!(
                "found a function but expected a term of type `{}`",
                expected,
            ))
            .with_label(Label::new_primary(span).with_message("the function")),
            TypeError::Mismatch {
                span,
                ref found,
                ref expected,
            } => Diagnostic::new_error(format!(
                "found a term of type `{}`, but expected a term of type `{}`",
                found, expected,
            ))
            .with_label(Label::new_primary(span).with_message("the term")),
            TypeError::ExpectedUniverse { ref found, span } => {
                Diagnostic::new_error(format!("expected type, found a value of type `{}`", found))
                    .with_label(Label::new_primary(span).with_message("the value"))
            },
            TypeError::UndefinedName { ref free_var, span } => {
                Diagnostic::new_bug(format!("cannot find `{}` in scope", free_var))
                    .with_label(Label::new_primary(span).with_message("not found in this scope"))
            },
            TypeError::UndefinedExternName { span, ref name } => {
                Diagnostic::new_error(format!("cannot find external definition for `{:?}`", name))
                    .with_label(
                        Label::new_primary(span).with_message("external definition not found"),
                    )
            },
            TypeError::LabelMismatch {
                span,
                ref expected,
                ref found,
            } => Diagnostic::new_error(format!(
                "expected field called `{}`, but found a field called `{}`",
                expected, found,
            ))
            .with_label(Label::new_primary(span)),
            TypeError::AmbiguousStruct { span } => Diagnostic::new_error("ambiguous struct")
                .with_label(Label::new_primary(span).with_message("type annotations needed here")),
            TypeError::ArrayLengthMismatch {
                span,
                found_len,
                ref expected_len,
            } => Diagnostic::new_error(format!(
                "mismatched array length: expected {} elements but found {}",
                expected_len, found_len
            ))
            .with_label(
                Label::new_primary(span).with_message(format!("array with {} elements", found_len)),
            ),
            TypeError::AmbiguousArrayLiteral { span } => Diagnostic::new_error(
                "ambiguous array literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotations needed here")),
            TypeError::NoFieldInType {
                label_span,
                ref expected_label,
                ref found,
            } => Diagnostic::new_error(format!(
                "the type `{}` does not contain a field called `{}`",
                found, expected_label
            ))
            .with_label(Label::new_primary(label_span).with_message("the field lookup")),
            TypeError::StructSizeMismatch {
                span,
                found_size,
                expected_size,
            } => Diagnostic::new_error(format!(
                "mismatched record size: expected {} fields but found {}",
                expected_size, found_size
            ))
            .with_label(
                Label::new_primary(span).with_message(format!("record with {} fields", found_size)),
            ),
        }
    }
/// Convert the error into a diagnostic message
Convert the error into a diagnostic message
Convert the error into a diagnostic message
pub fn to_diagnostic(&self) -> Diagnostic {
        match *self {
            TypeError::Internal(ref err) => err.to_diagnostic(),
            TypeError::ArgAppliedToNonFunction {
                fn_span,
                arg_span,
                ref found,
            } => Diagnostic::new_error(format!(
                "applied an argument to a term that was not a function - found type `{}`",
                found,
            ))
            .with_label(Label::new_primary(fn_span).with_message("the term"))
            .with_label(Label::new_secondary(arg_span).with_message("the applied argument")),
            TypeError::FunctionParamNeedsAnnotation {
                param_span,
                var_span: _, // TODO
                ref name,
            } => Diagnostic::new_error(format!(
                "type annotation needed for the function parameter `{}`",
                name
            ))
            .with_label(
                Label::new_primary(param_span)
                    .with_message("the parameter that requires an annotation"),
            ),
            TypeError::BinderNeedsAnnotation { span, ref binder } => Diagnostic::new_error(
                format!("type annotation needed for the binder `{}`", binder),
            )
            .with_label(
                Label::new_primary(span).with_message("the binder that requires an annotation"),
            ),
            TypeError::LiteralMismatch {
                literal_span,
                ref found,
                ref expected,
            } => {
                let found_text = match *found {
                    raw::Literal::String(_, _) => "string",
                    raw::Literal::Char(_, _) => "character",
                    raw::Literal::Int(_, _, _) => "numeric",
                    raw::Literal::Float(_, _, _) => "floating point",
                };
                Diagnostic::new_error(format!(
                    "found a {} literal, but expected a type `{}`",
                    found_text, expected,
                ))
                .with_label(Label::new_primary(literal_span).with_message("the literal"))
            },
            TypeError::AmbiguousStringLiteral { span } => Diagnostic::new_error(
                "ambiguous string literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousIntLiteral { span } => Diagnostic::new_error(
                "ambiguous integer literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousFloatLiteral { span } => Diagnostic::new_error(
                "ambiguous floating point literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousExtern { span } => Diagnostic::new_error(
                "ambiguous extern definition",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::AmbiguousEmptyMatch { span } => Diagnostic::new_error(
                "empty match expressions need type annotations",
            )
            .with_label(Label::new_primary(span).with_message("type annotation needed here")),
            TypeError::UnableToElaborateHole {
                span,
                expected: None,
                ..
            } => Diagnostic::new_error("unable to elaborate hole")
                .with_label(Label::new_primary(span).with_message("the hole")),
            TypeError::UnableToElaborateHole {
                span,
                expected: Some(ref expected),
                ..
            } => Diagnostic::new_error(format!(
                "unable to elaborate hole - expected: `{}`",
                expected,
            ))
            .with_label(Label::new_primary(span).with_message("the hole")),
            TypeError::UnexpectedFunction {
                span, ref expected, ..
            } => Diagnostic::new_error(format!(
                "found a function but expected a term of type `{}`",
                expected,
            ))
            .with_label(Label::new_primary(span).with_message("the function")),
            TypeError::Mismatch {
                span,
                ref found,
                ref expected,
            } => Diagnostic::new_error(format!(
                "found a term of type `{}`, but expected a term of type `{}`",
                found, expected,
            ))
            .with_label(Label::new_primary(span).with_message("the term")),
            TypeError::ExpectedUniverse { ref found, span } => {
                Diagnostic::new_error(format!("expected type, found a value of type `{}`", found))
                    .with_label(Label::new_primary(span).with_message("the value"))
            },
            TypeError::UndefinedName { ref free_var, span } => {
                Diagnostic::new_bug(format!("cannot find `{}` in scope", free_var))
                    .with_label(Label::new_primary(span).with_message("not found in this scope"))
            },
            TypeError::UndefinedExternName { span, ref name } => {
                Diagnostic::new_error(format!("cannot find external definition for `{:?}`", name))
                    .with_label(
                        Label::new_primary(span).with_message("external definition not found"),
                    )
            },
            TypeError::LabelMismatch {
                span,
                ref expected,
                ref found,
            } => Diagnostic::new_error(format!(
                "expected field called `{}`, but found a field called `{}`",
                expected, found,
            ))
            .with_label(Label::new_primary(span)),
            TypeError::AmbiguousStruct { span } => Diagnostic::new_error("ambiguous struct")
                .with_label(Label::new_primary(span).with_message("type annotations needed here")),
            TypeError::ArrayLengthMismatch {
                span,
                found_len,
                ref expected_len,
            } => Diagnostic::new_error(format!(
                "mismatched array length: expected {} elements but found {}",
                expected_len, found_len
            ))
            .with_label(
                Label::new_primary(span).with_message(format!("array with {} elements", found_len)),
            ),
            TypeError::AmbiguousArrayLiteral { span } => Diagnostic::new_error(
                "ambiguous array literal",
            )
            .with_label(Label::new_primary(span).with_message("type annotations needed here")),
            TypeError::NoFieldInType {
                label_span,
                ref expected_label,
                ref found,
            } => Diagnostic::new_error(format!(
                "the type `{}` does not contain a field called `{}`",
                found, expected_label
            ))
            .with_label(Label::new_primary(label_span).with_message("the field lookup")),
            TypeError::StructSizeMismatch {
                span,
                found_size,
                expected_size,
            } => Diagnostic::new_error(format!(
                "mismatched record size: expected {} fields but found {}",
                expected_size, found_size
            ))
            .with_label(
                Label::new_primary(span).with_message(format!("record with {} fields", found_size)),
            ),
        }
    }
pub fn to_diagnostic ( & self ) -> Diagnostic { match * self { TypeError :: Internal ( ref err ) => err . to_diagnostic ( ) , TypeError :: ArgAppliedToNonFunction { fn_span , arg_span , ref found , } => Diagnostic :: new_error ( format ! ( " " found ) ) . with_label ( Label :: new_primary ( fn_span ) . with_message ( " " ) ) . with_label ( Label :: new_secondary ( arg_span ) . with_message ( " " ) ) , TypeError :: FunctionParamNeedsAnnotation { param_span , var_span : _ , // TODO ref name , } => Diagnostic :: new_error ( format ! ( " " name ) ) . with_label ( Label :: new_primary ( param_span ) . with_message ( " " ) , ) , TypeError :: BinderNeedsAnnotation { span , ref binder } => Diagnostic :: new_error ( format ! ( " " binder ) , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) , ) , TypeError :: LiteralMismatch { literal_span , ref found , ref expected , } => { let found_text = match * found { raw :: Literal :: String ( _ , _ ) => " " , raw :: Literal :: Char ( _ , _ ) => " " , raw :: Literal :: Int ( _ , _ , _ ) => " " , raw :: Literal :: Float ( _ , _ , _ ) => " " , } ; Diagnostic :: new_error ( format ! ( " " found_text expected ) ) . with_label ( Label :: new_primary ( literal_span ) . with_message ( " " ) ) } , TypeError :: AmbiguousStringLiteral { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: AmbiguousIntLiteral { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: AmbiguousFloatLiteral { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: AmbiguousExtern { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: AmbiguousEmptyMatch { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: UnableToElaborateHole { span , expected : None , .. } => Diagnostic :: new_error ( " " ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: UnableToElaborateHole { span , expected : Some ( ref expected ) , .. } => Diagnostic :: new_error ( format ! ( " " expected ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: UnexpectedFunction { span , ref expected , .. } => Diagnostic :: new_error ( format ! ( " " expected ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: Mismatch { span , ref found , ref expected , } => Diagnostic :: new_error ( format ! ( " " found expected ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: ExpectedUniverse { ref found , span } => { Diagnostic :: new_error ( format ! ( " " found ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) } , TypeError :: UndefinedName { ref free_var , span } => { Diagnostic :: new_bug ( format ! ( " " free_var ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) } , TypeError :: UndefinedExternName { span , ref name } => { Diagnostic :: new_error ( format ! ( " " name ) ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) , ) } , TypeError :: LabelMismatch { span , ref expected , ref found , } => Diagnostic :: new_error ( format ! ( " " expected found ) ) . with_label ( Label :: new_primary ( span ) ) , TypeError :: AmbiguousStruct { span } => Diagnostic :: new_error ( " " ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: ArrayLengthMismatch { span , found_len , ref expected_len , } => Diagnostic :: new_error ( format ! ( " " expected_len found_len ) ) . with_label ( Label :: new_primary ( span ) . with_message ( format ! ( " " found_len ) ) , ) , TypeError :: AmbiguousArrayLiteral { span } => Diagnostic :: new_error ( " " , ) . with_label ( Label :: new_primary ( span ) . with_message ( " " ) ) , TypeError :: NoFieldInType { label_span , ref expected_label , ref found , } => Diagnostic :: new_error ( format ! ( " " found expected_label ) ) . with_label ( Label :: new_primary ( label_span ) . with_message ( " " ) ) , TypeError :: StructSizeMismatch { span , found_size , expected_size , } => Diagnostic :: new_error ( format ! ( " " expected_size found_size ) ) . with_label ( Label :: new_primary ( span ) . with_message ( format ! ( " " found_size ) ) , ) , } }
Convert the error into a diagnostic message
Convert the error into a diagnostic message
&self
&self