Skip to content

Commit 39bd3b2

Browse files
committed
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into find-cargo-toml-up-the-fs
2 parents 34e3ef6 + d3040c0 commit 39bd3b2

40 files changed

+659
-377
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_assists/src/ast_transform.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
22
use rustc_hash::FxHashMap;
33

4-
use hir::{db::HirDatabase, InFile, PathResolution};
4+
use hir::{InFile, PathResolution};
5+
use ra_ide_db::RootDatabase;
56
use ra_syntax::ast::{self, AstNode};
67

78
pub trait AstTransform<'a> {
@@ -33,18 +34,18 @@ impl<'a> AstTransform<'a> for NullTransformer {
3334
}
3435
}
3536

36-
pub struct SubstituteTypeParams<'a, DB: HirDatabase> {
37-
db: &'a DB,
37+
pub struct SubstituteTypeParams<'a> {
38+
db: &'a RootDatabase,
3839
substs: FxHashMap<hir::TypeParam, ast::TypeRef>,
3940
previous: Box<dyn AstTransform<'a> + 'a>,
4041
}
4142

42-
impl<'a, DB: HirDatabase> SubstituteTypeParams<'a, DB> {
43+
impl<'a> SubstituteTypeParams<'a> {
4344
pub fn for_trait_impl(
44-
db: &'a DB,
45+
db: &'a RootDatabase,
4546
trait_: hir::Trait,
4647
impl_block: ast::ImplBlock,
47-
) -> SubstituteTypeParams<'a, DB> {
48+
) -> SubstituteTypeParams<'a> {
4849
let substs = get_syntactic_substs(impl_block).unwrap_or_default();
4950
let generic_def: hir::GenericDef = trait_.into();
5051
let substs_by_param: FxHashMap<_, _> = generic_def
@@ -95,7 +96,7 @@ impl<'a, DB: HirDatabase> SubstituteTypeParams<'a, DB> {
9596
}
9697
}
9798

98-
impl<'a, DB: HirDatabase> AstTransform<'a> for SubstituteTypeParams<'a, DB> {
99+
impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
99100
fn get_substitution(
100101
&self,
101102
node: InFile<&ra_syntax::SyntaxNode>,
@@ -107,14 +108,14 @@ impl<'a, DB: HirDatabase> AstTransform<'a> for SubstituteTypeParams<'a, DB> {
107108
}
108109
}
109110

110-
pub struct QualifyPaths<'a, DB: HirDatabase> {
111-
db: &'a DB,
111+
pub struct QualifyPaths<'a> {
112+
db: &'a RootDatabase,
112113
from: Option<hir::Module>,
113114
previous: Box<dyn AstTransform<'a> + 'a>,
114115
}
115116

116-
impl<'a, DB: HirDatabase> QualifyPaths<'a, DB> {
117-
pub fn new(db: &'a DB, from: Option<hir::Module>) -> Self {
117+
impl<'a> QualifyPaths<'a> {
118+
pub fn new(db: &'a RootDatabase, from: Option<hir::Module>) -> Self {
118119
Self { db, from, previous: Box::new(NullTransformer) }
119120
}
120121

@@ -168,7 +169,7 @@ pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: InFile<N>
168169
N::cast(result).unwrap()
169170
}
170171

171-
impl<'a, DB: HirDatabase> AstTransform<'a> for QualifyPaths<'a, DB> {
172+
impl<'a> AstTransform<'a> for QualifyPaths<'a> {
172173
fn get_substitution(
173174
&self,
174175
node: InFile<&ra_syntax::SyntaxNode>,

crates/ra_fmt/src/lib.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,35 @@ pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr {
4343

4444
pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> {
4545
let block = block.block()?;
46-
let expr = block.expr()?;
47-
let non_trivial_children = block.syntax().children().filter(|it| match it.kind() {
48-
WHITESPACE | T!['{'] | T!['}'] => false,
49-
_ => it != expr.syntax(),
50-
});
51-
if non_trivial_children.count() > 0 {
52-
return None;
46+
let has_anything_else = |thing: &SyntaxNode| -> bool {
47+
let mut non_trivial_children =
48+
block.syntax().children_with_tokens().filter(|it| match it.kind() {
49+
WHITESPACE | T!['{'] | T!['}'] => false,
50+
_ => it.as_node() != Some(thing),
51+
});
52+
non_trivial_children.next().is_some()
53+
};
54+
55+
if let Some(expr) = block.expr() {
56+
if has_anything_else(expr.syntax()) {
57+
return None;
58+
}
59+
return Some(expr);
60+
} else {
61+
// Unwrap `{ continue; }`
62+
let (stmt,) = block.statements().next_tuple()?;
63+
if has_anything_else(stmt.syntax()) {
64+
return None;
65+
}
66+
if let ast::Stmt::ExprStmt(expr_stmt) = stmt {
67+
let expr = expr_stmt.expr()?;
68+
match expr.syntax().kind() {
69+
CONTINUE_EXPR | BREAK_EXPR | RETURN_EXPR => return Some(expr),
70+
_ => (),
71+
}
72+
}
5373
}
54-
Some(expr)
74+
None
5575
}
5676

5777
pub fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {

crates/ra_hir_ty/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ ra_prof = { path = "../ra_prof" }
2121
ra_syntax = { path = "../ra_syntax" }
2222
test_utils = { path = "../test_utils" }
2323

24-
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
25-
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
26-
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "af48f302a1f571b3ca418f7c5aa639a144a34f75" }
24+
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "2939913fb7bb94ac2a6721087dc086be11410702" }
25+
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "2939913fb7bb94ac2a6721087dc086be11410702" }
26+
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "2939913fb7bb94ac2a6721087dc086be11410702" }
2727

2828
lalrpop-intern = "0.15.1"
2929

crates/ra_hir_ty/src/traits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use crate::db::HirDatabase;
1414

1515
use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk};
1616

17-
use self::chalk::{from_chalk, ToChalk, TypeFamily};
17+
use self::chalk::{from_chalk, Interner, ToChalk};
1818

1919
pub(crate) mod chalk;
2020
mod builtin;
2121

2222
#[derive(Debug, Clone)]
2323
pub struct TraitSolver {
2424
krate: CrateId,
25-
inner: Arc<Mutex<chalk_solve::Solver<TypeFamily>>>,
25+
inner: Arc<Mutex<chalk_solve::Solver<Interner>>>,
2626
}
2727

2828
/// We need eq for salsa
@@ -38,8 +38,8 @@ impl TraitSolver {
3838
fn solve(
3939
&self,
4040
db: &impl HirDatabase,
41-
goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<TypeFamily>>>,
42-
) -> Option<chalk_solve::Solution<TypeFamily>> {
41+
goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<Interner>>>,
42+
) -> Option<chalk_solve::Solution<Interner>> {
4343
let context = ChalkContext { db, krate: self.krate };
4444
log::debug!("solve goal: {:?}", goal);
4545
let mut solver = match self.inner.lock() {
@@ -110,7 +110,7 @@ pub(crate) fn trait_solver_query(
110110
TraitSolver { krate, inner: Arc::new(Mutex::new(create_chalk_solver())) }
111111
}
112112

113-
fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> {
113+
fn create_chalk_solver() -> chalk_solve::Solver<Interner> {
114114
let solver_choice =
115115
chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE, expected_answers: None };
116116
solver_choice.into_solver()
@@ -242,9 +242,9 @@ pub(crate) fn trait_solve_query(
242242

243243
fn solution_from_chalk(
244244
db: &impl HirDatabase,
245-
solution: chalk_solve::Solution<TypeFamily>,
245+
solution: chalk_solve::Solution<Interner>,
246246
) -> Solution {
247-
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
247+
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| {
248248
let value = subst
249249
.value
250250
.into_iter()

0 commit comments

Comments
 (0)