Skip to content

Commit bb90116

Browse files
authored
Rollup merge of #104454 - lnicola:rust-analyzer-2022-11-15, r=lnicola
⬆️ rust-analyzer r? ``@ghost``
2 parents 63760b4 + 5d36be5 commit bb90116

File tree

102 files changed

+1477
-624
lines changed

Some content is hidden

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

102 files changed

+1477
-624
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ dependencies = [
221221
"tracing",
222222
]
223223

224+
[[package]]
225+
name = "command-group"
226+
version = "1.0.8"
227+
source = "registry+https://github.com/rust-lang/crates.io-index"
228+
checksum = "f7a8a86f409b4a59df3a3e4bee2de0b83f1755fdd2a25e3a9684c396fc4bed2c"
229+
dependencies = [
230+
"nix",
231+
"winapi",
232+
]
233+
224234
[[package]]
225235
name = "countme"
226236
version = "3.0.1"
@@ -390,6 +400,7 @@ name = "flycheck"
390400
version = "0.0.0"
391401
dependencies = [
392402
"cargo_metadata",
403+
"command-group",
393404
"crossbeam-channel",
394405
"jod-thread",
395406
"paths",
@@ -970,6 +981,19 @@ dependencies = [
970981
"windows-sys 0.28.0",
971982
]
972983

984+
[[package]]
985+
name = "nix"
986+
version = "0.22.3"
987+
source = "registry+https://github.com/rust-lang/crates.io-index"
988+
checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf"
989+
dependencies = [
990+
"bitflags",
991+
"cc",
992+
"cfg-if",
993+
"libc",
994+
"memoffset",
995+
]
996+
973997
[[package]]
974998
name = "notify"
975999
version = "5.0.0"

src/tools/rust-analyzer/crates/base-db/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
description = "TBD"
55
license = "MIT OR Apache-2.0"
66
edition = "2021"
7-
rust-version = "1.57"
7+
rust-version = "1.65"
88

99
[lib]
1010
doctest = false

src/tools/rust-analyzer/crates/cfg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
description = "TBD"
55
license = "MIT OR Apache-2.0"
66
edition = "2021"
7-
rust-version = "1.57"
7+
rust-version = "1.65"
88

99
[lib]
1010
doctest = false

src/tools/rust-analyzer/crates/flycheck/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
description = "TBD"
55
license = "MIT OR Apache-2.0"
66
edition = "2021"
7-
rust-version = "1.57"
7+
rust-version = "1.65"
88

99
[lib]
1010
doctest = false
@@ -17,6 +17,7 @@ rustc-hash = "1.1.0"
1717
serde = { version = "1.0.137", features = ["derive"] }
1818
serde_json = "1.0.86"
1919
jod-thread = "0.1.2"
20+
command-group = "1.0.8"
2021

2122
toolchain = { path = "../toolchain", version = "0.0.0" }
2223
stdx = { path = "../stdx", version = "0.0.0" }

src/tools/rust-analyzer/crates/flycheck/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use std::{
1010
time::Duration,
1111
};
1212

13+
use command_group::{CommandGroup, GroupChild};
1314
use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
1415
use paths::AbsPathBuf;
1516
use rustc_hash::FxHashMap;
1617
use serde::Deserialize;
17-
use stdx::{process::streaming_output, JodChild};
18+
use stdx::process::streaming_output;
1819

1920
pub use cargo_metadata::diagnostic::{
2021
Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
@@ -359,10 +360,12 @@ impl FlycheckActor {
359360
}
360361
}
361362

363+
struct JodChild(GroupChild);
364+
362365
/// A handle to a cargo process used for fly-checking.
363366
struct CargoHandle {
364367
/// The handle to the actual cargo process. As we cannot cancel directly from with
365-
/// a read syscall dropping and therefor terminating the process is our best option.
368+
/// a read syscall dropping and therefore terminating the process is our best option.
366369
child: JodChild,
367370
thread: jod_thread::JoinHandle<io::Result<(bool, String)>>,
368371
receiver: Receiver<CargoMessage>,
@@ -371,10 +374,10 @@ struct CargoHandle {
371374
impl CargoHandle {
372375
fn spawn(mut command: Command) -> std::io::Result<CargoHandle> {
373376
command.stdout(Stdio::piped()).stderr(Stdio::piped()).stdin(Stdio::null());
374-
let mut child = JodChild::spawn(command)?;
377+
let mut child = command.group_spawn().map(JodChild)?;
375378

376-
let stdout = child.stdout.take().unwrap();
377-
let stderr = child.stderr.take().unwrap();
379+
let stdout = child.0.inner().stdout.take().unwrap();
380+
let stderr = child.0.inner().stderr.take().unwrap();
378381

379382
let (sender, receiver) = unbounded();
380383
let actor = CargoActor::new(sender, stdout, stderr);
@@ -386,13 +389,13 @@ impl CargoHandle {
386389
}
387390

388391
fn cancel(mut self) {
389-
let _ = self.child.kill();
390-
let _ = self.child.wait();
392+
let _ = self.child.0.kill();
393+
let _ = self.child.0.wait();
391394
}
392395

393396
fn join(mut self) -> io::Result<()> {
394-
let _ = self.child.kill();
395-
let exit_status = self.child.wait()?;
397+
let _ = self.child.0.kill();
398+
let exit_status = self.child.0.wait()?;
396399
let (read_at_least_one_message, error) = self.thread.join()?;
397400
if read_at_least_one_message || exit_status.success() {
398401
Ok(())

src/tools/rust-analyzer/crates/hir-def/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.0.0"
44
description = "TBD"
55
license = "MIT OR Apache-2.0"
66
edition = "2021"
7-
rust-version = "1.57"
7+
rust-version = "1.65"
88

99
[lib]
1010
doctest = false

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,19 @@ impl TraitData {
236236
.by_key("rustc_skip_array_during_method_dispatch")
237237
.exists();
238238

239-
let mut collector =
240-
AssocItemCollector::new(db, module_id, tree_id.file_id(), ItemContainerId::TraitId(tr));
241-
collector.collect(&item_tree, tree_id.tree_id(), &tr_def.items);
242-
let (items, attribute_calls, diagnostics) = collector.finish();
243-
239+
let (items, attribute_calls, diagnostics) = match &tr_def.items {
240+
Some(items) => {
241+
let mut collector = AssocItemCollector::new(
242+
db,
243+
module_id,
244+
tree_id.file_id(),
245+
ItemContainerId::TraitId(tr),
246+
);
247+
collector.collect(&item_tree, tree_id.tree_id(), items);
248+
collector.finish()
249+
}
250+
None => Default::default(),
251+
};
244252
(
245253
Arc::new(TraitData {
246254
name,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ pub struct Trait {
666666
pub generic_params: Interned<GenericParams>,
667667
pub is_auto: bool,
668668
pub is_unsafe: bool,
669-
pub items: Box<[AssocItem]>,
669+
/// This is [`None`] if this Trait is a trait alias.
670+
pub items: Option<Box<[AssocItem]>>,
670671
pub ast_id: FileAstId<ast::Trait>,
671672
}
672673

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,7 @@ impl<'a> Ctx<'a> {
451451
.collect()
452452
});
453453
let ast_id = self.source_ast_id_map.ast_id(trait_def);
454-
let res = Trait {
455-
name,
456-
visibility,
457-
generic_params,
458-
is_auto,
459-
is_unsafe,
460-
items: items.unwrap_or_default(),
461-
ast_id,
462-
};
454+
let res = Trait { name, visibility, generic_params, is_auto, is_unsafe, items, ast_id };
463455
Some(id(self.data().traits.alloc(res)))
464456
}
465457

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,21 @@ impl<'a> Printer<'a> {
375375
}
376376
w!(self, "trait {}", name);
377377
self.print_generic_params(generic_params);
378-
self.print_where_clause_and_opening_brace(generic_params);
379-
self.indented(|this| {
380-
for item in &**items {
381-
this.print_mod_item((*item).into());
378+
match items {
379+
Some(items) => {
380+
self.print_where_clause_and_opening_brace(generic_params);
381+
self.indented(|this| {
382+
for item in &**items {
383+
this.print_mod_item((*item).into());
384+
}
385+
});
382386
}
383-
});
387+
None => {
388+
w!(self, " = ");
389+
// FIXME: Print the aliased traits
390+
self.print_where_clause_and_opening_brace(generic_params);
391+
}
392+
}
384393
wln!(self, "}}");
385394
}
386395
ModItem::Impl(it) => {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ macro_rules! m {
9494
($($s:stmt)*) => (stringify!($($s |)*);)
9595
}
9696
stringify!(;
97-
|;
98-
|92|;
99-
|let x = 92|;
97+
| ;
98+
|92| ;
99+
|let x = 92| ;
100100
|loop {}
101-
|;
101+
| ;
102102
|);
103103
"#]],
104104
);
@@ -118,7 +118,7 @@ m!(.. .. ..);
118118
macro_rules! m {
119119
($($p:pat)*) => (stringify!($($p |)*);)
120120
}
121-
stringify!(.. .. ..|);
121+
stringify!(.. .. .. |);
122122
"#]],
123123
);
124124
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ fn attribute_macro_syntax_completion_2() {
8282
#[proc_macros::identity_when_valid]
8383
fn foo() { bar.; blub }
8484
"#,
85-
expect![[r##"
85+
expect![[r#"
8686
#[proc_macros::identity_when_valid]
8787
fn foo() { bar.; blub }
8888
8989
fn foo() {
90-
bar.;
90+
bar. ;
9191
blub
92-
}"##]],
92+
}"#]],
9393
);
9494
}
9595

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl Import {
212212

213213
#[derive(Debug, Eq, PartialEq)]
214214
struct ImportDirective {
215+
/// The module this import directive is in.
215216
module_id: LocalModuleId,
216217
import: Import,
217218
status: PartialResolvedImport,
@@ -963,8 +964,10 @@ impl DefCollector<'_> {
963964

964965
fn update(
965966
&mut self,
967+
// The module for which `resolutions` have been resolve
966968
module_id: LocalModuleId,
967969
resolutions: &[(Option<Name>, PerNs)],
970+
// Visibility this import will have
968971
vis: Visibility,
969972
import_type: ImportType,
970973
) {
@@ -974,6 +977,7 @@ impl DefCollector<'_> {
974977

975978
fn update_recursive(
976979
&mut self,
980+
// The module for which `resolutions` have been resolve
977981
module_id: LocalModuleId,
978982
resolutions: &[(Option<Name>, PerNs)],
979983
// All resolutions are imported with this visibility; the visibilities in

src/tools/rust-analyzer/crates/hir-def/src/nameres/path_resolution.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ impl DefMap {
7373
pub(crate) fn resolve_visibility(
7474
&self,
7575
db: &dyn DefDatabase,
76+
// module to import to
7677
original_module: LocalModuleId,
78+
// pub(path)
79+
// ^^^^ this
7780
visibility: &RawVisibility,
7881
) -> Option<Visibility> {
7982
let mut vis = match visibility {
@@ -115,6 +118,7 @@ impl DefMap {
115118
&self,
116119
db: &dyn DefDatabase,
117120
mode: ResolveMode,
121+
// module to import to
118122
mut original_module: LocalModuleId,
119123
path: &ModPath,
120124
shadow: BuiltinShadowMode,
@@ -361,6 +365,9 @@ impl DefMap {
361365
);
362366
}
363367
};
368+
369+
curr_per_ns = curr_per_ns
370+
.filter_visibility(|vis| vis.is_visible_from_def_map(db, self, original_module));
364371
}
365372

366373
ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None, Some(self.krate))

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ extern {
5858
"#,
5959
expect![[r#"
6060
crate
61-
E: t
61+
E: _
6262
S: t v
63-
V: t v
63+
V: _
6464
foo: t
6565
6666
crate::foo
@@ -307,7 +307,7 @@ pub struct FromLib;
307307
Bar: t v
308308
309309
crate::foo
310-
Bar: t v
310+
Bar: _
311311
FromLib: t v
312312
"#]],
313313
);

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ use foo::*;
119119
use foo::bar::*;
120120
121121
//- /foo/mod.rs
122-
mod bar;
122+
pub mod bar;
123123
fn Foo() {};
124124
pub struct Foo {};
125125
@@ -132,6 +132,7 @@ pub(crate) struct PubCrateStruct;
132132
crate
133133
Foo: t
134134
PubCrateStruct: t v
135+
bar: t
135136
foo: t
136137
137138
crate::foo
@@ -336,3 +337,33 @@ mod d {
336337
"#]],
337338
);
338339
}
340+
341+
#[test]
342+
fn glob_name_collision_check_visibility() {
343+
check(
344+
r#"
345+
mod event {
346+
mod serenity {
347+
pub fn Event() {}
348+
}
349+
use serenity::*;
350+
351+
pub struct Event {}
352+
}
353+
354+
use event::Event;
355+
"#,
356+
expect![[r#"
357+
crate
358+
Event: t
359+
event: t
360+
361+
crate::event
362+
Event: t v
363+
serenity: t
364+
365+
crate::event::serenity
366+
Event: v
367+
"#]],
368+
);
369+
}

0 commit comments

Comments
 (0)