diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-07-17 04:09:20 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-07-17 04:09:20 +0900 |
| commit | c54d4ada26c6a92346076bcc27d628398345ed9e (patch) | |
| tree | 4bcd11a6083b09b5ebc410b77898a27f0290466b /compiler/rustc_borrowck/src | |
| parent | 95e77648e466c780a9adce2fa3d3eb5e423dc04e (diff) | |
| download | rust-c54d4ada26c6a92346076bcc27d628398345ed9e.tar.gz rust-c54d4ada26c6a92346076bcc27d628398345ed9e.zip | |
avoid some `Symbol` to `String` conversions
Diffstat (limited to 'compiler/rustc_borrowck/src')
4 files changed, 15 insertions, 20 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index b9cfc3732dc..146f86e5a11 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -23,7 +23,7 @@ use rustc_middle::ty::{ use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; use rustc_span::hygiene::DesugaringKind; use rustc_span::symbol::sym; -use rustc_span::{BytePos, Span}; +use rustc_span::{BytePos, Span, Symbol}; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::TraitEngineExt as _; @@ -1227,8 +1227,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { from_closure: false, region_name: RegionName { - source: - RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name), + source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name), .. }, span, @@ -1702,7 +1701,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { borrow_span: Span, name: &Option<String>, upvar_span: Span, - upvar_name: &str, + upvar_name: Symbol, escape_span: Span, ) -> DiagnosticBuilder<'cx, ErrorGuaranteed> { let tcx = self.infcx.tcx; diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 230ccf51990..72aee0267ac 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -12,7 +12,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::{self, RegionVid, TyCtxt}; -use rustc_span::symbol::Symbol; +use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, DesugaringKind, Span}; use crate::region_infer::BlameConstraint; @@ -282,7 +282,7 @@ impl<'tcx> BorrowExplanation<'tcx> { ) { if let ConstraintCategory::OpaqueType = category { let suggestable_name = - if region_name.was_named() { region_name.to_string() } else { "'_".to_string() }; + if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime }; let msg = format!( "you can add a bound to the {}to make it last less than `'static` and match `{}`", diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 5d3997289bb..7b2f771288f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -19,8 +19,7 @@ use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::Region; use rustc_middle::ty::TypeVisitor; use rustc_middle::ty::{self, RegionVid, Ty}; -use rustc_span::symbol::sym; -use rustc_span::symbol::Ident; +use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; use crate::borrowck_errors; @@ -758,7 +757,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { return; }; - let lifetime = if f.has_name() { fr_name.to_string() } else { "'_".to_string() }; + let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime }; let arg = match param.param.pat.simple_ident() { Some(simple_ident) => format!("argument `{}`", simple_ident), @@ -770,7 +769,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { self.infcx.tcx, diag, fn_returns, - lifetime, + lifetime.to_string(), Some(arg), captures, Some((param.param_ty_span, param.param_ty.to_string())), diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index e60e11f11df..49f8218b222 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -34,13 +34,13 @@ pub(crate) enum RegionNameSource { /// The `'static` region. Static, /// The free region corresponding to the environment of a closure. - SynthesizedFreeEnvRegion(Span, String), + SynthesizedFreeEnvRegion(Span, &'static str), /// The region corresponding to an argument. AnonRegionFromArgument(RegionNameHighlight), /// The region corresponding to a closure upvar. - AnonRegionFromUpvar(Span, String), + AnonRegionFromUpvar(Span, Symbol), /// The region corresponding to the return type of a closure. - AnonRegionFromOutput(RegionNameHighlight, String), + AnonRegionFromOutput(RegionNameHighlight, &'static str), /// The region from a type yielded by a generator. AnonRegionFromYieldTy(Span, String), /// An anonymous region from an async fn. @@ -110,7 +110,7 @@ impl RegionName { } RegionNameSource::SynthesizedFreeEnvRegion(span, note) => { diag.span_label(*span, format!("lifetime `{self}` represents this closure's body")); - diag.note(note); + diag.note(*note); } RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy( span, @@ -350,10 +350,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { Some(RegionName { name: region_name, - source: RegionNameSource::SynthesizedFreeEnvRegion( - fn_decl_span, - note.to_string(), - ), + source: RegionNameSource::SynthesizedFreeEnvRegion(fn_decl_span, note), }) } @@ -678,7 +675,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { Some(RegionName { name: region_name, - source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name.to_string()), + source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name), }) } @@ -756,7 +753,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { Some(RegionName { name: self.synthesize_region_name(), - source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description.to_string()), + source: RegionNameSource::AnonRegionFromOutput(highlight, mir_description), }) } |
