Make RegionName
Copy
by (transitively) interning the few string v… · rust-lang/rust@795be51 (original) (raw)
`@@ -15,7 +15,7 @@ use crate::{universal_regions::DefiningTy, MirBorrowckCtxt};
`
15
15
``
16
16
`/// A name for a particular region used in emitting diagnostics. This name could be a generated
`
17
17
`` /// name like '1
, a name used by the user like 'a
, or a name like 'static
.
``
18
``
`-
#[derive(Debug, Clone)]
`
``
18
`+
#[derive(Debug, Clone, Copy)]
`
19
19
`pub(crate) struct RegionName {
`
20
20
`/// The name of the region (interned).
`
21
21
`pub(crate) name: Symbol,
`
`@@ -26,7 +26,7 @@ pub(crate) struct RegionName {
`
26
26
`` /// Denotes the source of a region that is named by a RegionName
. For example, a free region that
``
27
27
`` /// was named by the user would get NamedLateParamRegion
and 'static
lifetime would get Static
.
``
28
28
`/// This helps to print the right kinds of diagnostics.
`
29
``
`-
#[derive(Debug, Clone)]
`
``
29
`+
#[derive(Debug, Clone, Copy)]
`
30
30
`pub(crate) enum RegionNameSource {
`
31
31
`/// A bound (not free) region that was instantiated at the def site (not an HRTB).
`
32
32
`NamedEarlyParamRegion(Span),
`
`@@ -43,7 +43,7 @@ pub(crate) enum RegionNameSource {
`
43
43
`/// The region corresponding to the return type of a closure.
`
44
44
`AnonRegionFromOutput(RegionNameHighlight, &'static str),
`
45
45
`/// The region from a type yielded by a coroutine.
`
46
``
`-
AnonRegionFromYieldTy(Span, String),
`
``
46
`+
AnonRegionFromYieldTy(Span, Symbol),
`
47
47
`/// An anonymous region from an async fn.
`
48
48
`AnonRegionFromAsyncFn(Span),
`
49
49
`/// An anonymous region from an impl self type or trait
`
`@@ -52,19 +52,19 @@ pub(crate) enum RegionNameSource {
`
52
52
``
53
53
`/// Describes what to highlight to explain to the user that we're giving an anonymous region a
`
54
54
`/// synthesized name, and how to highlight it.
`
55
``
`-
#[derive(Debug, Clone)]
`
``
55
`+
#[derive(Debug, Clone, Copy)]
`
56
56
`pub(crate) enum RegionNameHighlight {
`
57
57
`/// The anonymous region corresponds to a reference that was found by traversing the type in the HIR.
`
58
58
`MatchedHirTy(Span),
`
59
59
`` /// The anonymous region corresponds to a '_
in the generics list of a struct/enum/union.
``
60
60
`MatchedAdtAndSegment(Span),
`
61
61
`/// The anonymous region corresponds to a region where the type annotation is completely missing
`
62
62
`` /// from the code, e.g. in a closure arguments |x| { ... }
, where x
is a reference.
``
63
``
`-
CannotMatchHirTy(Span, String),
`
``
63
`+
CannotMatchHirTy(Span, Symbol),
`
64
64
`/// The anonymous region corresponds to a region where the type annotation is completely missing
`
65
65
`/// from the code, and even if we print out the full name of the type, the region name won't
`
66
66
`` /// be included. This currently occurs for opaque types like impl Future
.
``
67
``
`-
Occluded(Span, String),
`
``
67
`+
Occluded(Span, Symbol),
`
68
68
`}
`
69
69
``
70
70
`impl RegionName {
`
`@@ -249,7 +249,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
`
249
249
`assert!(self.regioncx.universal_regions().is_universal_region(fr));
`
250
250
``
251
251
`match self.region_names.borrow_mut().entry(fr) {
`
252
``
`-
IndexEntry::Occupied(precomputed_name) => Some(precomputed_name.get().clone()),
`
``
252
`+
IndexEntry::Occupied(precomputed_name) => Some(*precomputed_name.get()),
`
253
253
`IndexEntry::Vacant(slot) => {
`
254
254
`let new_name = self
`
255
255
`.give_name_from_error_region(fr)
`
`@@ -262,8 +262,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
`
262
262
`self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr)
`
263
263
`});
`
264
264
``
265
``
`-
if let Some(new_name) = &new_name {
`
266
``
`-
slot.insert(new_name.clone());
`
``
265
`+
if let Some(new_name) = new_name {
`
``
266
`+
slot.insert(new_name);
`
267
267
`}
`
268
268
`debug!("give_region_a_name: gave name {:?}", new_name);
`
269
269
``
`@@ -460,9 +460,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
`
460
460
`);
`
461
461
`if type_name.contains(&format!("'{counter}")) {
`
462
462
`// Only add a label if we can confirm that a region was labelled.
`
463
``
`-
RegionNameHighlight::CannotMatchHirTy(span, type_name)
`
``
463
`+
RegionNameHighlight::CannotMatchHirTy(span, Symbol::intern(&type_name))
`
464
464
`} else {
`
465
``
`-
RegionNameHighlight::Occluded(span, type_name)
`
``
465
`+
RegionNameHighlight::Occluded(span, Symbol::intern(&type_name))
`
466
466
`}
`
467
467
`}
`
468
468
``
`@@ -882,7 +882,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
`
882
882
``
883
883
`Some(RegionName {
`
884
884
`name: self.synthesize_region_name(),
`
885
``
`-
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, type_name),
`
``
885
`+
source: RegionNameSource::AnonRegionFromYieldTy(yield_span, Symbol::intern(&type_name)),
`
886
886
`})
`
887
887
`}
`
888
888
``
`@@ -974,7 +974,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
`
974
974
`Some(RegionName {
`
975
975
`name: region_name,
`
976
976
`source: RegionNameSource::AnonRegionFromArgument(
`
977
``
`-
RegionNameHighlight::CannotMatchHirTy(arg_span, arg_name?.to_string()),
`
``
977
`+
RegionNameHighlight::CannotMatchHirTy(arg_span, arg_name?),
`
978
978
`),
`
979
979
`})
`
980
980
`} else {
`