diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-29 16:04:35 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-29 16:04:35 +0100 |
commit | 30658b25d2bb00ec495e0f3396de772141482081 (patch) | |
tree | 2846ebee3a16875674aed26b534f905a30cb598f /crates/ra_hir_ty/src/infer | |
parent | 190a0595a478d059fdd95a179fe38d59cb6379be (diff) | |
parent | 367487fe88dca78cffad5138673d5259f7f7ba6b (diff) |
Merge #4648
4648: Support raw_ref_op's raw reference operator r=matklad a=robojumper
Fixes #4642.
This syntax (and its semantics) are implemented in rustc behind the `raw_ref_op` feature.
It is not entirely clear whether this is the syntax that will become stable, but [it seems like](https://github.com/rust-lang/rust/pull/72279) rust-analyzer must still support this unstable syntax to support future stable rust.
Also fixes a random inference failure involving a direct coercion from `&[T, _]` to `*const [T]`.
Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/infer')
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index b28724f0e..54bab3476 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -17,8 +17,8 @@ use crate::{ | |||
17 | autoderef, method_resolution, op, | 17 | autoderef, method_resolution, op, |
18 | traits::InEnvironment, | 18 | traits::InEnvironment, |
19 | utils::{generics, variant_data, Generics}, | 19 | utils::{generics, variant_data, Generics}, |
20 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, | 20 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, |
21 | Ty, TypeCtor, Uncertain, | 21 | TraitRef, Ty, TypeCtor, Uncertain, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | use super::{ | 24 | use super::{ |
@@ -350,19 +350,28 @@ impl<'a> InferenceContext<'a> { | |||
350 | // FIXME check the cast... | 350 | // FIXME check the cast... |
351 | cast_ty | 351 | cast_ty |
352 | } | 352 | } |
353 | Expr::Ref { expr, mutability } => { | 353 | Expr::Ref { expr, rawness, mutability } => { |
354 | let expectation = | 354 | let expectation = if let Some((exp_inner, exp_rawness, exp_mutability)) = |
355 | if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() { | 355 | &expected.ty.as_reference_or_ptr() |
356 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { | 356 | { |
357 | // FIXME: throw type error - expected mut reference but found shared ref, | 357 | if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { |
358 | // which cannot be coerced | 358 | // FIXME: throw type error - expected mut reference but found shared ref, |
359 | } | 359 | // which cannot be coerced |
360 | Expectation::rvalue_hint(Ty::clone(exp_inner)) | 360 | } |
361 | } else { | 361 | if *exp_rawness == Rawness::Ref && *rawness == Rawness::RawPtr { |
362 | Expectation::none() | 362 | // FIXME: throw type error - expected reference but found ptr, |
363 | }; | 363 | // which cannot be coerced |
364 | } | ||
365 | Expectation::rvalue_hint(Ty::clone(exp_inner)) | ||
366 | } else { | ||
367 | Expectation::none() | ||
368 | }; | ||
364 | let inner_ty = self.infer_expr_inner(*expr, &expectation); | 369 | let inner_ty = self.infer_expr_inner(*expr, &expectation); |
365 | Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) | 370 | let ty = match rawness { |
371 | Rawness::RawPtr => TypeCtor::RawPtr(*mutability), | ||
372 | Rawness::Ref => TypeCtor::Ref(*mutability), | ||
373 | }; | ||
374 | Ty::apply_one(ty, inner_ty) | ||
366 | } | 375 | } |
367 | Expr::Box { expr } => { | 376 | Expr::Box { expr } => { |
368 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 377 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |