Skip to content

Commit 356c651

Browse files
committed
Auto merge of #109377 - lnicola:rust-analyzer-2023-03-20, r=lnicola
⬆️ rust-analyzer r? `@ghost`
2 parents e91364b + 0f499b4 commit 356c651

File tree

106 files changed

+2220
-610
lines changed

Some content is hidden

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

106 files changed

+2220
-610
lines changed

src/tools/rust-analyzer/Cargo.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
169169

170170
[[package]]
171171
name = "chalk-derive"
172-
version = "0.88.0"
172+
version = "0.89.0"
173173
source = "registry+https://github.com/rust-lang/crates.io-index"
174-
checksum = "4df80a3fbc1f0e59f560eeeebca94bf655566a8ad3023c210a109deb6056455a"
174+
checksum = "ea176c50987dc4765961aa165001e8eb5a722a26308c5797a47303ea91686aab"
175175
dependencies = [
176176
"proc-macro2",
177177
"quote",
@@ -181,9 +181,9 @@ dependencies = [
181181

182182
[[package]]
183183
name = "chalk-ir"
184-
version = "0.88.0"
184+
version = "0.89.0"
185185
source = "registry+https://github.com/rust-lang/crates.io-index"
186-
checksum = "f39e5272016916956298cceea5147006f897972c274a768ed4d6e074efe5d3fb"
186+
checksum = "473b480241695428c14e8f84f1c9a47ef232450a50faf3a4041e5c9dc11e0a3b"
187187
dependencies = [
188188
"bitflags",
189189
"chalk-derive",
@@ -192,9 +192,9 @@ dependencies = [
192192

193193
[[package]]
194194
name = "chalk-recursive"
195-
version = "0.88.0"
195+
version = "0.89.0"
196196
source = "registry+https://github.com/rust-lang/crates.io-index"
197-
checksum = "d9d60b42ad7478d3e027e2f9ea4e99fbbb8fdee0c8c3cf068be269f57e603618"
197+
checksum = "6764b4fe67cac3a3758185084efbfbd39bf0352795824ba849ddd2b64cd4bb28"
198198
dependencies = [
199199
"chalk-derive",
200200
"chalk-ir",
@@ -205,9 +205,9 @@ dependencies = [
205205

206206
[[package]]
207207
name = "chalk-solve"
208-
version = "0.88.0"
208+
version = "0.89.0"
209209
source = "registry+https://github.com/rust-lang/crates.io-index"
210-
checksum = "ab30620ea5b36819525eaab2204f4b8e1842fc7ee36826424a28bef59ae7fecf"
210+
checksum = "55a7e6160966eceb6e7dcc2f479a2af4c477aaf5bccbc640d82515995ab1a6cc"
211211
dependencies = [
212212
"chalk-derive",
213213
"chalk-ir",

src/tools/rust-analyzer/bench_data/numerous_macro_rules

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ macro_rules! __ra_macro_fixture339 {($name : ident )=>{ impl Clone for $name
341341
macro_rules! __ra_macro_fixture340 {([$($stack : tt )*])=>{$($stack )* }; ([$($stack : tt )*]{$($tail : tt )* })=>{$($stack )* { remove_sections_inner ! ([]$($tail )*); }}; ([$($stack : tt )*]$t : tt $($tail : tt )*)=>{ remove_sections ! ([$($stack )* $t ]$($tail )*); }; }
342342
macro_rules! __ra_macro_fixture341 {($t : ty ,$z : expr )=>{ impl Zero for $t { fn zero ()-> Self {$z as $t } fn is_zero (& self )-> bool { self == & Self :: zero ()}}}; }
343343
macro_rules! __ra_macro_fixture342 {($($ident : ident ),* $(,)?)=>{$(# [ allow ( bad_style )] pub const $ident : super :: Name = super :: Name :: new_inline ( stringify ! ($ident )); )* }; }
344-
macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; }
345-
macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn AstDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn AstDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; }
344+
macro_rules! __ra_macro_fixture343 {($($trait : ident =>$expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinDeriveExpander {$($trait ),* } impl BuiltinDeriveExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> Result < tt :: Subtree , mbe :: ExpandError > { let expander = match * self {$(BuiltinDeriveExpander ::$trait =>$expand , )* }; expander ( db , id , tt )} fn find_by_name ( name : & name :: Name )-> Option < Self > { match name {$(id if id == & name :: name ! [$trait ]=> Some ( BuiltinDeriveExpander ::$trait ), )* _ => None , }}}}; }
345+
macro_rules! __ra_macro_fixture344 {( LAZY : $(($name : ident , $kind : ident )=>$expand : ident ),* , EAGER : $(($e_name : ident , $e_kind : ident )=>$e_expand : ident ),* )=>{# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum BuiltinFnLikeExpander {$($kind ),* }# [ derive ( Debug , Clone , Copy , PartialEq , Eq , Hash )] pub enum EagerExpander {$($e_kind ),* } impl BuiltinFnLikeExpander { pub fn expand (& self , db : & dyn ExpandDatabase , id : LazyMacroId , tt : & tt :: Subtree , )-> ExpandResult < tt :: Subtree > { let expander = match * self {$(BuiltinFnLikeExpander ::$kind =>$expand , )* }; expander ( db , id , tt )}} impl EagerExpander { pub fn expand (& self , db : & dyn ExpandDatabase , arg_id : EagerMacroId , tt : & tt :: Subtree , )-> ExpandResult < Option < ( tt :: Subtree , FragmentKind )>> { let expander = match * self {$(EagerExpander ::$e_kind =>$e_expand , )* }; expander ( db , arg_id , tt )}} fn find_by_name ( ident : & name :: Name )-> Option < Either < BuiltinFnLikeExpander , EagerExpander >> { match ident {$(id if id == & name :: name ! [$name ]=> Some ( Either :: Left ( BuiltinFnLikeExpander ::$kind )), )* $(id if id == & name :: name ! [$e_name ]=> Some ( Either :: Right ( EagerExpander ::$e_kind )), )* _ => return None , }}}; }
346346
macro_rules! __ra_macro_fixture345 {($($ty : ty =>$this : ident $im : block );*)=>{$(impl ToTokenTree for $ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . into (); leaf . into ()}} impl ToTokenTree for &$ty { fn to_token ($this )-> tt :: TokenTree { let leaf : tt :: Leaf = $im . clone (). into (); leaf . into ()}})* }}
347347
macro_rules! __ra_macro_fixture346 {($name : ident )=>{ impl $crate :: salsa :: InternKey for $name { fn from_intern_id ( v : $crate :: salsa :: InternId )-> Self {$name ( v )} fn as_intern_id (& self )-> $crate :: salsa :: InternId { self . 0 }}}; }
348348
macro_rules! __ra_macro_fixture347 {($($var : ident ($t : ty )),+ )=>{$(impl From <$t > for AttrOwner { fn from ( t : $t )-> AttrOwner { AttrOwner ::$var ( t )}})+ }; }

src/tools/rust-analyzer/crates/hir-def/src/adt.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct StructData {
4040
pub repr: Option<ReprOptions>,
4141
pub visibility: RawVisibility,
4242
pub rustc_has_incoherent_inherent_impls: bool,
43+
pub fundamental: bool,
4344
}
4445

4546
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -173,10 +174,10 @@ impl StructData {
173174
let item_tree = loc.id.item_tree(db);
174175
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
175176
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
176-
let rustc_has_incoherent_inherent_impls = item_tree
177-
.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into())
178-
.by_key("rustc_has_incoherent_inherent_impls")
179-
.exists();
177+
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
178+
let rustc_has_incoherent_inherent_impls =
179+
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
180+
let fundamental = attrs.by_key("fundamental").exists();
180181

181182
let strukt = &item_tree[loc.id.value];
182183
let (variant_data, diagnostics) = lower_fields(
@@ -196,6 +197,7 @@ impl StructData {
196197
repr,
197198
visibility: item_tree[strukt.visibility].clone(),
198199
rustc_has_incoherent_inherent_impls,
200+
fundamental,
199201
}),
200202
diagnostics.into(),
201203
)
@@ -215,10 +217,10 @@ impl StructData {
215217
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
216218
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
217219

218-
let rustc_has_incoherent_inherent_impls = item_tree
219-
.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into())
220-
.by_key("rustc_has_incoherent_inherent_impls")
221-
.exists();
220+
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
221+
let rustc_has_incoherent_inherent_impls =
222+
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
223+
let fundamental = attrs.by_key("fundamental").exists();
222224

223225
let union = &item_tree[loc.id.value];
224226
let (variant_data, diagnostics) = lower_fields(
@@ -238,6 +240,7 @@ impl StructData {
238240
repr,
239241
visibility: item_tree[union.visibility].clone(),
240242
rustc_has_incoherent_inherent_impls,
243+
fundamental,
241244
}),
242245
diagnostics.into(),
243246
)

src/tools/rust-analyzer/crates/hir-def/src/body.rs

+41-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr};
2424
use crate::{
2525
attr::Attrs,
2626
db::DefDatabase,
27-
expr::{dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId},
27+
expr::{
28+
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
29+
},
2830
item_scope::BuiltinShadowMode,
2931
macro_id_to_def_id,
3032
nameres::DefMap,
@@ -432,6 +434,44 @@ impl Body {
432434
pats.shrink_to_fit();
433435
bindings.shrink_to_fit();
434436
}
437+
438+
pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) {
439+
self.walk_pats(pat_id, &mut |pat| {
440+
if let Pat::Bind { id, .. } = pat {
441+
f(*id);
442+
}
443+
});
444+
}
445+
446+
pub fn walk_pats(&self, pat_id: PatId, f: &mut impl FnMut(&Pat)) {
447+
let pat = &self[pat_id];
448+
f(pat);
449+
match pat {
450+
Pat::Range { .. }
451+
| Pat::Lit(..)
452+
| Pat::Path(..)
453+
| Pat::ConstBlock(..)
454+
| Pat::Wild
455+
| Pat::Missing => {}
456+
&Pat::Bind { subpat, .. } => {
457+
if let Some(subpat) = subpat {
458+
self.walk_pats(subpat, f);
459+
}
460+
}
461+
Pat::Or(args) | Pat::Tuple { args, .. } | Pat::TupleStruct { args, .. } => {
462+
args.iter().copied().for_each(|p| self.walk_pats(p, f));
463+
}
464+
Pat::Ref { pat, .. } => self.walk_pats(*pat, f),
465+
Pat::Slice { prefix, slice, suffix } => {
466+
let total_iter = prefix.iter().chain(slice.iter()).chain(suffix.iter());
467+
total_iter.copied().for_each(|p| self.walk_pats(p, f));
468+
}
469+
Pat::Record { args, .. } => {
470+
args.iter().for_each(|RecordFieldPat { pat, .. }| self.walk_pats(*pat, f));
471+
}
472+
Pat::Box { inner } => self.walk_pats(*inner, f),
473+
}
474+
}
435475
}
436476

437477
impl Default for Body {

src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs

+2
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ impl ExprCollector<'_> {
499499
Movability::Movable
500500
};
501501
ClosureKind::Generator(movability)
502+
} else if e.async_token().is_some() {
503+
ClosureKind::Async
502504
} else {
503505
ClosureKind::Closure
504506
};

src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,14 @@ impl<'a> Printer<'a> {
360360
w!(self, "]");
361361
}
362362
Expr::Closure { args, arg_types, ret_type, body, closure_kind } => {
363-
if let ClosureKind::Generator(Movability::Static) = closure_kind {
364-
w!(self, "static ");
363+
match closure_kind {
364+
ClosureKind::Generator(Movability::Static) => {
365+
w!(self, "static ");
366+
}
367+
ClosureKind::Async => {
368+
w!(self, "async ");
369+
}
370+
_ => (),
365371
}
366372
w!(self, "|");
367373
for (i, (pat, ty)) in args.iter().zip(arg_types.iter()).enumerate() {

src/tools/rust-analyzer/crates/hir-def/src/data.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct FunctionData {
3535
pub visibility: RawVisibility,
3636
pub abi: Option<Interned<str>>,
3737
pub legacy_const_generics_indices: Box<[u32]>,
38+
pub rustc_allow_incoherent_impl: bool,
3839
flags: FnFlags,
3940
}
4041

@@ -84,13 +85,14 @@ impl FunctionData {
8485
}
8586
}
8687

87-
let legacy_const_generics_indices = item_tree
88-
.attrs(db, krate, ModItem::from(loc.id.value).into())
88+
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
89+
let legacy_const_generics_indices = attrs
8990
.by_key("rustc_legacy_const_generics")
9091
.tt_values()
9192
.next()
9293
.map(parse_rustc_legacy_const_generics)
9394
.unwrap_or_default();
95+
let rustc_allow_incoherent_impl = attrs.by_key("rustc_allow_incoherent_impl").exists();
9496

9597
Arc::new(FunctionData {
9698
name: func.name.clone(),
@@ -108,6 +110,7 @@ impl FunctionData {
108110
abi: func.abi.clone(),
109111
legacy_const_generics_indices,
110112
flags,
113+
rustc_allow_incoherent_impl,
111114
})
112115
}
113116

@@ -171,6 +174,7 @@ pub struct TypeAliasData {
171174
pub visibility: RawVisibility,
172175
pub is_extern: bool,
173176
pub rustc_has_incoherent_inherent_impls: bool,
177+
pub rustc_allow_incoherent_impl: bool,
174178
/// Bounds restricting the type alias itself (eg. `type Ty: Bound;` in a trait or impl).
175179
pub bounds: Vec<Interned<TypeBound>>,
176180
}
@@ -189,17 +193,22 @@ impl TypeAliasData {
189193
item_tree[typ.visibility].clone()
190194
};
191195

192-
let rustc_has_incoherent_inherent_impls = item_tree
193-
.attrs(db, loc.container.module(db).krate(), ModItem::from(loc.id.value).into())
194-
.by_key("rustc_has_incoherent_inherent_impls")
195-
.exists();
196+
let attrs = item_tree.attrs(
197+
db,
198+
loc.container.module(db).krate(),
199+
ModItem::from(loc.id.value).into(),
200+
);
201+
let rustc_has_incoherent_inherent_impls =
202+
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
203+
let rustc_allow_incoherent_impl = attrs.by_key("rustc_allow_incoherent_impl").exists();
196204

197205
Arc::new(TypeAliasData {
198206
name: typ.name.clone(),
199207
type_ref: typ.type_ref.clone(),
200208
visibility,
201209
is_extern: matches!(loc.container, ItemContainerId::ExternBlockId(_)),
202210
rustc_has_incoherent_inherent_impls,
211+
rustc_allow_incoherent_impl,
203212
bounds: typ.bounds.to_vec(),
204213
})
205214
}
@@ -212,11 +221,12 @@ pub struct TraitData {
212221
pub is_auto: bool,
213222
pub is_unsafe: bool,
214223
pub rustc_has_incoherent_inherent_impls: bool,
224+
pub skip_array_during_method_dispatch: bool,
225+
pub fundamental: bool,
215226
pub visibility: RawVisibility,
216227
/// Whether the trait has `#[rust_skip_array_during_method_dispatch]`. `hir_ty` will ignore
217228
/// method calls to this trait's methods when the receiver is an array and the crate edition is
218229
/// 2015 or 2018.
219-
pub skip_array_during_method_dispatch: bool,
220230
// box it as the vec is usually empty anyways
221231
pub attribute_calls: Option<Box<Vec<(AstId<ast::Item>, MacroCallId)>>>,
222232
}
@@ -245,6 +255,7 @@ impl TraitData {
245255
attrs.by_key("rustc_skip_array_during_method_dispatch").exists();
246256
let rustc_has_incoherent_inherent_impls =
247257
attrs.by_key("rustc_has_incoherent_inherent_impls").exists();
258+
let fundamental = attrs.by_key("fundamental").exists();
248259
let mut collector =
249260
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::TraitId(tr));
250261
collector.collect(&item_tree, tree_id.tree_id(), &tr_def.items);
@@ -260,6 +271,7 @@ impl TraitData {
260271
visibility,
261272
skip_array_during_method_dispatch,
262273
rustc_has_incoherent_inherent_impls,
274+
fundamental,
263275
}),
264276
diagnostics.into(),
265277
)
@@ -450,6 +462,7 @@ pub struct ConstData {
450462
pub name: Option<Name>,
451463
pub type_ref: Interned<TypeRef>,
452464
pub visibility: RawVisibility,
465+
pub rustc_allow_incoherent_impl: bool,
453466
}
454467

455468
impl ConstData {
@@ -463,10 +476,16 @@ impl ConstData {
463476
item_tree[konst.visibility].clone()
464477
};
465478

479+
let rustc_allow_incoherent_impl = item_tree
480+
.attrs(db, loc.container.module(db).krate(), ModItem::from(loc.id.value).into())
481+
.by_key("rustc_allow_incoherent_impl")
482+
.exists();
483+
466484
Arc::new(ConstData {
467485
name: konst.name.clone(),
468486
type_ref: konst.type_ref.clone(),
469487
visibility,
488+
rustc_allow_incoherent_impl,
470489
})
471490
}
472491
}

src/tools/rust-analyzer/crates/hir-def/src/db.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use base_db::{salsa, CrateId, SourceDatabase, Upcast};
55
use either::Either;
6-
use hir_expand::{db::AstDatabase, HirFileId};
6+
use hir_expand::{db::ExpandDatabase, HirFileId};
77
use intern::Interned;
88
use la_arena::ArenaMap;
99
use syntax::{ast, AstPtr};
@@ -64,7 +64,7 @@ pub trait InternDatabase: SourceDatabase {
6464
}
6565

6666
#[salsa::query_group(DefDatabaseStorage)]
67-
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
67+
pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDatabase> {
6868
#[salsa::input]
6969
fn enable_proc_attr_macros(&self) -> bool;
7070

src/tools/rust-analyzer/crates/hir-def/src/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub enum Expr {
245245
pub enum ClosureKind {
246246
Closure,
247247
Generator(Movability),
248+
Async,
248249
}
249250

250251
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ::mbe::TokenMap;
2020
use base_db::{fixture::WithFixture, ProcMacro, SourceDatabase};
2121
use expect_test::Expect;
2222
use hir_expand::{
23-
db::{AstDatabase, TokenExpander},
23+
db::{ExpandDatabase, TokenExpander},
2424
AstId, InFile, MacroDefId, MacroDefKind, MacroFile,
2525
};
2626
use stdx::format_to;

0 commit comments

Comments
 (0)