Commit 6b62f37
committed
Restrict
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.
This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.
As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.From<S> for {D,Subd}iagnosticMessage.1 parent a368898 commit 6b62f37
File tree
177 files changed
+791
-787
lines changed- compiler
- rustc_ast_lowering/src
- rustc_ast_passes/src
- rustc_attr/src
- rustc_borrowck/src
- diagnostics
- region_infer
- type_check
- rustc_builtin_macros/src
- rustc_codegen_cranelift/src
- abi
- driver
- intrinsics
- rustc_codegen_ssa/src
- back
- debuginfo
- rustc_const_eval/src
- const_eval
- interpret
- transform
- check_consts
- rustc_error_messages/src
- rustc_errors/src
- rustc_expand/src
- mbe
- rustc_hir_analysis/src
- astconv
- check
- coherence
- collect
- impl_wf_check
- outlives
- structured_errors
- rustc_hir_typeck/src
- fn_ctxt
- generator_interior
- drop_ranges
- method
- rustc_infer/src
- infer
- canonical
- error_reporting
- nice_region_error
- lexical_region_resolve
- opaque_types
- outlives
- traits/error_reporting
- rustc_lint/src
- rustc_metadata/src
- rustc_middle/src
- middle
- traits
- ty
- util
- 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_trait_selection/src/traits
- error_reporting
- query/type_op
- select
- specialize
- rustc_traits/src
- rustc_ty_utils/src
- src
- librustdoc
- html
- render
- passes
- lint
- tools
- clippy
- clippy_lints/src
- methods
- clippy_utils/src
- miri/src
- tests/run-make-fulldeps/hotplug_codegen_backend
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
177 files changed
+791
-787
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
626 | | - | |
| 626 | + | |
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
| |||
Lines changed: 12 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| |||
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
589 | | - | |
| 589 | + | |
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| |||
1139 | 1139 | | |
1140 | 1140 | | |
1141 | 1141 | | |
1142 | | - | |
| 1142 | + | |
1143 | 1143 | | |
1144 | 1144 | | |
1145 | 1145 | | |
| |||
1238 | 1238 | | |
1239 | 1239 | | |
1240 | 1240 | | |
1241 | | - | |
| 1241 | + | |
1242 | 1242 | | |
1243 | 1243 | | |
1244 | 1244 | | |
1245 | 1245 | | |
1246 | 1246 | | |
1247 | 1247 | | |
1248 | | - | |
| 1248 | + | |
1249 | 1249 | | |
1250 | 1250 | | |
1251 | 1251 | | |
| |||
2281 | 2281 | | |
2282 | 2282 | | |
2283 | 2283 | | |
2284 | | - | |
| 2284 | + | |
2285 | 2285 | | |
2286 | 2286 | | |
2287 | 2287 | | |
| |||
2293 | 2293 | | |
2294 | 2294 | | |
2295 | 2295 | | |
2296 | | - | |
| 2296 | + | |
2297 | 2297 | | |
2298 | 2298 | | |
2299 | 2299 | | |
| |||
2304 | 2304 | | |
2305 | 2305 | | |
2306 | 2306 | | |
2307 | | - | |
| 2307 | + | |
2308 | 2308 | | |
2309 | 2309 | | |
2310 | 2310 | | |
| |||
2626 | 2626 | | |
2627 | 2627 | | |
2628 | 2628 | | |
2629 | | - | |
| 2629 | + | |
2630 | 2630 | | |
2631 | 2631 | | |
2632 | 2632 | | |
| |||
3180 | 3180 | | |
3181 | 3181 | | |
3182 | 3182 | | |
3183 | | - | |
| 3183 | + | |
3184 | 3184 | | |
3185 | 3185 | | |
3186 | 3186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1073 | 1073 | | |
1074 | 1074 | | |
1075 | 1075 | | |
1076 | | - | |
| 1076 | + | |
1077 | 1077 | | |
1078 | 1078 | | |
1079 | 1079 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| |||
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
576 | | - | |
| 576 | + | |
577 | 577 | | |
578 | 578 | | |
579 | 579 | | |
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
585 | | - | |
| 585 | + | |
586 | 586 | | |
587 | 587 | | |
588 | 588 | | |
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
639 | | - | |
| 639 | + | |
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
646 | | - | |
| 646 | + | |
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
682 | | - | |
| 682 | + | |
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
688 | | - | |
| 688 | + | |
689 | 689 | | |
690 | 690 | | |
691 | 691 | | |
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
739 | | - | |
| 739 | + | |
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
| |||
788 | 788 | | |
789 | 789 | | |
790 | 790 | | |
791 | | - | |
| 791 | + | |
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
| |||
822 | 822 | | |
823 | 823 | | |
824 | 824 | | |
825 | | - | |
| 825 | + | |
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
537 | | - | |
| 536 | + | |
| 537 | + | |
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| |||
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
866 | | - | |
| 866 | + | |
867 | 867 | | |
868 | 868 | | |
869 | 869 | | |
| |||
0 commit comments