fn warning_emit_diagnostics_with<'a, O>(
    this: &Warning,
    out: &mut O,
    sources: &'a Sources,
    files: &'a impl Files<'a, FileId = SourceId>,
    config: &codespan_reporting::term::Config,
) -> Result<(), DiagnosticsError>
where
    O: WriteColor,
{
    let mut notes = Vec::new();
    let mut labels = Vec::new();

    let context = match this.kind() {
        WarningKind::NotUsed { span, context } => {
            labels.push(Label::primary(this.source_id(), span.range()).with_message("not used"));

            *context
        }
        WarningKind::LetPatternMightPanic { span, context } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("let binding might panic"),
            );

            let binding = sources
                .source_at(this.source_id())
                .and_then(|s| s.source(*span));

            if let Some(binding) = binding {
                let mut note = String::new();
                writeln!(note, "Hint: Rewrite to:")?;
                writeln!(note, "if {} {{", binding)?;
                writeln!(note, "    // ..")?;
                writeln!(note, "}}")?;
                notes.push(note);
            }

            *context
        }
        WarningKind::TemplateWithoutExpansions { span, context } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("template string without expansions like `${1 + 2}`"),
            );

            *context
        }
        WarningKind::RemoveTupleCallParams {
            span,
            variant,
            context,
        } => {
            labels.push(
                Label::secondary(this.source_id(), span.range())
                    .with_message("constructing this variant could be done without parentheses"),
            );

            let variant = sources
                .source_at(this.source_id())
                .and_then(|s| s.source(*variant));

            if let Some(variant) = variant {
                let mut note = String::new();
                writeln!(note, "Hint: Rewrite to `{}`", variant)?;
                notes.push(note);
            }

            *context
        }
        WarningKind::UnecessarySemiColon { span } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("unnecessary semicolon"),
            );

            None
        }
    };

    if let Some(context) = context {
        labels.push(
            Label::secondary(this.source_id(), context.range()).with_message("in this context"),
        );
    }

    let diagnostic = Diagnostic::warning()
        .with_message("warning")
        .with_labels(labels)
        .with_notes(notes);

    term::emit(out, config, files, &diagnostic)?;
    Ok(())
}
/// Helper to emit diagnostics for a warning.
Helper to emit diagnostics for a warning.
Helper to emit diagnostics for a warning .
fn warning_emit_diagnostics_with<'a, O>(
    this: &Warning,
    out: &mut O,
    sources: &'a Sources,
    files: &'a impl Files<'a, FileId = SourceId>,
    config: &codespan_reporting::term::Config,
) -> Result<(), DiagnosticsError>
where
    O: WriteColor,
{
    let mut notes = Vec::new();
    let mut labels = Vec::new();
    let context = match this.kind() {
        WarningKind::NotUsed { span, context } => {
            labels.push(Label::primary(this.source_id(), span.range()).with_message("not used"));
            *context
        }
        WarningKind::LetPatternMightPanic { span, context } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("let binding might panic"),
            );
            let binding = sources
                .source_at(this.source_id())
                .and_then(|s| s.source(*span));
            if let Some(binding) = binding {
                let mut note = String::new();
                writeln!(note, "Hint: Rewrite to:")?;
                writeln!(note, "if {} {{", binding)?;
                writeln!(note, "    // ..")?;
                writeln!(note, "}}")?;
                notes.push(note);
            }
            *context
        }
        WarningKind::TemplateWithoutExpansions { span, context } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("template string without expansions like `${1 + 2}`"),
            );
            *context
        }
        WarningKind::RemoveTupleCallParams {
            span,
            variant,
            context,
        } => {
            labels.push(
                Label::secondary(this.source_id(), span.range())
                    .with_message("constructing this variant could be done without parentheses"),
            );
            let variant = sources
                .source_at(this.source_id())
                .and_then(|s| s.source(*variant));
            if let Some(variant) = variant {
                let mut note = String::new();
                writeln!(note, "Hint: Rewrite to `{}`", variant)?;
                notes.push(note);
            }
            *context
        }
        WarningKind::UnecessarySemiColon { span } => {
            labels.push(
                Label::primary(this.source_id(), span.range())
                    .with_message("unnecessary semicolon"),
            );
            None
        }
    };
    if let Some(context) = context {
        labels.push(
            Label::secondary(this.source_id(), context.range()).with_message("in this context"),
        );
    }
    let diagnostic = Diagnostic::warning()
        .with_message("warning")
        .with_labels(labels)
        .with_notes(notes);
    term::emit(out, config, files, &diagnostic)?;
    Ok(())
}
fn warning_emit_diagnostics_with < ' a , O > ( this : & Warning , out : & mut O , sources : & ' a Sources , files : & ' a impl Files < ' a , FileId = SourceId > , config : & codespan_reporting :: term :: Config , ) -> Result < ( ) , DiagnosticsError > where O : WriteColor , { let mut notes = Vec :: new ( ) ; let mut labels = Vec :: new ( ) ; let context = match this . kind ( ) { WarningKind :: NotUsed { span , context } => { labels . push ( Label :: primary ( this . source_id ( ) , span . range ( ) ) . with_message ( " " ) ) ; * context } WarningKind :: LetPatternMightPanic { span , context } => { labels . push ( Label :: primary ( this . source_id ( ) , span . range ( ) ) . with_message ( " " ) , ) ; let binding = sources . source_at ( this . source_id ( ) ) . and_then ( | s | s . source ( * span ) ) ; if let Some ( binding ) = binding { let mut note = String :: new ( ) ; writeln ! ( note " " ) ? ; writeln ! ( note " " binding ) ? ; writeln ! ( note " " ) ? ; writeln ! ( note " " ) ? ; notes . push ( note ) ; } * context } WarningKind :: TemplateWithoutExpansions { span , context } => { labels . push ( Label :: primary ( this . source_id ( ) , span . range ( ) ) . with_message ( " " ) , ) ; * context } WarningKind :: RemoveTupleCallParams { span , variant , context , } => { labels . push ( Label :: secondary ( this . source_id ( ) , span . range ( ) ) . with_message ( " " ) , ) ; let variant = sources . source_at ( this . source_id ( ) ) . and_then ( | s | s . source ( * variant ) ) ; if let Some ( variant ) = variant { let mut note = String :: new ( ) ; writeln ! ( note " " variant ) ? ; notes . push ( note ) ; } * context } WarningKind :: UnecessarySemiColon { span } => { labels . push ( Label :: primary ( this . source_id ( ) , span . range ( ) ) . with_message ( " " ) , ) ; None } } ; if let Some ( context ) = context { labels . push ( Label :: secondary ( this . source_id ( ) , context . range ( ) ) . with_message ( " " ) , ) ; } let diagnostic = Diagnostic :: warning ( ) . with_message ( " " ) . with_labels ( labels ) . with_notes ( notes ) ; term :: emit ( out , config , files , & diagnostic ) ? ; Ok ( ( ) ) }
Helper to emit diagnostics for a warning.
Helper to emit diagnostics for a warning .
this
&Warning
out
&mut O
sources
&'a Sources
files
&'a impl Files<'a, FileId = SourceId>
config
&codespan_reporting::term::Config
this
&Warning
out
&mut O
sources
&'a Sources
files
&'a impl Files<'a, FileId = SourceId>
config
&codespan_reporting::term::Config