|
18 | 18 |
|
19 | 19 | #include "rust-unify.h" |
20 | 20 | #include "fold-const.h" |
| 21 | +#include "rust-tyty-util.h" |
21 | 22 | #include "rust-tyty.h" |
22 | | -#include "tree.h" |
23 | 23 |
|
24 | 24 | namespace Rust { |
25 | 25 | namespace Resolver { |
@@ -302,35 +302,67 @@ UnifyRules::go () |
302 | 302 | else if (ltype->get_kind () == TyTy::TypeKind::CONST |
303 | 303 | && rtype->get_kind () == TyTy::TypeKind::CONST) |
304 | 304 | { |
305 | | - const auto &lhs = *ltype->as_const_type (); |
306 | | - const auto &rhs = *rtype->as_const_type (); |
| 305 | + auto lhs = ltype->as_const_type (); |
| 306 | + auto rhs = rtype->as_const_type (); |
307 | 307 |
|
308 | 308 | bool both_are_decls |
309 | | - = lhs.const_kind () == TyTy::BaseConstType::ConstKind::Decl |
310 | | - && rhs.const_kind () == TyTy::BaseConstType::ConstKind::Decl; |
| 309 | + = lhs->const_kind () == TyTy::BaseConstType::ConstKind::Decl |
| 310 | + && rhs->const_kind () == TyTy::BaseConstType::ConstKind::Decl; |
311 | 311 | bool have_decls |
312 | | - = lhs.const_kind () == TyTy::BaseConstType::ConstKind::Decl |
313 | | - || rhs.const_kind () == TyTy::BaseConstType::ConstKind::Decl; |
| 312 | + = lhs->const_kind () == TyTy::BaseConstType::ConstKind::Decl |
| 313 | + || rhs->const_kind () == TyTy::BaseConstType::ConstKind::Decl; |
314 | 314 |
|
315 | 315 | if (have_decls && !both_are_decls) |
316 | 316 | { |
317 | | - if (lhs.const_kind () == TyTy::BaseConstType::ConstKind::Decl) |
| 317 | + if (lhs->const_kind () == TyTy::BaseConstType::ConstKind::Decl) |
318 | 318 | { |
319 | | - TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var ( |
320 | | - lhs.as_base_type ()->get_locus ()); |
321 | | - ltype = iv.get_tyty (); |
| 319 | + auto l = lhs->as_base_type ()->get_locus (); |
| 320 | + auto p = static_cast<TyTy::ConstParamType *> (lhs); |
| 321 | + auto it = TyTy::TyVar::get_implicit_infer_var (l); |
| 322 | + auto iv = TyTy::TyVar::get_implicit_const_infer_var (l, &it); |
| 323 | + auto ivt = iv.get_tyty (); |
| 324 | + |
| 325 | + infers.emplace_back (0, 0, nullptr, it.get_tyty ()); |
| 326 | + infers.emplace_back (ltype->get_ref (), ltype->get_ty_ref (), |
| 327 | + p, ivt); |
| 328 | + |
| 329 | + ltype = ivt; |
| 330 | + p->set_ty_ref (ltype->get_ref ()); |
322 | 331 | } |
323 | | - else if (rhs.const_kind () |
| 332 | + else if (rhs->const_kind () |
324 | 333 | == TyTy::BaseConstType::ConstKind::Decl) |
325 | 334 | { |
326 | | - TyTy::TyVar iv = TyTy::TyVar::get_implicit_const_infer_var ( |
327 | | - rhs.as_base_type ()->get_locus ()); |
328 | | - rtype = iv.get_tyty (); |
| 335 | + auto l = rhs->as_base_type ()->get_locus (); |
| 336 | + auto p = static_cast<TyTy::ConstParamType *> (rhs); |
| 337 | + auto it = TyTy::TyVar::get_implicit_infer_var (l); |
| 338 | + auto iv = TyTy::TyVar::get_implicit_const_infer_var (l, &it); |
| 339 | + auto ivt = iv.get_tyty (); |
| 340 | + |
| 341 | + infers.emplace_back (0, 0, nullptr, it.get_tyty ()); |
| 342 | + infers.emplace_back (rtype->get_ref (), rtype->get_ty_ref (), |
| 343 | + p, ivt); |
| 344 | + |
| 345 | + rtype = ivt; |
| 346 | + p->set_ty_ref (rtype->get_ref ()); |
329 | 347 | } |
330 | 348 | } |
331 | 349 | } |
332 | 350 | } |
333 | 351 |
|
| 352 | + if (ltype->get_kind () != TyTy::TypeKind::CONST |
| 353 | + && rtype->get_kind () == TyTy::TypeKind::CONST) |
| 354 | + { |
| 355 | + auto *rc = rtype->as_const_type (); |
| 356 | + rtype = rc->get_specified_type (); |
| 357 | + } |
| 358 | + |
| 359 | + if (ltype->get_kind () == TyTy::TypeKind::CONST |
| 360 | + && rtype->get_kind () != TyTy::TypeKind::CONST) |
| 361 | + { |
| 362 | + auto *lc = ltype->as_const_type (); |
| 363 | + ltype = lc->get_specified_type (); |
| 364 | + } |
| 365 | + |
334 | 366 | switch (ltype->get_kind ()) |
335 | 367 | { |
336 | 368 | case TyTy::INFER: |
|
0 commit comments