Skip to content

Commit f1e801b

Browse files
committed
⬆️ rust-analyzer
2 parents f03ce30 + 634cfe3 commit f1e801b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1636
-281
lines changed

Diff for: src/tools/rust-analyzer/.github/ISSUE_TEMPLATE/bug_report.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Before submitting, please make sure that you're not running into one of these kn
1919
Otherwise please try to provide information which will help us to fix the issue faster. Minimal reproducible examples with few dependencies are especially lovely <3.
2020
-->
2121

22-
**rust-analyzer version**: (eg. output of "Rust Analyzer: Show RA Version" command)
22+
**rust-analyzer version**: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via <kbd>Ctrl/⌘</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>)
2323

2424
**rustc version**: (eg. output of `rustc -V`)
2525

Diff for: src/tools/rust-analyzer/.github/workflows/release.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ env:
1818
FETCH_DEPTH: 0 # pull in the tags for the version string
1919
MACOSX_DEPLOYMENT_TARGET: 10.15
2020
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
21+
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
2122

2223
jobs:
2324
dist:
@@ -36,6 +37,9 @@ jobs:
3637
- os: ubuntu-18.04
3738
target: aarch64-unknown-linux-gnu
3839
code-target: linux-arm64
40+
- os: ubuntu-18.04
41+
target: arm-unknown-linux-gnueabihf
42+
code-target: linux-armhf
3943
- os: macos-11
4044
target: x86_64-apple-darwin
4145
code-target: darwin-x64
@@ -67,13 +71,17 @@ jobs:
6771
node-version: 14.x
6872

6973
- name: Update apt repositories
70-
if: matrix.target == 'aarch64-unknown-linux-gnu'
74+
if: matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'arm-unknown-linux-gnueabihf'
7175
run: sudo apt-get update
7276

73-
- name: Install target toolchain
77+
- name: Install AArch64 target toolchain
7478
if: matrix.target == 'aarch64-unknown-linux-gnu'
7579
run: sudo apt-get install gcc-aarch64-linux-gnu
7680

81+
- name: Install ARM target toolchain
82+
if: matrix.target == 'arm-unknown-linux-gnueabihf'
83+
run: sudo apt-get install gcc-arm-linux-gnueabihf
84+
7785
- name: Dist
7886
run: cargo xtask dist --client-patch-version ${{ github.run_number }}
7987

@@ -204,6 +212,10 @@ jobs:
204212
with:
205213
name: dist-aarch64-unknown-linux-gnu
206214
path: dist
215+
- uses: actions/download-artifact@v1
216+
with:
217+
name: dist-arm-unknown-linux-gnueabihf
218+
path: dist
207219
- uses: actions/download-artifact@v1
208220
with:
209221
name: dist-x86_64-pc-windows-msvc

Diff for: src/tools/rust-analyzer/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer
4343

4444
## License
4545

46-
Rust analyzer is primarily distributed under the terms of both the MIT
46+
rust-analyzer is primarily distributed under the terms of both the MIT
4747
license and the Apache License (Version 2.0).
4848

4949
See LICENSE-APACHE and LICENSE-MIT for details.

Diff for: src/tools/rust-analyzer/crates/flycheck/src/lib.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct FlycheckHandle {
5757
// XXX: drop order is significant
5858
sender: Sender<Restart>,
5959
_thread: jod_thread::JoinHandle,
60+
id: usize,
6061
}
6162

6263
impl FlycheckHandle {
@@ -72,18 +73,22 @@ impl FlycheckHandle {
7273
.name("Flycheck".to_owned())
7374
.spawn(move || actor.run(receiver))
7475
.expect("failed to spawn thread");
75-
FlycheckHandle { sender, _thread: thread }
76+
FlycheckHandle { id, sender, _thread: thread }
7677
}
7778

7879
/// Schedule a re-start of the cargo check worker.
7980
pub fn update(&self) {
8081
self.sender.send(Restart).unwrap();
8182
}
83+
84+
pub fn id(&self) -> usize {
85+
self.id
86+
}
8287
}
8388

