pub fn into_diagnostic(self, interner: &NodeInterner) -> Diagnostic {
        match self {
            ResolverError::DuplicateDefinition {
                first_ident,
                second_ident,
            } => {
                let first_span = interner.ident_span(&first_ident);
                let second_span = interner.ident_span(&second_ident);

                let name = interner.ident_name(&first_ident);

                let mut diag = Diagnostic::simple_error(
                    format!("duplicate definitions of {} found", name),
                    "first definition found here".to_string(),
                    first_span,
                );
                diag.add_secondary("second definition found here".to_string(), second_span);
                diag
            }
            ResolverError::UnusedVariable { ident_id } => {
                let name = interner.ident_name(&ident_id);
                let span = interner.ident_span(&ident_id);

                let mut diag = Diagnostic::simple_error(
                    format!("unused variable {}", name),
                    "unused variable ".to_string(),
                    span,
                );

                diag.add_note("A new variable usually means a constraint has been added and is being unused. \n For this reason, it is almost always a bug to declare a variable and not use it.".to_owned());
                diag
            }
            ResolverError::VariableNotDeclared { name, span } => Diagnostic::simple_error(
                format!("cannot find `{}` in this scope ", name),
                "not found in this scope".to_string(),
                span,
            ),
            ResolverError::PathIsNotIdent { span } => Diagnostic::simple_error(
                "cannot use path as an identifier".to_string(),
                String::new(),
                span,
            ),
            ResolverError::PathUnresolved {
                span,
                name,
                segment,
            } => {
                let mut diag = Diagnostic::simple_error(
                    format!("could not resolve path : {}", name),
                    String::new(),
                    span,
                );
                // XXX: When the secondary and primary labels have spans that
                // overlap, you cannot differentiate between them.
                // This error is an example of this.
                diag.add_secondary(
                    format!("could not resolve `{}` in path", &segment.0.contents),
                    segment.0.span(),
                );

                diag
            }
            ResolverError::Expected {
                span,
                expected,
                got,
            } => Diagnostic::simple_error(
                format!("expected {} got {}", expected, got),
                String::new(),
                span,
            ),
        }
    }
/// Only user errors can be transformed into a Diagnostic
/// ICEs will make the compiler panic, as they could affect the
/// soundness of the generated program
Only user errors can be transformed into a Diagnostic
ICEs will make the compiler panic, as they could affect the
soundness of the generated program
Only user errors can be transformed into a Diagnostic ICEs will make the compiler panic as they could affect the soundness of the generated program
pub fn into_diagnostic(self, interner: &NodeInterner) -> Diagnostic {
        match self {
            ResolverError::DuplicateDefinition {
                first_ident,
                second_ident,
            } => {
                let first_span = interner.ident_span(&first_ident);
                let second_span = interner.ident_span(&second_ident);
                let name = interner.ident_name(&first_ident);
                let mut diag = Diagnostic::simple_error(
                    format!("duplicate definitions of {} found", name),
                    "first definition found here".to_string(),
                    first_span,
                );
                diag.add_secondary("second definition found here".to_string(), second_span);
                diag
            }
            ResolverError::UnusedVariable { ident_id } => {
                let name = interner.ident_name(&ident_id);
                let span = interner.ident_span(&ident_id);
                let mut diag = Diagnostic::simple_error(
                    format!("unused variable {}", name),
                    "unused variable ".to_string(),
                    span,
                );
                diag.add_note("A new variable usually means a constraint has been added and is being unused. \n For this reason, it is almost always a bug to declare a variable and not use it.".to_owned());
                diag
            }
            ResolverError::VariableNotDeclared { name, span } => Diagnostic::simple_error(
                format!("cannot find `{}` in this scope ", name),
                "not found in this scope".to_string(),
                span,
            ),
            ResolverError::PathIsNotIdent { span } => Diagnostic::simple_error(
                "cannot use path as an identifier".to_string(),
                String::new(),
                span,
            ),
            ResolverError::PathUnresolved {
                span,
                name,
                segment,
            } => {
                let mut diag = Diagnostic::simple_error(
                    format!("could not resolve path : {}", name),
                    String::new(),
                    span,
                );
                // XXX: When the secondary and primary labels have spans that
                // overlap, you cannot differentiate between them.
                // This error is an example of this.
                diag.add_secondary(
                    format!("could not resolve `{}` in path", &segment.0.contents),
                    segment.0.span(),
                );
                diag
            }
            ResolverError::Expected {
                span,
                expected,
                got,
            } => Diagnostic::simple_error(
                format!("expected {} got {}", expected, got),
                String::new(),
                span,
            ),
        }
    }
pub fn into_diagnostic ( self , interner : & NodeInterner ) -> Diagnostic { match self { ResolverError :: DuplicateDefinition { first_ident , second_ident , } => { let first_span = interner . ident_span ( & first_ident ) ; let second_span = interner . ident_span ( & second_ident ) ; let name = interner . ident_name ( & first_ident ) ; let mut diag = Diagnostic :: simple_error ( format ! ( " " name ) , " " . to_string ( ) , first_span , ) ; diag . add_secondary ( " " . to_string ( ) , second_span ) ; diag } ResolverError :: UnusedVariable { ident_id } => { let name = interner . ident_name ( & ident_id ) ; let span = interner . ident_span ( & ident_id ) ; let mut diag = Diagnostic :: simple_error ( format ! ( " " name ) , " " . to_string ( ) , span , ) ; diag . add_note ( " \n " . to_owned ( ) ) ; diag } ResolverError :: VariableNotDeclared { name , span } => Diagnostic :: simple_error ( format ! ( " " name ) , " " . to_string ( ) , span , ) , ResolverError :: PathIsNotIdent { span } => Diagnostic :: simple_error ( " " . to_string ( ) , String :: new ( ) , span , ) , ResolverError :: PathUnresolved { span , name , segment , } => { let mut diag = Diagnostic :: simple_error ( format ! ( " " name ) , String :: new ( ) , span , ) ; // XXX: When the secondary and primary labels have spans that // overlap, you cannot differentiate between them. // This error is an example of this. diag . add_secondary ( format ! ( " " segment 0 contents ) , segment . 0 . span ( ) , ) ; diag } ResolverError :: Expected { span , expected , got , } => Diagnostic :: simple_error ( format ! ( " " expected got ) , String :: new ( ) , span , ) , } }
Only user errors can be transformed into a Diagnostic
ICEs will make the compiler panic, as they could affect the
soundness of the generated program
Only user errors can be transformed into a Diagnostic ICEs will make the compiler panic as they could affect the soundness of the generated program
self
interner
&NodeInterner
self
interner
&NodeInterner