mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Remove needless Cow
This commit is contained in:
parent
c2166ec628
commit
66797fa54f
@ -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
|
||||
/// loop that goes over each available MIR and applies `run_pass`.
|
||||
pub trait MirPass<'tcx> {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
let name = std::any::type_name::<Self>();
|
||||
if let Some(tail) = name.rfind(':') {
|
||||
Cow::from(&name[tail + 1..])
|
||||
} else {
|
||||
Cow::from(name)
|
||||
}
|
||||
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
|
||||
@ -13,8 +12,8 @@ use rustc_session::config::{OutputFilenames, OutputType};
|
||||
pub struct Marker(pub &'static str);
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for Marker {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(self.0)
|
||||
fn name(&self) -> &str {
|
||||
self.0
|
||||
}
|
||||
|
||||
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::ty::TyCtxt;
|
||||
use rustc_session::Session;
|
||||
@ -8,13 +6,9 @@ use crate::{validate, MirPass};
|
||||
|
||||
/// Just like `MirPass`, except it cannot mutate `Body`.
|
||||
pub trait MirLint<'tcx> {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
let name = std::any::type_name::<Self>();
|
||||
if let Some(tail) = name.rfind(':') {
|
||||
Cow::from(&name[tail + 1..])
|
||||
} else {
|
||||
Cow::from(name)
|
||||
}
|
||||
if let Some((_, tail)) = name.rsplit_once(':') { tail } else { name }
|
||||
}
|
||||
|
||||
fn is_enabled(&self, _sess: &Session) -> bool {
|
||||
@ -32,7 +26,7 @@ impl<'tcx, T> MirPass<'tcx> for Lint<T>
|
||||
where
|
||||
T: MirLint<'tcx>,
|
||||
{
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
self.0.name()
|
||||
}
|
||||
|
||||
@ -55,7 +49,7 @@ impl<'tcx, T> MirPass<'tcx> for WithMinOptLevel<T>
|
||||
where
|
||||
T: MirPass<'tcx>,
|
||||
{
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
fn name(&self) -> &str {
|
||||
self.1.name()
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,6 @@ use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Vis
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
|
||||
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 {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(&self.label)
|
||||
fn name(&self) -> &str {
|
||||
&self.label
|
||||
}
|
||||
|
||||
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::ty::TyCtxt;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// A pass that replaces a branch with a goto when its condition is known.
|
||||
pub struct SimplifyConstCondition {
|
||||
label: String,
|
||||
@ -16,8 +14,8 @@ impl SimplifyConstCondition {
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyConstCondition {
|
||||
fn name(&self) -> Cow<'_, str> {
|
||||
Cow::Borrowed(&self.label)
|
||||
fn name(&self) -> &str {
|
||||
&self.label
|
||||
}
|
||||
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
|
Loading…
Reference in New Issue
Block a user