diff options
| author | fee1-dead <ent3rm4n@gmail.com> | 2023-01-09 23:35:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-09 23:35:27 +0800 |
| commit | c1f8a3ffb2b9b155b400a675727ebd470938805c (patch) | |
| tree | e301a684ac7a910ba6c7dab3cd9a44e3359a93c9 /compiler/rustc_trait_selection | |
| parent | b7587f1867c73f3517d7071bb4989dd7e19540f1 (diff) | |
| parent | afefbb66c3abea2e9b3acacddf7516b24c2bbeb8 (diff) | |
| download | rust-c1f8a3ffb2b9b155b400a675727ebd470938805c.tar.gz rust-c1f8a3ffb2b9b155b400a675727ebd470938805c.zip | |
Rollup merge of #105655 - RedDocMD:bug-105645, r=oli-obk
Remove invalid case for mutable borrow suggestion If we have a call such as `foo(&mut buf)` and after reference collapsing the type is inferred as `&T` where-as the required type is `&mut T`, don't suggest `foo(&mut mut buf)`. This is wrong syntactically and the issue lies elsewhere, not in the borrow. Fixes #105645
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index c52365ae3b7..43985495827 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1519,6 +1519,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { .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", |
