Commit 6e531ef
committed
Merge and reframe strict_provenance_lints
There does not seem to be any good reason to have separate lints for
ptr2int and int2ptr casts. The main reason to enable this lint is to
help with replacing `as` casts with strict provenance APIs (if possible)
or explicit provenance APIs (when needed). That applies equally to both
directions.
Merging the lints requires coming up with new name and lint explanation.
This is a good chance to reconsider the purpose and messaging of the
lints which have been essentially unchanged since the early days of the
"strict provenance experiment". For reasons described below, I called
the merged lint `implicit_provenance_casts`, rewrote its explanation
from scratch, and made some changes to diagnostics.
First, the lint is not (only) about strict provenance any more. While
strict provenance is often the best fix, migrating `as` casts to exposed
provenance APIs also silences the lint. The exposed provenance APIs
aren't any better for Miri and CHERI, but at least provenance
considerations are made *explicit*, not picked up as side effect of the
`as` keyword. (Banning use of exposed provenance APIs can be done with
clippy's existing `disallowed_methods` lint.)
Second, provenance is now officially part of the language and
prominently explained in the `std::ptr` documentation. The new lint
refers to those docs and is more consistent with them.
Third, while strict provenance is encouraged whenever possible, exposed
provenance is also part of the language and here to stay. Indeed, if we
eventually enable the lint by default and make it `cargo fix`-able to
keep the ecosystem migration manageable, we may want to suggest exposed
provenance APIs to err on the side of not introducing UB. Thus, I made
the diagnostics more neutral and descriptive. I've kept the suggestions
that introduce strict provenance APIs, but we may want to reconsider
this later.1 parent 0cf9681 commit 6e531ef
30 files changed
Lines changed: 280 additions & 291 deletions
File tree
- compiler/rustc_lint/src
- library
- alloctests
- benches
- tests
- alloc/src
- coretests/tests
- core/src
- ptr
- std/src
- os
- unix
- windows/io
- sys
- args
- env
- pal/sgx
- src/doc/unstable-book/src/language-features
- tests/ui
- feature-gates
- lint
This file was deleted.
| 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 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
97 | | - | |
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
| |||
254 | 252 | | |
255 | 253 | | |
256 | 254 | | |
257 | | - | |
258 | | - | |
| 255 | + | |
259 | 256 | | |
260 | 257 | | |
261 | 258 | | |
| |||
380 | 377 | | |
381 | 378 | | |
382 | 379 | | |
| 380 | + | |
| 381 | + | |
383 | 382 | | |
384 | 383 | | |
385 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2935 | 2935 | | |
2936 | 2936 | | |
2937 | 2937 | | |
2938 | | - | |
| 2938 | + | |
2939 | 2939 | | |
2940 | | - | |
| 2940 | + | |
2941 | 2941 | | |
2942 | | - | |
| 2942 | + | |
| 2943 | + | |
2943 | 2944 | | |
2944 | 2945 | | |
2945 | 2946 | | |
2946 | | - | |
| 2947 | + | |
2947 | 2948 | | |
2948 | 2949 | | |
2949 | 2950 | | |
2950 | 2951 | | |
2951 | | - | |
| 2952 | + | |
2952 | 2953 | | |
2953 | 2954 | | |
2954 | | - | |
| 2955 | + | |
2955 | 2956 | | |
2956 | 2957 | | |
2957 | 2958 | | |
2958 | 2959 | | |
2959 | 2960 | | |
2960 | 2961 | | |
2961 | 2962 | | |
2962 | | - | |
2963 | | - | |
2964 | | - | |
2965 | | - | |
2966 | | - | |
2967 | | - | |
2968 | | - | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
2969 | 2967 | | |
2970 | 2968 | | |
2971 | 2969 | | |
2972 | | - | |
| 2970 | + | |
2973 | 2971 | | |
2974 | 2972 | | |
2975 | 2973 | | |
2976 | | - | |
| 2974 | + | |
2977 | 2975 | | |
2978 | 2976 | | |
2979 | 2977 | | |
| |||
0 commit comments