-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Start using pattern types in libcore #136006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ use rustc_abi::FieldIdx; | |
| use rustc_middle::mir::visit::MutVisitor; | ||
| use rustc_middle::mir::*; | ||
| use rustc_middle::span_bug; | ||
| use rustc_middle::ty::{self, Ty, TyCtxt}; | ||
| use rustc_middle::ty::{self, PatternKind, Ty, TyCtxt}; | ||
|
|
||
| use crate::patch::MirPatch; | ||
|
|
||
|
|
@@ -137,8 +137,10 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs { | |
| build_ptr_tys(tcx, boxed_ty, unique_def, nonnull_def); | ||
|
|
||
| new_projections.extend_from_slice(&build_projection(unique_ty, nonnull_ty)); | ||
| // While we can't project into `NonNull<_>` in a basic block | ||
| // due to MCP#807, this is debug info where it's fine. | ||
| // While we can't project into a pattern type in a basic block, | ||
| // this is debug info where it's fine. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "it's fine" because the pattern type is erased in the debug info?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because debug info has no UB, we can just do whatever works instead of having to worry about soundness |
||
| let pat_ty = Ty::new_pat(tcx, ptr_ty, tcx.mk_pat(PatternKind::NotNull)); | ||
| new_projections.push(PlaceElem::Field(FieldIdx::ZERO, pat_ty)); | ||
| new_projections.push(PlaceElem::Field(FieldIdx::ZERO, ptr_ty)); | ||
| new_projections.push(PlaceElem::Deref); | ||
| } else if let Some(new_projections) = new_projections.as_mut() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,13 +70,10 @@ use crate::{fmt, hash, intrinsics, mem, ptr}; | |
| /// [null pointer optimization]: crate::option#representation | ||
| #[stable(feature = "nonnull", since = "1.25.0")] | ||
| #[repr(transparent)] | ||
| #[rustc_layout_scalar_valid_range_start(1)] | ||
| #[rustc_nonnull_optimization_guaranteed] | ||
| #[rustc_diagnostic_item = "NonNull"] | ||
| pub struct NonNull<T: PointeeSized> { | ||
| // Remember to use `.as_ptr()` instead of `.pointer`, as field projecting to | ||
| // this is banned by <https://github.com/rust-lang/compiler-team/issues/807>. | ||
| pointer: *const T, | ||
| pointer: crate::pattern_type!(*const T is !null), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm excited to do this, but it feels odd to me to have both Would it maybe be feasible to split this to have zero library changes, just enough new test coverage to justify the compiler updates, then a follow-up no-compiler-review-needed change to the library part?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I guess the box elaboration needs to be in the same PR as the library change, doesn't it :/
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea... I can land some changes ahead of time, but I can only test them with a custom minicore
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gave this another try, I should be able to hit the cg_ssa changes with a test written on rustc today, but I'm missing some necessary component to actually go down this path. I tried https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=72f945c494a52dbb039b2aff32453d41 (and we already have a test that this is a permutation of: https://github.com/rust-lang/rust/blob/main/tests/ui/type/pattern_types/unsize.rs |
||
| } | ||
|
|
||
| /// `NonNull` pointers are not `Send` because the data they reference may be aliased. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.