File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,8 @@ impl<'a> InferenceContext<'a> {
259
259
// details of coercion errors though, so I think it's useful to leave
260
260
// the structure like it is.
261
261
262
+ let snapshot = self . table . snapshot ( ) ;
263
+
262
264
let mut autoderef = Autoderef :: new ( & mut self . table , from_ty. clone ( ) ) ;
263
265
let mut first_error = None ;
264
266
let mut found = None ;
@@ -315,6 +317,7 @@ impl<'a> InferenceContext<'a> {
315
317
let InferOk { value : ty, goals } = match found {
316
318
Some ( d) => d,
317
319
None => {
320
+ self . table . rollback_to ( snapshot) ;
318
321
let err = first_error. expect ( "coerce_borrowed_pointer had no error" ) ;
319
322
return Err ( err) ;
320
323
}
Original file line number Diff line number Diff line change @@ -242,6 +242,45 @@ fn test() {
242
242
) ;
243
243
}
244
244
245
+ #[ test]
246
+ fn coerce_autoderef_implication_1 ( ) {
247
+ check_no_mismatches (
248
+ r"
249
+ //- minicore: deref
250
+ struct Foo<T>;
251
+ impl core::ops::Deref for Foo<u32> { type Target = (); }
252
+
253
+ fn takes_ref_foo<T>(x: &Foo<T>) {}
254
+ fn test() {
255
+ let foo = Foo;
256
+ //^^^ type: Foo<{unknown}>
257
+ takes_ref_foo(&foo);
258
+
259
+ let foo = Foo;
260
+ //^^^ type: Foo<u32>
261
+ let _: &() = &foo;
262
+ }" ,
263
+ ) ;
264
+ }
265
+
266
+ #[ test]
267
+ fn coerce_autoderef_implication_2 ( ) {
268
+ check (
269
+ r"
270
+ //- minicore: deref
271
+ struct Foo<T>;
272
+ impl core::ops::Deref for Foo<u32> { type Target = (); }
273
+
274
+ fn takes_ref_foo<T>(x: &Foo<T>) {}
275
+ fn test() {
276
+ let foo = Foo;
277
+ //^^^ type: Foo<{unknown}>
278
+ let _: &u32 = &Foo;
279
+ //^^^^ expected &u32, got &Foo<{unknown}>
280
+ }" ,
281
+ ) ;
282
+ }
283
+
245
284
#[ test]
246
285
fn closure_return_coerce ( ) {
247
286
check_no_mismatches (
You can’t perform that action at this time.
0 commit comments