1
Fork 0

cleanup: remove static lifetimes from consts

This commit is contained in:
ljedrz 2018-12-04 12:46:10 +01:00
parent 91d5d56c00
commit d0c64bb296
26 changed files with 88 additions and 91 deletions

View file

@ -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);

View file

@ -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)?;

View file

@ -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),
@ -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,
@ -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),
@ -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,
@ -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,
@ -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,

View file

@ -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);
)*
}
);

View file

@ -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> {

View file

@ -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,

View file

@ -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");
}

View file

@ -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(),
@ -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";

View file

@ -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.

View file

@ -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",
];

View file

@ -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
}

View file

@ -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(|| {

View file

@ -28,7 +28,7 @@ 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;
@ -36,7 +36,7 @@ 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);

View file

@ -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

View file

@ -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

View file

@ -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>")?;

View file

@ -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;
```
@ -1163,7 +1163,7 @@ 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
@ -1171,10 +1171,10 @@ const B: &'static Cell<usize> = &A;
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,

View file

@ -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;

View file

@ -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 {

View file

@ -53,8 +53,7 @@ macro_rules! declare_features {
/// Represents active features that are currently being implemented or
/// currently being considered for addition/removal.
const ACTIVE_FEATURES:
&'static [(&'static str, &'static str, Option<u32>,
Option<Edition>, fn(&mut Features, Span))] =
&[(&str, &str, Option<u32>, Option<Edition>, fn(&mut Features, Span))] =
&[$((stringify!($feature), $ver, $issue, $edition, set!($feature))),+];
/// A set of features to be used by later passes.
@ -769,7 +768,7 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
}
// Attributes that have a special meaning to rustc or rustdoc
pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGate)] = &[
pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeGate)] = &[
// Normal attributes
("warn", Normal, Ungated),
@ -1383,48 +1382,48 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue
}
const EXPLAIN_BOX_SYNTAX: &'static str =
const EXPLAIN_BOX_SYNTAX: &str =
"box expression syntax is experimental; you can call `Box::new` instead.";
pub const EXPLAIN_STMT_ATTR_SYNTAX: &'static str =
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
"attributes on expressions are experimental.";
pub const EXPLAIN_ASM: &'static str =
pub const EXPLAIN_ASM: &str =
"inline assembly is not stable enough for use and is subject to change";
pub const EXPLAIN_GLOBAL_ASM: &'static str =
pub const EXPLAIN_GLOBAL_ASM: &str =
"`global_asm!` is not stable enough for use and is subject to change";
pub const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &'static str =
pub const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &str =
"custom test frameworks are an unstable feature";
pub const EXPLAIN_LOG_SYNTAX: &'static str =
pub const EXPLAIN_LOG_SYNTAX: &str =
"`log_syntax!` is not stable enough for use and is subject to change";
pub const EXPLAIN_CONCAT_IDENTS: &'static str =
pub const EXPLAIN_CONCAT_IDENTS: &str =
"`concat_idents` is not stable enough for use and is subject to change";
pub const EXPLAIN_FORMAT_ARGS_NL: &'static str =
pub const EXPLAIN_FORMAT_ARGS_NL: &str =
"`format_args_nl` is only for internal language use and is subject to change";
pub const EXPLAIN_TRACE_MACROS: &'static str =
pub const EXPLAIN_TRACE_MACROS: &str =
"`trace_macros` is not stable enough for use and is subject to change";
pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str =
pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &str =
"allow_internal_unstable side-steps feature gating and stability checks";
pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &'static str =
pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &str =
"allow_internal_unsafe side-steps the unsafe_code lint";
pub const EXPLAIN_CUSTOM_DERIVE: &'static str =
pub const EXPLAIN_CUSTOM_DERIVE: &str =
"`#[derive]` for custom traits is deprecated and will be removed in the future.";
pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &'static str =
pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &str =
"`#[derive]` for custom traits is deprecated and will be removed in the future. \
Prefer using procedural macro custom derive.";
pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str =
pub const EXPLAIN_DERIVE_UNDERSCORE: &str =
"attributes of the form `#[derive_*]` are reserved for the compiler";
pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &'static str =
pub const EXPLAIN_UNSIZED_TUPLE_COERCION: &str =
"unsized tuple coercion is not stable enough for use and is subject to change";
struct PostExpansionVisitor<'a> {

View file

@ -22,7 +22,7 @@ enum InnerAttributeParsePolicy<'a> {
NotPermitted { reason: &'a str },
}
const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &'static str = "an inner attribute is not \
const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
permitted in this context";
impl<'a> Parser<'a> {

View file

@ -306,7 +306,7 @@ const UNICODE_ARRAY: &[(char, &str, char)] = &[
('', "Fullwidth Greater-Than Sign", '>'), ];
const ASCII_ARRAY: &'static [(char, &'static str)] = &[
const ASCII_ARRAY: &[(char, &str)] = &[
(' ', "Space"),
('_', "Underscore"),
('-', "Minus/Hyphen"),

View file

@ -47,7 +47,7 @@ impl State {
}
}
const OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"];
const OPTIONS: &[&str] = &["volatile", "alignstack", "intel"];
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,

View file

@ -28,7 +28,7 @@ use syntax::symbol::Symbol;
use syntax_pos::Span;
use syntax::tokenstream;
pub const MACRO: &'static str = "global_asm";
pub const MACRO: &str = "global_asm";
pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,

View file

@ -30,8 +30,7 @@ use syntax_pos::{Span, DUMMY_SP};
use deriving;
const PROC_MACRO_KINDS: [&'static str; 3] =
["proc_macro_derive", "proc_macro_attribute", "proc_macro"];
const PROC_MACRO_KINDS: [&str; 3] = ["proc_macro_derive", "proc_macro_attribute", "proc_macro"];
struct ProcMacroDerive {
trait_name: ast::Name,

View file

@ -33,7 +33,7 @@ pub enum Edition {
// must be in order from oldest to newest
pub const ALL_EDITIONS: &[Edition] = &[Edition::Edition2015, Edition::Edition2018];
pub const EDITION_NAME_LIST: &'static str = "2015|2018";
pub const EDITION_NAME_LIST: &str = "2015|2018";
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;