aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock29
-rw-r--r--crates/hir_ty/src/traits/chalk.rs14
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs18
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs12
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt45
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs51
6 files changed, 132 insertions, 37 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a6dc0dc4b..9ebb15a96 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -129,9 +129,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
129 129
130[[package]] 130[[package]]
131name = "cargo_metadata" 131name = "cargo_metadata"
132version = "0.11.1" 132version = "0.11.2"
133source = "registry+https://github.com/rust-lang/crates.io-index" 133source = "registry+https://github.com/rust-lang/crates.io-index"
134checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35" 134checksum = "c990b1694d29f8e477f456db1b2fcd5dd1cd6e29d5be082df45213e8834eb39a"
135dependencies = [ 135dependencies = [
136 "semver", 136 "semver",
137 "serde", 137 "serde",
@@ -252,12 +252,12 @@ dependencies = [
252 252
253[[package]] 253[[package]]
254name = "crossbeam-channel" 254name = "crossbeam-channel"
255version = "0.4.3" 255version = "0.4.4"
256source = "registry+https://github.com/rust-lang/crates.io-index" 256source = "registry+https://github.com/rust-lang/crates.io-index"
257checksum = "09ee0cc8804d5393478d743b035099520087a5186f3b93fa58cec08fa62407b6" 257checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
258dependencies = [ 258dependencies = [
259 "cfg-if",
260 "crossbeam-utils", 259 "crossbeam-utils",
260 "maybe-uninit",
261] 261]
262 262
263[[package]] 263[[package]]
@@ -451,12 +451,9 @@ dependencies = [
451 451
452[[package]] 452[[package]]
453name = "hashbrown" 453name = "hashbrown"
454version = "0.8.2" 454version = "0.9.0"
455source = "registry+https://github.com/rust-lang/crates.io-index" 455source = "registry+https://github.com/rust-lang/crates.io-index"
456checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" 456checksum = "00d63df3d41950fb462ed38308eea019113ad1508da725bbedcd0fa5a85ef5f7"
457dependencies = [
458 "autocfg",
459]
460 457
461[[package]] 458[[package]]
462name = "heck" 459name = "heck"
@@ -635,9 +632,9 @@ dependencies = [
635 632
636[[package]] 633[[package]]
637name = "indexmap" 634name = "indexmap"
638version = "1.5.2" 635version = "1.6.0"
639source = "registry+https://github.com/rust-lang/crates.io-index" 636source = "registry+https://github.com/rust-lang/crates.io-index"
640checksum = "4e47a3566dd4fd4eec714ae6ceabdee0caec795be835c223d92c2d40f1e8cf1c" 637checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2"
641dependencies = [ 638dependencies = [
642 "autocfg", 639 "autocfg",
643 "hashbrown", 640 "hashbrown",
@@ -912,9 +909,9 @@ dependencies = [
912 909
913[[package]] 910[[package]]
914name = "net2" 911name = "net2"
915version = "0.2.34" 912version = "0.2.35"
916source = "registry+https://github.com/rust-lang/crates.io-index" 913source = "registry+https://github.com/rust-lang/crates.io-index"
917checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" 914checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853"
918dependencies = [ 915dependencies = [
919 "cfg-if", 916 "cfg-if",
920 "libc", 917 "libc",
@@ -1495,9 +1492,9 @@ version = "0.0.0"
1495 1492
1496[[package]] 1493[[package]]
1497name = "syn" 1494name = "syn"
1498version = "1.0.39" 1495version = "1.0.40"
1499source = "registry+https://github.com/rust-lang/crates.io-index" 1496source = "registry+https://github.com/rust-lang/crates.io-index"
1500checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9" 1497checksum = "963f7d3cc59b59b9325165add223142bbf1df27655d07789f109896d353d8350"
1501dependencies = [ 1498dependencies = [
1502 "proc-macro2", 1499 "proc-macro2",
1503 "quote", 1500 "quote",
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 17c83b6a4..01b5717a3 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -244,13 +244,17 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
244 let id = from_chalk(self.db, trait_id); 244 let id = from_chalk(self.db, trait_id);
245 self.db.trait_data(id).name.to_string() 245 self.db.trait_data(id).name.to_string()
246 } 246 }
247 // FIXME: lookup names 247 fn adt_name(&self, adt_id: chalk_ir::AdtId<Interner>) -> String {
248 fn adt_name(&self, struct_id: chalk_ir::AdtId<Interner>) -> String { 248 let id = from_chalk(self.db, adt_id);
249 let datum = self.db.struct_datum(self.krate, struct_id); 249 match id {
250 format!("{:?}", datum.name(&Interner)) 250 hir_def::AdtId::StructId(id) => self.db.struct_data(id).name.to_string(),
251 hir_def::AdtId::EnumId(id) => self.db.enum_data(id).name.to_string(),
252 hir_def::AdtId::UnionId(id) => self.db.union_data(id).name.to_string(),
253 }
251 } 254 }
252 fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String { 255 fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String {
253 format!("Assoc_{}", assoc_ty_id.0) 256 let id = self.db.associated_ty_data(assoc_ty_id).name;
257 self.db.type_alias_data(id).name.to_string()
254 } 258 }
255 fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String { 259 fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String {
256 format!("Opaque_{}", opaque_ty_id.0) 260 format!("Opaque_{}", opaque_ty_id.0)
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index fc0f9c201..eb35db3ff 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -26,7 +26,7 @@ pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
26pub type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; 26pub type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
27 27
28impl chalk_ir::interner::Interner for Interner { 28impl chalk_ir::interner::Interner for Interner {
29 type InternedType = Box<chalk_ir::TyData<Self>>; // FIXME use Arc? 29 type InternedType = Arc<chalk_ir::TyData<Self>>;
30 type InternedLifetime = chalk_ir::LifetimeData<Self>; 30 type InternedLifetime = chalk_ir::LifetimeData<Self>;
31 type InternedConst = Arc<chalk_ir::ConstData<Self>>; 31 type InternedConst = Arc<chalk_ir::ConstData<Self>>;
32 type InternedConcreteConst = (); 32 type InternedConcreteConst = ();
@@ -34,7 +34,7 @@ impl chalk_ir::interner::Interner for Interner {
34 type InternedGoal = Arc<GoalData<Self>>; 34 type InternedGoal = Arc<GoalData<Self>>;
35 type InternedGoals = Vec<Goal<Self>>; 35 type InternedGoals = Vec<Goal<Self>>;
36 type InternedSubstitution = Vec<GenericArg<Self>>; 36 type InternedSubstitution = Vec<GenericArg<Self>>;
37 type InternedProgramClause = chalk_ir::ProgramClauseData<Self>; 37 type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>;
38 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>; 38 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>;
39 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; 39 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
40 type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>; 40 type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
@@ -197,11 +197,11 @@ impl chalk_ir::interner::Interner for Interner {
197 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt))) 197 tls::with_current_program(|prog| Some(prog?.debug_quantified_where_clauses(clauses, fmt)))
198 } 198 }
199 199
200 fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> { 200 fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Arc<chalk_ir::TyData<Self>> {
201 Box::new(ty) 201 Arc::new(ty)
202 } 202 }
203 203
204 fn ty_data<'a>(&self, ty: &'a Box<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> { 204 fn ty_data<'a>(&self, ty: &'a Arc<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> {
205 ty 205 ty
206 } 206 }
207 207
@@ -230,7 +230,7 @@ impl chalk_ir::interner::Interner for Interner {
230 constant 230 constant
231 } 231 }
232 232
233 fn const_eq(&self, _ty: &Box<chalk_ir::TyData<Self>>, _c1: &(), _c2: &()) -> bool { 233 fn const_eq(&self, _ty: &Arc<chalk_ir::TyData<Self>>, _c1: &(), _c2: &()) -> bool {
234 true 234 true
235 } 235 }
236 236
@@ -284,13 +284,13 @@ impl chalk_ir::interner::Interner for Interner {
284 fn intern_program_clause( 284 fn intern_program_clause(
285 &self, 285 &self,
286 data: chalk_ir::ProgramClauseData<Self>, 286 data: chalk_ir::ProgramClauseData<Self>,
287 ) -> chalk_ir::ProgramClauseData<Self> { 287 ) -> Arc<chalk_ir::ProgramClauseData<Self>> {
288 data 288 Arc::new(data)
289 } 289 }
290 290
291 fn program_clause_data<'a>( 291 fn program_clause_data<'a>(
292 &self, 292 &self,
293 clause: &'a chalk_ir::ProgramClauseData<Self>, 293 clause: &'a Arc<chalk_ir::ProgramClauseData<Self>>,
294 ) -> &'a chalk_ir::ProgramClauseData<Self> { 294 ) -> &'a chalk_ir::ProgramClauseData<Self> {
295 clause 295 clause
296 } 296 }
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index fe62f3fa7..d6bacba1d 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -464,6 +464,18 @@ impl ToChalk for hir_def::ImplId {
464 } 464 }
465} 465}
466 466
467impl ToChalk for hir_def::AdtId {
468 type Chalk = AdtId;
469
470 fn to_chalk(self, _db: &dyn HirDatabase) -> Self::Chalk {
471 chalk_ir::AdtId(self.into())
472 }
473
474 fn from_chalk(_db: &dyn HirDatabase, id: AdtId) -> Self {
475 id.0
476 }
477}
478
467impl ToChalk for CallableDefId { 479impl ToChalk for CallableDefId {
468 type Chalk = FnDefId; 480 type Chalk = FnDefId;
469 481
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt b/crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt
index 89dae7d5a..00e8da8a7 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt
@@ -44,4 +44,49 @@
44 }, 44 },
45 fixes: [], 45 fixes: [],
46 }, 46 },
47 MappedRustDiagnostic {
48 url: "file:///test/crates/hir_def/src/path.rs",
49 diagnostic: Diagnostic {
50 range: Range {
51 start: Position {
52 line: 264,
53 character: 8,
54 },
55 end: Position {
56 line: 264,
57 character: 76,
58 },
59 },
60 severity: Some(
61 Error,
62 ),
63 code: None,
64 source: Some(
65 "rustc",
66 ),
67 message: "Please register your known path in the path module",
68 related_information: Some(
69 [
70 DiagnosticRelatedInformation {
71 location: Location {
72 uri: "file:///test/crates/hir_def/src/data.rs",
73 range: Range {
74 start: Position {
75 line: 79,
76 character: 15,
77 },
78 end: Position {
79 line: 79,
80 character: 41,
81 },
82 },
83 },
84 message: "Exact error occured here",
85 },
86 ],
87 ),
88 tags: None,
89 },
90 fixes: [],
91 },
47] 92]
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index f69a949f2..33606edda 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -225,12 +225,43 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
225 225
226 // If error occurs from macro expansion, add related info pointing to 226 // If error occurs from macro expansion, add related info pointing to
227 // where the error originated 227 // where the error originated
228 if !is_from_macro(&primary_span.file_name) && primary_span.expansion.is_some() { 228 // Also, we would generate an additional diagnostic, so that exact place of macro
229 related_information.push(lsp_types::DiagnosticRelatedInformation { 229 // will be highlighted in the error origin place.
230 location: location_naive(workspace_root, &primary_span), 230 let additional_diagnostic =
231 message: "Error originated from macro here".to_string(), 231 if !is_from_macro(&primary_span.file_name) && primary_span.expansion.is_some() {
232 }); 232 let in_macro_location = location_naive(workspace_root, &primary_span);
233 } 233
234 // Add related information for the main disagnostic.
235 related_information.push(lsp_types::DiagnosticRelatedInformation {
236 location: in_macro_location.clone(),
237 message: "Error originated from macro here".to_string(),
238 });
239
240 // For the additional in-macro diagnostic we add the inverse message pointing to the error location in code.
241 let information_for_additional_diagnostic =
242 vec![lsp_types::DiagnosticRelatedInformation {
243 location: location.clone(),
244 message: "Exact error occured here".to_string(),
245 }];
246
247 let diagnostic = lsp_types::Diagnostic {
248 range: in_macro_location.range,
249 severity,
250 code: code.clone().map(lsp_types::NumberOrString::String),
251 source: Some(source.clone()),
252 message: message.clone(),
253 related_information: Some(information_for_additional_diagnostic),
254 tags: if tags.is_empty() { None } else { Some(tags.clone()) },
255 };
256
257 Some(MappedRustDiagnostic {
258 url: in_macro_location.uri,
259 diagnostic,
260 fixes: fixes.clone(),
261 })
262 } else {
263 None
264 };
234 265
235 let diagnostic = lsp_types::Diagnostic { 266 let diagnostic = lsp_types::Diagnostic {
236 range: location.range, 267 range: location.range,
@@ -246,8 +277,14 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
246 tags: if tags.is_empty() { None } else { Some(tags.clone()) }, 277 tags: if tags.is_empty() { None } else { Some(tags.clone()) },
247 }; 278 };
248 279
249 MappedRustDiagnostic { url: location.uri, diagnostic, fixes: fixes.clone() } 280 let main_diagnostic =
281 MappedRustDiagnostic { url: location.uri, diagnostic, fixes: fixes.clone() };
282 match additional_diagnostic {
283 None => vec![main_diagnostic],
284 Some(additional_diagnostic) => vec![main_diagnostic, additional_diagnostic],
285 }
250 }) 286 })
287 .flatten()
251 .collect() 288 .collect()
252} 289}
253 290