fn add_suggestion_for_rename_of_use(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        name: Symbol,
        import: &Import<'_>,
        binding_span: Span,
    ) {
        let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
            format!("Other{}", name)
        } else {
            format!("other_{}", name)
        };

        let mut suggestion = None;
        match import.kind {
            ImportKind::Single { type_ns_only: true, .. } => {
                suggestion = Some(format!("self as {}", suggested_name))
            }
            ImportKind::Single { source, .. } => {
                if let Some(pos) =
                    source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
                {
                    if let Ok(snippet) = self.session.source_map().span_to_snippet(binding_span) {
                        if pos <= snippet.len() {
                            suggestion = Some(format!(
                                "{} as {}{}",
                                &snippet[..pos],
                                suggested_name,
                                if snippet.ends_with(';') { ";" } else { "" }
                            ))
                        }
                    }
                }
            }
            ImportKind::ExternCrate { source, target, .. } => {
                suggestion = Some(format!(
                    "extern crate {} as {};",
                    source.unwrap_or(target.name),
                    suggested_name,
                ))
            }
            _ => unreachable!(),
        }

        let rename_msg = "you can use `as` to change the binding name of the import";
        if let Some(suggestion) = suggestion {
            err.span_suggestion(
                binding_span,
                rename_msg,
                suggestion,
                Applicability::MaybeIncorrect,
            );
        } else {
            err.span_label(binding_span, rename_msg);
        }
    }
/// This function adds a suggestion to change the binding name of a new import that conflicts
/// with an existing import.
///
/// ```text,ignore (diagnostic)
/// help: you can use `as` to change the binding name of the import
///    |
/// LL | use foo::bar as other_bar;
///    |     ^^^^^^^^^^^^^^^^^^^^^
/// ```
This function adds a suggestion to change the binding name of a new import that conflicts
with an existing import.


This function adds a suggestion to change the binding name of a new import that conflicts with an existing import .
fn add_suggestion_for_rename_of_use(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        name: Symbol,
        import: &Import<'_>,
        binding_span: Span,
    ) {
        let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
            format!("Other{}", name)
        } else {
            format!("other_{}", name)
        };
        let mut suggestion = None;
        match import.kind {
            ImportKind::Single { type_ns_only: true, .. } => {
                suggestion = Some(format!("self as {}", suggested_name))
            }
            ImportKind::Single { source, .. } => {
                if let Some(pos) =
                    source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
                {
                    if let Ok(snippet) = self.session.source_map().span_to_snippet(binding_span) {
                        if pos <= snippet.len() {
                            suggestion = Some(format!(
                                "{} as {}{}",
                                &snippet[..pos],
                                suggested_name,
                                if snippet.ends_with(';') { ";" } else { "" }
                            ))
                        }
                    }
                }
            }
            ImportKind::ExternCrate { source, target, .. } => {
                suggestion = Some(format!(
                    "extern crate {} as {};",
                    source.unwrap_or(target.name),
                    suggested_name,
                ))
            }
            _ => unreachable!(),
        }
        let rename_msg = "you can use `as` to change the binding name of the import";
        if let Some(suggestion) = suggestion {
            err.span_suggestion(
                binding_span,
                rename_msg,
                suggestion,
                Applicability::MaybeIncorrect,
            );
        } else {
            err.span_label(binding_span, rename_msg);
        }
    }
fn add_suggestion_for_rename_of_use ( & self , err : & mut DiagnosticBuilder < ' _ > , name : Symbol , import : & Import < ' _ > , binding_span : Span , ) { let suggested_name = if name . as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) { format ! ( " " name ) } else { format ! ( " " name ) } ; let mut suggestion = None ; match import . kind { ImportKind :: Single { type_ns_only : true , .. } => { suggestion = Some ( format ! ( " " suggested_name ) ) } ImportKind :: Single { source , .. } => { if let Some ( pos ) = source . span . hi ( ) . 0 . checked_sub ( binding_span . lo ( ) . 0 ) . map ( | pos | pos as usize ) { if let Ok ( snippet ) = self . session . source_map ( ) . span_to_snippet ( binding_span ) { if pos <= snippet . len ( ) { suggestion = Some ( format ! ( " " snippet [ pos ] suggested_name if snippet ends_with ( ';' ) { " " } else { " " } ) ) } } } } ImportKind :: ExternCrate { source , target , .. } => { suggestion = Some ( format ! ( " " source unwrap_or ( target name ) suggested_name ) ) } _ => unreachable ! ( ) , } let rename_msg = " " ; if let Some ( suggestion ) = suggestion { err . span_suggestion ( binding_span , rename_msg , suggestion , Applicability :: MaybeIncorrect , ) ; } else { err . span_label ( binding_span , rename_msg ) ; } }
This function adds a suggestion to change the binding name of a new import that conflicts
with an existing import.
This function adds a suggestion to change the binding name of a new import that conflicts with an existing import .
&self
err
&mut DiagnosticBuilder<'_>
name
Symbol
import
&Import<'_>
binding_span
Span
&self
err
&mut DiagnosticBuilder<'_>
name
Symbol
import
&Import<'_>
binding_span
Span