diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-28 23:10:37 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-28 23:10:37 +1000 |
| commit | 72727b165400fcb003631a4d20b70e11e8e8c42f (patch) | |
| tree | 1b30de71acc88c83a1b2fa90cc7cc5782b8232d7 /compiler/rustc_lint | |
| parent | f6c56bcd66ebf0bfcb65ddd696c7e88210c38f00 (diff) | |
| parent | a8c837e7ffc6b559987c8fc71581ded676cf29f3 (diff) | |
| download | rust-72727b165400fcb003631a4d20b70e11e8e8c42f.tar.gz rust-72727b165400fcb003631a4d20b70e11e8e8c42f.zip | |
Rollup merge of #145941 - Urgau:int_to_ptr_transmutes-unsized, r=lcnr
Disable `integer_to_ptr_transmutes` suggestion for unsized types This PR disables the machine-applicable `integer_to_ptr_transmutes` lint suggestion for unsized types, as [`std::ptr::with_exposed_provenance`](https://doc.rust-lang.org/std/ptr/fn.with_exposed_provenance.html) requires sized types. We should probably mention [`std::ptr::from_raw_parts`](https://doc.rust-lang.org/std/ptr/fn.from_raw_parts.html) when it becomes stable. Related to https://github.com/rust-lang/rust/issues/145935
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/lints.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/transmute.rs | 30 |
2 files changed, 19 insertions, 13 deletions
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 426500dda4a..56d65ed08f9 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1554,7 +1554,7 @@ impl<'a> LintDiagnostic<'a, ()> for DropGlue<'_> { #[help(lint_help_exposed_provenance)] pub(crate) struct IntegerToPtrTransmutes<'tcx> { #[subdiagnostic] - pub suggestion: IntegerToPtrTransmutesSuggestion<'tcx>, + pub suggestion: Option<IntegerToPtrTransmutesSuggestion<'tcx>>, } #[derive(Subdiagnostic)] diff --git a/compiler/rustc_lint/src/transmute.rs b/compiler/rustc_lint/src/transmute.rs index 239c8649041..98510eea73b 100644 --- a/compiler/rustc_lint/src/transmute.rs +++ b/compiler/rustc_lint/src/transmute.rs @@ -169,19 +169,25 @@ fn check_int_to_ptr_transmute<'tcx>( expr.hir_id, expr.span, IntegerToPtrTransmutes { - suggestion: if dst.is_ref() { - IntegerToPtrTransmutesSuggestion::ToRef { - dst: *inner_ty, - suffix, - ref_mutbl: mutbl.prefix_str(), - start_call: expr.span.shrink_to_lo().until(arg.span), - } + suggestion: if layout_inner_ty.is_sized() { + Some(if dst.is_ref() { + IntegerToPtrTransmutesSuggestion::ToRef { + dst: *inner_ty, + suffix, + ref_mutbl: mutbl.prefix_str(), + start_call: expr.span.shrink_to_lo().until(arg.span), + } + } else { + IntegerToPtrTransmutesSuggestion::ToPtr { + dst: *inner_ty, + suffix, + start_call: expr.span.shrink_to_lo().until(arg.span), + } + }) } else { - IntegerToPtrTransmutesSuggestion::ToPtr { - dst: *inner_ty, - suffix, - start_call: expr.span.shrink_to_lo().until(arg.span), - } + // We can't suggest using `with_exposed_provenance` for unsized type + // so don't suggest anything. + None }, }, ); |
