Merge pull request #138816 from oxalica/rust-analyzer

authored by Sandro and committed by GitHub 4a5b37d6 6836fa84

+220 -5
+1 -1
pkgs/development/node-packages/node-packages.nix
··· 111170 111170 "rust-analyzer-build-deps-../../misc/vscode-extensions/rust-analyzer/build-deps" = nodeEnv.buildNodePackage { 111171 111171 name = "rust-analyzer"; 111172 111172 packageName = "rust-analyzer"; 111173 - version = "0.2.735"; 111173 + version = "0.2.751"; 111174 111174 src = ../../misc/vscode-extensions/rust-analyzer/build-deps; 111175 111175 dependencies = [ 111176 111176 sources."@babel/code-frame-7.12.11"
+6 -3
pkgs/development/tools/rust/rust-analyzer/default.nix
··· 6 6 7 7 rustPlatform.buildRustPackage rec { 8 8 pname = "rust-analyzer-unwrapped"; 9 - version = "2021-09-06"; 10 - cargoSha256 = "sha256-CTCDSoViyVMHxUKQz8fE+r3rkXf7yRgzZ90fZmMtcNM="; 9 + version = "2021-09-20"; 10 + cargoSha256 = "sha256-OPolZ0oXGRcKvWxXkRMjyEXzvf1p41hGfHBpbDbLJck="; 11 11 12 12 src = fetchFromGitHub { 13 13 owner = "rust-analyzer"; 14 14 repo = "rust-analyzer"; 15 15 rev = version; 16 - sha256 = "sha256-TacpTVvHAIs4kZ5vibj8luy/kryYwxY+OXFNPnqiXP0="; 16 + sha256 = "sha256-k2UGz+h9++8wtV+XdGZbWysjkIDe+UNudKL46eisZzw="; 17 17 }; 18 18 19 19 patches = [ 20 20 # Code format and git history check require more dependencies but don't really matter for packaging. 21 21 # So just ignore them. 22 22 ./ignore-git-and-rustfmt-tests.patch 23 + 24 + # Patch for our rust 1.54.0 in nixpkgs. Remove it when we have rust >= 1.55.0 25 + ./no-1-55-control-flow.patch 23 26 ]; 24 27 25 28 buildAndTestSubdir = "crates/rust-analyzer";
+212
pkgs/development/tools/rust/rust-analyzer/no-1-55-control-flow.patch
··· 1 + diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs 2 + index 3b0c29e87..2841a39e2 100644 3 + --- a/crates/hir/src/lib.rs 4 + +++ b/crates/hir/src/lib.rs 5 + @@ -31,7 +31,7 @@ pub mod db; 6 + 7 + mod display; 8 + 9 + -use std::{iter, ops::ControlFlow, sync::Arc}; 10 + +use std::{iter, sync::Arc}; 11 + 12 + use arrayvec::ArrayVec; 13 + use base_db::{CrateDisplayName, CrateId, Edition, FileId}; 14 + @@ -70,7 +70,7 @@ use itertools::Itertools; 15 + use nameres::diagnostics::DefDiagnosticKind; 16 + use once_cell::unsync::Lazy; 17 + use rustc_hash::FxHashSet; 18 + -use stdx::{format_to, impl_from}; 19 + +use stdx::{format_to, impl_from, ControlFlow}; 20 + use syntax::{ 21 + ast::{self, AttrsOwner, NameOwner}, 22 + AstNode, AstPtr, SmolStr, SyntaxKind, SyntaxNodePtr, 23 + diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs 24 + index c88a8b653..039b5589e 100644 25 + --- a/crates/hir_ty/src/method_resolution.rs 26 + +++ b/crates/hir_ty/src/method_resolution.rs 27 + @@ -2,7 +2,7 @@ 28 + //! For details about how this works in rustc, see the method lookup page in the 29 + //! [rustc guide](https://rust-lang.github.io/rustc-guide/method-lookup.html) 30 + //! and the corresponding code mostly in librustc_typeck/check/method/probe.rs. 31 + -use std::{iter, ops::ControlFlow, sync::Arc}; 32 + +use std::{iter, sync::Arc}; 33 + 34 + use arrayvec::ArrayVec; 35 + use base_db::{CrateId, Edition}; 36 + @@ -13,6 +13,7 @@ use hir_def::{ 37 + }; 38 + use hir_expand::name::Name; 39 + use rustc_hash::{FxHashMap, FxHashSet}; 40 + +use stdx::{try_control_flow, ControlFlow}; 41 + 42 + use crate::{ 43 + autoderef, 44 + @@ -483,7 +484,7 @@ pub fn iterate_method_candidates_dyn( 45 + 46 + let deref_chain = autoderef_method_receiver(db, krate, ty); 47 + for i in 0..deref_chain.len() { 48 + - iterate_method_candidates_with_autoref( 49 + + try_control_flow!(iterate_method_candidates_with_autoref( 50 + &deref_chain[i..], 51 + db, 52 + env.clone(), 53 + @@ -492,7 +493,7 @@ pub fn iterate_method_candidates_dyn( 54 + visible_from_module, 55 + name, 56 + callback, 57 + - )?; 58 + + )); 59 + } 60 + ControlFlow::Continue(()) 61 + } 62 + @@ -522,7 +523,7 @@ fn iterate_method_candidates_with_autoref( 63 + name: Option<&Name>, 64 + mut callback: &mut dyn FnMut(&Canonical<Ty>, AssocItemId) -> ControlFlow<()>, 65 + ) -> ControlFlow<()> { 66 + - iterate_method_candidates_by_receiver( 67 + + try_control_flow!(iterate_method_candidates_by_receiver( 68 + &deref_chain[0], 69 + &deref_chain[1..], 70 + db, 71 + @@ -532,7 +533,7 @@ fn iterate_method_candidates_with_autoref( 72 + visible_from_module, 73 + name, 74 + &mut callback, 75 + - )?; 76 + + )); 77 + 78 + let refed = Canonical { 79 + binders: deref_chain[0].binders.clone(), 80 + @@ -540,7 +541,7 @@ fn iterate_method_candidates_with_autoref( 81 + .intern(&Interner), 82 + }; 83 + 84 + - iterate_method_candidates_by_receiver( 85 + + try_control_flow!(iterate_method_candidates_by_receiver( 86 + &refed, 87 + deref_chain, 88 + db, 89 + @@ -550,7 +551,7 @@ fn iterate_method_candidates_with_autoref( 90 + visible_from_module, 91 + name, 92 + &mut callback, 93 + - )?; 94 + + )); 95 + 96 + let ref_muted = Canonical { 97 + binders: deref_chain[0].binders.clone(), 98 + @@ -586,7 +587,7 @@ fn iterate_method_candidates_by_receiver( 99 + // be found in any of the derefs of receiver_ty, so we have to go through 100 + // that. 101 + for self_ty in std::iter::once(receiver_ty).chain(rest_of_deref_chain) { 102 + - iterate_inherent_methods( 103 + + try_control_flow!(iterate_inherent_methods( 104 + self_ty, 105 + db, 106 + env.clone(), 107 + @@ -595,11 +596,11 @@ fn iterate_method_candidates_by_receiver( 108 + krate, 109 + visible_from_module, 110 + &mut callback, 111 + - )? 112 + + )) 113 + } 114 + 115 + for self_ty in std::iter::once(receiver_ty).chain(rest_of_deref_chain) { 116 + - iterate_trait_method_candidates( 117 + + try_control_flow!(iterate_trait_method_candidates( 118 + self_ty, 119 + db, 120 + env.clone(), 121 + @@ -608,7 +609,7 @@ fn iterate_method_candidates_by_receiver( 122 + name, 123 + Some(receiver_ty), 124 + &mut callback, 125 + - )? 126 + + )) 127 + } 128 + 129 + ControlFlow::Continue(()) 130 + @@ -624,7 +625,7 @@ fn iterate_method_candidates_for_self_ty( 131 + name: Option<&Name>, 132 + mut callback: &mut dyn FnMut(&Canonical<Ty>, AssocItemId) -> ControlFlow<()>, 133 + ) -> ControlFlow<()> { 134 + - iterate_inherent_methods( 135 + + try_control_flow!(iterate_inherent_methods( 136 + self_ty, 137 + db, 138 + env.clone(), 139 + @@ -633,7 +634,7 @@ fn iterate_method_candidates_for_self_ty( 140 + krate, 141 + visible_from_module, 142 + &mut callback, 143 + - )?; 144 + + )); 145 + iterate_trait_method_candidates(self_ty, db, env, krate, traits_in_scope, name, None, callback) 146 + } 147 + 148 + @@ -697,7 +698,7 @@ fn iterate_trait_method_candidates( 149 + } 150 + known_implemented = true; 151 + // FIXME: we shouldn't be ignoring the binders here 152 + - callback(self_ty, *item)? 153 + + try_control_flow!(callback(self_ty, *item)) 154 + } 155 + } 156 + ControlFlow::Continue(()) 157 + @@ -774,7 +775,7 @@ fn iterate_inherent_methods( 158 + continue; 159 + } 160 + let receiver_ty = receiver_ty.unwrap_or(self_ty); 161 + - callback(receiver_ty, item)?; 162 + + try_control_flow!(callback(receiver_ty, item)); 163 + } 164 + } 165 + } 166 + diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs 167 + index 506d3ba3c..590963c17 100644 168 + --- a/crates/ide/src/hover.rs 169 + +++ b/crates/ide/src/hover.rs 170 + @@ -1,4 +1,4 @@ 171 + -use std::{collections::HashSet, ops::ControlFlow}; 172 + +use std::collections::HashSet; 173 + 174 + use either::Either; 175 + use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo}; 176 + @@ -12,7 +12,7 @@ use ide_db::{ 177 + RootDatabase, 178 + }; 179 + use itertools::Itertools; 180 + -use stdx::format_to; 181 + +use stdx::{format_to, ControlFlow}; 182 + use syntax::{ 183 + algo, ast, display::fn_as_proc_macro_label, match_ast, AstNode, Direction, SyntaxKind::*, 184 + SyntaxNode, SyntaxToken, TextRange, TextSize, T, 185 + diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs 186 + index e7d4753de..fddf95147 100644 187 + --- a/crates/stdx/src/lib.rs 188 + +++ b/crates/stdx/src/lib.rs 189 + @@ -7,6 +7,22 @@ pub mod panic_context; 190 + 191 + pub use always_assert::{always, never}; 192 + 193 + +/// std::ops::ControlFlow from rust std 1.55.0 194 + +pub enum ControlFlow<B, C = ()> { 195 + + Continue(C), 196 + + Break(B), 197 + +} 198 + + 199 + +#[macro_export] 200 + +macro_rules! try_control_flow { 201 + + ($e:expr) => { 202 + + match $e { 203 + + $crate::ControlFlow::Continue(c) => c, 204 + + $crate::ControlFlow::Break(b) => return $crate::ControlFlow::Break(b), 205 + + } 206 + + }; 207 + +} 208 + + 209 + #[inline(always)] 210 + pub fn is_ci() -> bool { 211 + option_env!("CI").is_some() 212 +
+1 -1
pkgs/misc/vscode-extensions/rust-analyzer/build-deps/package.json
··· 1 1 { 2 2 "name": "rust-analyzer", 3 - "version": "0.2.735", 3 + "version": "0.2.751", 4 4 "dependencies": { 5 5 "https-proxy-agent": "^5.0.0", 6 6 "node-fetch": "^2.6.1",