Skip to content

Commit 28e8f01

Browse files
committed
Auto merge of rust-lang#130483 - matthiaskrgr:rollup-q1r0g0y, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#129477 (Fix fluent diagnostics) - rust-lang#129674 (Add new_cyclic_in for Rc and Arc) - rust-lang#130452 (Update Trusty target maintainers) - rust-lang#130467 (Miri subtree update) - rust-lang#130477 (Revert rust-lang#129749 to fix segfault in LLVM) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f609b7e + f8090dd commit 28e8f01

File tree

752 files changed

+2927
-2691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

752 files changed

+2927
-2691
lines changed

Cargo.lock

+13-45
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ dependencies = [
104104
"unicode-width",
105105
]
106106

107-
[[package]]
108-
name = "ansi_term"
109-
version = "0.12.1"
110-
source = "registry+https://github.com/rust-lang/crates.io-index"
111-
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
112-
dependencies = [
113-
"winapi",
114-
]
115-
116107
[[package]]
117108
name = "anstream"
118109
version = "0.6.15"
@@ -714,7 +705,7 @@ dependencies = [
714705
"miow",
715706
"miropt-test-tools",
716707
"regex",
717-
"rustfix 0.8.1",
708+
"rustfix",
718709
"serde",
719710
"serde_json",
720711
"tracing",
@@ -2278,7 +2269,7 @@ dependencies = [
22782269
"rustc_version",
22792270
"smallvec",
22802271
"tempfile",
2281-
"ui_test 0.21.2",
2272+
"ui_test 0.26.5",
22822273
"windows-sys 0.52.0",
22832274
]
22842275

@@ -2807,16 +2798,6 @@ version = "0.1.1"
28072798
source = "registry+https://github.com/rust-lang/crates.io-index"
28082799
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
28092800

2810-
[[package]]
2811-
name = "prettydiff"
2812-
version = "0.6.4"
2813-
source = "registry+https://github.com/rust-lang/crates.io-index"
2814-
checksum = "8ff1fec61082821f8236cf6c0c14e8172b62ce8a72a0eedc30d3b247bb68dc11"
2815-
dependencies = [
2816-
"ansi_term",
2817-
"pad",
2818-
]
2819-
28202801
[[package]]
28212802
name = "prettydiff"
28222803
version = "0.7.0"
@@ -4625,18 +4606,6 @@ dependencies = [
46254606
"rustdoc",
46264607
]
46274608

4628-
[[package]]
4629-
name = "rustfix"
4630-
version = "0.6.1"
4631-
source = "registry+https://github.com/rust-lang/crates.io-index"
4632-
checksum = "ecd2853d9e26988467753bd9912c3a126f642d05d229a4b53f5752ee36c56481"
4633-
dependencies = [
4634-
"anyhow",
4635-
"log",
4636-
"serde",
4637-
"serde_json",
4638-
]
4639-
46404609
[[package]]
46414610
name = "rustfix"
46424611
version = "0.8.1"
@@ -5518,36 +5487,36 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
55185487

55195488
[[package]]
55205489
name = "ui_test"
5521-
version = "0.21.2"
5490+
version = "0.25.0"
55225491
source = "registry+https://github.com/rust-lang/crates.io-index"
5523-
checksum = "aaf4bf7c184b8dfc7a4d3b90df789b1eb992ee42811cd115f32a7a1eb781058d"
5492+
checksum = "f7e4f339f62edc873975c47115f9e71c5454ddaa37c1142b42fc0b2672c8dacb"
55245493
dependencies = [
5525-
"annotate-snippets 0.9.2",
5494+
"annotate-snippets 0.11.4",
55265495
"anyhow",
55275496
"bstr",
55285497
"cargo-platform",
5529-
"cargo_metadata 0.15.4",
5498+
"cargo_metadata 0.18.1",
55305499
"color-eyre",
55315500
"colored",
55325501
"comma",
55335502
"crossbeam-channel",
55345503
"indicatif",
55355504
"lazy_static",
55365505
"levenshtein",
5537-
"prettydiff 0.6.4",
5506+
"prettydiff",
55385507
"regex",
55395508
"rustc_version",
5540-
"rustfix 0.6.1",
5509+
"rustfix",
55415510
"serde",
55425511
"serde_json",
5543-
"tempfile",
5512+
"spanned",
55445513
]
55455514

55465515
[[package]]
55475516
name = "ui_test"
5548-
version = "0.25.0"
5517+
version = "0.26.5"
55495518
source = "registry+https://github.com/rust-lang/crates.io-index"
5550-
checksum = "f7e4f339f62edc873975c47115f9e71c5454ddaa37c1142b42fc0b2672c8dacb"
5519+
checksum = "32ee4c40e5a5f9fa6864ff976473e5d6a6e9884b6ce68b40690d9f87e1994c83"
55515520
dependencies = [
55525521
"annotate-snippets 0.11.4",
55535522
"anyhow",
@@ -5559,12 +5528,11 @@ dependencies = [
55595528
"comma",
55605529
"crossbeam-channel",
55615530
"indicatif",
5562-
"lazy_static",
55635531
"levenshtein",
5564-
"prettydiff 0.7.0",
5532+
"prettydiff",
55655533
"regex",
55665534
"rustc_version",
5567-
"rustfix 0.8.1",
5535+
"rustfix",
55685536
"serde",
55695537
"serde_json",
55705538
"spanned",

compiler/rustc_fluent_macro/src/fluent.rs

-17
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
138138
// with a lowercase as rustc errors do.
139139
err.replace_range(0..1, &err.chars().next().unwrap().to_lowercase().to_string());
140140

141-
let line_starts: Vec<usize> = std::iter::once(0)
142-
.chain(
143-
this.source()
144-
.char_indices()
145-
.filter_map(|(i, c)| Some(i + 1).filter(|_| c == '\n')),
146-
)
147-
.collect();
148-
let line_start = line_starts
149-
.iter()
150-
.enumerate()
151-
.map(|(line, idx)| (line + 1, idx))
152-
.filter(|(_, idx)| **idx <= pos.start)
153-
.last()
154-
.unwrap()
155-
.0;
156-
157141
let message = annotate_snippets::Level::Error.title(&err).snippet(
158142
Snippet::source(this.source())
159-
.line_start(line_start)
160143
.origin(&relative_ftl_path)
161144
.fold(true)
162145
.annotation(annotate_snippets::Level::Error.span(pos.start..pos.end - 1)),

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,7 @@ struct LLVMRustThinLTOData {
12111211
// Not 100% sure what these are, but they impact what's internalized and
12121212
// what's inlined across modules, I believe.
12131213
#if LLVM_VERSION_GE(18, 0)
1214-
#if LLVM_VERSION_GE(20, 0)
1215-
FunctionImporter::ImportListsTy ImportLists;
1216-
#else
12171214
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
1218-
#endif
12191215
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
12201216
DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
12211217
#else
@@ -1424,13 +1420,13 @@ LLVMRustPrepareThinLTOInternalize(const LLVMRustThinLTOData *Data,
14241420
return true;
14251421
}
14261422

1427-
extern "C" bool LLVMRustPrepareThinLTOImport(LLVMRustThinLTOData *Data,
1423+
extern "C" bool LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data,
14281424
LLVMModuleRef M,
14291425
LLVMTargetMachineRef TM) {
14301426
Module &Mod = *unwrap(M);
14311427
TargetMachine &Target = *unwrap(TM);
14321428

1433-
const auto &ImportList = Data->ImportLists[Mod.getModuleIdentifier()];
1429+
const auto &ImportList = Data->ImportLists.lookup(Mod.getModuleIdentifier());
14341430
auto Loader = [&](StringRef Identifier) {
14351431
const auto &Memory = Data->ModuleMap.lookup(Identifier);
14361432
auto &Context = Mod.getContext();
@@ -1613,7 +1609,7 @@ extern "C" void LLVMRustComputeLTOCacheKey(RustStringRef KeyOut,
16131609
LLVMRustThinLTOData *Data) {
16141610
SmallString<40> Key;
16151611
llvm::lto::Config conf;
1616-
const auto &ImportList = Data->ImportLists[ModId];
1612+
const auto &ImportList = Data->ImportLists.lookup(ModId);
16171613
const auto &ExportList = Data->ExportLists.lookup(ModId);
16181614
const auto &ResolvedODR = Data->ResolvedODR.lookup(ModId);
16191615
const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(ModId);

library/alloc/src/rc.rs

+79-36
Original file line numberDiff line numberDiff line change
@@ -460,42 +460,7 @@ impl<T> Rc<T> {
460460
where
461461
F: FnOnce(&Weak<T>) -> T,
462462
{
463-
// Construct the inner in the "uninitialized" state with a single
464-
// weak reference.
465-
let uninit_ptr: NonNull<_> = Box::leak(Box::new(RcBox {
466-
strong: Cell::new(0),
467-
weak: Cell::new(1),
468-
value: mem::MaybeUninit::<T>::uninit(),
469-
}))
470-
.into();
471-
472-
let init_ptr: NonNull<RcBox<T>> = uninit_ptr.cast();
473-
474-
let weak = Weak { ptr: init_ptr, alloc: Global };
475-
476-
// It's important we don't give up ownership of the weak pointer, or
477-
// else the memory might be freed by the time `data_fn` returns. If
478-
// we really wanted to pass ownership, we could create an additional
479-
// weak pointer for ourselves, but this would result in additional
480-
// updates to the weak reference count which might not be necessary
481-
// otherwise.
482-
let data = data_fn(&weak);
483-
484-
let strong = unsafe {
485-
let inner = init_ptr.as_ptr();
486-
ptr::write(ptr::addr_of_mut!((*inner).value), data);
487-
488-
let prev_value = (*inner).strong.get();
489-
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
490-
(*inner).strong.set(1);
491-
492-
Rc::from_inner(init_ptr)
493-
};
494-
495-
// Strong references should collectively own a shared weak reference,
496-
// so don't run the destructor for our old weak reference.
497-
mem::forget(weak);
498-
strong
463+
Self::new_cyclic_in(data_fn, Global)
499464
}
500465

501466
/// Constructs a new `Rc` with uninitialized contents.
@@ -762,6 +727,84 @@ impl<T, A: Allocator> Rc<T, A> {
762727
}
763728
}
764729

730+
/// Constructs a new `Rc<T, A>` in the given allocator while giving you a `Weak<T, A>` to the allocation,
731+
/// to allow you to construct a `T` which holds a weak pointer to itself.
732+
///
733+
/// Generally, a structure circularly referencing itself, either directly or
734+
/// indirectly, should not hold a strong reference to itself to prevent a memory leak.
735+
/// Using this function, you get access to the weak pointer during the
736+
/// initialization of `T`, before the `Rc<T, A>` is created, such that you can
737+
/// clone and store it inside the `T`.
738+
///
739+
/// `new_cyclic_in` first allocates the managed allocation for the `Rc<T, A>`,
740+
/// then calls your closure, giving it a `Weak<T, A>` to this allocation,
741+
/// and only afterwards completes the construction of the `Rc<T, A>` by placing
742+
/// the `T` returned from your closure into the allocation.
743+
///
744+
/// Since the new `Rc<T, A>` is not fully-constructed until `Rc<T, A>::new_cyclic_in`
745+
/// returns, calling [`upgrade`] on the weak reference inside your closure will
746+
/// fail and result in a `None` value.
747+
///
748+
/// # Panics
749+
///
750+
/// If `data_fn` panics, the panic is propagated to the caller, and the
751+
/// temporary [`Weak<T, A>`] is dropped normally.
752+
///
753+
/// # Examples
754+
///
755+
/// See [`new_cyclic`].
756+
///
757+
/// [`new_cyclic`]: Rc::new_cyclic
758+
/// [`upgrade`]: Weak::upgrade
759+
#[cfg(not(no_global_oom_handling))]
760+
#[unstable(feature = "allocator_api", issue = "32838")]
761+
pub fn new_cyclic_in<F>(data_fn: F, alloc: A) -> Rc<T, A>
762+
where
763+
F: FnOnce(&Weak<T, A>) -> T,
764+
{
765+
// Construct the inner in the "uninitialized" state with a single
766+
// weak reference.
767+
let (uninit_raw_ptr, alloc) = Box::into_raw_with_allocator(Box::new_in(
768+
RcBox {
769+
strong: Cell::new(0),
770+
weak: Cell::new(1),
771+
value: mem::MaybeUninit::<T>::uninit(),
772+
},
773+
alloc,
774+
));
775+
let uninit_ptr: NonNull<_> = (unsafe { &mut *uninit_raw_ptr }).into();
776+
let init_ptr: NonNull<RcBox<T>> = uninit_ptr.cast();
777+
778+
let weak = Weak { ptr: init_ptr, alloc: alloc };
779+
780+
// It's important we don't give up ownership of the weak pointer, or
781+
// else the memory might be freed by the time `data_fn` returns. If
782+
// we really wanted to pass ownership, we could create an additional
783+
// weak pointer for ourselves, but this would result in additional
784+
// updates to the weak reference count which might not be necessary
785+
// otherwise.
786+
let data = data_fn(&weak);
787+
788+
let strong = unsafe {
789+
let inner = init_ptr.as_ptr();
790+
ptr::write(ptr::addr_of_mut!((*inner).value), data);
791+
792+
let prev_value = (*inner).strong.get();
793+
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
794+
(*inner).strong.set(1);
795+
796+
// Strong references should collectively own a shared weak reference,
797+
// so don't run the destructor for our old weak reference.
798+
// Calling into_raw_with_allocator has the double effect of giving us back the allocator,
799+
// and forgetting the weak reference.
800+
let alloc = weak.into_raw_with_allocator().1;
801+
802+
Rc::from_inner_in(init_ptr, alloc)
803+
};
804+
805+
strong
806+
}
807+
765808
/// Constructs a new `Rc<T>` in the provided allocator, returning an error if the allocation
766809
/// fails
767810
///

0 commit comments

Comments
 (0)