8489
pub enum Message {
8590
/// Request adding a diagnostic with fixes included to a file
86-
AddDiagnostic { workspace_root: AbsPathBuf, diagnostic: Diagnostic },
91+
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },
8792

8893
/// Request check progress notification to client
8994
Progress {
@@ -96,8 +101,9 @@ pub enum Message {
96101
impl fmt::Debug for Message {
97102
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98103
match self {
99-
Message::AddDiagnostic { workspace_root, diagnostic } => f
104+
Message::AddDiagnostic { id, workspace_root, diagnostic } => f
100105
.debug_struct("AddDiagnostic")
106+
.field("id", id)
101107
.field("workspace_root", workspace_root)
102108
.field("diagnostic_code", &diagnostic.code.as_ref().map(|it| &it.code))
103109
.finish(),
@@ -183,7 +189,7 @@ impl FlycheckActor {
183189
}
184190
}
185191
Event::CheckEvent(None) => {
186-
tracing::debug!("flycheck finished");
192+
tracing::debug!(flycheck_id = self.id, "flycheck finished");
187193

188194
// Watcher finished
189195
let cargo_handle = self.cargo_handle.take().unwrap();
@@ -203,6 +209,7 @@ impl FlycheckActor {
203209

204210
CargoMessage::Diagnostic(msg) => {
205211
self.send(Message::AddDiagnostic {
212+
id: self.id,
206213
workspace_root: self.workspace_root.clone(),
207214
diagnostic: msg,
208215
});

Diff for: src/tools/rust-analyzer/crates/hir-def/src/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl HasChildSource<LocalTypeOrConstParamId> for GenericDefId {
451451
if let GenericDefId::TraitId(id) = *self {
452452
let trait_ref = id.lookup(db).source(db).value;
453453
let idx = idx_iter.next().unwrap();
454-
params.insert(idx, Either::Right(trait_ref))
454+
params.insert(idx, Either::Right(trait_ref));
455455
}
456456

457457
if let Some(generic_params_list) = generic_params_list {

Diff for: src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! unaffected, so we don't have to recompute name resolution results or item data (see `data.rs`).
1515
//!
1616
//! The `ItemTree` for the currently open file can be displayed by using the VS Code command
17-
//! "Rust Analyzer: Debug ItemTree".
17+
//! "rust-analyzer: Debug ItemTree".
1818
//!
1919
//! Compared to rustc's architecture, `ItemTree` has properties from both rustc's AST and HIR: many
2020
//! syntax-level Rust features are already desugared to simpler forms in the `ItemTree`, but name

Diff for: src/tools/rust-analyzer/crates/hir-def/src/visibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub(crate) fn field_visibilities_query(
224224
let resolver = variant_id.module(db).resolver(db);
225225
let mut res = ArenaMap::default();
226226
for (field_id, field_data) in var_data.fields().iter() {
227-
res.insert(field_id, field_data.visibility.resolve(db, &resolver))
227+
res.insert(field_id, field_data.visibility.resolve(db, &resolver));
228228
}
229229
Arc::new(res)
230230
}

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/fixup.rs

+108-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::mem;
55
use mbe::{SyntheticToken, SyntheticTokenId, TokenMap};
66
use rustc_hash::FxHashMap;
77
use syntax::{
8-
ast::{self, AstNode},
8+
ast::{self, AstNode, HasLoopBody},
99
match_ast, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
1010
};
1111
use tt::Subtree;
@@ -142,8 +142,59 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
142142
]);
143143
}
144144
},
145+
ast::WhileExpr(it) => {
146+
if it.condition().is_none() {
147+
// insert placeholder token after the while token
148+
let while_token = match it.while_token() {
149+
Some(t) => t,
150+
None => continue,
151+
};
152+
append.insert(while_token.into(), vec![
153+
SyntheticToken {
154+
kind: SyntaxKind::IDENT,
155+
text: "__ra_fixup".into(),
156+
range: end_range,
157+
id: EMPTY_ID,
158+
},
159+
]);
160+
}
161+
if it.loop_body().is_none() {
162+
append.insert(node.clone().into(), vec![
163+
SyntheticToken {
164+
kind: SyntaxKind::L_CURLY,
165+
text: "{".into(),
166+
range: end_range,
167+
id: EMPTY_ID,
168+
},
169+
SyntheticToken {
170+
kind: SyntaxKind::R_CURLY,
171+
text: "}".into(),
172+
range: end_range,
173+
id: EMPTY_ID,
174+
},
175+
]);
176+
}
177+
},
178+
ast::LoopExpr(it) => {
179+
if it.loop_body().is_none() {
180+
append.insert(node.clone().into(), vec![
181+
SyntheticToken {
182+
kind: SyntaxKind::L_CURLY,
183+
text: "{".into(),
184+
range: end_range,
185+
id: EMPTY_ID,
186+
},
187+
SyntheticToken {
188+
kind: SyntaxKind::R_CURLY,
189+
text: "}".into(),
190+
range: end_range,
191+
id: EMPTY_ID,
192+
},
193+
]);
194+
}
195+
},
145196
// FIXME: foo::
146-
// FIXME: for, loop, match etc.
197+
// FIXME: for, match etc.
147198
_ => (),
148199
}
149200
}
@@ -376,6 +427,61 @@ fn foo() {
376427
// the {} gets parsed as the condition, I think?
377428
expect![[r#"
378429
fn foo () {if {} {}}
430+
"#]],
431+
)
432+
}
433+
434+
#[test]
435+
fn fixup_while_1() {
436+
check(
437+
r#"
438+
fn foo() {
439+
while
440+
}
441+
"#,
442+
expect![[r#"
443+
fn foo () {while __ra_fixup {}}
444+
"#]],
445+
)
446+
}
447+
448+
#[test]
449+
fn fixup_while_2() {
450+
check(
451+
r#"
452+
fn foo() {
453+
while foo
454+
}
455+
"#,
456+
expect![[r#"
457+
fn foo () {while foo {}}
458+
"#]],
459+
)
460+
}
461+
#[test]
462+
fn fixup_while_3() {
463+
check(
464+
r#"
465+
fn foo() {
466+
while {}
467+
}
468+
"#,
469+
expect![[r#"
470+
fn foo () {while __ra_fixup {}}
471+
"#]],
472+
)
473+
}
474+
475+
#[test]
476+
fn fixup_loop() {
477+
check(
478+
r#"
479+
fn foo() {
480+
loop
481+
}
482+
"#,
483+
expect![[r#"
484+
fn foo () {loop {}}
379485
"#]],
380486
)
381487
}

Diff for: src/tools/rust-analyzer/crates/hir-expand/src/name.rs

+2
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ pub mod known {
381381
bitor,
382382
bitxor_assign,
383383
bitxor,
384+
branch,
384385
deref_mut,
385386
deref,
386387
div_assign,
@@ -396,6 +397,7 @@ pub mod known {
396397
not,
397398
owned_box,
398399
partial_ord,
400+
poll,
399401
r#fn,
400402
rem_assign,
401403
rem,

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs

+7-56
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use chalk_ir::{
1010
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyVariableKind,
1111
};
1212
use hir_def::{
13-
expr::{ArithOp, Array, BinaryOp, CmpOp, Expr, ExprId, Literal, Ordering, Statement, UnaryOp},
13+
expr::{ArithOp, Array, BinaryOp, CmpOp, Expr, ExprId, Literal, Statement, UnaryOp},
1414
generics::TypeOrConstParamData,
1515
path::{GenericArg, GenericArgs},
1616
resolver::resolver_for_expr,
17-
ConstParamId, FieldId, FunctionId, ItemContainerId, Lookup,
17+
ConstParamId, FieldId, ItemContainerId, Lookup,
1818
};
19-
use hir_expand::name::{name, Name};
19+
use hir_expand::name::Name;
2020
use stdx::always;
2121
use syntax::ast::RangeOp;
2222

@@ -28,7 +28,7 @@ use crate::{
2828
const_or_path_to_chalk, generic_arg_to_chalk, lower_to_chalk_mutability, ParamLoweringMode,
2929
},
3030
mapping::{from_chalk, ToChalk},
31-
method_resolution::{self, VisibleFromModule},
31+
method_resolution::{self, lang_names_for_bin_op, VisibleFromModule},
3232
primitive::{self, UintTy},
3333
static_lifetime, to_chalk_trait_id,
3434
utils::{generics, Generics},
@@ -947,7 +947,9 @@ impl<'a> InferenceContext<'a> {
947947
let lhs_ty = self.infer_expr(lhs, &lhs_expectation);
948948
let rhs_ty = self.table.new_type_var();
949949

950-
let func = self.resolve_binop_method(op);
950+
let func = lang_names_for_bin_op(op).and_then(|(name, lang_item)| {
951+
self.db.trait_data(self.resolve_lang_item(lang_item)?.as_trait()?).method_by_name(&name)
952+
});
951953
let func = match func {
952954
Some(func) => func,
953955
None => {
@@ -1473,55 +1475,4 @@ impl<'a> InferenceContext<'a> {
14731475
},
14741476
})
14751477
}
1476-
1477-
fn resolve_binop_method(&self, op: BinaryOp) -> Option<FunctionId> {
1478-
let (name, lang_item) = match op {
1479-
BinaryOp::LogicOp(_) => return None,
1480-
BinaryOp::ArithOp(aop) => match aop {
1481-
ArithOp::Add => (name!(add), name!(add)),
1482-
ArithOp::Mul => (name!(mul), name!(mul)),
1483-
ArithOp::Sub => (name!(sub), name!(sub)),
1484-
ArithOp::Div => (name!(div), name!(div)),
1485-
ArithOp::Rem => (name!(rem), name!(rem)),
1486-
ArithOp::Shl => (name!(shl), name!(shl)),
1487-
ArithOp::Shr => (name!(shr), name!(shr)),
1488-
ArithOp::BitXor => (name!(bitxor), name!(bitxor)),
1489-
ArithOp::BitOr => (name!(bitor), name!(bitor)),
1490-
ArithOp::BitAnd => (name!(bitand), name!(bitand)),
1491-
},
1492-
BinaryOp::Assignment { op: Some(aop) } => match aop {
1493-
ArithOp::Add => (name!(add_assign), name!(add_assign)),
1494-
ArithOp::Mul => (name!(mul_assign), name!(mul_assign)),
1495-
ArithOp::Sub => (name!(sub_assign), name!(sub_assign)),
1496-
ArithOp::Div => (name!(div_assign), name!(div_assign)),
1497-
ArithOp::Rem => (name!(rem_assign), name!(rem_assign)),
1498-
ArithOp::Shl => (name!(shl_assign), name!(shl_assign)),
1499-
ArithOp::Shr => (name!(shr_assign), name!(shr_assign)),
1500-
ArithOp::BitXor => (name!(bitxor_assign), name!(bitxor_assign)),
1501-
ArithOp::BitOr => (name!(bitor_assign), name!(bitor_assign)),
1502-
ArithOp::BitAnd => (name!(bitand_assign), name!(bitand_assign)),
1503-
},
1504-
BinaryOp::CmpOp(cop) => match cop {
1505-
CmpOp::Eq { negated: false } => (name!(eq), name!(eq)),
1506-
CmpOp::Eq { negated: true } => (name!(ne), name!(eq)),
1507-
CmpOp::Ord { ordering: Ordering::Less, strict: false } => {
1508-
(name!(le), name!(partial_ord))
1509-
}
1510-
CmpOp::Ord { ordering: Ordering::Less, strict: true } => {
1511-
(name!(lt), name!(partial_ord))
1512-
}
1513-
CmpOp::Ord { ordering: Ordering::Greater, strict: false } => {
1514-
(name!(ge), name!(partial_ord))
1515-
}
1516-
CmpOp::Ord { ordering: Ordering::Greater, strict: true } => {
1517-
(name!(gt), name!(partial_ord))
1518-
}
1519-
},
1520-
BinaryOp::Assignment { op: None } => return None,
1521-
};
1522-
1523-
let trait_ = self.resolve_lang_item(lang_item)?.as_trait()?;
1524-
1525-
self.db.trait_data(trait_).method_by_name(&name)
1526-
}
15271478
}

0 commit comments

Comments
 (0)