@@ -13,7 +13,7 @@ use crate::pointee_type::PointeeTypes;
13
13
use crate :: pointer_id:: { PointerId , PointerTable } ;
14
14
use crate :: type_desc:: { self , Ownership , Quantity , TypeDesc } ;
15
15
use crate :: util:: { self , ty_callee, Callee } ;
16
- use log:: trace;
16
+ use log:: { error , trace} ;
17
17
use rustc_ast:: Mutability ;
18
18
use rustc_middle:: mir:: {
19
19
BasicBlock , Body , BorrowKind , Location , Operand , Place , PlaceElem , PlaceRef , Rvalue , Statement ,
@@ -963,6 +963,8 @@ where
963
963
// `to` is `&mut T`, we start by calling `p.as_deref_mut()`, which produces
964
964
// `Option<&mut T>` without consuming `p`.
965
965
if !from. own . is_copy ( ) {
966
+ // Note that all non-`Copy` ownership types are also safe. We don't reach this
967
+ // code when `from.own` is `Raw` or `RawMut`.
966
968
match to. own {
967
969
Ownership :: Raw | Ownership :: Imm => {
968
970
( self . emit ) ( RewriteKind :: OptionDowngrade {
@@ -978,8 +980,17 @@ where
978
980
} ) ;
979
981
from. own = Ownership :: Mut ;
980
982
}
983
+ Ownership :: Rc if from. own == Ownership :: Rc => {
984
+ // `p.clone()` allows using an `Option<Rc<T>>` without consuming the
985
+ // original. However, `RewriteKind::Clone` is not yet implemented.
986
+ error ! ( "Option<Rc> -> Option<Rc> clone rewrite NYI" ) ;
987
+ }
981
988
_ => {
982
- // Remaining cases are unsupported.
989
+ // Remaining cases don't have a valid downgrade operation. We leave them
990
+ // as is, and the `unwrap`/`map` operations below will consume the original
991
+ // value. Some cases are also impossible to implement, like casting from
992
+ // `Rc` to `Box`, which will be caught when attempting the `qty`/`own`
993
+ // casts below.
983
994
}
984
995
}
985
996
}
0 commit comments