Commit d4de1f2
committed
Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".
That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
* can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
* asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
* `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
(though note that this isn't a real guarantee until after completing the work on
#69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
* can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`
This PR is a companion to other ongoing work, namely:
* #69426
and it's ongoing implementation:
#93222
the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
would make the choices of API changes (esp. naming) in this PR fit better overall
In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
* it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
* it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
* this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
* warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
* `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
we have to make `.emit()` idempotent wrt the guarantees it returns
* thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
* the APIs were already mostly identical, allowing for low-effort porting to this new setup
* only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
* `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
* `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)
This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.
r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`File tree
134 files changed
+1497
-1143
lines changed- compiler
- rustc_borrowck/src
- diagnostics
- region_infer
- rustc_builtin_macros/src
- rustc_codegen_ssa/src/back
- rustc_const_eval/src
- const_eval
- transform/check_consts
- rustc_errors/src
- rustc_expand/src
- mbe
- rustc_infer/src
- infer
- error_reporting
- nice_region_error
- traits/error_reporting
- rustc_interface/src
- rustc_lint/src
- rustc_macros/src
- rustc_metadata/src
- rustc_middle/src
- middle
- mir/interpret
- traits
- ty
- rustc_mir_build/src/thir/pattern
- rustc_mir_transform/src
- rustc_parse/src
- lexer
- parser
- rustc_passes/src
- rustc_query_system/src/query
- rustc_resolve/src
- late
- rustc_session/src
- rustc_trait_selection/src/traits
- error_reporting
- select
- specialize
- rustc_typeck/src
- astconv
- check
- fn_ctxt
- method
- coherence
- impl_wf_check
- structured_errors
- src
- librustdoc
- clean
- passes
- test/ui-fulldeps
- tools
- clippy
- clippy_lints/src
- clippy_utils/src
- rustfmt/src
- parse
- macros
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
134 files changed
+1497
-1143
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | | - | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
54 | | - | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
135 | | - | |
| 139 | + | |
136 | 140 | | |
137 | 141 | | |
138 | 142 | | |
| |||
164 | 168 | | |
165 | 169 | | |
166 | 170 | | |
167 | | - | |
| 171 | + | |
168 | 172 | | |
169 | 173 | | |
170 | 174 | | |
| |||
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
203 | | - | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
| |||
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
246 | | - | |
| 250 | + | |
247 | 251 | | |
248 | 252 | | |
249 | 253 | | |
| |||
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
265 | | - | |
| 269 | + | |
266 | 270 | | |
267 | 271 | | |
268 | 272 | | |
269 | 273 | | |
270 | | - | |
| 274 | + | |
271 | 275 | | |
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
277 | 281 | | |
278 | | - | |
| 282 | + | |
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
| |||
287 | 291 | | |
288 | 292 | | |
289 | 293 | | |
290 | | - | |
| 294 | + | |
291 | 295 | | |
292 | 296 | | |
293 | 297 | | |
| |||
309 | 313 | | |
310 | 314 | | |
311 | 315 | | |
312 | | - | |
| 316 | + | |
313 | 317 | | |
314 | 318 | | |
315 | 319 | | |
| |||
327 | 331 | | |
328 | 332 | | |
329 | 333 | | |
330 | | - | |
| 334 | + | |
331 | 335 | | |
332 | 336 | | |
333 | 337 | | |
| |||
346 | 350 | | |
347 | 351 | | |
348 | 352 | | |
349 | | - | |
| 353 | + | |
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
| |||
357 | 361 | | |
358 | 362 | | |
359 | 363 | | |
360 | | - | |
| 364 | + | |
361 | 365 | | |
362 | 366 | | |
363 | 367 | | |
| |||
376 | 380 | | |
377 | 381 | | |
378 | 382 | | |
379 | | - | |
| 383 | + | |
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| |||
387 | 391 | | |
388 | 392 | | |
389 | 393 | | |
390 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
391 | 398 | | |
392 | 399 | | |
393 | 400 | | |
| |||
400 | 407 | | |
401 | 408 | | |
402 | 409 | | |
403 | | - | |
| 410 | + | |
404 | 411 | | |
405 | 412 | | |
406 | 413 | | |
| |||
410 | 417 | | |
411 | 418 | | |
412 | 419 | | |
413 | | - | |
| 420 | + | |
414 | 421 | | |
415 | 422 | | |
416 | 423 | | |
| |||
435 | 442 | | |
436 | 443 | | |
437 | 444 | | |
438 | | - | |
| 445 | + | |
439 | 446 | | |
440 | 447 | | |
441 | 448 | | |
| |||
454 | 461 | | |
455 | 462 | | |
456 | 463 | | |
457 | | - | |
| 464 | + | |
458 | 465 | | |
459 | 466 | | |
460 | 467 | | |
461 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
462 | 472 | | |
463 | 473 | | |
464 | 474 | | |
| |||
467 | 477 | | |
468 | 478 | | |
469 | 479 | | |
470 | | - | |
| 480 | + | |
471 | 481 | | |
472 | 482 | | |
473 | 483 | | |
| |||
476 | 486 | | |
477 | 487 | | |
478 | 488 | | |
479 | | - | |
| 489 | + | |
480 | 490 | | |
481 | 491 | | |
482 | 492 | | |
| |||
Lines changed: 26 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| |||
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
133 | | - | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
| |||
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
191 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
192 | 200 | | |
193 | 201 | | |
194 | 202 | | |
| |||
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
207 | | - | |
| 215 | + | |
208 | 216 | | |
209 | 217 | | |
210 | 218 | | |
| |||
231 | 239 | | |
232 | 240 | | |
233 | 241 | | |
234 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | 249 | | |
| |||
247 | 259 | | |
248 | 260 | | |
249 | 261 | | |
250 | | - | |
| 262 | + | |
251 | 263 | | |
252 | 264 | | |
253 | 265 | | |
| |||
288 | 300 | | |
289 | 301 | | |
290 | 302 | | |
291 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
292 | 308 | | |
293 | 309 | | |
294 | 310 | | |
| |||
304 | 320 | | |
305 | 321 | | |
306 | 322 | | |
307 | | - | |
| 323 | + | |
308 | 324 | | |
309 | 325 | | |
310 | 326 | | |
| |||
329 | 345 | | |
330 | 346 | | |
331 | 347 | | |
332 | | - | |
| 348 | + | |
333 | 349 | | |
334 | 350 | | |
335 | 351 | | |
| |||
0 commit comments