aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/lib.rs2
-rw-r--r--crates/hir_def/src/lib.rs9
-rw-r--r--crates/hir_def/src/nameres.rs28
-rw-r--r--crates/hir_def/src/nameres/collector.rs2
-rw-r--r--crates/hir_expand/src/builtin_derive.rs4
-rw-r--r--crates/hir_expand/src/builtin_macro.rs7
-rw-r--r--crates/hir_expand/src/eager.rs5
-rw-r--r--crates/hir_expand/src/lib.rs18
-rw-r--r--crates/hir_ty/src/chalk_ext.rs2
-rw-r--r--crates/hir_ty/src/display.rs20
-rw-r--r--crates/hir_ty/src/infer/expr.rs6
-rw-r--r--crates/hir_ty/src/infer/pat.rs4
-rw-r--r--crates/hir_ty/src/infer/path.rs2
-rw-r--r--crates/hir_ty/src/lib.rs4
-rw-r--r--crates/hir_ty/src/traits/chalk/interner.rs89
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs4
-rw-r--r--crates/ide/src/syntax_highlighting/highlight.rs14
17 files changed, 135 insertions, 85 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 817a01db1..04875240b 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1825,7 +1825,7 @@ impl Type {
1825 Solution::Unique(s) => s 1825 Solution::Unique(s) => s
1826 .value 1826 .value
1827 .subst 1827 .subst
1828 .interned() 1828 .as_slice(&Interner)
1829 .first() 1829 .first()
1830 .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())), 1830 .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())),
1831 Solution::Ambig(_) => None, 1831 Solution::Ambig(_) => None,
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index e2af0e514..b72884925 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -690,7 +690,9 @@ fn macro_call_as_call_id(
690 ) 690 )
691 .map(MacroCallId::from) 691 .map(MacroCallId::from)
692 } else { 692 } else {
693 Ok(def.as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike(call.ast_id)).into()) 693 Ok(def
694 .as_lazy_macro(db.upcast(), krate, MacroCallKind::FnLike { ast_id: call.ast_id })
695 .into())
694 }; 696 };
695 Ok(res) 697 Ok(res)
696} 698}
@@ -707,7 +709,10 @@ fn derive_macro_as_call_id(
707 .as_lazy_macro( 709 .as_lazy_macro(
708 db.upcast(), 710 db.upcast(),
709 krate, 711 krate,
710 MacroCallKind::Derive(item_attr.ast_id, last_segment.to_string()), 712 MacroCallKind::Derive {
713 ast_id: item_attr.ast_id,
714 derive_name: last_segment.to_string(),
715 },
711 ) 716 )
712 .into(); 717 .into();
713 Ok(res) 718 Ok(res)
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 7dd68219f..d966fc239 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -613,12 +613,12 @@ mod diagnostics {
613 DiagnosticKind::UnresolvedProcMacro { ast } => { 613 DiagnosticKind::UnresolvedProcMacro { ast } => {
614 let mut precise_location = None; 614 let mut precise_location = None;
615 let (file, ast, name) = match ast { 615 let (file, ast, name) = match ast {
616 MacroCallKind::FnLike(ast) => { 616 MacroCallKind::FnLike { ast_id } => {
617 let node = ast.to_node(db.upcast()); 617 let node = ast_id.to_node(db.upcast());
618 (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None) 618 (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)), None)
619 } 619 }
620 MacroCallKind::Derive(ast, name) => { 620 MacroCallKind::Derive { ast_id, derive_name } => {
621 let node = ast.to_node(db.upcast()); 621 let node = ast_id.to_node(db.upcast());
622 622
623 // Compute the precise location of the macro name's token in the derive 623 // Compute the precise location of the macro name's token in the derive
624 // list. 624 // list.
@@ -639,7 +639,7 @@ mod diagnostics {
639 }); 639 });
640 for token in tokens { 640 for token in tokens {
641 if token.kind() == SyntaxKind::IDENT 641 if token.kind() == SyntaxKind::IDENT
642 && token.text() == name.as_str() 642 && token.text() == derive_name.as_str()
643 { 643 {
644 precise_location = Some(token.text_range()); 644 precise_location = Some(token.text_range());
645 break 'outer; 645 break 'outer;
@@ -648,9 +648,9 @@ mod diagnostics {
648 } 648 }
649 649
650 ( 650 (
651 ast.file_id, 651 ast_id.file_id,
652 SyntaxNodePtr::from(AstPtr::new(&node)), 652 SyntaxNodePtr::from(AstPtr::new(&node)),
653 Some(name.clone()), 653 Some(derive_name.clone()),
654 ) 654 )
655 } 655 }
656 }; 656 };
@@ -669,13 +669,13 @@ mod diagnostics {
669 669
670 DiagnosticKind::MacroError { ast, message } => { 670 DiagnosticKind::MacroError { ast, message } => {
671 let (file, ast) = match ast { 671 let (file, ast) = match ast {
672 MacroCallKind::FnLike(ast) => { 672 MacroCallKind::FnLike { ast_id, .. } => {
673 let node = ast.to_node(db.upcast()); 673 let node = ast_id.to_node(db.upcast());
674 (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) 674 (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
675 } 675 }
676 MacroCallKind::Derive(ast, _) => { 676 MacroCallKind::Derive { ast_id, .. } => {
677 let node = ast.to_node(db.upcast()); 677 let node = ast_id.to_node(db.upcast());
678 (ast.file_id, SyntaxNodePtr::from(AstPtr::new(&node))) 678 (ast_id.file_id, SyntaxNodePtr::from(AstPtr::new(&node)))
679 } 679 }
680 }; 680 };
681 sink.push(MacroError { file, node: ast, message: message.clone() }); 681 sink.push(MacroError { file, node: ast, message: message.clone() });
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 6dbbe2d05..f431da3f2 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -1520,7 +1520,7 @@ impl ModCollector<'_, '_> {
1520 // Built-in macro failed eager expansion. 1520 // Built-in macro failed eager expansion.
1521 self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error( 1521 self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error(
1522 self.module_id, 1522 self.module_id,
1523 MacroCallKind::FnLike(ast_id.ast_id), 1523 MacroCallKind::FnLike { ast_id: ast_id.ast_id },
1524 error.unwrap().to_string(), 1524 error.unwrap().to_string(),
1525 )); 1525 ));
1526 return; 1526 return;
diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs
index 6ece4b289..392079ed4 100644
--- a/crates/hir_expand/src/builtin_derive.rs
+++ b/crates/hir_expand/src/builtin_derive.rs
@@ -308,7 +308,7 @@ $0
308 308
309 let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); 309 let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap();
310 310
311 let attr_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0])); 311 let ast_id = AstId::new(file_id.into(), ast_id_map.ast_id(&items[0]));
312 312
313 let loc = MacroCallLoc { 313 let loc = MacroCallLoc {
314 def: MacroDefId { 314 def: MacroDefId {
@@ -317,7 +317,7 @@ $0
317 local_inner: false, 317 local_inner: false,
318 }, 318 },
319 krate: CrateId(0), 319 krate: CrateId(0),
320 kind: MacroCallKind::Derive(attr_id, name.to_string()), 320 kind: MacroCallKind::Derive { ast_id, derive_name: name.to_string() },
321 }; 321 };
322 322
323 let id: MacroCallId = db.intern_macro(loc).into(); 323 let id: MacroCallId = db.intern_macro(loc).into();
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index a7d0f5b1f..80365fc16 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -566,10 +566,9 @@ mod tests {
566 let loc = MacroCallLoc { 566 let loc = MacroCallLoc {
567 def, 567 def,
568 krate, 568 krate,
569 kind: MacroCallKind::FnLike(AstId::new( 569 kind: MacroCallKind::FnLike {
570 file_id.into(), 570 ast_id: AstId::new(file_id.into(), ast_id_map.ast_id(&macro_call)),
571 ast_id_map.ast_id(&macro_call), 571 },
572 )),
573 }; 572 };
574 573
575 let id: MacroCallId = db.intern_macro(loc).into(); 574 let id: MacroCallId = db.intern_macro(loc).into();
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index 9705526fa..ef126e4ad 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -174,8 +174,9 @@ fn lazy_expand(
174) -> ExpandResult<Option<InFile<SyntaxNode>>> { 174) -> ExpandResult<Option<InFile<SyntaxNode>>> {
175 let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value); 175 let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value);
176 176
177 let id: MacroCallId = 177 let id: MacroCallId = def
178 def.as_lazy_macro(db, krate, MacroCallKind::FnLike(macro_call.with_value(ast_id))).into(); 178 .as_lazy_macro(db, krate, MacroCallKind::FnLike { ast_id: macro_call.with_value(ast_id) })
179 .into();
179 180
180 let err = db.macro_expand_error(id); 181 let err = db.macro_expand_error(id);
181 let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node)); 182 let value = db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node));
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 3e332ee47..a179102f0 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -290,22 +290,24 @@ pub struct MacroCallLoc {
290 290
291#[derive(Debug, Clone, PartialEq, Eq, Hash)] 291#[derive(Debug, Clone, PartialEq, Eq, Hash)]
292pub enum MacroCallKind { 292pub enum MacroCallKind {
293 FnLike(AstId<ast::MacroCall>), 293 FnLike { ast_id: AstId<ast::MacroCall> },
294 Derive(AstId<ast::Item>, String), 294 Derive { ast_id: AstId<ast::Item>, derive_name: String },
295} 295}
296 296
297impl MacroCallKind { 297impl MacroCallKind {
298 fn file_id(&self) -> HirFileId { 298 fn file_id(&self) -> HirFileId {
299 match self { 299 match self {
300 MacroCallKind::FnLike(ast_id) => ast_id.file_id, 300 MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id,
301 MacroCallKind::Derive(ast_id, _) => ast_id.file_id, 301 MacroCallKind::Derive { ast_id, .. } => ast_id.file_id,
302 } 302 }
303 } 303 }
304 304
305 fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> { 305 fn node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> {
306 match self { 306 match self {
307 MacroCallKind::FnLike(ast_id) => ast_id.with_value(ast_id.to_node(db).syntax().clone()), 307 MacroCallKind::FnLike { ast_id, .. } => {
308 MacroCallKind::Derive(ast_id, _) => { 308 ast_id.with_value(ast_id.to_node(db).syntax().clone())
309 }
310 MacroCallKind::Derive { ast_id, .. } => {
309 ast_id.with_value(ast_id.to_node(db).syntax().clone()) 311 ast_id.with_value(ast_id.to_node(db).syntax().clone())
310 } 312 }
311 } 313 }
@@ -313,10 +315,10 @@ impl MacroCallKind {
313 315
314 fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> { 316 fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> {
315 match self { 317 match self {
316 MacroCallKind::FnLike(ast_id) => { 318 MacroCallKind::FnLike { ast_id, .. } => {
317 Some(ast_id.to_node(db).token_tree()?.syntax().clone()) 319 Some(ast_id.to_node(db).token_tree()?.syntax().clone())
318 } 320 }
319 MacroCallKind::Derive(ast_id, _) => Some(ast_id.to_node(db).syntax().clone()), 321 MacroCallKind::Derive { ast_id, .. } => Some(ast_id.to_node(db).syntax().clone()),
320 } 322 }
321 } 323 }
322} 324}
diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs
index 28ed3aac6..8c4542956 100644
--- a/crates/hir_ty/src/chalk_ext.rs
+++ b/crates/hir_ty/src/chalk_ext.rs
@@ -75,7 +75,7 @@ impl TyExt for Ty {
75 } 75 }
76 fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> { 76 fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> {
77 match self.kind(&Interner) { 77 match self.kind(&Interner) {
78 TyKind::Ref(mutability, lifetime, ty) => Some((ty, *lifetime, *mutability)), 78 TyKind::Ref(mutability, lifetime, ty) => Some((ty, lifetime.clone(), *mutability)),
79 _ => None, 79 _ => None,
80 } 80 }
81 } 81 }
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index d7a3977e5..92224b46b 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -265,7 +265,7 @@ impl HirDisplay for ProjectionTy {
265 write!(f, " as {}", trait_.name)?; 265 write!(f, " as {}", trait_.name)?;
266 if self.substitution.len(&Interner) > 1 { 266 if self.substitution.len(&Interner) > 1 {
267 write!(f, "<")?; 267 write!(f, "<")?;
268 f.write_joined(&self.substitution.interned()[1..], ", ")?; 268 f.write_joined(&self.substitution.as_slice(&Interner)[1..], ", ")?;
269 write!(f, ">")?; 269 write!(f, ">")?;
270 } 270 }
271 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?; 271 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
@@ -416,7 +416,7 @@ impl HirDisplay for Ty {
416 write!(f, ",)")?; 416 write!(f, ",)")?;
417 } else { 417 } else {
418 write!(f, "(")?; 418 write!(f, "(")?;
419 f.write_joined(&*substs.interned(), ", ")?; 419 f.write_joined(&*substs.as_slice(&Interner), ", ")?;
420 write!(f, ")")?; 420 write!(f, ")")?;
421 } 421 }
422 } 422 }
@@ -444,7 +444,7 @@ impl HirDisplay for Ty {
444 // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self? 444 // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
445 if total_len > 0 { 445 if total_len > 0 {
446 write!(f, "<")?; 446 write!(f, "<")?;
447 f.write_joined(&parameters.interned()[..total_len], ", ")?; 447 f.write_joined(&parameters.as_slice(&Interner)[..total_len], ", ")?;
448 write!(f, ">")?; 448 write!(f, ">")?;
449 } 449 }
450 } 450 }
@@ -491,7 +491,7 @@ impl HirDisplay for Ty {
491 .map(|generic_def_id| f.db.generic_defaults(generic_def_id)) 491 .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
492 .filter(|defaults| !defaults.is_empty()) 492 .filter(|defaults| !defaults.is_empty())
493 { 493 {
494 None => parameters.interned().as_ref(), 494 None => parameters.as_slice(&Interner),
495 Some(default_parameters) => { 495 Some(default_parameters) => {
496 let mut default_from = 0; 496 let mut default_from = 0;
497 for (i, parameter) in parameters.iter(&Interner).enumerate() { 497 for (i, parameter) in parameters.iter(&Interner).enumerate() {
@@ -515,11 +515,11 @@ impl HirDisplay for Ty {
515 } 515 }
516 } 516 }
517 } 517 }
518 &parameters.interned()[0..default_from] 518 &parameters.as_slice(&Interner)[0..default_from]
519 } 519 }
520 } 520 }
521 } else { 521 } else {
522 parameters.interned().as_ref() 522 parameters.as_slice(&Interner)
523 }; 523 };
524 if !parameters_to_write.is_empty() { 524 if !parameters_to_write.is_empty() {
525 write!(f, "<")?; 525 write!(f, "<")?;
@@ -542,7 +542,7 @@ impl HirDisplay for Ty {
542 write!(f, "{}::{}", trait_.name, type_alias_data.name)?; 542 write!(f, "{}::{}", trait_.name, type_alias_data.name)?;
543 if parameters.len(&Interner) > 0 { 543 if parameters.len(&Interner) > 0 {
544 write!(f, "<")?; 544 write!(f, "<")?;
545 f.write_joined(&*parameters.interned(), ", ")?; 545 f.write_joined(&*parameters.as_slice(&Interner), ", ")?;
546 write!(f, ">")?; 546 write!(f, ">")?;
547 } 547 }
548 } else { 548 } else {
@@ -749,13 +749,13 @@ fn write_bounds_like_dyn_trait(
749 // existential) here, which is the only thing that's 749 // existential) here, which is the only thing that's
750 // possible in actual Rust, and hence don't print it 750 // possible in actual Rust, and hence don't print it
751 write!(f, "{}", f.db.trait_data(trait_).name)?; 751 write!(f, "{}", f.db.trait_data(trait_).name)?;
752 if let [_, params @ ..] = &*trait_ref.substitution.interned().as_slice() { 752 if let [_, params @ ..] = &*trait_ref.substitution.as_slice(&Interner) {
753 if is_fn_trait { 753 if is_fn_trait {
754 if let Some(args) = 754 if let Some(args) =
755 params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple()) 755 params.first().and_then(|it| it.assert_ty_ref(&Interner).as_tuple())
756 { 756 {
757 write!(f, "(")?; 757 write!(f, "(")?;
758 f.write_joined(&*args.interned(), ", ")?; 758 f.write_joined(args.as_slice(&Interner), ", ")?;
759 write!(f, ")")?; 759 write!(f, ")")?;
760 } 760 }
761 } else if !params.is_empty() { 761 } else if !params.is_empty() {
@@ -814,7 +814,7 @@ fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<()
814 write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?; 814 write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?;
815 if tr.substitution.len(&Interner) > 1 { 815 if tr.substitution.len(&Interner) > 1 {
816 write!(f, "<")?; 816 write!(f, "<")?;
817 f.write_joined(&tr.substitution.interned()[1..], ", ")?; 817 f.write_joined(&tr.substitution.as_slice(&Interner)[1..], ", ")?;
818 write!(f, ">")?; 818 write!(f, ">")?;
819 } 819 }
820 Ok(()) 820 Ok(())
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index cbbfa8b5c..7961f4a52 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -462,7 +462,11 @@ impl<'a> InferenceContext<'a> {
462 }; 462 };
463 match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) { 463 match canonicalized.decanonicalize_ty(derefed_ty.value).kind(&Interner) {
464 TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| { 464 TyKind::Tuple(_, substs) => name.as_tuple_index().and_then(|idx| {
465 substs.interned().get(idx).map(|a| a.assert_ty_ref(&Interner)).cloned() 465 substs
466 .as_slice(&Interner)
467 .get(idx)
468 .map(|a| a.assert_ty_ref(&Interner))
469 .cloned()
466 }), 470 }),
467 TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => { 471 TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
468 let local_id = self.db.struct_data(*s).variant_data.field(name)?; 472 let local_id = self.db.struct_data(*s).variant_data.field(name)?;
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index a41e8e116..aea354cde 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -122,7 +122,7 @@ impl<'a> InferenceContext<'a> {
122 let ty = match &body[pat] { 122 let ty = match &body[pat] {
123 &Pat::Tuple { ref args, ellipsis } => { 123 &Pat::Tuple { ref args, ellipsis } => {
124 let expectations = match expected.as_tuple() { 124 let expectations = match expected.as_tuple() {
125 Some(parameters) => &*parameters.interned().as_slice(), 125 Some(parameters) => &*parameters.as_slice(&Interner),
126 _ => &[], 126 _ => &[],
127 }; 127 };
128 128
@@ -242,7 +242,7 @@ impl<'a> InferenceContext<'a> {
242 let (inner_ty, alloc_ty) = match expected.as_adt() { 242 let (inner_ty, alloc_ty) = match expected.as_adt() {
243 Some((adt, subst)) if adt == box_adt => ( 243 Some((adt, subst)) if adt == box_adt => (
244 subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(), 244 subst.at(&Interner, 0).assert_ty_ref(&Interner).clone(),
245 subst.interned().get(1).and_then(|a| a.ty(&Interner).cloned()), 245 subst.as_slice(&Interner).get(1).and_then(|a| a.ty(&Interner).cloned()),
246 ), 246 ),
247 _ => (self.result.standard_types.unknown.clone(), None), 247 _ => (self.result.standard_types.unknown.clone(), None),
248 }; 248 };
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs
index f8955aa32..495282eba 100644
--- a/crates/hir_ty/src/infer/path.rs
+++ b/crates/hir_ty/src/infer/path.rs
@@ -101,7 +101,7 @@ impl<'a> InferenceContext<'a> {
101 let substs = ctx.substs_from_path(path, typable, true); 101 let substs = ctx.substs_from_path(path, typable, true);
102 let ty = TyBuilder::value_ty(self.db, typable) 102 let ty = TyBuilder::value_ty(self.db, typable)
103 .use_parent_substs(&parent_substs) 103 .use_parent_substs(&parent_substs)
104 .fill(substs.interned()[parent_substs.len(&Interner)..].iter().cloned()) 104 .fill(substs.as_slice(&Interner)[parent_substs.len(&Interner)..].iter().cloned())
105 .build(); 105 .build();
106 Some(ty) 106 Some(ty)
107 } 107 }
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 874c95411..beb58d711 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -109,7 +109,7 @@ pub type WhereClause = chalk_ir::WhereClause<Interner>;
109pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution { 109pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution {
110 Substitution::from_iter( 110 Substitution::from_iter(
111 &Interner, 111 &Interner,
112 s.interned()[..std::cmp::min(s.len(&Interner), n)].iter().cloned(), 112 s.as_slice(&Interner)[..std::cmp::min(s.len(&Interner), n)].iter().cloned(),
113 ) 113 )
114} 114}
115 115
@@ -187,7 +187,7 @@ impl CallableSig {
187 .shifted_out_to(&Interner, DebruijnIndex::ONE) 187 .shifted_out_to(&Interner, DebruijnIndex::ONE)
188 .expect("unexpected lifetime vars in fn ptr") 188 .expect("unexpected lifetime vars in fn ptr")
189 .0 189 .0
190 .interned() 190 .as_slice(&Interner)
191 .iter() 191 .iter()
192 .map(|arg| arg.assert_ty_ref(&Interner).clone()) 192 .map(|arg| arg.assert_ty_ref(&Interner).clone())
193 .collect(), 193 .collect(),
diff --git a/crates/hir_ty/src/traits/chalk/interner.rs b/crates/hir_ty/src/traits/chalk/interner.rs
index bd9395b7e..b6a3cec6d 100644
--- a/crates/hir_ty/src/traits/chalk/interner.rs
+++ b/crates/hir_ty/src/traits/chalk/interner.rs
@@ -2,9 +2,13 @@
2//! representation of the various objects Chalk deals with (types, goals etc.). 2//! representation of the various objects Chalk deals with (types, goals etc.).
3 3
4use super::tls; 4use super::tls;
5use crate::GenericArg;
5use base_db::salsa::InternId; 6use base_db::salsa::InternId;
6use chalk_ir::{GenericArg, Goal, GoalData}; 7use chalk_ir::{Goal, GoalData};
7use hir_def::TypeAliasId; 8use hir_def::{
9 intern::{impl_internable, InternStorage, Internable, Interned},
10 TypeAliasId,
11};
8use smallvec::SmallVec; 12use smallvec::SmallVec;
9use std::{fmt, sync::Arc}; 13use std::{fmt, sync::Arc};
10 14
@@ -26,22 +30,47 @@ pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
26pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>; 30pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
27pub(crate) type Variances = chalk_ir::Variances<Interner>; 31pub(crate) type Variances = chalk_ir::Variances<Interner>;
28 32
33#[derive(PartialEq, Eq, Hash, Debug)]
34pub struct InternedWrapper<T>(T);
35
36impl<T> std::ops::Deref for InternedWrapper<T> {
37 type Target = T;
38
39 fn deref(&self) -> &Self::Target {
40 &self.0
41 }
42}
43
44impl_internable!(
45 InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>,
46 InternedWrapper<SmallVec<[GenericArg; 2]>>,
47 InternedWrapper<chalk_ir::TyData<Interner>>,
48 InternedWrapper<chalk_ir::LifetimeData<Interner>>,
49 InternedWrapper<chalk_ir::ConstData<Interner>>,
50 InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Interner>>>,
51 InternedWrapper<Vec<chalk_ir::ProgramClause<Interner>>>,
52 InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Interner>>>,
53 InternedWrapper<Vec<chalk_ir::Variance>>,
54);
55
29impl chalk_ir::interner::Interner for Interner { 56impl chalk_ir::interner::Interner for Interner {
30 type InternedType = Arc<chalk_ir::TyData<Self>>; 57 type InternedType = Interned<InternedWrapper<chalk_ir::TyData<Interner>>>;
31 type InternedLifetime = chalk_ir::LifetimeData<Self>; 58 type InternedLifetime = Interned<InternedWrapper<chalk_ir::LifetimeData<Self>>>;
32 type InternedConst = Arc<chalk_ir::ConstData<Self>>; 59 type InternedConst = Interned<InternedWrapper<chalk_ir::ConstData<Self>>>;
33 type InternedConcreteConst = (); 60 type InternedConcreteConst = ();
34 type InternedGenericArg = chalk_ir::GenericArgData<Self>; 61 type InternedGenericArg = chalk_ir::GenericArgData<Self>;
35 type InternedGoal = Arc<GoalData<Self>>; 62 type InternedGoal = Arc<GoalData<Self>>;
36 type InternedGoals = Vec<Goal<Self>>; 63 type InternedGoals = Vec<Goal<Self>>;
37 type InternedSubstitution = SmallVec<[GenericArg<Self>; 2]>; 64 type InternedSubstitution = Interned<InternedWrapper<SmallVec<[GenericArg; 2]>>>;
38 type InternedProgramClause = Arc<chalk_ir::ProgramClauseData<Self>>; 65 type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
39 type InternedProgramClauses = Arc<[chalk_ir::ProgramClause<Self>]>; 66 type InternedProgramClauses = Interned<InternedWrapper<Vec<chalk_ir::ProgramClause<Self>>>>;
40 type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>; 67 type InternedQuantifiedWhereClauses =
41 type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>; 68 Interned<InternedWrapper<Vec<chalk_ir::QuantifiedWhereClause<Self>>>>;
42 type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>; 69 type InternedVariableKinds = Interned<InternedWrapper<Vec<chalk_ir::VariableKind<Interner>>>>;
70 type InternedCanonicalVarKinds =
71 Interned<InternedWrapper<Vec<chalk_ir::CanonicalVarKind<Self>>>>;
43 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>; 72 type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
44 type InternedVariances = Arc<[chalk_ir::Variance]>; 73 type InternedVariances = Interned<InternedWrapper<Vec<chalk_ir::Variance>>>;
45 type DefId = InternId; 74 type DefId = InternId;
46 type InternedAdtId = hir_def::AdtId; 75 type InternedAdtId = hir_def::AdtId;
47 type Identifier = TypeAliasId; 76 type Identifier = TypeAliasId;
@@ -99,7 +128,7 @@ impl chalk_ir::interner::Interner for Interner {
99 } 128 }
100 129
101 fn debug_generic_arg( 130 fn debug_generic_arg(
102 parameter: &GenericArg<Interner>, 131 parameter: &GenericArg,
103 fmt: &mut fmt::Formatter<'_>, 132 fmt: &mut fmt::Formatter<'_>,
104 ) -> Option<fmt::Result> { 133 ) -> Option<fmt::Result> {
105 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt))) 134 tls::with_current_program(|prog| Some(prog?.debug_generic_arg(parameter, fmt)))
@@ -194,30 +223,30 @@ impl chalk_ir::interner::Interner for Interner {
194 223
195 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType { 224 fn intern_ty(&self, kind: chalk_ir::TyKind<Self>) -> Self::InternedType {
196 let flags = kind.compute_flags(self); 225 let flags = kind.compute_flags(self);
197 Arc::new(chalk_ir::TyData { kind, flags }) 226 Interned::new(InternedWrapper(chalk_ir::TyData { kind, flags }))
198 } 227 }
199 228
200 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> { 229 fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a chalk_ir::TyData<Self> {
201 ty 230 &ty.0
202 } 231 }
203 232
204 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime { 233 fn intern_lifetime(&self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
205 lifetime 234 Interned::new(InternedWrapper(lifetime))
206 } 235 }
207 236
208 fn lifetime_data<'a>( 237 fn lifetime_data<'a>(
209 &self, 238 &self,
210 lifetime: &'a Self::InternedLifetime, 239 lifetime: &'a Self::InternedLifetime,
211 ) -> &'a chalk_ir::LifetimeData<Self> { 240 ) -> &'a chalk_ir::LifetimeData<Self> {
212 lifetime 241 &lifetime.0
213 } 242 }
214 243
215 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst { 244 fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
216 Arc::new(constant) 245 Interned::new(InternedWrapper(constant))
217 } 246 }
218 247
219 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> { 248 fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
220 constant 249 &constant.0
221 } 250 }
222 251
223 fn const_eq( 252 fn const_eq(
@@ -264,23 +293,23 @@ impl chalk_ir::interner::Interner for Interner {
264 293
265 fn intern_substitution<E>( 294 fn intern_substitution<E>(
266 &self, 295 &self,
267 data: impl IntoIterator<Item = Result<GenericArg<Self>, E>>, 296 data: impl IntoIterator<Item = Result<GenericArg, E>>,
268 ) -> Result<Self::InternedSubstitution, E> { 297 ) -> Result<Self::InternedSubstitution, E> {
269 data.into_iter().collect() 298 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
270 } 299 }
271 300
272 fn substitution_data<'a>( 301 fn substitution_data<'a>(
273 &self, 302 &self,
274 substitution: &'a Self::InternedSubstitution, 303 substitution: &'a Self::InternedSubstitution,
275 ) -> &'a [GenericArg<Self>] { 304 ) -> &'a [GenericArg] {
276 substitution 305 &substitution.as_ref().0
277 } 306 }
278 307
279 fn intern_program_clause( 308 fn intern_program_clause(
280 &self, 309 &self,
281 data: chalk_ir::ProgramClauseData<Self>, 310 data: chalk_ir::ProgramClauseData<Self>,
282 ) -> Self::InternedProgramClause { 311 ) -> Self::InternedProgramClause {
283 Arc::new(data) 312 data
284 } 313 }
285 314
286 fn program_clause_data<'a>( 315 fn program_clause_data<'a>(
@@ -294,7 +323,7 @@ impl chalk_ir::interner::Interner for Interner {
294 &self, 323 &self,
295 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>, 324 data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
296 ) -> Result<Self::InternedProgramClauses, E> { 325 ) -> Result<Self::InternedProgramClauses, E> {
297 data.into_iter().collect() 326 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
298 } 327 }
299 328
300 fn program_clauses_data<'a>( 329 fn program_clauses_data<'a>(
@@ -308,7 +337,7 @@ impl chalk_ir::interner::Interner for Interner {
308 &self, 337 &self,
309 data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>, 338 data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
310 ) -> Result<Self::InternedQuantifiedWhereClauses, E> { 339 ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
311 data.into_iter().collect() 340 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
312 } 341 }
313 342
314 fn quantified_where_clauses_data<'a>( 343 fn quantified_where_clauses_data<'a>(
@@ -322,21 +351,21 @@ impl chalk_ir::interner::Interner for Interner {
322 &self, 351 &self,
323 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>, 352 data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
324 ) -> Result<Self::InternedVariableKinds, E> { 353 ) -> Result<Self::InternedVariableKinds, E> {
325 data.into_iter().collect() 354 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
326 } 355 }
327 356
328 fn variable_kinds_data<'a>( 357 fn variable_kinds_data<'a>(
329 &self, 358 &self,
330 parameter_kinds: &'a Self::InternedVariableKinds, 359 parameter_kinds: &'a Self::InternedVariableKinds,
331 ) -> &'a [chalk_ir::VariableKind<Self>] { 360 ) -> &'a [chalk_ir::VariableKind<Self>] {
332 &parameter_kinds 361 &parameter_kinds.as_ref().0
333 } 362 }
334 363
335 fn intern_canonical_var_kinds<E>( 364 fn intern_canonical_var_kinds<E>(
336 &self, 365 &self,
337 data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>, 366 data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
338 ) -> Result<Self::InternedCanonicalVarKinds, E> { 367 ) -> Result<Self::InternedCanonicalVarKinds, E> {
339 data.into_iter().collect() 368 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
340 } 369 }
341 370
342 fn canonical_var_kinds_data<'a>( 371 fn canonical_var_kinds_data<'a>(
@@ -376,7 +405,7 @@ impl chalk_ir::interner::Interner for Interner {
376 &self, 405 &self,
377 data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>, 406 data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
378 ) -> Result<Self::InternedVariances, E> { 407 ) -> Result<Self::InternedVariances, E> {
379 data.into_iter().collect() 408 Ok(Interned::new(InternedWrapper(data.into_iter().collect::<Result<_, _>>()?)))
380 } 409 }
381 410
382 fn variances_data<'a>( 411 fn variances_data<'a>(
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 7818f6387..e78581ea5 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -99,7 +99,7 @@ pub(super) fn generic_predicate_to_inline_bound(
99 // have the expected self type 99 // have the expected self type
100 return None; 100 return None;
101 } 101 }
102 let args_no_self = trait_ref.substitution.interned()[1..] 102 let args_no_self = trait_ref.substitution.as_slice(&Interner)[1..]
103 .iter() 103 .iter()
104 .map(|ty| ty.clone().cast(&Interner)) 104 .map(|ty| ty.clone().cast(&Interner))
105 .collect(); 105 .collect();
@@ -111,7 +111,7 @@ pub(super) fn generic_predicate_to_inline_bound(
111 return None; 111 return None;
112 } 112 }
113 let trait_ = projection_ty.trait_(db); 113 let trait_ = projection_ty.trait_(db);
114 let args_no_self = projection_ty.substitution.interned()[1..] 114 let args_no_self = projection_ty.substitution.as_slice(&Interner)[1..]
115 .iter() 115 .iter()
116 .map(|ty| ty.clone().cast(&Interner)) 116 .map(|ty| ty.clone().cast(&Interner))
117 .collect(); 117 .collect();
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs
index 5ccb84714..e921784bf 100644
--- a/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/crates/ide/src/syntax_highlighting/highlight.rs
@@ -323,8 +323,18 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
323 hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait), 323 hir::ModuleDef::Trait(_) => HlTag::Symbol(SymbolKind::Trait),
324 hir::ModuleDef::TypeAlias(type_) => { 324 hir::ModuleDef::TypeAlias(type_) => {
325 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias)); 325 let mut h = Highlight::new(HlTag::Symbol(SymbolKind::TypeAlias));
326 if type_.as_assoc_item(db).is_some() { 326 if let Some(item) = type_.as_assoc_item(db) {
327 h |= HlMod::Associated 327 h |= HlMod::Associated;
328 match item.container(db) {
329 AssocItemContainer::Impl(i) => {
330 if i.trait_(db).is_some() {
331 h |= HlMod::Trait;
332 }
333 }
334 AssocItemContainer::Trait(_t) => {
335 h |= HlMod::Trait;
336 }
337 }
328 } 338 }
329 return h; 339 return h;
330 } 340 }