Skip to content

Commit 5da76ee

Browse files
committed
Auto merge of #95711 - Dylan-DPC:rollup-ujss3oi, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #95659 (Rely on #[link] attribute for unwind on Fuchsia.) - #95684 (rustdoc: Fix item info display overflow) - #95693 (interp: pass TyCtxt to Machine methods that do not take InterpCx) - #95699 (fix: Vec leak when capacity is 0) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 26b5e0c + b452749 commit 5da76ee

File tree

11 files changed

+57
-12
lines changed

11 files changed

+57
-12
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_hir::def::DefKind;
22
use rustc_middle::mir;
3-
use rustc_middle::ty::{self, Ty};
3+
use rustc_middle::ty::{self, Ty, TyCtxt};
44
use std::borrow::Borrow;
55
use std::collections::hash_map::Entry;
66
use std::hash::Hash;
@@ -471,6 +471,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
471471
}
472472

473473
fn before_access_global(
474+
_tcx: TyCtxt<'tcx>,
474475
machine: &Self,
475476
alloc_id: AllocId,
476477
alloc: ConstAllocation<'tcx>,

compiler/rustc_const_eval/src/interpret/machine.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt::Debug;
77
use std::hash::Hash;
88

99
use rustc_middle::mir;
10-
use rustc_middle::ty::{self, Ty};
10+
use rustc_middle::ty::{self, Ty, TyCtxt};
1111
use rustc_span::def_id::DefId;
1212
use rustc_target::abi::Size;
1313
use rustc_target::spec::abi::Abi;
@@ -246,6 +246,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
246246
/// `def_id` is `Some` if this is the "lazy" allocation of a static.
247247
#[inline]
248248
fn before_access_global(
249+
_tcx: TyCtxt<'tcx>,
249250
_machine: &Self,
250251
_alloc_id: AllocId,
251252
_allocation: ConstAllocation<'tcx>,
@@ -317,6 +318,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
317318
/// need to mutate.
318319
#[inline(always)]
319320
fn memory_read(
321+
_tcx: TyCtxt<'tcx>,
320322
_machine: &Self,
321323
_alloc_extra: &Self::AllocExtra,
322324
_tag: Self::PointerTag,
@@ -328,6 +330,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
328330
/// Hook for performing extra checks on a memory write access.
329331
#[inline(always)]
330332
fn memory_written(
333+
_tcx: TyCtxt<'tcx>,
331334
_machine: &mut Self,
332335
_alloc_extra: &mut Self::AllocExtra,
333336
_tag: Self::PointerTag,
@@ -339,6 +342,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
339342
/// Hook for performing extra operations on a memory deallocation.
340343
#[inline(always)]
341344
fn memory_deallocated(
345+
_tcx: TyCtxt<'tcx>,
342346
_machine: &mut Self,
343347
_alloc_extra: &mut Self::AllocExtra,
344348
_tag: Self::PointerTag,

compiler/rustc_const_eval/src/interpret/memory.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
327327
// Let the machine take some extra action
328328
let size = alloc.size();
329329
M::memory_deallocated(
330+
*self.tcx,
330331
&mut self.machine,
331332
&mut alloc.extra,
332333
ptr.provenance,
@@ -509,7 +510,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
509510
(self.tcx.eval_static_initializer(def_id)?, Some(def_id))
510511
}
511512
};
512-
M::before_access_global(&self.machine, id, alloc, def_id, is_write)?;
513+
M::before_access_global(*self.tcx, &self.machine, id, alloc, def_id, is_write)?;
513514
// We got tcx memory. Let the machine initialize its "extra" stuff.
514515
let alloc = M::init_allocation_extra(
515516
self,
@@ -575,7 +576,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
575576
)?;
576577
if let Some((alloc_id, offset, ptr, alloc)) = ptr_and_alloc {
577578
let range = alloc_range(offset, size);
578-
M::memory_read(&self.machine, &alloc.extra, ptr.provenance, range)?;
579+
M::memory_read(*self.tcx, &self.machine, &alloc.extra, ptr.provenance, range)?;
579580
Ok(Some(AllocRef { alloc, range, tcx: *self.tcx, alloc_id }))
580581
} else {
581582
// Even in this branch we have to be sure that we actually access the allocation, in
@@ -636,7 +637,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
636637
// We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`.
637638
let (alloc, machine) = self.get_alloc_raw_mut(alloc_id)?;
638639
let range = alloc_range(offset, size);
639-
M::memory_written(machine, &mut alloc.extra, ptr.provenance, range)?;
640+
M::memory_written(tcx, machine, &mut alloc.extra, ptr.provenance, range)?;
640641
Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id }))
641642
} else {
642643
Ok(None)
@@ -1009,7 +1010,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10091010
};
10101011
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
10111012
let src_range = alloc_range(src_offset, size);
1012-
M::memory_read(&self.machine, &src_alloc.extra, src.provenance, src_range)?;
1013+
M::memory_read(*tcx, &self.machine, &src_alloc.extra, src.provenance, src_range)?;
10131014
// We need the `dest` ptr for the next operation, so we get it now.
10141015
// We already did the source checks and called the hooks so we are good to return early.
10151016
let Some((dest_alloc_id, dest_offset, dest)) = dest_parts else {
@@ -1034,7 +1035,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10341035
// Destination alloc preparations and access hooks.
10351036
let (dest_alloc, extra) = self.get_alloc_raw_mut(dest_alloc_id)?;
10361037
let dest_range = alloc_range(dest_offset, size * num_copies);
1037-
M::memory_written(extra, &mut dest_alloc.extra, dest.provenance, dest_range)?;
1038+
M::memory_written(*tcx, extra, &mut dest_alloc.extra, dest.provenance, dest_range)?;
10381039
let dest_bytes = dest_alloc
10391040
.get_bytes_mut_ptr(&tcx, dest_range)
10401041
.map_err(|e| e.to_interp_error(dest_alloc_id))?

compiler/rustc_mir_transform/src/const_prop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
265265
}
266266

267267
fn before_access_global(
268+
_tcx: TyCtxt<'tcx>,
268269
_machine: &Self,
269270
_alloc_id: AllocId,
270271
alloc: ConstAllocation<'tcx, Self::PointerTag, Self::AllocExtra>,

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
261261
}
262262

263263
fn before_access_global(
264+
_tcx: TyCtxt<'tcx>,
264265
_machine: &Self,
265266
_alloc_id: AllocId,
266267
alloc: ConstAllocation<'tcx, Self::PointerTag, Self::AllocExtra>,

library/alloc/src/raw_vec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ impl<T, A: Allocator> RawVec<T, A> {
168168

169169
#[cfg(not(no_global_oom_handling))]
170170
fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
171-
if mem::size_of::<T>() == 0 {
171+
// Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
172+
if mem::size_of::<T>() == 0 || capacity == 0 {
172173
Self::new_in(alloc)
173174
} else {
174175
// We avoid `unwrap_or_else` here because it bloats the amount of

library/unwind/build.rs

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ fn main() {
4040
// This is handled in the target spec with late_link_args_[static|dynamic]
4141
} else if target.contains("uwp-windows-gnu") {
4242
println!("cargo:rustc-link-lib=unwind");
43-
} else if target.contains("fuchsia") {
44-
println!("cargo:rustc-link-lib=unwind");
4543
} else if target.contains("haiku") {
4644
println!("cargo:rustc-link-lib=gcc_s");
4745
} else if target.contains("redox") {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.4
1+
0.8.5

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ pub(crate) fn render_impl_summary(
17721772
let is_trait = i.inner_impl().trait_.is_some();
17731773
if is_trait {
17741774
if let Some(portability) = portability(&i.impl_item, Some(parent)) {
1775-
write!(w, "<span class=\"item-info\">{}</span>", portability);
1775+
write!(w, "<div class=\"item-info\">{}</div>", portability);
17761776
}
17771777
}
17781778

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This test ensures that the "item-info" elements don't overflow.
2+
goto: file://|DOC_PATH|/lib2/struct.LongItemInfo.html
3+
// We set a fixed size so there is no chance of "random" resize.
4+
size: (1200, 870)
5+
// Logically, the "item-decl" and the "item-info" should have the same scroll width.
6+
compare-elements-property: (".docblock.item-decl", ".item-info", ["scrollWidth"])
7+
assert-property: (".item-info", {"scrollWidth": "890"})
8+
// Just to be sure we're comparing the correct "item-info":
9+
assert-text: (
10+
".item-info",
11+
"This is supported on Android or Linux or Emscripten or DragonFly BSD",
12+
STARTS_WITH,
13+
)
14+
15+
// Checking the "item-info" on an impl block as well:
16+
goto: file://|DOC_PATH|/lib2/struct.LongItemInfo2.html
17+
compare-elements-property: (
18+
"#impl-SimpleTrait .item-info",
19+
"#impl-SimpleTrait + .docblock",
20+
["scrollWidth"],
21+
)
22+
assert-property: ("#impl-SimpleTrait .item-info", {"scrollWidth": "866"})
23+
// Just to be sure we're comparing the correct "item-info":
24+
assert-text: (
25+
"#impl-SimpleTrait .item-info",
26+
"This is supported on Android or Linux or Emscripten or DragonFly BSD",
27+
STARTS_WITH,
28+
)

src/test/rustdoc-gui/src/lib2/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@ pub struct HasALongTraitWithParams {}
120120
pub trait LongTraitWithParamsBananaBananaBanana<T> {}
121121

122122
impl LongTraitWithParamsBananaBananaBanana<usize> for HasALongTraitWithParams {}
123+
124+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
125+
pub struct LongItemInfo;
126+
127+
pub trait SimpleTrait {}
128+
pub struct LongItemInfo2;
129+
130+
/// Some docs.
131+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "emscripten", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
132+
impl SimpleTrait for LongItemInfo2 {}

0 commit comments

Comments
 (0)