From b3c9912dbad13d7a3c369df4913e36d7fd7315ad Mon Sep 17 00:00:00 2001 From: Yashhwanth Ram Date: Fri, 10 Apr 2020 18:37:44 +0530 Subject: [PATCH] Suggest x.into() when it is a better choice than x.try_into() when converting ints in librustc_typeck Fixes #70851 --- src/librustc_typeck/check/demand.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 369bb183bcd7..7ef4bfb01418 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -755,6 +755,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (&ty::Int(ref exp), &ty::Int(ref found)) => { let is_fallible = match (found.bit_width(), exp.bit_width()) { (Some(found), Some(exp)) if found > exp => true, + (None, Some(8 | 16)) | (Some(8 | 16), None) => false, (None, _) | (_, None) => true, _ => false, }; @@ -764,6 +765,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (&ty::Uint(ref exp), &ty::Uint(ref found)) => { let is_fallible = match (found.bit_width(), exp.bit_width()) { (Some(found), Some(exp)) if found > exp => true, + (None, Some(8 | 16)) | (Some(8 | 16), None) => false, (None, _) | (_, None) => true, _ => false, };