Skip to content

Commit 1670ff6

Browse files
committed
Auto merge of #118473 - matthiaskrgr:rollup-q96bm3u, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #118452 (rustdoc-search: allow spaces around `::` in path query) - #118453 (Tweak message on ADT with private fields building) - #118456 (rustc_span: Remove unused symbols.) - #118458 (rustdoc: remove small from `small-section-header`) - #118464 (Dispose llvm::TargetMachines prior to llvm::Context being disposed) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c52b876 + 640a431 commit 1670ff6

33 files changed

+188
-154
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::ffi::{CStr, CString};
2525
use std::fs::File;
2626
use std::io;
2727
use std::iter;
28+
use std::mem::ManuallyDrop;
2829
use std::path::Path;
2930
use std::slice;
3031
use std::sync::Arc;
@@ -734,7 +735,7 @@ pub unsafe fn optimize_thin_module(
734735
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
735736
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
736737
let mut module = ModuleCodegen {
737-
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
738+
module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) },
738739
name: thin_module.name().to_string(),
739740
kind: ModuleKind::Regular,
740741
};

compiler/rustc_codegen_llvm/src/lib.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use rustc_span::symbol::Symbol;
5252
use std::any::Any;
5353
use std::ffi::CStr;
5454
use std::io::Write;
55+
use std::mem::ManuallyDrop;
5556

5657
mod back {
5758
pub mod archive;
@@ -407,8 +408,9 @@ pub struct ModuleLlvm {
407408
llcx: &'static mut llvm::Context,
408409
llmod_raw: *const llvm::Module,
409410

410-
// independent from llcx and llmod_raw, resources get disposed by drop impl
411-
tm: OwnedTargetMachine,
411+
// This field is `ManuallyDrop` because it is important that the `TargetMachine`
412+
// is disposed prior to the `Context` being disposed otherwise UAFs can occur.
413+
tm: ManuallyDrop<OwnedTargetMachine>,
412414
}
413415

414416
unsafe impl Send for ModuleLlvm {}
@@ -419,15 +421,23 @@ impl ModuleLlvm {
419421
unsafe {
420422
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
421423
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
422-
ModuleLlvm { llmod_raw, llcx, tm: create_target_machine(tcx, mod_name) }
424+
ModuleLlvm {
425+
llmod_raw,
426+
llcx,
427+
tm: ManuallyDrop::new(create_target_machine(tcx, mod_name)),
428+
}
423429
}
424430
}
425431

426432
fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
427433
unsafe {
428434
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
429435
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
430-
ModuleLlvm { llmod_raw, llcx, tm: create_informational_target_machine(tcx.sess) }
436+
ModuleLlvm {
437+
llmod_raw,
438+
llcx,
439+
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess)),
440+
}
431441
}
432442
}
433443

@@ -448,7 +458,7 @@ impl ModuleLlvm {
448458
}
449459
};
450460

451-
Ok(ModuleLlvm { llmod_raw, llcx, tm })
461+
Ok(ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) })
452462
}
453463
}
454464

@@ -460,6 +470,7 @@ impl ModuleLlvm {
460470
impl Drop for ModuleLlvm {
461471
fn drop(&mut self) {
462472
unsafe {
473+
ManuallyDrop::drop(&mut self.tm);
463474
llvm::LLVMContextDispose(&mut *(self.llcx as *mut _));
464475
}
465476
}

compiler/rustc_hir_typeck/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20902090
[] => unreachable!(),
20912091
};
20922092
err.note(format!(
2093-
"... and other private field{s} {names}that {were} not provided",
2093+
"{}private field{s} {names}that {were} not provided",
2094+
if used_fields.is_empty() { "" } else { "...and other " },
20942095
s = pluralize!(remaining_private_fields_len),
20952096
were = pluralize!("was", remaining_private_fields_len),
20962097
));

compiler/rustc_span/src/symbol.rs

-27
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,11 @@ symbols! {
128128
AcqRel,
129129
Acquire,
130130
AddToDiagnostic,
131-
Alignment,
132131
Any,
133132
Arc,
134133
ArcWeak,
135134
Argument,
136135
ArgumentMethods,
137-
Arguments,
138136
ArrayIntoIter,
139137
AsMut,
140138
AsRef,
@@ -164,7 +162,6 @@ symbols! {
164162
Break,
165163
C,
166164
CStr,
167-
CString,
168165
Capture,
169166
Center,
170167
Cleanup,
@@ -174,7 +171,6 @@ symbols! {
174171
Context,
175172
Continue,
176173
Copy,
177-
Count,
178174
Cow,
179175
Debug,
180176
DebugStruct,
@@ -199,7 +195,6 @@ symbols! {
199195
Fn,
200196
FnMut,
201197
FnOnce,
202-
FormatSpec,
203198
Formatter,
204199
From,
205200
FromIterator,
@@ -208,8 +203,6 @@ symbols! {
208203
FsPermissions,
209204
Future,
210205
FutureOutput,
211-
FxHashMap,
212-
FxHashSet,
213206
GlobalAlloc,
214207
Hash,
215208
HashMap,
@@ -253,7 +246,6 @@ symbols! {
253246
NonZeroI32,
254247
NonZeroI64,
255248
NonZeroI8,
256-
NonZeroIsize,
257249
NonZeroU128,
258250
NonZeroU16,
259251
NonZeroU32,
@@ -275,7 +267,6 @@ symbols! {
275267
Path,
276268
PathBuf,
277269
Pending,
278-
Pin,
279270
Pointer,
280271
Poll,
281272
ProcMacro,
@@ -333,7 +324,6 @@ symbols! {
333324
TyCtxt,
334325
TyKind,
335326
Unknown,
336-
UnsafeArg,
337327
Vec,
338328
VecDeque,
339329
Wrapper,
@@ -389,7 +379,6 @@ symbols! {
389379
allow_fail,
390380
allow_internal_unsafe,
391381
allow_internal_unstable,
392-
allowed,
393382
alu32,
394383
always,
395384
and,
@@ -405,8 +394,6 @@ symbols! {
405394
arm,
406395
arm_target_feature,
407396
array,
408-
arrays,
409-
as_mut_ptr,
410397
as_ptr,
411398
as_ref,
412399
as_str,
@@ -589,7 +576,6 @@ symbols! {
589576
const_try,
590577
constant,
591578
constructor,
592-
context,
593579
convert_identity,
594580
copy,
595581
copy_closures,
@@ -776,8 +762,6 @@ symbols! {
776762
field,
777763
field_init_shorthand,
778764
file,
779-
fill,
780-
flags,
781765
float,
782766
float_to_int_unchecked,
783767
floorf32,
@@ -1059,7 +1043,6 @@ symbols! {
10591043
mir_unwind_unreachable,
10601044
mir_variant,
10611045
miri,
1062-
misc,
10631046
mmx_reg,
10641047
modifiers,
10651048
module,
@@ -1157,9 +1140,7 @@ symbols! {
11571140
omit_gdb_pretty_printer_section,
11581141
on,
11591142
on_unimplemented,
1160-
oom,
11611143
opaque,
1162-
ops,
11631144
opt_out_copy,
11641145
optimize,
11651146
optimize_attribute,
@@ -1217,7 +1198,6 @@ symbols! {
12171198
pointer,
12181199
pointer_like,
12191200
poll,
1220-
position,
12211201
post_dash_lto: "post-lto",
12221202
powerpc_target_feature,
12231203
powf32,
@@ -1226,7 +1206,6 @@ symbols! {
12261206
powif64,
12271207
pre_dash_lto: "pre-lto",
12281208
precise_pointer_size_matching,
1229-
precision,
12301209
pref_align_of,
12311210
prefetch_read_data,
12321211
prefetch_read_instruction,
@@ -1236,7 +1215,6 @@ symbols! {
12361215
prelude,
12371216
prelude_import,
12381217
preserves_flags,
1239-
primitive,
12401218
print_macro,
12411219
println_macro,
12421220
proc_dash_macro: "proc-macro",
@@ -1260,7 +1238,6 @@ symbols! {
12601238
ptr_const_is_null,
12611239
ptr_copy,
12621240
ptr_copy_nonoverlapping,
1263-
ptr_drop_in_place,
12641241
ptr_eq,
12651242
ptr_from_ref,
12661243
ptr_guaranteed_cmp,
@@ -1622,7 +1599,6 @@ symbols! {
16221599
structural_match,
16231600
structural_peq,
16241601
structural_teq,
1625-
sty,
16261602
sub,
16271603
sub_assign,
16281604
sub_with_overflow,
@@ -1744,7 +1720,6 @@ symbols! {
17441720
unrestricted_attribute_tokens,
17451721
unsafe_block_in_unsafe_fn,
17461722
unsafe_cell,
1747-
unsafe_cell_from_mut,
17481723
unsafe_cell_raw_get,
17491724
unsafe_no_drop_flag,
17501725
unsafe_pin_internals,
@@ -1769,7 +1744,6 @@ symbols! {
17691744
used_with_arg,
17701745
using,
17711746
usize,
1772-
v1,
17731747
va_arg,
17741748
va_copy,
17751749
va_end,
@@ -1801,7 +1775,6 @@ symbols! {
18011775
wasm_import_module,
18021776
wasm_target_feature,
18031777
while_let,
1804-
width,
18051778
windows,
18061779
windows_subsystem,
18071780
with_negative_coherence,

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ impl<'a> AssocItemLink<'a> {
11451145
fn write_impl_section_heading(mut w: impl fmt::Write, title: &str, id: &str) {
11461146
write!(
11471147
w,
1148-
"<h2 id=\"{id}\" class=\"small-section-header\">\
1148+
"<h2 id=\"{id}\" class=\"section-header\">\
11491149
{title}\
11501150
<a href=\"#{id}\" class=\"anchor\">§</a>\
11511151
</h2>"

src/librustdoc/html/render/print_item.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
430430
last_section = Some(my_section);
431431
write!(
432432
w,
433-
"<h2 id=\"{id}\" class=\"small-section-header\">\
433+
"<h2 id=\"{id}\" class=\"section-header\">\
434434
<a href=\"#{id}\">{name}</a>\
435435
</h2>{ITEM_TABLE_OPEN}",
436436
id = cx.derive_id(my_section.id()),
@@ -827,7 +827,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
827827
fn write_small_section_header(w: &mut Buffer, id: &str, title: &str, extra_content: &str) {
828828
write!(
829829
w,
830-
"<h2 id=\"{0}\" class=\"small-section-header\">\
830+
"<h2 id=\"{0}\" class=\"section-header\">\
831831
{1}<a href=\"#{0}\" class=\"anchor\">§</a>\
832832
</h2>{2}",
833833
id, title, extra_content
@@ -1260,7 +1260,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
12601260
if let Some(inner_type) = &t.inner_type {
12611261
write!(
12621262
w,
1263-
"<h2 id=\"aliased-type\" class=\"small-section-header\">\
1263+
"<h2 id=\"aliased-type\" class=\"section-header\">\
12641264
Aliased Type<a href=\"#aliased-type\" class=\"anchor\">§</a></h2>"
12651265
);
12661266

@@ -1685,7 +1685,7 @@ fn item_variants(
16851685
let tcx = cx.tcx();
16861686
write!(
16871687
w,
1688-
"<h2 id=\"variants\" class=\"variants small-section-header\">\
1688+
"<h2 id=\"variants\" class=\"variants section-header\">\
16891689
Variants{}<a href=\"#variants\" class=\"anchor\">§</a>\
16901690
</h2>\
16911691
{}\
@@ -1772,7 +1772,7 @@ fn item_variants(
17721772
write!(
17731773
w,
17741774
"<div class=\"sub-variant-field\">\
1775-
<span id=\"{id}\" class=\"small-section-header\">\
1775+
<span id=\"{id}\" class=\"section-header\">\
17761776
<a href=\"#{id}\" class=\"anchor field\">§</a>\
17771777
<code>{f}: {t}</code>\
17781778
</span>",
@@ -1929,7 +1929,7 @@ fn item_fields(
19291929
if fields.peek().is_some() {
19301930
write!(
19311931
w,
1932-
"<h2 id=\"fields\" class=\"fields small-section-header\">\
1932+
"<h2 id=\"fields\" class=\"fields section-header\">\
19331933
{}{}<a href=\"#fields\" class=\"anchor\">§</a>\
19341934
</h2>\
19351935
{}",
@@ -1943,7 +1943,7 @@ fn item_fields(
19431943
let id = cx.derive_id(format!("{typ}.{field_name}", typ = ItemType::StructField));
19441944
write!(
19451945
w,
1946-
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
1946+
"<span id=\"{id}\" class=\"{item_type} section-header\">\
19471947
<a href=\"#{id}\" class=\"anchor field\">§</a>\
19481948
<code>{field_name}: {ty}</code>\
19491949
</span>",

src/librustdoc/html/static/css/rustdoc.css

+5-5
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ ul.all-items {
205205

206206
#toggle-all-docs,
207207
a.anchor,
208-
.small-section-header a,
208+
.section-header a,
209209
#src-sidebar a,
210210
.rust a,
211211
.sidebar h2 a,
@@ -742,13 +742,13 @@ nav.sub {
742742
margin: 0 0 15px 0;
743743
}
744744

745-
.small-section-header {
745+
.section-header {
746746
/* fields use <span> tags, but should get their own lines */
747747
display: block;
748748
position: relative;
749749
}
750750

751-
.small-section-header:hover > .anchor, .impl:hover > .anchor,
751+
.section-header:hover > .anchor, .impl:hover > .anchor,
752752
.trait-impl:hover > .anchor, .variant:hover > .anchor {
753753
display: initial;
754754
}
@@ -761,11 +761,11 @@ nav.sub {
761761
.anchor.field {
762762
left: -5px;
763763
}
764-
.small-section-header > .anchor {
764+
.section-header > .anchor {
765765
left: -15px;
766766
padding-right: 8px;
767767
}
768-
h2.small-section-header > .anchor {
768+
h2.section-header > .anchor {
769769
padding-right: 6px;
770770
}
771771

0 commit comments

Comments
 (0)