rust/compiler/rustc_const_eval/src/interpret
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
..
intrinsics Implement Copy for LocationDetail 2023-04-13 18:04:30 +00:00
cast.rs Add CastKind::Transmute to MIR 2023-03-22 15:15:41 -07:00
discriminant.rs Various minor Idx-related tweaks 2023-04-16 02:42:50 -07:00
eval_context.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
intern.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
intrinsics.rs Lower intrinsics::offset to mir::BinOp::Offset 2023-04-25 19:23:45 -07:00
machine.rs Report a backtrace for memory leaks under Miri 2023-04-16 08:52:00 -04:00
memory.rs Report a backtrace for memory leaks under Miri 2023-04-16 08:52:00 -04:00
mod.rs Add UnwindAction::Unreachable 2023-04-06 09:34:16 +01:00
operand.rs Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible 2023-04-04 10:39:26 +00:00
operator.rs share BinOp::Offset between CTFE and Miri 2023-04-28 16:00:08 +02:00
place.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
projection.rs Use target instead of machine for mir interpreter integer handling. 2023-02-15 08:56:18 +00:00
step.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
terminator.rs Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
traits.rs add is_sized method on Abi and Layout, and use it 2022-11-13 12:23:53 +01:00
util.rs rename needs_subst to has_param 2023-04-27 08:35:19 +01:00
validity.rs Use trimmed paths in constantant validation errors 2023-04-27 00:33:52 +02:00
visitor.rs basic dyn* support for Miri 2023-02-20 15:08:05 +01:00