Commit f9157f5
committed
Auto merge of rust-lang#51242 - ytausky:mut-ref, r=estebank
Suggest not mutably borrowing a mutable reference
This PR would (hopefully) solve rust-lang#45392. I deviated a bit from @estebank's instructions since the error span only included the borrowed expression (e.g. the `b` in `&mut b`). I also didn't check the mutability of the local binding, since this whole case is concerned with an immutable local.
I can see two outstanding questions:
1. `note_immutability_blame` is called in two places, but I only have one test case. I think it covers the call in `report_bckerror`, but I'm not sure how to trigger the call from `report_aliasability_violation`.
2. There is one failing test, where the local binding is `self: &mut Self`. I'm not entirely sure what the correct output should be, but I think the new message should also apply. Unfortunately, since this parameter is parsed differently, its `let_span` covers both the pattern and the type, leading to a wrong suggestion text. I'm not sure how to correctly identify this case.File tree
6 files changed
+114
-39
lines changed- src
- librustc_borrowck/borrowck
- libsyntax/parse
- test/ui
- borrowck
- did_you_mean
6 files changed
+114
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
| 902 | + | |
903 | 903 | | |
904 | 904 | | |
905 | 905 | | |
| |||
1105 | 1105 | | |
1106 | 1106 | | |
1107 | 1107 | | |
1108 | | - | |
| 1108 | + | |
1109 | 1109 | | |
1110 | 1110 | | |
1111 | 1111 | | |
| |||
1184 | 1184 | | |
1185 | 1185 | | |
1186 | 1186 | | |
1187 | | - | |
| 1187 | + | |
| 1188 | + | |
1188 | 1189 | | |
1189 | 1190 | | |
1190 | 1191 | | |
1191 | 1192 | | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
| 1193 | + | |
1206 | 1194 | | |
1207 | 1195 | | |
1208 | 1196 | | |
| |||
1242 | 1230 | | |
1243 | 1231 | | |
1244 | 1232 | | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
1245 | 1273 | | |
1246 | 1274 | | |
1247 | 1275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5190 | 5190 | | |
5191 | 5191 | | |
5192 | 5192 | | |
5193 | | - | |
| 5193 | + | |
5194 | 5194 | | |
5195 | 5195 | | |
5196 | 5196 | | |
5197 | 5197 | | |
5198 | 5198 | | |
5199 | 5199 | | |
5200 | | - | |
| 5200 | + | |
5201 | 5201 | | |
5202 | | - | |
| 5202 | + | |
5203 | 5203 | | |
5204 | 5204 | | |
5205 | 5205 | | |
5206 | 5206 | | |
5207 | | - | |
| 5207 | + | |
5208 | 5208 | | |
5209 | 5209 | | |
5210 | 5210 | | |
5211 | 5211 | | |
5212 | | - | |
| 5212 | + | |
5213 | 5213 | | |
5214 | 5214 | | |
5215 | 5215 | | |
5216 | 5216 | | |
5217 | 5217 | | |
5218 | 5218 | | |
5219 | | - | |
| 5219 | + | |
5220 | 5220 | | |
5221 | 5221 | | |
5222 | | - | |
| 5222 | + | |
5223 | 5223 | | |
5224 | 5224 | | |
5225 | 5225 | | |
5226 | 5226 | | |
5227 | 5227 | | |
5228 | 5228 | | |
5229 | 5229 | | |
5230 | | - | |
| 5230 | + | |
5231 | 5231 | | |
5232 | 5232 | | |
5233 | | - | |
| 5233 | + | |
5234 | 5234 | | |
5235 | 5235 | | |
5236 | 5236 | | |
5237 | 5237 | | |
5238 | 5238 | | |
5239 | | - | |
| 5239 | + | |
5240 | 5240 | | |
5241 | 5241 | | |
5242 | | - | |
| 5242 | + | |
5243 | 5243 | | |
5244 | 5244 | | |
5245 | 5245 | | |
5246 | 5246 | | |
5247 | 5247 | | |
5248 | 5248 | | |
5249 | | - | |
| 5249 | + | |
| 5250 | + | |
5250 | 5251 | | |
5251 | | - | |
| 5252 | + | |
5252 | 5253 | | |
5253 | | - | |
5254 | | - | |
| 5254 | + | |
| 5255 | + | |
5255 | 5256 | | |
5256 | 5257 | | |
5257 | 5258 | | |
5258 | 5259 | | |
5259 | 5260 | | |
5260 | 5261 | | |
5261 | | - | |
| 5262 | + | |
| 5263 | + | |
5262 | 5264 | | |
5263 | | - | |
| 5265 | + | |
5264 | 5266 | | |
5265 | | - | |
5266 | | - | |
| 5267 | + | |
| 5268 | + | |
5267 | 5269 | | |
5268 | 5270 | | |
5269 | 5271 | | |
5270 | 5272 | | |
5271 | 5273 | | |
5272 | 5274 | | |
5273 | 5275 | | |
5274 | | - | |
| 5276 | + | |
5275 | 5277 | | |
5276 | 5278 | | |
5277 | 5279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
0 commit comments