From 78f7e854f981c5f0c23f0eaf4c750ce1aa581ac6 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 25 Nov 2018 23:51:23 +0200 Subject: [PATCH] address review comments --- src/librustc_typeck/check/mod.rs | 12 ++++-------- .../coercion/coerce-issue-49593-box-never.rs | 18 +++++++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e3770cee72ff7..8f044f9a7c35f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2743,14 +2743,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { trait_ref, self_ty, expected_vid ); match self_ty.sty { - ty::Infer(ty::TyVar(v)) => { - let root_vid = self.root_var(v); - debug!("self_type_matches_expected_vid - root_vid={:?}", root_vid); - if root_vid == expected_vid { - true - } else { - false - } + ty::Infer(ty::TyVar(found_vid)) => { + let found_vid = self.root_var(found_vid); + debug!("self_type_matches_expected_vid - found_vid={:?}", found_vid); + expected_vid == found_vid } _ => false } diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never.rs b/src/test/ui/coercion/coerce-issue-49593-box-never.rs index 7cdc6c8c4a4c8..407484e3d2665 100644 --- a/src/test/ui/coercion/coerce-issue-49593-box-never.rs +++ b/src/test/ui/coercion/coerce-issue-49593-box-never.rs @@ -14,21 +14,21 @@ #![allow(unreachable_code)] use std::error::Error; -use std::char::ParseCharError; /* some Error */ +use std::mem; fn raw_ptr_box(t: T) -> *mut T { panic!() } -fn foo(x: !) -> Box { - /* *mut $0 is coerced to *mut Error here */ Box::<_ /* ! */>::new(x) +fn foo(x: !) -> Box { + /* *mut $0 is coerced to Box here */ Box::<_ /* ! */>::new(x) } -fn foo_raw_ptr(x: !) -> *mut Error { +fn foo_raw_ptr(x: !) -> *mut dyn Error { /* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) } -fn no_coercion(d: *mut Error) -> *mut Error { +fn no_coercion(d: *mut dyn Error) -> *mut dyn Error { /* an unsize coercion won't compile here, and it is indeed not used because there is nothing requiring the _ to be Sized */ d as *mut _ @@ -41,17 +41,21 @@ impl Xyz for S {} impl Xyz for T {} fn foo_no_never() { - let mut x /* : Box */ = None; + let mut x /* : Option */ = None; let mut first_iter = false; loop { if !first_iter { - let y: Box + let y: Box = /* Box<$0> is coerced to Box here */ Box::new(x.unwrap()); } x = Some(S); first_iter = true; } + + let mut y : Option = None; + // assert types are equal + mem::replace(&mut x, &mut y); } fn main() {