Remove needless Cow
This commit is contained in:
parent
c2166ec628
commit
66797fa54f
5 changed files with 12 additions and 26 deletions
|
@ -100,13 +100,9 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
|
||||||
/// pass will be named after the type, and it will consist of a main
|
/// pass will be named after the type, and it will consist of a main
|
||||||
/// loop that goes over each available MIR and applies `run_pass`.
|
/// loop that goes over each available MIR and applies `run_pass`.
|
||||||
pub trait MirPass<'tcx> {
|
pub trait MirPass<'tcx> {
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
let name = std::any::type_name::<Self>();
|
let name = std::any::type_name::<Self>();
|
||||||
if let Some(tail) = name.rfind(':') {
|
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
||||||
Cow::from(&name[tail + 1..])
|
|
||||||
} else {
|
|
||||||
Cow::from(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
|
/// Returns `true` if this pass is enabled with the current combination of compiler flags.
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! This pass just dumps MIR at a specified point.
|
//! This pass just dumps MIR at a specified point.
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
|
@ -13,8 +12,8 @@ use rustc_session::config::{OutputFilenames, OutputType};
|
||||||
pub struct Marker(pub &'static str);
|
pub struct Marker(pub &'static str);
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for Marker {
|
impl<'tcx> MirPass<'tcx> for Marker {
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
Cow::Borrowed(self.0)
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
|
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
|
use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
|
@ -8,13 +6,9 @@ use crate::{validate, MirPass};
|
||||||
|
|
||||||
/// Just like `MirPass`, except it cannot mutate `Body`.
|
/// Just like `MirPass`, except it cannot mutate `Body`.
|
||||||
pub trait MirLint<'tcx> {
|
pub trait MirLint<'tcx> {
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
let name = std::any::type_name::<Self>();
|
let name = std::any::type_name::<Self>();
|
||||||
if let Some(tail) = name.rfind(':') {
|
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
||||||
Cow::from(&name[tail + 1..])
|
|
||||||
} else {
|
|
||||||
Cow::from(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_enabled(&self, _sess: &Session) -> bool {
|
fn is_enabled(&self, _sess: &Session) -> bool {
|
||||||
|
@ -32,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
|
||||||
where
|
where
|
||||||
T: MirLint<'tcx>,
|
T: MirLint<'tcx>,
|
||||||
{
|
{
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
self.0.name()
|
self.0.name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
|
||||||
where
|
where
|
||||||
T: MirPass<'tcx>,
|
T: MirPass<'tcx>,
|
||||||
{
|
{
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
self.1.name()
|
self.1.name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Vis
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
pub struct SimplifyCfg {
|
pub struct SimplifyCfg {
|
||||||
|
@ -57,8 +56,8 @@ pub fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
|
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
Cow::Borrowed(&self.label)
|
&self.label
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
|
|
|
@ -2,8 +2,6 @@ use crate::MirPass;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
/// A pass that replaces a branch with a goto when its condition is known.
|
/// A pass that replaces a branch with a goto when its condition is known.
|
||||||
pub struct SimplifyConstCondition {
|
pub struct SimplifyConstCondition {
|
||||||
label: String,
|
label: String,
|
||||||
|
@ -16,8 +14,8 @@ impl SimplifyConstCondition {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
||||||
fn name(&self) -> Cow<'_, str> {
|
fn name(&self) -> &str {
|
||||||
Cow::Borrowed(&self.label)
|
&self.label
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue