X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_lint%2Fsrc%2Ftypes.rs;h=d9f4da23d2f865fb8115c5583f2f2b4b66217cc0;hb=d00ca112020680928aadb221aad13bd52634823b;hp=38c71e6e9258973a3b05ac33278f74ae13bb3c3d;hpb=828461b4b27c4a955587887936e54057efc5e2c1;p=rust.git diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 38c71e6e925..d9f4da23d2f 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -331,18 +331,23 @@ fn lint_int_literal<'tcx>( } cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| { - lint.build(&format!("literal out of range for `{}`", t.name_str())) - .note(&format!( - "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`", - cx.sess() - .source_map() - .span_to_snippet(lit.span) - .expect("must get snippet from literal"), - t.name_str(), - min, - max, - )) - .emit(); + let mut err = lint.build(&format!("literal out of range for `{}`", t.name_str())); + err.note(&format!( + "the literal `{}` does not fit into the type `{}` whose range is `{}..={}`", + cx.sess() + .source_map() + .span_to_snippet(lit.span) + .expect("must get snippet from literal"), + t.name_str(), + min, + max, + )); + if let Some(sugg_ty) = + get_type_suggestion(&cx.typeck_results().node_type(e.hir_id), v, negative) + { + err.help(&format!("consider using `{}` instead", sugg_ty)); + } + err.emit(); }); } } @@ -1131,7 +1136,7 @@ fn emit_ffi_unsafe_type_lint( fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool { struct ProhibitOpaqueTypes<'a, 'tcx> { cx: &'a LateContext<'tcx>, - }; + } impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> { type BreakTy = Ty<'tcx>;