]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Rollup merge of #105655 - RedDocMD:bug-105645, r=oli-obk
[rust.git] / compiler / rustc_trait_selection / src / traits / error_reporting / suggestions.rs
index c52365ae3b7c7309cc90bd44db5de64e07573482..439854958270c4851385dd0d97d930a5edf559e4 100644 (file)
@@ -1519,6 +1519,13 @@ fn suggest_change_mut(
                         .source_map()
                         .span_take_while(span, |c| c.is_whitespace() || *c == '&');
                     if points_at_arg && mutability.is_not() && refs_number > 0 {
+                        // If we have a call like foo(&mut buf), then don't suggest foo(&mut mut buf)
+                        if snippet
+                            .trim_start_matches(|c: char| c.is_whitespace() || c == '&')
+                            .starts_with("mut")
+                        {
+                            return;
+                        }
                         err.span_suggestion_verbose(
                             sp,
                             "consider changing this borrow's mutability",