@@ -217,7 +217,11 @@ fn report_bin_hex_error(
217217 cx. struct_span_lint ( OVERFLOWING_LITERALS , expr. span , |lint| {
218218 let ( t, actually) = match ty {
219219 attr:: IntType :: SignedInt ( t) => {
220- let actually = size. sign_extend ( val) as i128 ;
220+ let actually = if negative {
221+ -( size. sign_extend ( val) as i128 )
222+ } else {
223+ size. sign_extend ( val) as i128
224+ } ;
221225 ( t. name_str ( ) , actually. to_string ( ) )
222226 }
223227 attr:: IntType :: UnsignedInt ( t) => {
@@ -226,11 +230,22 @@ fn report_bin_hex_error(
226230 }
227231 } ;
228232 let mut err = lint. build ( & format ! ( "literal out of range for `{}`" , t) ) ;
229- err. note ( & format ! (
230- "the literal `{}` (decimal `{}`) does not fit into \
231- the type `{}` and will become `{}{}`",
232- repr_str, val, t, actually, t
233- ) ) ;
233+ if negative {
234+ // If the value is negative,
235+ // emits a note about the value itself, apart from the literal.
236+ err. note ( & format ! (
237+ "the literal `{}` (decimal `{}`) does not fit into \
238+ the type `{}`",
239+ repr_str, val, t
240+ ) ) ;
241+ err. note ( & format ! ( "and the value `-{}` will become `{}{}`" , repr_str, actually, t) ) ;
242+ } else {
243+ err. note ( & format ! (
244+ "the literal `{}` (decimal `{}`) does not fit into \
245+ the type `{}` and will become `{}{}`",
246+ repr_str, val, t, actually, t
247+ ) ) ;
248+ }
234249 if let Some ( sugg_ty) =
235250 get_type_suggestion ( & cx. typeck_results ( ) . node_type ( expr. hir_id ) , val, negative)
236251 {
0 commit comments