Skip to content

Commit

Permalink
cleanup: remove static lifetimes from consts
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Dec 4, 2018
1 parent 91d5d56 commit d0c64bb
Show file tree
Hide file tree
Showing 26 changed files with 88 additions and 91 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl String {
return Cow::Borrowed("");
};

const REPLACEMENT: &'static str = "\u{FFFD}";
const REPLACEMENT: &str = "\u{FFFD}";

let mut res = String::with_capacity(v.len());
res.push_str(first_valid);
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ impl<'a> Formatter<'a> {
for part in formatted.parts {
match *part {
flt2dec::Part::Zero(mut nzeroes) => {
const ZEROES: &'static str = // 64 zeroes
const ZEROES: &str = // 64 zeroes
"0000000000000000000000000000000000000000000000000000000000000000";
while nzeroes > ZEROES.len() {
self.buf.write_str(ZEROES)?;
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/unicode/printable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(crate) fn is_printable(x: char) -> bool {
}
}

const SINGLETONS0U: &'static [(u8, u8)] = &[
const SINGLETONS0U: &[(u8, u8)] = &[
(0x00, 1),
(0x03, 5),
(0x05, 6),
Expand Down Expand Up @@ -122,7 +122,7 @@ const SINGLETONS0U: &'static [(u8, u8)] = &[
(0xfe, 3),
(0xff, 9),
];
const SINGLETONS0L: &'static [u8] = &[
const SINGLETONS0L: &[u8] = &[
0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57,
0x58, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e,
0x0f, 0x4b, 0x4c, 0xfb, 0xfc, 0x2e, 0x2f, 0x3f,
Expand Down Expand Up @@ -162,7 +162,7 @@ const SINGLETONS0L: &'static [u8] = &[
0x91, 0xfe, 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9,
0xd0, 0xd1, 0xd8, 0xd9, 0xe7, 0xfe, 0xff,
];
const SINGLETONS1U: &'static [(u8, u8)] = &[
const SINGLETONS1U: &[(u8, u8)] = &[
(0x00, 6),
(0x01, 1),
(0x03, 1),
Expand Down Expand Up @@ -197,7 +197,7 @@ const SINGLETONS1U: &'static [(u8, u8)] = &[
(0xf0, 4),
(0xf9, 4),
];
const SINGLETONS1L: &'static [u8] = &[
const SINGLETONS1L: &[u8] = &[
0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e,
0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e,
0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x36,
Expand All @@ -219,7 +219,7 @@ const SINGLETONS1L: &'static [u8] = &[
0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0,
0xc0, 0xd0, 0x3f, 0x71, 0x72, 0x7b,
];
const NORMAL0: &'static [u8] = &[
const NORMAL0: &[u8] = &[
0x00, 0x20,
0x5f, 0x22,
0x82, 0xdf, 0x04,
Expand Down Expand Up @@ -363,7 +363,7 @@ const NORMAL0: &'static [u8] = &[
0x1b, 0x03,
0x0f, 0x0d,
];
const NORMAL1: &'static [u8] = &[
const NORMAL1: &[u8] = &[
0x5e, 0x22,
0x7b, 0x05,
0x03, 0x04,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ macro_rules! define_dep_nodes {
#[allow(dead_code, non_upper_case_globals)]
pub mod label_strs {
$(
pub const $variant: &'static str = stringify!($variant);
pub const $variant: &str = stringify!($variant);
)*
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub trait PpAnn {

pub struct NoAnn;
impl PpAnn for NoAnn {}
pub const NO_ANN: &'static dyn PpAnn = &NoAnn;
pub const NO_ANN: &dyn PpAnn = &NoAnn;

impl PpAnn for hir::Crate {
fn try_fetch_item(&self, item: ast::NodeId) -> Option<&hir::Item> {
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ mod impls_misc;
mod impls_ty;
mod impls_syntax;

pub const ATTR_DIRTY: &'static str = "rustc_dirty";
pub const ATTR_CLEAN: &'static str = "rustc_clean";
pub const ATTR_IF_THIS_CHANGED: &'static str = "rustc_if_this_changed";
pub const ATTR_THEN_THIS_WOULD_NEED: &'static str = "rustc_then_this_would_need";
pub const ATTR_PARTITION_REUSED: &'static str = "rustc_partition_reused";
pub const ATTR_PARTITION_CODEGENED: &'static str = "rustc_partition_codegened";
pub const ATTR_EXPECTED_CGU_REUSE: &'static str = "rustc_expected_cgu_reuse";
pub const ATTR_DIRTY: &str = "rustc_dirty";
pub const ATTR_CLEAN: &str = "rustc_clean";
pub const ATTR_IF_THIS_CHANGED: &str = "rustc_if_this_changed";
pub const ATTR_THEN_THIS_WOULD_NEED: &str = "rustc_then_this_would_need";
pub const ATTR_PARTITION_REUSED: &str = "rustc_partition_reused";
pub const ATTR_PARTITION_CODEGENED: &str = "rustc_partition_codegened";
pub const ATTR_EXPECTED_CGU_REUSE: &str = "rustc_expected_cgu_reuse";

pub const IGNORED_ATTRIBUTES: &'static [&'static str] = &[
pub const IGNORED_ATTRIBUTES: &[&str] = &[
"cfg",
ATTR_IF_THIS_CHANGED,
ATTR_THEN_THIS_WOULD_NEED,
Expand Down
43 changes: 21 additions & 22 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,43 +780,42 @@ macro_rules! options {
}

pub type $setter_name = fn(&mut $struct_name, v: Option<&str>) -> bool;
pub const $stat: &'static [(&'static str, $setter_name,
Option<&'static str>, &'static str)] =
pub const $stat: &[(&str, $setter_name, Option<&str>, &str)] =
&[ $( (stringify!($opt), $mod_set::$opt, $mod_desc::$parse, $desc) ),* ];

#[allow(non_upper_case_globals, dead_code)]
mod $mod_desc {
pub const parse_bool: Option<&'static str> = None;
pub const parse_opt_bool: Option<&'static str> =
pub const parse_bool: Option<&str> = None;
pub const parse_opt_bool: Option<&str> =
Some("one of: `y`, `yes`, `on`, `n`, `no`, or `off`");
pub const parse_string: Option<&'static str> = Some("a string");
pub const parse_string_push: Option<&'static str> = Some("a string");
pub const parse_pathbuf_push: Option<&'static str> = Some("a path");
pub const parse_opt_string: Option<&'static str> = Some("a string");
pub const parse_opt_pathbuf: Option<&'static str> = Some("a path");
pub const parse_list: Option<&'static str> = Some("a space-separated list of strings");
pub const parse_opt_list: Option<&'static str> = Some("a space-separated list of strings");
pub const parse_uint: Option<&'static str> = Some("a number");
pub const parse_passes: Option<&'static str> =
pub const parse_string: Option<&str> = Some("a string");
pub const parse_string_push: Option<&str> = Some("a string");
pub const parse_pathbuf_push: Option<&str> = Some("a path");
pub const parse_opt_string: Option<&str> = Some("a string");
pub const parse_opt_pathbuf: Option<&str> = Some("a path");
pub const parse_list: Option<&str> = Some("a space-separated list of strings");
pub const parse_opt_list: Option<&str> = Some("a space-separated list of strings");
pub const parse_uint: Option<&str> = Some("a number");
pub const parse_passes: Option<&str> =
Some("a space-separated list of passes, or `all`");
pub const parse_opt_uint: Option<&'static str> =
pub const parse_opt_uint: Option<&str> =
Some("a number");
pub const parse_panic_strategy: Option<&'static str> =
pub const parse_panic_strategy: Option<&str> =
Some("either `unwind` or `abort`");
pub const parse_relro_level: Option<&'static str> =
pub const parse_relro_level: Option<&str> =
Some("one of: `full`, `partial`, or `off`");
pub const parse_sanitizer: Option<&'static str> =
pub const parse_sanitizer: Option<&str> =
Some("one of: `address`, `leak`, `memory` or `thread`");
pub const parse_linker_flavor: Option<&'static str> =
pub const parse_linker_flavor: Option<&str> =
Some(::rustc_target::spec::LinkerFlavor::one_of());
pub const parse_optimization_fuel: Option<&'static str> =
pub const parse_optimization_fuel: Option<&str> =
Some("crate=integer");
pub const parse_unpretty: Option<&'static str> =
pub const parse_unpretty: Option<&str> =
Some("`string` or `string=string`");
pub const parse_lto: Option<&'static str> =
pub const parse_lto: Option<&str> =
Some("either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
`fat`, or omitted");
pub const parse_cross_lang_lto: Option<&'static str> =
pub const parse_cross_lang_lto: Option<&str> =
Some("either a boolean (`yes`, `no`, `on`, `off`, etc), \
or the path to the linker plugin");
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
// "lib" (i.e. non-default), this value is used (see issue #16552).

#[cfg(target_pointer_width = "64")]
const PRIMARY_LIB_DIR: &'static str = "lib64";
const PRIMARY_LIB_DIR: &str = "lib64";

#[cfg(target_pointer_width = "32")]
const PRIMARY_LIB_DIR: &'static str = "lib32";
const PRIMARY_LIB_DIR: &str = "lib32";

const SECONDARY_LIB_DIR: &'static str = "lib";
const SECONDARY_LIB_DIR: &str = "lib";

match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => libdir.into(),
Expand All @@ -198,4 +198,4 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {

// The name of rustc's own place to organize libraries.
// Used to be "rustc", now the default is "rustlib"
const RUST_LIB_DIR: &'static str = "rustlib";
const RUST_LIB_DIR: &str = "rustlib";
2 changes: 1 addition & 1 deletion src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use lazy_static;
use session::Session;

// The name of the associated type for `Fn` return types
pub const FN_OUTPUT_NAME: &'static str = "Output";
pub const FN_OUTPUT_NAME: &str = "Output";

// Useful type to use with `Result<>` indicate that an error has already
// been reported to the user, so no need to continue checking.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// These are weak symbols that point to the profile version and the
// profile name, which need to be treated as exported so LTO doesn't nix
// them.
const PROFILER_WEAK_SYMBOLS: [&'static str; 2] = [
const PROFILER_WEAK_SYMBOLS: [&str; 2] = [
"__llvm_profile_raw_version",
"__llvm_profile_filename",
];
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_utils/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl SymbolPathBuffer {

impl ItemPathBuffer for SymbolPathBuffer {
fn root_mode(&self) -> &RootMode {
const ABSOLUTE: &'static RootMode = &RootMode::Absolute;
const ABSOLUTE: &RootMode = &RootMode::Absolute;
ABSOLUTE
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_incremental/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use syntax::ast;
use rustc::ich::{ATTR_PARTITION_REUSED, ATTR_PARTITION_CODEGENED,
ATTR_EXPECTED_CGU_REUSE};

const MODULE: &'static str = "module";
const CFG: &'static str = "cfg";
const KIND: &'static str = "kind";
const MODULE: &str = "module";
const CFG: &str = "cfg";
const KIND: &str = "kind";

pub fn assert_module_sources<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
tcx.dep_graph.with_ignore(|| {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/persist/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ use rustc::session::config::nightly_options;
use rustc_serialize::opaque::Encoder;

/// The first few bytes of files generated by incremental compilation
const FILE_MAGIC: &'static [u8] = b"RSIC";
const FILE_MAGIC: &[u8] = b"RSIC";

/// Change this if the header format changes
const HEADER_FORMAT_VERSION: u16 = 0;

/// A version string that hopefully is always different for compiler versions
/// with different encodings of incremental compilation artifacts. Contains
/// the git commit hash.
const RUSTC_VERSION: Option<&'static str> = option_env!("CFG_VERSION");
const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");

pub fn write_file_header(stream: &mut Encoder) {
stream.emit_raw_bytes(FILE_MAGIC);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ use std::time::{UNIX_EPOCH, SystemTime, Duration};

use rand::{RngCore, thread_rng};

const LOCK_FILE_EXT: &'static str = ".lock";
const DEP_GRAPH_FILENAME: &'static str = "dep-graph.bin";
const WORK_PRODUCTS_FILENAME: &'static str = "work-products.bin";
const QUERY_CACHE_FILENAME: &'static str = "query-cache.bin";
const LOCK_FILE_EXT: &str = ".lock";
const DEP_GRAPH_FILENAME: &str = "dep-graph.bin";
const WORK_PRODUCTS_FILENAME: &str = "work-products.bin";
const QUERY_CACHE_FILENAME: &str = "query-cache.bin";

// We encode integers using the following base, so they are shorter than decimal
// or hexadecimal numbers (we want short file and directory names). Since these
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const METADATA_VERSION: u8 = 4;
/// This header is followed by the position of the `CrateRoot`,
/// which is encoded as a 32-bit big-endian unsigned integer,
/// and further followed by the rustc version string.
pub const METADATA_HEADER: &'static [u8; 12] =
pub const METADATA_HEADER: &[u8; 12] =
&[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];

/// A value of type T referred to by its absolute position
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/dataflow/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ where MWF: MirWithFlowState<'tcx>,
block: BasicBlock,
mir: &Mir) -> io::Result<()> {
// Header rows
const HDRS: [&'static str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"];
const HDR_FMT: &'static str = "bgcolor=\"grey\"";
const HDRS: [&str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"];
const HDR_FMT: &str = "bgcolor=\"grey\"";
write!(w, "<table><tr><td rowspan=\"{}\">", HDRS.len())?;
write!(w, "{:?}", block.index())?;
write!(w, "</td></tr><tr>")?;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ static X: i32 = 1;
const C: i32 = 2;
// these three are not allowed:
const CR: &'static mut i32 = &mut C;
const CR: &mut i32 = &mut C;
static STATIC_REF: &'static mut i32 = &mut X;
static CONST_REF: &'static mut i32 = &mut C;
```
Expand Down Expand Up @@ -1163,18 +1163,18 @@ You can also have this error while using a cell type:
use std::cell::Cell;
const A: Cell<usize> = Cell::new(1);
const B: &'static Cell<usize> = &A;
const B: &Cell<usize> = &A;
// error: cannot borrow a constant which may contain interior mutability,
// create a static instead
// or:
struct C { a: Cell<usize> }
const D: C = C { a: Cell::new(1) };
const E: &'static Cell<usize> = &D.a; // error
const E: &Cell<usize> = &D.a; // error
// or:
const F: &'static C = &D; // error
const F: &C = &D; // error
```
This is because cell types do operations that are not thread-safe. Due to this,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::path::{Path, PathBuf};
use super::graphviz::write_mir_fn_graphviz;
use transform::MirSource;

const INDENT: &'static str = " ";
const INDENT: &str = " ";
/// Alignment for lining up comments following MIR statements
pub(crate) const ALIGN: usize = 40;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ macro_rules! supported_targets {
$(mod $module;)*

/// List of supported targets
const TARGETS: &'static [&'static str] = &[$($triple),*];
const TARGETS: &[&str] = &[$($triple),*];

fn load_specific(target: &str) -> TargetResult {
match target {
Expand Down
Loading

0 comments on commit d0c64bb

Please sign in to comment.