rust/compiler/rustc_lint/src
Nicholas Nethercote 6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
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.
2023-05-03 08:44:39 +10:00
..
nonstandard_style
array_into_iter.rs errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
builtin.rs Add GenericArgKind::as_{type,const,region} 2023-04-19 14:54:31 +00:00
context.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
deref_into_dyn_supertrait.rs Don't eagerly convert principal to string 2023-02-17 14:44:58 +00:00
early.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
enum_intrinsics_non_enums.rs rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
errors.rs Spelling - compiler 2023-04-17 16:09:18 -04:00
expect.rs Auto merge of #106776 - oli-obk:om_nom_nom_nom_nom, r=cjgillot 2023-01-13 13:57:21 +00:00
for_loops_over_fallibles.rs use the correct param env 2023-03-21 09:57:22 +01:00
hidden_unicode_codepoints.rs migrate: hidden_unicode_codepoints.rs 2023-01-09 17:07:25 -05:00
internal.rs Add deny lint to prevent untranslatable diagnostics using static strings 2023-04-25 18:44:49 +01:00
late.rs Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
let_underscore.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
levels.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
lib.rs Add deny lint to prevent untranslatable diagnostics using static strings 2023-04-25 18:44:49 +01:00
lints.rs uplift clippy::clone_double_ref as suspicious_double_ref_op 2023-04-28 17:24:48 +00:00
map_unit_fn.rs Fix #109152, fix the scenario that we may can not get span of func 2023-03-15 14:07:39 +08:00
methods.rs Do not suppress temporary_cstring_as_ptr in macros. 2023-04-04 18:55:02 +00:00
multiple_supertrait_upcastable.rs Reintroduce multiple_supertrait_upcastable lint 2023-01-28 15:08:07 +00:00
non_ascii_idents.rs Fix typos in compiler 2023-04-10 22:02:52 +02:00
non_fmt_panic.rs errors: generate typed identifiers in each crate 2023-02-22 09:15:53 +00:00
nonstandard_style.rs reimpl make non_upper_case_globals lint not report trait impls 2023-04-20 16:28:49 +12:00
noop_method_call.rs add match to diagnostic messages 2023-04-29 15:47:23 +00:00
opaque_hidden_inferred_bound.rs add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls 2023-04-20 12:36:50 -06:00
pass_by_value.rs remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
passes.rs Take a LocalDefId in hir::Visitor::visit_fn. 2023-01-28 09:51:50 +00:00
redundant_semicolon.rs refactor: cleanup 2023-01-09 18:57:02 -05:00
tests.rs Update to last upstream version 2021-07-08 17:14:28 +02:00
traits.rs refactor: cleanup 2023-01-09 18:57:02 -05:00
types.rs Update ty::VariantDef to use IndexVec<FieldIdx, FieldDef> 2023-03-30 09:23:40 -07:00
unused.rs add subst_identity_iter and subst_identity_iter_copied methods on EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls 2023-04-20 12:36:50 -06:00