Skip to content

Commit 66797fa

Browse files
committed
Remove needless Cow
1 parent c2166ec commit 66797fa

File tree

5 files changed

+12
-26
lines changed

5 files changed

+12
-26
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,9 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
100100
/// pass will be named after the type, and it will consist of a main
101101
/// loop that goes over each available MIR and applies `run_pass`.
102102
pub trait MirPass<'tcx> {
103-
fn name(&self) -> Cow<'_, str> {
103+
fn name(&self) -> &str {
104104
let name = std::any::type_name::<Self>();
105-
if let Some(tail) = name.rfind(':') {
106-
Cow::from(&name[tail + 1..])
107-
} else {
108-
Cow::from(name)
109-
}
105+
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
110106
}
111107

112108
/// Returns `true` if this pass is enabled with the current combination of compiler flags.

compiler/rustc_mir_transform/src/dump_mir.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! This pass just dumps MIR at a specified point.
22
3-
use std::borrow::Cow;
43
use std::fs::File;
54
use std::io;
65

@@ -13,8 +12,8 @@ use rustc_session::config::{OutputFilenames, OutputType};
1312
pub struct Marker(pub &'static str);
1413

1514
impl<'tcx> MirPass<'tcx> for Marker {
16-
fn name(&self) -> Cow<'_, str> {
17-
Cow::Borrowed(self.0)
15+
fn name(&self) -> &str {
16+
self.0
1817
}
1918

2019
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}

compiler/rustc_mir_transform/src/pass_manager.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::borrow::Cow;
2-
31
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
42
use rustc_middle::ty::TyCtxt;
53
use rustc_session::Session;
@@ -8,13 +6,9 @@ use crate::{validate, MirPass};
86

97
/// Just like `MirPass`, except it cannot mutate `Body`.
108
pub trait MirLint<'tcx> {
11-
fn name(&self) -> Cow<'_, str> {
9+
fn name(&self) -> &str {
1210
let name = std::any::type_name::<Self>();
13-
if let Some(tail) = name.rfind(':') {
14-
Cow::from(&name[tail + 1..])
15-
} else {
16-
Cow::from(name)
17-
}
11+
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
1812
}
1913

2014
fn is_enabled(&self, _sess: &Session) -> bool {
@@ -32,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
3226
where
3327
T: MirLint<'tcx>,
3428
{
35-
fn name(&self) -> Cow<'_, str> {
29+
fn name(&self) -> &str {
3630
self.0.name()
3731
}
3832

@@ -55,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
5549
where
5650
T: MirPass<'tcx>,
5751
{
58-
fn name(&self) -> Cow<'_, str> {
52+
fn name(&self) -> &str {
5953
self.1.name()
6054
}
6155

compiler/rustc_mir_transform/src/simplify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Vis
3535
use rustc_middle::mir::*;
3636
use rustc_middle::ty::TyCtxt;
3737
use smallvec::SmallVec;
38-
use std::borrow::Cow;
3938
use std::convert::TryInto;
4039

4140
pub struct SimplifyCfg {
@@ -57,8 +56,8 @@ pub fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
5756
}
5857

5958
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
60-
fn name(&self) -> Cow<'_, str> {
61-
Cow::Borrowed(&self.label)
59+
fn name(&self) -> &str {
60+
&self.label
6261
}
6362

6463
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/simplify_branches.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use crate::MirPass;
22
use rustc_middle::mir::*;
33
use rustc_middle::ty::TyCtxt;
44

5-
use std::borrow::Cow;
6-
75
/// A pass that replaces a branch with a goto when its condition is known.
86
pub struct SimplifyConstCondition {
97
label: String,
@@ -16,8 +14,8 @@ impl SimplifyConstCondition {
1614
}
1715

1816
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
19-
fn name(&self) -> Cow<'_, str> {
20-
Cow::Borrowed(&self.label)
17+
fn name(&self) -> &str {
18+
&self.label
2119
}
2220

2321
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

0 commit comments

Comments
 (0)