diff --git a/rls/src/config.rs b/rls/src/config.rs index 2da3fde2b23..767bfc333ac 100644 --- a/rls/src/config.rs +++ b/rls/src/config.rs @@ -103,6 +103,17 @@ impl AsRef for Inferrable { } } +/// Returns whether RLS was built using nightly channel. +/// +/// It is very similar to what rust and rustfmt uses [1] - it relies on +/// CFG_RELEASE_CHANNEL being set by Rust bootstrap. +/// In case the env var is missing, we assume that we're built by Cargo and are +/// using nightly since that's the only channel supported right now. +/// [1]: https://github.com/rust-lang/rustfmt/blob/dfa94d150555da40780413d7f1a1378565208c99/src/config/config_type.rs#L53-L67 +pub fn is_nightly() -> bool { + option_env!("CFG_RELEASE_CHANNEL").map_or(true, |c| c == "nightly" || c == "dev") +} + /// RLS configuration options. #[derive(Clone, Debug, Deserialize)] #[allow(missing_docs)] @@ -251,10 +262,7 @@ impl Config { /// Ensures that unstable options are only allowed if `unstable_features` is /// true and that is not allowed on stable release channels. pub fn normalise(&mut self) { - let allow_unstable = - option_env!("CFG_RELEASE_CHANNEL").map(|c| c == "nightly").unwrap_or(true); - - if !allow_unstable { + if !is_nightly() { if self.unstable_features { eprintln!("`unstable_features` setting can only be used on nightly channel"); }