diff options
author | oxalica <oxalicc@pm.me> | 2020-09-18 02:33:12 +0800 |
---|---|---|
committer | Jon <jonringer@users.noreply.github.com> | 2020-09-21 10:55:15 -0700 |
commit | 0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8 (patch) | |
tree | c5dfa210f3f7316edc05ac5fca96a97ca2ab356d /pkgs/development/tools/rust | |
parent | 8403806a3953ac75ad1141e578e55293114a0617 (diff) | |
download | nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar.gz nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar.bz2 nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar.lz nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar.xz nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.tar.zst nixpkgs-0e0dc5544cebe4435031ffaaf00f02bfd9b3aed8.zip |
rust-analyzer: 2020-08-24 -> 2020-09-21
Diffstat (limited to 'pkgs/development/tools/rust')
4 files changed, 303 insertions, 15 deletions
diff --git a/pkgs/development/tools/rust/rust-analyzer/default.nix b/pkgs/development/tools/rust/rust-analyzer/default.nix index c9c87991a8a..5d66f6e2100 100644 --- a/pkgs/development/tools/rust/rust-analyzer/default.nix +++ b/pkgs/development/tools/rust/rust-analyzer/default.nix @@ -2,10 +2,10 @@ { rust-analyzer-unwrapped = callPackage ./generic.nix rec { - rev = "2020-08-24"; + rev = "2020-09-21"; version = "unstable-${rev}"; - sha256 = "11q5shrq55krgpj7rjfqw84131j5g55zyrwww3cxcbr8ndi3xdnf"; - cargoSha256 = "15kjcgxmigm0lwbp8p0kdxax86ldjqq9q8ysj6khfhqd0173184n"; + sha256 = "1wjm69r1c6s8a4rd91csg7c48bp8jamxsrm5m6rg3bk2gqp8yzz8"; + cargoSha256 = "089w2i6lvpjxkxghkb2mij9sxfxlcc1zv4iq4qmzq8gnc6ddz12d"; }; rust-analyzer = callPackage ./wrapper.nix {} { diff --git a/pkgs/development/tools/rust/rust-analyzer/generic.nix b/pkgs/development/tools/rust/rust-analyzer/generic.nix index 7092f5291dd..3bd6d1ccee1 100644 --- a/pkgs/development/tools/rust/rust-analyzer/generic.nix +++ b/pkgs/development/tools/rust/rust-analyzer/generic.nix @@ -1,9 +1,10 @@ -{ lib, stdenv, fetchFromGitHub, rustPlatform, darwin -, useJemalloc ? false +{ lib, stdenv, fetchFromGitHub, rustPlatform, darwin, cmake +, useMimalloc ? false , doCheck ? true # Version specific args -, rev, version, sha256, cargoSha256 }: +, rev, version, sha256, cargoSha256 +}: rustPlatform.buildRustPackage { pname = "rust-analyzer-unwrapped"; @@ -15,11 +16,17 @@ rustPlatform.buildRustPackage { inherit rev sha256; }; + patches = [ + # FIXME: Temporary fix for our rust 1.45.0 since rust-analyzer requires 1.46.0 + ./no-loop-in-const-fn.patch + ./no-option-zip.patch + ]; + buildAndTestSubdir = "crates/rust-analyzer"; - cargoBuildFlags = lib.optional useJemalloc "--features=jemalloc"; + cargoBuildFlags = lib.optional useMimalloc "--features=mimalloc"; - nativeBuildInputs = lib.optionals doCheck [ rustPlatform.rustcSrc ]; + nativeBuildInputs = lib.optional useMimalloc cmake; buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.CoreServices ]; @@ -27,16 +34,11 @@ rustPlatform.buildRustPackage { RUST_ANALYZER_REV = rev; inherit doCheck; - # Skip tests running `rustup` for `cargo fmt`. - preCheck = '' - fakeRustup=$(mktemp -d) - ln -s $(command -v true) $fakeRustup/rustup - export PATH=$PATH''${PATH:+:}$fakeRustup + preCheck = lib.optionalString doCheck '' export RUST_SRC_PATH=${rustPlatform.rustcSrc} ''; - # Temporary disabled until #93119 is fixed. - doInstallCheck = false; + doInstallCheck = true; installCheckPhase = '' runHook preInstallCheck versionOutput="$($out/bin/rust-analyzer --version)" diff --git a/pkgs/development/tools/rust/rust-analyzer/no-loop-in-const-fn.patch b/pkgs/development/tools/rust/rust-analyzer/no-loop-in-const-fn.patch new file mode 100644 index 00000000000..e750b3c4e12 --- /dev/null +++ b/pkgs/development/tools/rust/rust-analyzer/no-loop-in-const-fn.patch @@ -0,0 +1,223 @@ +This patch revert 4b989009e3839cfc6f021d1552a46561cee6cde2 (CONST LOOPS ARE HERE). + +diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs +index 5f885edfd..e72929f8c 100644 +--- a/crates/parser/src/grammar/expressions.rs ++++ b/crates/parser/src/grammar/expressions.rs +@@ -316,7 +316,7 @@ fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option<CompletedMark + } + + const LHS_FIRST: TokenSet = +- atom::ATOM_EXPR_FIRST.union(TokenSet::new(&[T![&], T![*], T![!], T![.], T![-]])); ++ atom::ATOM_EXPR_FIRST.union(token_set![T![&], T![*], T![!], T![.], T![-]]); + + fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { + let m; +diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs +index 66a92a4e1..ba6dd2fbc 100644 +--- a/crates/parser/src/grammar/expressions/atom.rs ++++ b/crates/parser/src/grammar/expressions/atom.rs +@@ -15,7 +15,7 @@ use super::*; + // let _ = b"e"; + // let _ = br"f"; + // } +-pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ ++pub(crate) const LITERAL_FIRST: TokenSet = token_set![ + TRUE_KW, + FALSE_KW, + INT_NUMBER, +@@ -25,8 +25,8 @@ pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ + STRING, + RAW_STRING, + BYTE_STRING, +- RAW_BYTE_STRING, +-]); ++ RAW_BYTE_STRING ++]; + + pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { + if !p.at_ts(LITERAL_FIRST) { +@@ -39,7 +39,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { + + // E.g. for after the break in `if break {}`, this should not match + pub(super) const ATOM_EXPR_FIRST: TokenSet = +- LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[ ++ LITERAL_FIRST.union(paths::PATH_FIRST).union(token_set![ + T!['('], + T!['{'], + T!['['], +@@ -59,9 +59,9 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = + T![loop], + T![for], + LIFETIME, +- ])); ++ ]); + +-const EXPR_RECOVERY_SET: TokenSet = TokenSet::new(&[LET_KW, R_DOLLAR]); ++const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW, R_DOLLAR]; + + pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { + if let Some(m) = literal(p) { +diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs +index 22810e6fb..8fd8f3b80 100644 +--- a/crates/parser/src/grammar/items.rs ++++ b/crates/parser/src/grammar/items.rs +@@ -26,7 +26,7 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { + } + } + +-pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ ++pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ + FN_KW, + STRUCT_KW, + ENUM_KW, +@@ -41,7 +41,7 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ + USE_KW, + MACRO_KW, + T![;], +-]); ++]; + + pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { + let m = p.start(); +diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs +index 5d297e2d6..52562afa4 100644 +--- a/crates/parser/src/grammar/paths.rs ++++ b/crates/parser/src/grammar/paths.rs +@@ -3,7 +3,7 @@ + use super::*; + + pub(super) const PATH_FIRST: TokenSet = +- TokenSet::new(&[IDENT, T![self], T![super], T![crate], T![:], T![<]]); ++ token_set![IDENT, T![self], T![super], T![crate], T![:], T![<]]; + + pub(super) fn is_path_start(p: &Parser) -> bool { + is_use_path_start(p) || p.at(T![<]) +diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs +index 796f206e1..07b1d6dd5 100644 +--- a/crates/parser/src/grammar/patterns.rs ++++ b/crates/parser/src/grammar/patterns.rs +@@ -2,18 +2,9 @@ + + use super::*; + +-pub(super) const PATTERN_FIRST: TokenSet = +- expressions::LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[ +- T![box], +- T![ref], +- T![mut], +- T!['('], +- T!['['], +- T![&], +- T![_], +- T![-], +- T![.], +- ])); ++pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST ++ .union(paths::PATH_FIRST) ++ .union(token_set![T![box], T![ref], T![mut], T!['('], T!['['], T![&], T![_], T![-], T![.]]); + + pub(crate) fn pattern(p: &mut Parser) { + pattern_r(p, PAT_RECOVERY_SET); +@@ -83,7 +74,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { + } + + const PAT_RECOVERY_SET: TokenSet = +- TokenSet::new(&[LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]); ++ token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]; + + fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { + let m = match p.nth(0) { +diff --git a/crates/parser/src/grammar/types.rs b/crates/parser/src/grammar/types.rs +index 1ea130ac5..9d00eb9b9 100644 +--- a/crates/parser/src/grammar/types.rs ++++ b/crates/parser/src/grammar/types.rs +@@ -2,7 +2,7 @@ + + use super::*; + +-pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(TokenSet::new(&[ ++pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![ + T!['('], + T!['['], + T![<], +@@ -16,16 +16,16 @@ pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(TokenSet::new(&[ + T![for], + T![impl], + T![dyn], +-])); ++]); + +-const TYPE_RECOVERY_SET: TokenSet = TokenSet::new(&[ ++const TYPE_RECOVERY_SET: TokenSet = token_set![ + T![')'], + T![,], + L_DOLLAR, + // test_err struct_field_recover + // struct S { f pub g: () } + T![pub], +-]); ++]; + + pub(crate) fn type_(p: &mut Parser) { + type_with_bounds_cond(p, true); +diff --git a/crates/parser/src/token_set.rs b/crates/parser/src/token_set.rs +index a68f0144e..994017acf 100644 +--- a/crates/parser/src/token_set.rs ++++ b/crates/parser/src/token_set.rs +@@ -9,21 +9,15 @@ pub(crate) struct TokenSet(u128); + impl TokenSet { + pub(crate) const EMPTY: TokenSet = TokenSet(0); + +- pub(crate) const fn new(kinds: &[SyntaxKind]) -> TokenSet { +- let mut res = 0u128; +- let mut i = 0; +- while i < kinds.len() { +- res |= mask(kinds[i]); +- i += 1 +- } +- TokenSet(res) ++ pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet { ++ TokenSet(mask(kind)) + } + + pub(crate) const fn union(self, other: TokenSet) -> TokenSet { + TokenSet(self.0 | other.0) + } + +- pub(crate) const fn contains(&self, kind: SyntaxKind) -> bool { ++ pub(crate) fn contains(&self, kind: SyntaxKind) -> bool { + self.0 & mask(kind) != 0 + } + } +@@ -32,10 +26,16 @@ const fn mask(kind: SyntaxKind) -> u128 { + 1u128 << (kind as usize) + } + ++#[macro_export] ++macro_rules! token_set { ++ ($($t:expr),*) => { TokenSet::EMPTY$(.union(TokenSet::singleton($t)))* }; ++ ($($t:expr),* ,) => { token_set!($($t),*) }; ++} ++ + #[test] + fn token_set_works_for_tokens() { + use crate::SyntaxKind::*; +- let ts = TokenSet::new(&[EOF, SHEBANG]); ++ let ts = token_set![EOF, SHEBANG]; + assert!(ts.contains(EOF)); + assert!(ts.contains(SHEBANG)); + assert!(!ts.contains(PLUS)); +diff --git a/xtask/src/install.rs b/xtask/src/install.rs +index d829790d7..b25a6e301 100644 +--- a/xtask/src/install.rs ++++ b/xtask/src/install.rs +@@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result}; + use crate::not_bash::{pushd, run}; + + // Latest stable, feel free to send a PR if this lags behind. +-const REQUIRED_RUST_VERSION: u32 = 46; ++const REQUIRED_RUST_VERSION: u32 = 43; + + pub struct InstallCmd { + pub client: Option<ClientOpt>, diff --git a/pkgs/development/tools/rust/rust-analyzer/no-option-zip.patch b/pkgs/development/tools/rust/rust-analyzer/no-option-zip.patch new file mode 100644 index 00000000000..06c8a1a595e --- /dev/null +++ b/pkgs/development/tools/rust/rust-analyzer/no-option-zip.patch @@ -0,0 +1,63 @@ +diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs +index 0bd679260..e0b76e079 100644 +--- a/crates/assists/src/handlers/merge_imports.rs ++++ b/crates/assists/src/handlers/merge_imports.rs +@@ -32,7 +32,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<() + if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) { + let (merged, to_delete) = + next_prev().filter_map(|dir| neighbor(&use_item, dir)).find_map(|use_item2| { +- try_merge_imports(&use_item, &use_item2, MergeBehaviour::Full).zip(Some(use_item2)) ++ Some((try_merge_imports(&use_item, &use_item2, MergeBehaviour::Full)?, use_item2)) + })?; + + rewriter.replace_ast(&use_item, &merged); +@@ -44,7 +44,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<() + } else { + let (merged, to_delete) = + next_prev().filter_map(|dir| neighbor(&tree, dir)).find_map(|use_tree| { +- try_merge_trees(&tree, &use_tree, MergeBehaviour::Full).zip(Some(use_tree)) ++ Some((try_merge_trees(&tree, &use_tree, MergeBehaviour::Full)?, use_tree)) + })?; + + rewriter.replace_ast(&tree, &merged); +diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs +index 6d110aaaf..1f1838729 100644 +--- a/crates/assists/src/utils/insert_use.rs ++++ b/crates/assists/src/utils/insert_use.rs +@@ -223,7 +223,7 @@ fn common_prefix(lhs: &ast::Path, rhs: &ast::Path) -> Option<(ast::Path, ast::Pa + } + res = Some((lhs_curr.clone(), rhs_curr.clone())); + +- match lhs_curr.parent_path().zip(rhs_curr.parent_path()) { ++ match zip(lhs_curr.parent_path(), rhs_curr.parent_path()) { + Some((lhs, rhs)) => { + lhs_curr = lhs; + rhs_curr = rhs; +@@ -309,8 +309,8 @@ fn find_insert_position( + let path_node_iter = scope + .as_syntax_node() + .children() +- .filter_map(|node| ast::Use::cast(node.clone()).zip(Some(node))) +- .flat_map(|(use_, node)| use_.use_tree().and_then(|tree| tree.path()).zip(Some(node))); ++ .filter_map(|node| zip(ast::Use::cast(node.clone()), Some(node))) ++ .flat_map(|(use_, node)| zip(use_.use_tree().and_then(|tree| tree.path()), Some(node))); + // Iterator that discards anything thats not in the required grouping + // This implementation allows the user to rearrange their import groups as this only takes the first group that fits + let group_iter = path_node_iter +@@ -328,7 +328,7 @@ fn find_insert_position( + segments + .clone() + .zip(check_segments) +- .flat_map(|(seg, seg2)| seg.name_ref().zip(seg2.name_ref())) ++ .flat_map(|(seg, seg2)| zip(seg.name_ref(), seg2.name_ref())) + .all(|(l, r)| l.text() <= r.text()) + }); + match post_insert { +@@ -743,3 +743,7 @@ use foo::bar::baz::Qux;", + check(path, ra_fixture_before, ra_fixture_after, None) + } + } ++ ++fn zip<T, U>(x: Option<T>, y: Option<U>) -> Option<(T, U)> { ++ Some((x?, y?)) ++} |