diff options
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 19 | ||||
-rw-r--r-- | crates/ide/src/diagnostics.rs | 5 | ||||
-rw-r--r-- | crates/proc_macro_api/src/process.rs | 20 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/diagnostics.rs | 29 |
5 files changed, 54 insertions, 27 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 5a6f0c67f..8a289f52a 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -720,7 +720,13 @@ fn transform_receiver_ty( | |||
720 | .push(self_ty.value.clone()) | 720 | .push(self_ty.value.clone()) |
721 | .fill_with_unknown() | 721 | .fill_with_unknown() |
722 | .build(), | 722 | .build(), |
723 | AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?, | 723 | AssocContainerId::ImplId(impl_id) => { |
724 | let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; | ||
725 | Substs::build_for_def(db, function_id) | ||
726 | .use_parent_substs(&impl_substs) | ||
727 | .fill_with_unknown() | ||
728 | .build() | ||
729 | } | ||
724 | AssocContainerId::ContainerId(_) => unreachable!(), | 730 | AssocContainerId::ContainerId(_) => unreachable!(), |
725 | }; | 731 | }; |
726 | let sig = db.callable_item_signature(function_id.into()); | 732 | let sig = db.callable_item_signature(function_id.into()); |
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 0f17ff151..a6a54e542 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -1087,3 +1087,22 @@ fn method_resolution_foreign_opaque_type() { | |||
1087 | "#]], | 1087 | "#]], |
1088 | ); | 1088 | ); |
1089 | } | 1089 | } |
1090 | |||
1091 | #[test] | ||
1092 | fn method_with_allocator_box_self_type() { | ||
1093 | check_types( | ||
1094 | r#" | ||
1095 | struct Slice<T> {} | ||
1096 | struct Box<T, A> {} | ||
1097 | |||
1098 | impl<T> Slice<T> { | ||
1099 | pub fn into_vec<A>(self: Box<Self, A>) { } | ||
1100 | } | ||
1101 | |||
1102 | fn main() { | ||
1103 | let foo: Slice<u32>; | ||
1104 | (foo.into_vec()); // we don't actually support arbitrary self types, but we shouldn't crash at least | ||
1105 | } //^ {unknown} | ||
1106 | "#, | ||
1107 | ); | ||
1108 | } | ||
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 9d3d88289..c8453edb3 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -135,6 +135,11 @@ pub(crate) fn diagnostics( | |||
135 | res.borrow_mut().push(warning_with_fix(d, &sema)); | 135 | res.borrow_mut().push(warning_with_fix(d, &sema)); |
136 | }) | 136 | }) |
137 | .on::<hir::diagnostics::InactiveCode, _>(|d| { | 137 | .on::<hir::diagnostics::InactiveCode, _>(|d| { |
138 | // If there's inactive code somewhere in a macro, don't propagate to the call-site. | ||
139 | if d.display_source().file_id.expansion_info(db).is_some() { | ||
140 | return; | ||
141 | } | ||
142 | |||
138 | // Override severity and mark as unused. | 143 | // Override severity and mark as unused. |
139 | res.borrow_mut().push( | 144 | res.borrow_mut().push( |
140 | Diagnostic::hint(sema.diagnostics_display_range(d).range, d.message()) | 145 | Diagnostic::hint(sema.diagnostics_display_range(d).range, d.message()) |
diff --git a/crates/proc_macro_api/src/process.rs b/crates/proc_macro_api/src/process.rs index 907cb3db7..b66613c38 100644 --- a/crates/proc_macro_api/src/process.rs +++ b/crates/proc_macro_api/src/process.rs | |||
@@ -19,7 +19,7 @@ use crate::{ | |||
19 | 19 | ||
20 | #[derive(Debug, Default)] | 20 | #[derive(Debug, Default)] |
21 | pub(crate) struct ProcMacroProcessSrv { | 21 | pub(crate) struct ProcMacroProcessSrv { |
22 | inner: Option<Weak<Sender<Task>>>, | 22 | inner: Weak<Sender<Task>>, |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(Debug)] | 25 | #[derive(Debug)] |
@@ -42,7 +42,7 @@ impl ProcMacroProcessSrv { | |||
42 | }); | 42 | }); |
43 | 43 | ||
44 | let task_tx = Arc::new(task_tx); | 44 | let task_tx = Arc::new(task_tx); |
45 | let srv = ProcMacroProcessSrv { inner: Some(Arc::downgrade(&task_tx)) }; | 45 | let srv = ProcMacroProcessSrv { inner: Arc::downgrade(&task_tx) }; |
46 | let thread = ProcMacroProcessThread { handle, sender: task_tx }; | 46 | let thread = ProcMacroProcessThread { handle, sender: task_tx }; |
47 | 47 | ||
48 | Ok((thread, srv)) | 48 | Ok((thread, srv)) |
@@ -79,13 +79,8 @@ impl ProcMacroProcessSrv { | |||
79 | where | 79 | where |
80 | R: TryFrom<Response, Error = &'static str>, | 80 | R: TryFrom<Response, Error = &'static str>, |
81 | { | 81 | { |
82 | let sender = match &self.inner { | ||
83 | None => return Err(tt::ExpansionError::Unknown("No sender is found.".to_string())), | ||
84 | Some(it) => it, | ||
85 | }; | ||
86 | |||
87 | let (result_tx, result_rx) = bounded(0); | 82 | let (result_tx, result_rx) = bounded(0); |
88 | let sender = match sender.upgrade() { | 83 | let sender = match self.inner.upgrade() { |
89 | None => { | 84 | None => { |
90 | return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) | 85 | return Err(tt::ExpansionError::Unknown("Proc macro process is closed.".into())) |
91 | } | 86 | } |
@@ -109,14 +104,9 @@ impl ProcMacroProcessSrv { | |||
109 | } | 104 | } |
110 | 105 | ||
111 | fn client_loop(task_rx: Receiver<Task>, mut process: Process) { | 106 | fn client_loop(task_rx: Receiver<Task>, mut process: Process) { |
112 | let (mut stdin, mut stdout) = match process.stdio() { | 107 | let (mut stdin, mut stdout) = process.stdio().expect("couldn't access child stdio"); |
113 | None => return, | ||
114 | Some(it) => it, | ||
115 | }; | ||
116 | |||
117 | for task in task_rx { | ||
118 | let Task { req, result_tx } = task; | ||
119 | 108 | ||
109 | for Task { req, result_tx } in task_rx { | ||
120 | match send_request(&mut stdin, &mut stdout, req) { | 110 | match send_request(&mut stdin, &mut stdout, req) { |
121 | Ok(res) => result_tx.send(res).unwrap(), | 111 | Ok(res) => result_tx.send(res).unwrap(), |
122 | Err(_err) => { | 112 | Err(_err) => { |
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 368f627ac..0090fd2c2 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs | |||
@@ -6,12 +6,25 @@ use std::path::Path; | |||
6 | use anyhow::anyhow; | 6 | use anyhow::anyhow; |
7 | use rustc_hash::FxHashSet; | 7 | use rustc_hash::FxHashSet; |
8 | 8 | ||
9 | use hir::Crate; | 9 | use hir::{db::HirDatabase, Crate, Module}; |
10 | use ide::{DiagnosticsConfig, Severity}; | 10 | use ide::{DiagnosticsConfig, Severity}; |
11 | use ide_db::base_db::SourceDatabaseExt; | 11 | use ide_db::base_db::SourceDatabaseExt; |
12 | 12 | ||
13 | use crate::cli::{load_cargo::load_cargo, Result}; | 13 | use crate::cli::{load_cargo::load_cargo, Result}; |
14 | 14 | ||
15 | fn all_modules(db: &dyn HirDatabase) -> Vec<Module> { | ||
16 | let mut worklist: Vec<_> = | ||
17 | Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect(); | ||
18 | let mut modules = Vec::new(); | ||
19 | |||
20 | while let Some(module) = worklist.pop() { | ||
21 | modules.push(module); | ||
22 | worklist.extend(module.children(db)); | ||
23 | } | ||
24 | |||
25 | modules | ||
26 | } | ||
27 | |||
15 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { | 28 | pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) -> Result<()> { |
16 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; | 29 | let (host, _vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; |
17 | let db = host.raw_database(); | 30 | let db = host.raw_database(); |
@@ -20,18 +33,12 @@ pub fn diagnostics(path: &Path, load_output_dirs: bool, with_proc_macro: bool) - | |||
20 | let mut found_error = false; | 33 | let mut found_error = false; |
21 | let mut visited_files = FxHashSet::default(); | 34 | let mut visited_files = FxHashSet::default(); |
22 | 35 | ||
23 | let mut work = Vec::new(); | 36 | let work = all_modules(db).into_iter().filter(|module| { |
24 | let krates = Crate::all(db); | 37 | let file_id = module.definition_source(db).file_id.original_file(db); |
25 | for krate in krates { | ||
26 | let module = krate.root_module(db); | ||
27 | let file_id = module.definition_source(db).file_id; | ||
28 | let file_id = file_id.original_file(db); | ||
29 | let source_root = db.file_source_root(file_id); | 38 | let source_root = db.file_source_root(file_id); |
30 | let source_root = db.source_root(source_root); | 39 | let source_root = db.source_root(source_root); |
31 | if !source_root.is_library { | 40 | !source_root.is_library |
32 | work.push(module); | 41 | }); |
33 | } | ||
34 | } | ||
35 | 42 | ||
36 | for module in work { | 43 | for module in work { |
37 | let file_id = module.definition_source(db).file_id.original_file(db); | 44 | let file_id = module.definition_source(db).file_id.original_file(db); |