Skip to content

Rollup of 9 pull requests #143254

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

Merged
merged 99 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
de5c506
update to literal-escaper 0.0.4 for better API without `unreachable` …
hkBst Mar 7, 2025
74e92a8
Format goto_type_definition
lnicola Jun 16, 2025
47b29ea
In "Wrap return type" assist, don't wrap exit points if they already …
ChayimFriedman2 Jun 22, 2025
a78bc7c
Don't run doctests
ChayimFriedman2 Jun 22, 2025
3db7cff
Preparing for merge from rust-lang/rust
lnicola Jun 23, 2025
3c4a690
Merge from rust-lang/rust
lnicola Jun 23, 2025
18855c9
Document sysroot_project field in rust-project.json
Wilfred Jun 23, 2025
4b37534
Merge pull request #20063 from lnicola/sync-from-rust
lnicola Jun 23, 2025
d0ebff0
fix: Fix cargo project manifest not pointing to the workspace root
Veykril Jun 23, 2025
6c3a870
Merge pull request #20069 from Veykril/push-mnqkqxomtlxn
Veykril Jun 23, 2025
b3c7913
fix: Use `ROOT` hygiene for `args` inside new `format_args!` expansion
ShoyuVanilla Jun 23, 2025
dd142e4
Merge pull request #20073 from ShoyuVanilla/fix-fmt-args-hygiene
ChayimFriedman2 Jun 23, 2025
c37994c
fix: Respect `.cargo/config.toml` `build.target-dir`
Veykril Jun 23, 2025
e40aa42
Add troubleshooting FAQ to the book
ChayimFriedman2 Jun 23, 2025
c751049
Merge pull request #20076 from ChayimFriedman2/faq
lnicola Jun 23, 2025
98e7b94
feat: Extend vscode 'run' command with optional mode argument for run…
markpots5 Jun 23, 2025
7ce7c2e
Merge pull request #20072 from Veykril/push-sorvvvzskywv
Veykril Jun 24, 2025
c30af1b
Merge pull request #20062 from ChayimFriedman2/doctests
Veykril Jun 24, 2025
1d3b517
Do not default to 'static for trait object lifetimes
Veykril Jun 18, 2025
bb164bf
Merge pull request #20036 from Veykril/push-yquvoyrxkksx
Veykril Jun 24, 2025
04c9089
Merge pull request #20064 from Wilfred/document_sysroot_project
Veykril Jun 24, 2025
e8388b0
Merge pull request #20061 from ChayimFriedman2/wrap-ret-ty
Veykril Jun 24, 2025
40aeda9
Cleanup `folding_ranges` and support more things
Veykril Jun 24, 2025
1fffcff
Merge pull request #20080 from Veykril/push-vnrwqppplykm
Veykril Jun 24, 2025
0b648f8
Merge pull request #20012 from lnicola/bump-literal-escaper
Veykril Jun 24, 2025
7eb776e
Remove special casing in command factory (revert changes in ctx.ts), …
markpots5 Jun 24, 2025
18e008b
ci: Fix cancel parallel jobs on windows
ShoyuVanilla Jun 24, 2025
8b52bab
Short circuit a couple hir-ty/lower queries
Veykril Jun 24, 2025
6968130
Merge pull request #20087 from Veykril/push-rrtkwpzmmwwz
Veykril Jun 24, 2025
abb956b
Fix link in the book
ChayimFriedman2 Jun 25, 2025
4e61517
Merge pull request #20089 from ChayimFriedman2/faq
ChayimFriedman2 Jun 25, 2025
19b1938
De-arc trait items query
Veykril Jun 24, 2025
d083ae8
Merge pull request #20084 from ShoyuVanilla/fix-windows-cancel-par
Veykril Jun 25, 2025
0876a56
Merge pull request #20077 from markpots5/master
Veykril Jun 25, 2025
ca062eb
Merge pull request #20088 from Veykril/push-qrslvzzlqqoz
Veykril Jun 25, 2025
7d6f77f
Drop rustc workspace loading error, if we don't needs its sources
Veykril Jun 25, 2025
cd4100d
Merge pull request #20092 from Veykril/push-kollxvpyknqs
Veykril Jun 25, 2025
a12b96f
Don't show notifications on failed rustfmt calls
lnicola Jun 25, 2025
a010990
Adjust minicore for Sized Hierarchy changes
Veykril Jun 25, 2025
889770a
Merge pull request #20096 from lnicola/silence-rustfmt-failed
Veykril Jun 25, 2025
587ded9
Unify formatting of progress messages
regexident Jun 25, 2025
ed5618f
minor: Decrease minimal toolchain version for `comp-time-deps` by `0.1`
ShoyuVanilla Jun 25, 2025
fb8ff25
Merge pull request #20098 from regexident/cleanup-progress-messages
davidbarsky Jun 25, 2025
3e5c46f
Merge pull request #20101 from ShoyuVanilla/comp-time-deps-sooner
lnicola Jun 26, 2025
62e112a
feat: highlighting of related return values while the cursor is on an…
roife Apr 9, 2025
4373a5d
refactor: improve macro handling in navigation for control-flow kws
roife Apr 9, 2025
7ab46b4
refactor: rename `branches` to `branch_exit_points` in highlight_related
roife Apr 15, 2025
bff9f4c
refactor: simplify functions related to branch_exit_points in highlig…
roife Apr 15, 2025
dc9e9fd
refactor: enhance highlighting for control flow kws in macros
roife Jun 26, 2025
54c14fc
Prettify AST in `PathTransform` if it's coming from a macro
ChayimFriedman2 Jun 26, 2025
a45726d
Merge pull request #19546 from roife/branch-value-highlights
Veykril Jun 26, 2025
0af0367
Cleanup `provideCodeActions` vscode hook
Veykril Jun 26, 2025
50a540c
Merge pull request #20104 from Veykril/push-nqnmmlvksyty
Veykril Jun 26, 2025
c190510
Parse new const trait syntax
Veykril Jun 26, 2025
4a50562
Merge pull request #20105 from Veykril/push-qtmwnuqvsruw
Veykril Jun 26, 2025
919e8ef
Salsa idiomize `VariantFields` query
Veykril Jun 26, 2025
d3b9969
Merge pull request #20103 from ChayimFriedman2/path-transform-prettify
Veykril Jun 26, 2025
e019a37
Bring back the firewall query
Veykril Jun 26, 2025
7f03278
Merge pull request #20106 from Veykril/push-pytuxksnntux
Veykril Jun 26, 2025
1bd7565
Backport new sized-hierarchy trait bounds in old ways
ShoyuVanilla Jun 25, 2025
1a2e7aa
Merge pull request #20100 from ShoyuVanilla/ignore-sized-hierarchy
ChayimFriedman2 Jun 26, 2025
5996241
Fix completion in when typing `integer.|`
ChayimFriedman2 Jun 26, 2025
502bac3
Merge pull request #20110 from ChayimFriedman2/ambiguous-float
Veykril Jun 27, 2025
ea2e042
ci: Cancel workflow only after the main matrix has finished
Veykril Jun 28, 2025
9cd5826
Merge pull request #20116 from Veykril/push-uypnmlyvotlm
Veykril Jun 28, 2025
0f93d8a
ci: Fix up release workflow
Veykril Jun 28, 2025
7d5579d
Merge pull request #20118 from Veykril/push-nolsxzxmykls
Veykril Jun 28, 2025
58dce8c
give Pointer::into_parts a more scary name and offer a safer alternative
RalfJung Jun 28, 2025
75c6e14
rename Pointer::from_addr_invalid to match strict provenance API
RalfJung Jun 28, 2025
0609735
Do not append `--compile-time-deps` to overwritten build script commands
Veykril Jun 29, 2025
638329b
Merge pull request #20121 from Veykril/push-vkkuutpsuypq
Veykril Jun 29, 2025
890f81b
Make combining LLD with external LLVM config a hard error
Kobzol Jun 29, 2025
1a8b6f5
Disable rust-lld in post-dist tests
Kobzol Jun 29, 2025
0cb0b22
Use `tracing-forest` instead of `tracing-tree` for bootstrap tracing
jieyouxu Jun 29, 2025
a203e41
Remove unnecessary parens in closure
chenyukang Jun 29, 2025
2a66a5b
Merge pull request #20122 from chenyukang/yukang-fix-remove-parens
ChayimFriedman2 Jun 29, 2025
25a6fd3
Augment the macro-stats test.
nnethercote Jun 30, 2025
e0761a5
Improve macro-stats printing.
nnethercote Jun 30, 2025
bc06bb1
Remove last use of `rustc_pat_analysis::Captures`
zachs18 Jun 30, 2025
863d0b5
Merge pull request #20124 from zachs18/patch-1
Veykril Jun 30, 2025
c3c995a
Handle build scripts better in `-Zmacro-stats` output.
nnethercote Jun 30, 2025
c8cef5b
Move some early config checks to the compiletest lib
jieyouxu Jun 30, 2025
f03074d
Move compiletest `main.rs` to `src/bin/`
jieyouxu Jun 30, 2025
e664e7e
Move `RUST_TEST_NOCAPTURE` warning to early config check
jieyouxu Jun 30, 2025
5cf2a50
Add change tracker entry
Kobzol Jun 30, 2025
3b5b350
Preparing for merge from rust-lang/rust
lnicola Jun 30, 2025
0edf572
Merge from rust-lang/rust
lnicola Jun 30, 2025
c5f4b80
Merge pull request #20128 from lnicola/sync-from-rust
lnicola Jun 30, 2025
26e1115
Update books
rustbot Jun 30, 2025
bb65bc8
Ensure -V --verbose processes both codegen_backend and codegen-backend
danielframpton Jun 25, 2025
8b8cd35
Rollup merge of #143019 - danielframpton:codegen-backend-parse, r=bjorn3
matthiaskrgr Jun 30, 2025
8292936
Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obk
matthiaskrgr Jun 30, 2025
1be0c62
Rollup merge of #143175 - Kobzol:bootstrap-lld-external-llvm-config, …
matthiaskrgr Jun 30, 2025
d3c02b4
Rollup merge of #143180 - jieyouxu:forest, r=Kobzol
matthiaskrgr Jun 30, 2025
172fc60
Rollup merge of #143223 - nnethercote:improve-macro-stats-printing, r…
matthiaskrgr Jun 30, 2025
f2231d5
Rollup merge of #143228 - nnethercote:macro-stats-build-scripts, r=Ko…
matthiaskrgr Jun 30, 2025
8156725
Rollup merge of #143229 - jieyouxu:compiletest-maintenance-1, r=Kobzol
matthiaskrgr Jun 30, 2025
6d41b34
Rollup merge of #143246 - lnicola:sync-from-ra, r=lnicola
matthiaskrgr Jun 30, 2025
3f6dc54
Rollup merge of #143248 - rustbot:docs-update, r=ehuss
matthiaskrgr Jun 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub(crate) fn codegen_const_value<'tcx>(
}
}
Scalar::Ptr(ptr, _size) => {
let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative
let (prov, offset) = ptr.prov_and_relative_offset();
let alloc_id = prov.alloc_id();
let base_addr = match fx.tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
}
}
Scalar::Ptr(ptr, _size) => {
let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative
let (prov, offset) = ptr.prov_and_relative_offset();
let alloc_id = prov.alloc_id();
let base_addr = match self.tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
}
}
Scalar::Ptr(ptr, _size) => {
let (prov, offset) = ptr.into_parts();
let (prov, offset) = ptr.prov_and_relative_offset();
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
let base_addr = match global_alloc {
GlobalAlloc::Memory(alloc) => {
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ pub(super) fn op_to_const<'tcx>(

match immediate {
Left(ref mplace) => {
// We know `offset` is relative to the allocation, so we can use `into_parts`.
let (prov, offset) = mplace.ptr().into_parts();
let alloc_id = prov.expect("cannot have `fake` place for non-ZST type").alloc_id();
let (prov, offset) =
mplace.ptr().into_pointer_or_addr().unwrap().prov_and_relative_offset();
let alloc_id = prov.alloc_id();
ConstValue::Indirect { alloc_id, offset }
}
// see comment on `let force_as_immediate` above
Expand All @@ -232,9 +232,10 @@ pub(super) fn op_to_const<'tcx>(
imm.layout.ty,
);
let msg = "`op_to_const` on an immediate scalar pair must only be used on slice references to the beginning of an actual allocation";
// We know `offset` is relative to the allocation, so we can use `into_parts`.
let (prov, offset) = a.to_pointer(ecx).expect(msg).into_parts();
let alloc_id = prov.expect(msg).alloc_id();
let ptr = a.to_pointer(ecx).expect(msg);
let (prov, offset) =
ptr.into_pointer_or_addr().expect(msg).prov_and_relative_offset();
let alloc_id = prov.alloc_id();
let data = ecx.tcx.global_alloc(alloc_id).unwrap_memory();
assert!(offset == abi::Size::ZERO, "{}", msg);
let meta = b.to_target_usize(ecx).expect(msg);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
if addr != 0 {
diag.arg(
"pointer",
Pointer::<Option<CtfeProvenance>>::from_addr_invalid(addr).to_string(),
Pointer::<Option<CtfeProvenance>>::without_provenance(addr).to_string(),
);
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
// Allow these casts, but make the pointer not dereferenceable.
// (I.e., they behave like transmutation.)
// This is correct because no pointers can ever be exposed in compile-time evaluation.
interp_ok(Pointer::from_addr_invalid(addr))
interp_ok(Pointer::without_provenance(addr))
}

#[inline(always)]
Expand All @@ -756,8 +756,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
ptr: Pointer<CtfeProvenance>,
_size: i64,
) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
// We know `offset` is relative to the allocation, so we can use `into_parts`.
let (prov, offset) = ptr.into_parts();
let (prov, offset) = ptr.prov_and_relative_offset();
Some((prov.alloc_id(), offset, prov.immutable()))
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
Some((alloc_id, offset, extra)) => Ok((alloc_id, offset, extra)),
None => {
assert!(M::Provenance::OFFSET_IS_ADDR);
let (_, addr) = ptr.into_parts();
// Offset is absolute, as we just asserted.
let (_, addr) = ptr.into_raw_parts();
Err(addr.bytes())
}
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'tcx, Prov: Provenance> MPlaceTy<'tcx, Prov> {
pub fn fake_alloc_zst(layout: TyAndLayout<'tcx>) -> Self {
assert!(layout.is_zst());
let align = layout.align.abi;
let ptr = Pointer::from_addr_invalid(align.bytes()); // no provenance, absolute address
let ptr = Pointer::without_provenance(align.bytes()); // no provenance, absolute address
MPlaceTy { mplace: MemPlace { ptr, meta: MemPlaceMeta::None, misaligned: None }, layout }
}

Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
Ub(DanglingIntPointer { addr: i, .. }) => DanglingPtrNoProvenance {
ptr_kind,
// FIXME this says "null pointer" when null but we need translate
pointer: format!("{}", Pointer::<Option<AllocId>>::from_addr_invalid(i))
pointer: format!("{}", Pointer::<Option<AllocId>>::without_provenance(i))
},
Ub(PointerOutOfBounds { .. }) => DanglingPtrOutOfBounds {
ptr_kind
Expand Down Expand Up @@ -868,7 +868,9 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
fn add_data_range(&mut self, ptr: Pointer<Option<M::Provenance>>, size: Size) {
if let Some(data_bytes) = self.data_bytes.as_mut() {
// We only have to store the offset, the rest is the same for all pointers here.
let (_prov, offset) = ptr.into_parts();
// The logic is agnostic to wether the offset is relative or absolute as long as
// it is consistent.
let (_prov, offset) = ptr.into_raw_parts();
// Add this.
data_bytes.add_range(offset, size);
};
Expand All @@ -894,7 +896,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
.as_mplace_or_imm()
.expect_left("place must be in memory")
.ptr();
let (_prov, offset) = ptr.into_parts();
let (_prov, offset) = ptr.into_raw_parts();
offset
}

Expand All @@ -903,7 +905,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
// Our value must be in memory, otherwise we would not have set up `data_bytes`.
let mplace = self.ecx.force_allocation(place)?;
// Determine starting offset and size.
let (_prov, start_offset) = mplace.ptr().into_parts();
let (_prov, start_offset) = mplace.ptr().into_raw_parts();
let (size, _align) = self
.ecx
.size_and_align_of_val(&mplace)?
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,9 @@ fn get_backend_from_raw_matches(
matches: &Matches,
) -> Box<dyn CodegenBackend> {
let debug_flags = matches.opt_strs("Z");
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
let backend_name = debug_flags
.iter()
.find_map(|x| x.strip_prefix("codegen-backend=").or(x.strip_prefix("codegen_backend=")));
let target = parse_target_triple(early_dcx, matches);
let sysroot = Sysroot::new(matches.opt_str("sysroot").map(PathBuf::from));
let target = config::build_target_config(early_dcx, &target, sysroot.path());
Expand Down
34 changes: 27 additions & 7 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ fn configure_and_expand(
fn print_macro_stats(ecx: &ExtCtxt<'_>) {
use std::fmt::Write;

let crate_name = ecx.ecfg.crate_name.as_str();
let crate_name = if crate_name == "build_script_build" {
// This is a build script. Get the package name from the environment.
let pkg_name =
std::env::var("CARGO_PKG_NAME").unwrap_or_else(|_| "<unknown crate>".to_string());
format!("{pkg_name} build script")
} else {
crate_name.to_string()
};

// No instability because we immediately sort the produced vector.
#[allow(rustc::potential_query_instability)]
let mut macro_stats: Vec<_> = ecx
Expand Down Expand Up @@ -327,7 +337,7 @@ fn print_macro_stats(ecx: &ExtCtxt<'_>) {
// non-interleaving, though.
let mut s = String::new();
_ = writeln!(s, "{prefix} {}", "=".repeat(banner_w));
_ = writeln!(s, "{prefix} MACRO EXPANSION STATS: {}", ecx.ecfg.crate_name);
_ = writeln!(s, "{prefix} MACRO EXPANSION STATS: {}", crate_name);
_ = writeln!(
s,
"{prefix} {:<name_w$}{:>uses_w$}{:>lines_w$}{:>avg_lines_w$}{:>bytes_w$}{:>avg_bytes_w$}",
Expand All @@ -341,20 +351,30 @@ fn print_macro_stats(ecx: &ExtCtxt<'_>) {
}
for (bytes, lines, uses, name, kind) in macro_stats {
let mut name = ExpnKind::Macro(kind, *name).descr();
let uses_with_underscores = thousands::usize_with_underscores(uses);
let avg_lines = lines as f64 / uses as f64;
let avg_bytes = bytes as f64 / uses as f64;
if name.len() >= name_w {
// If the name is long, print it on a line by itself, then
// set the name to empty and print things normally, to show the
// stats on the next line.

// Ensure the "Macro Name" and "Uses" columns are as compact as possible.
let mut uses_w = uses_w;
if name.len() + uses_with_underscores.len() >= name_w + uses_w {
// The name would abut or overlap the uses value. Print the name
// on a line by itself, then set the name to empty and print things
// normally, to show the stats on the next line.
_ = writeln!(s, "{prefix} {:<name_w$}", name);
name = String::new();
}
} else if name.len() >= name_w {
// The name won't abut or overlap with the uses value, but it does
// overlap with the empty part of the uses column. Shrink the width
// of the uses column to account for the excess name length.
uses_w = uses_with_underscores.len() + 1
};

_ = writeln!(
s,
"{prefix} {:<name_w$}{:>uses_w$}{:>lines_w$}{:>avg_lines_w$}{:>bytes_w$}{:>avg_bytes_w$}",
name,
thousands::usize_with_underscores(uses),
uses_with_underscores,
thousands::usize_with_underscores(lines),
thousands::f64p1_with_underscores(avg_lines),
thousands::usize_with_underscores(bytes),
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ impl<'tcx> ConstValue<'tcx> {
return Some(&[]);
}
// Non-empty slice, must have memory. We know this is a relative pointer.
let (inner_prov, offset) = ptr.into_parts();
let data = tcx.global_alloc(inner_prov?.alloc_id()).unwrap_memory();
let (inner_prov, offset) =
ptr.into_pointer_or_addr().ok()?.prov_and_relative_offset();
let data = tcx.global_alloc(inner_prov.alloc_id()).unwrap_memory();
(data, offset.bytes(), offset.bytes() + len)
}
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl Allocation {
let ptr_bytes = &mut bytes[idx..idx + ptr_size];
let bits = read_target_uint(endian, ptr_bytes).unwrap();
let (ptr_prov, ptr_offset) =
adjust_ptr(Pointer::new(alloc_id, Size::from_bytes(bits)))?.into_parts();
adjust_ptr(Pointer::new(alloc_id, Size::from_bytes(bits)))?.into_raw_parts();
write_target_uint(endian, ptr_bytes, ptr_offset.bytes().into()).unwrap();
new_provenance.push((offset, ptr_prov));
}
Expand Down Expand Up @@ -769,7 +769,7 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
// as-is into memory. This also double-checks that `val.size()` matches `range.size`.
let (bytes, provenance) = match val.to_bits_or_ptr_internal(range.size)? {
Right(ptr) => {
let (provenance, offset) = ptr.into_parts();
let (provenance, offset) = ptr.into_raw_parts();
(u128::from(offset.bytes()), Some(provenance))
}
Left(data) => (data, None),
Expand Down
25 changes: 16 additions & 9 deletions compiler/rustc_middle/src/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl From<CtfeProvenance> for Pointer {
impl<Prov> From<Pointer<Prov>> for Pointer<Option<Prov>> {
#[inline(always)]
fn from(ptr: Pointer<Prov>) -> Self {
let (prov, offset) = ptr.into_parts();
let (prov, offset) = ptr.into_raw_parts();
Pointer::new(Some(prov), offset)
}
}
Expand All @@ -314,19 +314,17 @@ impl<Prov> Pointer<Option<Prov>> {
assert!(Prov::OFFSET_IS_ADDR);
self.offset
}
}

impl<Prov> Pointer<Option<Prov>> {
/// Creates a pointer to the given address, with invalid provenance (i.e., cannot be used for
/// any memory access).
#[inline(always)]
pub fn from_addr_invalid(addr: u64) -> Self {
pub fn without_provenance(addr: u64) -> Self {
Pointer { provenance: None, offset: Size::from_bytes(addr) }
}

#[inline(always)]
pub fn null() -> Self {
Pointer::from_addr_invalid(0)
Pointer::without_provenance(0)
}
}

Expand All @@ -336,11 +334,11 @@ impl<Prov> Pointer<Prov> {
Pointer { provenance, offset }
}

/// Obtain the constituents of this pointer. Not that the meaning of the offset depends on the type `Prov`!
/// This function must only be used in the implementation of `Machine::ptr_get_alloc`,
/// and when a `Pointer` is taken apart to be stored efficiently in an `Allocation`.
/// Obtain the constituents of this pointer. Note that the meaning of the offset depends on the
/// type `Prov`! This is a low-level function that should only be used when absolutely
/// necessary. Prefer `prov_and_relative_offset` if possible.
#[inline(always)]
pub fn into_parts(self) -> (Prov, Size) {
pub fn into_raw_parts(self) -> (Prov, Size) {
(self.provenance, self.offset)
}

Expand All @@ -361,3 +359,12 @@ impl<Prov> Pointer<Prov> {
self.wrapping_offset(Size::from_bytes(i as u64), cx)
}
}

impl Pointer<CtfeProvenance> {
/// Return the provenance and relative offset stored in this pointer. Safer alternative to
/// `into_raw_parts` since the type ensures that the offset is indeed relative.
#[inline(always)]
pub fn prov_and_relative_offset(self) -> (CtfeProvenance, Size) {
(self.provenance, self.offset)
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<Prov> Scalar<Prov> {
/// Create a Scalar from a pointer with an `Option<_>` provenance (where `None` represents a
/// plain integer / "invalid" pointer).
pub fn from_maybe_pointer(ptr: Pointer<Option<Prov>>, cx: &impl HasDataLayout) -> Self {
match ptr.into_parts() {
match ptr.into_raw_parts() {
(Some(prov), offset) => Scalar::from_pointer(Pointer::new(prov, offset), cx),
(None, offset) => {
Scalar::Int(ScalarInt::try_from_uint(offset.bytes(), cx.pointer_size()).unwrap())
Expand Down Expand Up @@ -276,7 +276,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
Right(ptr) => interp_ok(ptr.into()),
Left(bits) => {
let addr = u64::try_from(bits).unwrap();
interp_ok(Pointer::from_addr_invalid(addr))
interp_ok(Pointer::without_provenance(addr))
}
}
}
Expand All @@ -299,7 +299,7 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> {
Ok(ScalarInt::try_from_uint(ptr.offset.bytes(), Size::from_bytes(sz)).unwrap())
} else {
// We know `offset` is relative, since `OFFSET_IS_ADDR == false`.
let (prov, offset) = ptr.into_parts();
let (prov, offset) = ptr.into_raw_parts();
// Because `OFFSET_IS_ADDR == false`, this unwrap can never fail.
Err(Scalar::Ptr(Pointer::new(prov.get_alloc_id().unwrap(), offset), sz))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
) -> Result<(), PrintError> {
define_scoped_cx!(self);

let (prov, offset) = ptr.into_parts();
let (prov, offset) = ptr.prov_and_relative_offset();
match ty.kind() {
// Byte strings (&[u8; N])
ty::Ref(_, inner, _) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ fn op_to_prop_const<'tcx>(
}

let pointer = mplace.ptr().into_pointer_or_addr().ok()?;
let (prov, offset) = pointer.into_parts();
let (prov, offset) = pointer.prov_and_relative_offset();
let alloc_id = prov.alloc_id();
intern_const_alloc_for_constprop(ecx, alloc_id).discard_err()?;

Expand Down
Loading
Loading