fn suggest_change_mut(
        &self,
        obligation: &PredicateObligation<'tcx>,
        err: &mut DiagnosticBuilder<'tcx>,
        trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
        points_at_arg: bool,
    ) {
        let span = obligation.cause.span;
        if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
            let refs_number = snippet.chars()
                .filter(|c| !c.is_whitespace())
                .take_while(|c| *c == '&')
                .count();
            if let Some('\'') = snippet.chars()
                .filter(|c| !c.is_whitespace())
                .skip(refs_number)
                .next()
            { // Do not suggest removal of borrow from type arguments.
                return;
            }
            let trait_ref = self.resolve_vars_if_possible(trait_ref);
            if trait_ref.has_infer_types() {
                // Do not ICE while trying to find if a reborrow would succeed on a trait with
                // unresolved bindings.
                return;
            }

            if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
                let trait_type = match mutability {
                    hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
                    hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
                };

                let new_obligation = self.mk_obligation_for_def_id(
                    trait_ref.skip_binder().def_id,
                    trait_type,
                    ObligationCause::dummy(),
                    obligation.param_env,
                );

                if self.evaluate_obligation_no_overflow(
                    &new_obligation,
                ).must_apply_modulo_regions() {
                    let sp = self.tcx.sess.source_map()
                        .span_take_while(span, |c| c.is_whitespace() || *c == '&');
                    if points_at_arg &&
                        mutability == hir::Mutability::Not &&
                        refs_number > 0
                    {
                        err.span_suggestion(
                            sp,
                            "consider changing this borrow's mutability",
                            "&mut ".to_string(),
                            Applicability::MachineApplicable,
                        );
                    } else {
                        err.note(&format!(
                            "`{}` is implemented for `{:?}`, but not for `{:?}`",
                            trait_ref.print_only_trait_path(),
                            trait_type,
                            trait_ref.skip_binder().self_ty(),
                        ));
                    }
                }
            }
        }
    }
/// Check if the trait bound is implemented for a different mutability and note it in the
/// final error.
Check if the trait bound is implemented for a different mutability and note it in the
final error.
Check if the trait bound is implemented for a different mutability and note it in the final error .
fn suggest_change_mut(
        &self,
        obligation: &PredicateObligation<'tcx>,
        err: &mut DiagnosticBuilder<'tcx>,
        trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
        points_at_arg: bool,
    ) {
        let span = obligation.cause.span;
        if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
            let refs_number = snippet.chars()
                .filter(|c| !c.is_whitespace())
                .take_while(|c| *c == '&')
                .count();
            if let Some('\'') = snippet.chars()
                .filter(|c| !c.is_whitespace())
                .skip(refs_number)
                .next()
            { // Do not suggest removal of borrow from type arguments.
                return;
            }
            let trait_ref = self.resolve_vars_if_possible(trait_ref);
            if trait_ref.has_infer_types() {
                // Do not ICE while trying to find if a reborrow would succeed on a trait with
                // unresolved bindings.
                return;
            }
            if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
                let trait_type = match mutability {
                    hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
                    hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
                };
                let new_obligation = self.mk_obligation_for_def_id(
                    trait_ref.skip_binder().def_id,
                    trait_type,
                    ObligationCause::dummy(),
                    obligation.param_env,
                );
                if self.evaluate_obligation_no_overflow(
                    &new_obligation,
                ).must_apply_modulo_regions() {
                    let sp = self.tcx.sess.source_map()
                        .span_take_while(span, |c| c.is_whitespace() || *c == '&');
                    if points_at_arg &&
                        mutability == hir::Mutability::Not &&
                        refs_number > 0
                    {
                        err.span_suggestion(
                            sp,
                            "consider changing this borrow's mutability",
                            "&mut ".to_string(),
                            Applicability::MachineApplicable,
                        );
                    } else {
                        err.note(&format!(
                            "`{}` is implemented for `{:?}`, but not for `{:?}`",
                            trait_ref.print_only_trait_path(),
                            trait_type,
                            trait_ref.skip_binder().self_ty(),
                        ));
                    }
                }
            }
        }
    }
fn suggest_change_mut ( & self , obligation : & PredicateObligation < ' tcx > , err : & mut DiagnosticBuilder < ' tcx > , trait_ref : & ty :: Binder < ty :: TraitRef < ' tcx > > , points_at_arg : bool , ) { let span = obligation . cause . span ; if let Ok ( snippet ) = self . tcx . sess . source_map ( ) . span_to_snippet ( span ) { let refs_number = snippet . chars ( ) . filter ( | c | ! c . is_whitespace ( ) ) . take_while ( | c | * c == '&' ) . count ( ) ; if let Some ( '\'' ) = snippet . chars ( ) . filter ( | c | ! c . is_whitespace ( ) ) . skip ( refs_number ) . next ( ) { // Do not suggest removal of borrow from type arguments. return ; } let trait_ref = self . resolve_vars_if_possible ( trait_ref ) ; if trait_ref . has_infer_types ( ) { // Do not ICE while trying to find if a reborrow would succeed on a trait with // unresolved bindings. return ; } if let ty :: Ref ( region , t_type , mutability ) = trait_ref . skip_binder ( ) . self_ty ( ) . kind { let trait_type = match mutability { hir :: Mutability :: Mut => self . tcx . mk_imm_ref ( region , t_type ) , hir :: Mutability :: Not => self . tcx . mk_mut_ref ( region , t_type ) , } ; let new_obligation = self . mk_obligation_for_def_id ( trait_ref . skip_binder ( ) . def_id , trait_type , ObligationCause :: dummy ( ) , obligation . param_env , ) ; if self . evaluate_obligation_no_overflow ( & new_obligation , ) . must_apply_modulo_regions ( ) { let sp = self . tcx . sess . source_map ( ) . span_take_while ( span , | c | c . is_whitespace ( ) || * c == '&' ) ; if points_at_arg && mutability == hir :: Mutability :: Not && refs_number > 0 { err . span_suggestion ( sp , " " , " " . to_string ( ) , Applicability :: MachineApplicable , ) ; } else { err . note ( & format ! ( " " trait_ref print_only_trait_path ( ) trait_type trait_ref skip_binder ( ) self_ty ( ) ) ) ; } } } } }
Check if the trait bound is implemented for a different mutability and note it in the
final error.
Check if the trait bound is implemented for a different mutability and note it in the final error .
&self
obligation
&PredicateObligation<'tcx>
err
&mut DiagnosticBuilder<'tcx>
trait_ref
&ty::Binder<ty::TraitRef<'tcx>>
points_at_arg
bool