aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/infer.rs5
-rw-r--r--crates/hir_ty/src/infer/expr.rs1
-rw-r--r--crates/hir_ty/src/infer/unify.rs4
-rw-r--r--crates/hir_ty/src/lib.rs2
-rw-r--r--crates/hir_ty/src/tests/macros.rs40
5 files changed, 50 insertions, 2 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 8f9cf7480..e4407ff50 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -45,6 +45,11 @@ use crate::{
45 to_assoc_type_id, to_chalk_trait_id, AliasEq, AliasTy, Interner, TyKind, 45 to_assoc_type_id, to_chalk_trait_id, AliasEq, AliasTy, Interner, TyKind,
46}; 46};
47 47
48// This lint has a false positive here. See the link below for details.
49//
50// https://github.com/rust-lang/rust/issues/57411
51#[allow(unreachable_pub)]
52pub use unify::could_unify;
48pub(crate) use unify::unify; 53pub(crate) use unify::unify;
49 54
50mod unify; 55mod unify;
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 3f3187ea2..e6ede05ca 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -767,6 +767,7 @@ impl<'a> InferenceContext<'a> {
767 None => self.table.new_float_var(), 767 None => self.table.new_float_var(),
768 }, 768 },
769 }, 769 },
770 Expr::MacroStmts { tail } => self.infer_expr(*tail, expected),
770 }; 771 };
771 // use a new type variable if we got unknown here 772 // use a new type variable if we got unknown here
772 let ty = self.insert_type_vars_shallow(ty); 773 let ty = self.insert_type_vars_shallow(ty);
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 75250a369..6e7b0f5a6 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -157,6 +157,10 @@ impl<T> Canonicalized<T> {
157 } 157 }
158} 158}
159 159
160pub fn could_unify(t1: &Ty, t2: &Ty) -> bool {
161 InferenceTable::new().unify(t1, t2)
162}
163
160pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> { 164pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> {
161 let mut table = InferenceTable::new(); 165 let mut table = InferenceTable::new();
162 let vars = Substitution( 166 let vars = Substitution(
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 69265286f..6f9c698e6 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -41,7 +41,7 @@ use crate::{
41}; 41};
42 42
43pub use autoderef::autoderef; 43pub use autoderef::autoderef;
44pub use infer::{InferenceResult, InferenceVar}; 44pub use infer::{could_unify, InferenceResult, InferenceVar};
45pub use lower::{ 45pub use lower::{
46 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, 46 associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
47 TyDefId, TyLoweringContext, ValueTyDefId, 47 TyDefId, TyLoweringContext, ValueTyDefId,
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs
index 7eda51866..01935ec99 100644
--- a/crates/hir_ty/src/tests/macros.rs
+++ b/crates/hir_ty/src/tests/macros.rs
@@ -226,12 +226,49 @@ fn expr_macro_expanded_in_stmts() {
226 "#, 226 "#,
227 expect![[r#" 227 expect![[r#"
228 !0..8 'leta=();': () 228 !0..8 'leta=();': ()
229 !0..8 'leta=();': ()
230 !3..4 'a': ()
231 !5..7 '()': ()
229 57..84 '{ ...); } }': () 232 57..84 '{ ...); } }': ()
230 "#]], 233 "#]],
231 ); 234 );
232} 235}
233 236
234#[test] 237#[test]
238fn recurisve_macro_expanded_in_stmts() {
239 check_infer(
240 r#"
241 macro_rules! ng {
242 ([$($tts:tt)*]) => {
243 $($tts)*;
244 };
245 ([$($tts:tt)*] $head:tt $($rest:tt)*) => {
246 ng! {
247 [$($tts)* $head] $($rest)*
248 }
249 };
250 }
251 fn foo() {
252 ng!([] let a = 3);
253 let b = a;
254 }
255 "#,
256 expect![[r#"
257 !0..7 'leta=3;': {unknown}
258 !0..7 'leta=3;': {unknown}
259 !0..13 'ng!{[leta=3]}': {unknown}
260 !0..13 'ng!{[leta=]3}': {unknown}
261 !0..13 'ng!{[leta]=3}': {unknown}
262 !3..4 'a': i32
263 !5..6 '3': i32
264 196..237 '{ ...= a; }': ()
265 229..230 'b': i32
266 233..234 'a': i32
267 "#]],
268 );
269}
270
271#[test]
235fn recursive_inner_item_macro_rules() { 272fn recursive_inner_item_macro_rules() {
236 check_infer( 273 check_infer(
237 r#" 274 r#"
@@ -246,7 +283,8 @@ fn recursive_inner_item_macro_rules() {
246 "#, 283 "#,
247 expect![[r#" 284 expect![[r#"
248 !0..1 '1': i32 285 !0..1 '1': i32
249 !0..7 'mac!($)': {unknown} 286 !0..26 'macro_...>{1};}': {unknown}
287 !0..26 'macro_...>{1};}': {unknown}
250 107..143 '{ ...!(); }': () 288 107..143 '{ ...!(); }': ()
251 129..130 'a': i32 289 129..130 'a': i32
252 "#]], 290 "#]],