1
Fork 0
rust/compiler/rustc_lint/src
Matthias Krüger 8f9ccc5d1b
Rollup merge of #135249 - s-cerevisiae:fix-overflowing-literals-help, r=chenyukang
Fix overflows in the implementation of `overflowing_literals` lint's help

This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases.

1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes #135248)
2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes #131849)

Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
2025-01-16 17:00:46 +01:00
..
early Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
nonstandard_style
types Suggest the smallest fitting type instead 2025-01-12 20:20:39 +08:00
async_closures.rs Stabilize async closures 2024-12-13 00:04:56 +00:00
async_fn_in_trait.rs nightly feature tracking: get rid of the per-feature bool fields 2024-10-23 09:14:41 +01:00
builtin.rs Rollup merge of #135269 - estebank:unneeded-into, r=compiler-errors 2025-01-09 09:05:10 +01:00
context.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
dangling.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
default_could_be_derived.rs Provide structured suggestion for impl Default of type where all fields have defaults 2024-12-31 18:06:01 +00:00
deref_into_dyn_supertrait.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
drop_forget_useless.rs remove Ty::is_copy_modulo_regions 2024-12-02 13:57:56 +01:00
early.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
enum_intrinsics_non_enums.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
errors.rs Add warn(unreachable_pub) to rustc_lint. 2024-08-27 15:24:11 +10:00
expect.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
for_loops_over_fallibles.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
foreign_modules.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
hidden_unicode_codepoints.rs Account for format_args in HiddenUnicodeCodepoints lint 2024-12-31 05:03:22 +00:00
if_let_rescope.rs Use links to edition guide for edition migrations 2024-12-15 20:28:16 -08:00
impl_trait_overcaptures.rs Make sure to mark IMPL_TRAIT_REDUNDANT_CAPTURES as Allow in edition 2024 2025-01-13 16:41:01 +00:00
internal.rs Merge some patterns together 2024-12-18 10:21:20 +00:00
invalid_from_utf8.rs Remove extern crate rustc_session from rustc_lint. 2024-04-29 13:57:41 +10:00
late.rs Do not filter empty passes & Make CTFE Clippy into lintless pass 2024-11-05 15:27:09 +01:00
let_underscore.rs use TypingEnv when no infcx is available 2024-11-18 10:38:56 +01:00
levels.rs Rollup merge of #134481 - estebank:unstable-lint-span, r=compiler-errors 2024-12-18 21:38:11 -05:00
lib.rs Implement default_overrides_default_fields lint 2024-12-25 23:25:45 +00:00
lints.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
macro_expr_fragment_specifier_2024_migration.rs Rename RefTokenTreeCursor. 2024-12-18 10:39:07 +11:00
map_unit_fn.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
multiple_supertrait_upcastable.rs Compiler: Rename "object safe" to "dyn compatible" 2024-09-25 13:26:48 +02:00
non_ascii_idents.rs Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu 2024-12-18 02:56:38 +00:00
non_fmt_panic.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
non_local_def.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
nonstandard_style.rs Avoid naming variables str 2025-01-07 14:30:02 +02:00
noop_method_call.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
opaque_hidden_inferred_bound.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
pass_by_value.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
passes.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
precedence.rs Temporarily switch ambiguous_negative_literals lint to allow 2024-07-31 19:36:47 +02:00
ptr_nulls.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
redundant_semicolon.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
reference_casting.rs move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
shadowed_into_iter.rs Use links to edition guide for edition migrations 2024-12-15 20:28:16 -08:00
static_mut_refs.rs Fix #131977 parens mangled in shared mut static lint suggestion 2024-10-24 03:34:37 +00:00
tests.rs update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
traits.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
types.rs turn hir::ItemKind::Fn into a named-field variant 2025-01-04 11:35:31 +01:00
unit_bindings.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
unqualified_local_imports.rs Update unstable lint docs to include required feature attributes 2025-01-12 19:31:05 +05:30
unused.rs Rename PatKind::Lit to Expr 2025-01-08 07:34:59 +00:00