@@ -103,16 +103,14 @@ TypeCoercionRules::do_coercion (TyTy::BaseType *receiver)
103
103
}
104
104
105
105
// unsize
106
- bool unsafe_error = false ;
107
- CoercionResult unsize_coercion
108
- = coerce_unsized (receiver, expected, unsafe_error);
109
- bool valid_unsize_coercion = !unsize_coercion.is_error ();
110
- if (valid_unsize_coercion)
106
+ tl::expected<CoercionResult, CoerceUnsizedError> unsize_coercion
107
+ = coerce_unsized (receiver, expected);
108
+ if (unsize_coercion)
111
109
{
112
- try_result = unsize_coercion;
110
+ try_result = unsize_coercion. value () ;
113
111
return true ;
114
112
}
115
- else if (unsafe_error )
113
+ else if (unsize_coercion. error () == CoerceUnsizedError::Unsafe )
116
114
{
117
115
// location_t lhs = mappings.lookup_location (receiver->get_ref ());
118
116
// location_t rhs = mappings.lookup_location (expected->get_ref ());
@@ -316,9 +314,10 @@ TypeCoercionRules::coerce_borrowed_pointer (TyTy::BaseType *receiver,
316
314
// &[T; n] or &mut [T; n] -> &[T]
317
315
// or &mut [T; n] -> &mut [T]
318
316
// or &Concrete -> &Trait, etc.
319
- TypeCoercionRules::CoercionResult
317
+ tl::expected<TypeCoercionRules::CoercionResult,
318
+ TypeCoercionRules::CoerceUnsizedError>
320
319
TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
321
- TyTy::BaseType *target, bool &unsafe_error )
320
+ TyTy::BaseType *target)
322
321
{
323
322
rust_debug (" coerce_unsized(source={%s}, target={%s})" ,
324
323
source->debug_str ().c_str (), target->debug_str ().c_str ());
@@ -342,11 +341,11 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
342
341
Mutability to_mutbl = target_ref->mutability ();
343
342
if (!coerceable_mutability (from_mutbl, to_mutbl))
344
343
{
345
- unsafe_error = true ;
346
344
location_t lhs = mappings.lookup_location (source->get_ref ());
347
345
location_t rhs = mappings.lookup_location (target->get_ref ());
348
346
mismatched_mutability_error (locus, lhs, rhs);
349
- return TypeCoercionRules::CoercionResult::get_error ();
347
+ return tl::unexpected<CoerceUnsizedError> (
348
+ CoerceUnsizedError::Unsafe);
350
349
}
351
350
352
351
ty_a = source_ref->get_base ();
@@ -367,11 +366,11 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
367
366
Mutability to_mutbl = target_ref->mutability ();
368
367
if (!coerceable_mutability (from_mutbl, to_mutbl))
369
368
{
370
- unsafe_error = true ;
371
369
location_t lhs = mappings.lookup_location (source->get_ref ());
372
370
location_t rhs = mappings.lookup_location (target->get_ref ());
373
371
mismatched_mutability_error (locus, lhs, rhs);
374
- return TypeCoercionRules::CoercionResult::get_error ();
372
+ return tl::unexpected<CoerceUnsizedError> (
373
+ CoerceUnsizedError::Unsafe);
375
374
}
376
375
377
376
ty_a = source_ref->get_base ();
@@ -399,10 +398,7 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
399
398
{
400
399
bool bounds_compatible = b->bounds_compatible (*a, locus, false );
401
400
if (!bounds_compatible)
402
- {
403
- unsafe_error = true ;
404
- return TypeCoercionRules::CoercionResult::get_error ();
405
- }
401
+ return tl::unexpected<CoerceUnsizedError> (CoerceUnsizedError::Unsafe);
406
402
407
403
// return the unsize coercion
408
404
TyTy::BaseType *result = b->clone ();
@@ -430,7 +426,7 @@ TypeCoercionRules::coerce_unsized (TyTy::BaseType *source,
430
426
}
431
427
432
428
adjustments.clear ();
433
- return TypeCoercionRules::CoercionResult::get_error ( );
429
+ return tl::unexpected<CoerceUnsizedError> (CoerceUnsizedError::Regular );
434
430
}
435
431
436
432
bool
0 commit comments