Skip to content

Commit

Permalink
Auto merge of #118473 - matthiaskrgr:rollup-q96bm3u, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 30, 2023
2 parents c52b876 + 640a431 commit 1670ff6
Show file tree
Hide file tree
Showing 33 changed files with 188 additions and 154 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::ffi::{CStr, CString};
use std::fs::File;
use std::io;
use std::iter;
use std::mem::ManuallyDrop;
use std::path::Path;
use std::slice;
use std::sync::Arc;
Expand Down Expand Up @@ -734,7 +735,7 @@ pub unsafe fn optimize_thin_module(
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
let mut module = ModuleCodegen {
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) },
name: thin_module.name().to_string(),
kind: ModuleKind::Regular,
};
Expand Down
21 changes: 16 additions & 5 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use rustc_span::symbol::Symbol;
use std::any::Any;
use std::ffi::CStr;
use std::io::Write;
use std::mem::ManuallyDrop;

mod back {
pub mod archive;
Expand Down Expand Up @@ -407,8 +408,9 @@ pub struct ModuleLlvm {
llcx: &'static mut llvm::Context,
llmod_raw: *const llvm::Module,

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

unsafe impl Send for ModuleLlvm {}
Expand All @@ -419,15 +421,23 @@ impl ModuleLlvm {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm { llmod_raw, llcx, tm: create_target_machine(tcx, mod_name) }
ModuleLlvm {
llmod_raw,
llcx,
tm: ManuallyDrop::new(create_target_machine(tcx, mod_name)),
}
}
}

fn new_metadata(tcx: TyCtxt<'_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm { llmod_raw, llcx, tm: create_informational_target_machine(tcx.sess) }
ModuleLlvm {
llmod_raw,
llcx,
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess)),
}
}
}

Expand All @@ -448,7 +458,7 @@ impl ModuleLlvm {
}
};

Ok(ModuleLlvm { llmod_raw, llcx, tm })
Ok(ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) })
}
}

Expand All @@ -460,6 +470,7 @@ impl ModuleLlvm {
impl Drop for ModuleLlvm {
fn drop(&mut self) {
unsafe {
ManuallyDrop::drop(&mut self.tm);
llvm::LLVMContextDispose(&mut *(self.llcx as *mut _));
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
[] => unreachable!(),
};
err.note(format!(
"... and other private field{s} {names}that {were} not provided",
"{}private field{s} {names}that {were} not provided",
if used_fields.is_empty() { "" } else { "...and other " },
s = pluralize!(remaining_private_fields_len),
were = pluralize!("was", remaining_private_fields_len),
));
Expand Down
27 changes: 0 additions & 27 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ symbols! {
AcqRel,
Acquire,
AddToDiagnostic,
Alignment,
Any,
Arc,
ArcWeak,
Argument,
ArgumentMethods,
Arguments,
ArrayIntoIter,
AsMut,
AsRef,
Expand Down Expand Up @@ -164,7 +162,6 @@ symbols! {
Break,
C,
CStr,
CString,
Capture,
Center,
Cleanup,
Expand All @@ -174,7 +171,6 @@ symbols! {
Context,
Continue,
Copy,
Count,
Cow,
Debug,
DebugStruct,
Expand All @@ -199,7 +195,6 @@ symbols! {
Fn,
FnMut,
FnOnce,
FormatSpec,
Formatter,
From,
FromIterator,
Expand All @@ -208,8 +203,6 @@ symbols! {
FsPermissions,
Future,
FutureOutput,
FxHashMap,
FxHashSet,
GlobalAlloc,
Hash,
HashMap,
Expand Down Expand Up @@ -253,7 +246,6 @@ symbols! {
NonZeroI32,
NonZeroI64,
NonZeroI8,
NonZeroIsize,
NonZeroU128,
NonZeroU16,
NonZeroU32,
Expand All @@ -275,7 +267,6 @@ symbols! {
Path,
PathBuf,
Pending,
Pin,
Pointer,
Poll,
ProcMacro,
Expand Down Expand Up @@ -333,7 +324,6 @@ symbols! {
TyCtxt,
TyKind,
Unknown,
UnsafeArg,
Vec,
VecDeque,
Wrapper,
Expand Down Expand Up @@ -389,7 +379,6 @@ symbols! {
allow_fail,
allow_internal_unsafe,
allow_internal_unstable,
allowed,
alu32,
always,
and,
Expand All @@ -405,8 +394,6 @@ symbols! {
arm,
arm_target_feature,
array,
arrays,
as_mut_ptr,
as_ptr,
as_ref,
as_str,
Expand Down Expand Up @@ -589,7 +576,6 @@ symbols! {
const_try,
constant,
constructor,
context,
convert_identity,
copy,
copy_closures,
Expand Down Expand Up @@ -776,8 +762,6 @@ symbols! {
field,
field_init_shorthand,
file,
fill,
flags,
float,
float_to_int_unchecked,
floorf32,
Expand Down Expand Up @@ -1059,7 +1043,6 @@ symbols! {
mir_unwind_unreachable,
mir_variant,
miri,
misc,
mmx_reg,
modifiers,
module,
Expand Down Expand Up @@ -1157,9 +1140,7 @@ symbols! {
omit_gdb_pretty_printer_section,
on,
on_unimplemented,
oom,
opaque,
ops,
opt_out_copy,
optimize,
optimize_attribute,
Expand Down Expand Up @@ -1217,7 +1198,6 @@ symbols! {
pointer,
pointer_like,
poll,
position,
post_dash_lto: "post-lto",
powerpc_target_feature,
powf32,
Expand All @@ -1226,7 +1206,6 @@ symbols! {
powif64,
pre_dash_lto: "pre-lto",
precise_pointer_size_matching,
precision,
pref_align_of,
prefetch_read_data,
prefetch_read_instruction,
Expand All @@ -1236,7 +1215,6 @@ symbols! {
prelude,
prelude_import,
preserves_flags,
primitive,
print_macro,
println_macro,
proc_dash_macro: "proc-macro",
Expand All @@ -1260,7 +1238,6 @@ symbols! {
ptr_const_is_null,
ptr_copy,
ptr_copy_nonoverlapping,
ptr_drop_in_place,
ptr_eq,
ptr_from_ref,
ptr_guaranteed_cmp,
Expand Down Expand Up @@ -1622,7 +1599,6 @@ symbols! {
structural_match,
structural_peq,
structural_teq,
sty,
sub,
sub_assign,
sub_with_overflow,
Expand Down Expand Up @@ -1744,7 +1720,6 @@ symbols! {
unrestricted_attribute_tokens,
unsafe_block_in_unsafe_fn,
unsafe_cell,
unsafe_cell_from_mut,
unsafe_cell_raw_get,
unsafe_no_drop_flag,
unsafe_pin_internals,
Expand All @@ -1769,7 +1744,6 @@ symbols! {
used_with_arg,
using,
usize,
v1,
va_arg,
va_copy,
va_end,
Expand Down Expand Up @@ -1801,7 +1775,6 @@ symbols! {
wasm_import_module,
wasm_target_feature,
while_let,
width,
windows,
windows_subsystem,
with_negative_coherence,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl<'a> AssocItemLink<'a> {
fn write_impl_section_heading(mut w: impl fmt::Write, title: &str, id: &str) {
write!(
w,
"<h2 id=\"{id}\" class=\"small-section-header\">\
"<h2 id=\"{id}\" class=\"section-header\">\
{title}\
<a href=\"#{id}\" class=\"anchor\">§</a>\
</h2>"
Expand Down
14 changes: 7 additions & 7 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
last_section = Some(my_section);
write!(
w,
"<h2 id=\"{id}\" class=\"small-section-header\">\
"<h2 id=\"{id}\" class=\"section-header\">\
<a href=\"#{id}\">{name}</a>\
</h2>{ITEM_TABLE_OPEN}",
id = cx.derive_id(my_section.id()),
Expand Down Expand Up @@ -827,7 +827,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
fn write_small_section_header(w: &mut Buffer, id: &str, title: &str, extra_content: &str) {
write!(
w,
"<h2 id=\"{0}\" class=\"small-section-header\">\
"<h2 id=\"{0}\" class=\"section-header\">\
{1}<a href=\"#{0}\" class=\"anchor\">§</a>\
</h2>{2}",
id, title, extra_content
Expand Down Expand Up @@ -1260,7 +1260,7 @@ fn item_type_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &c
if let Some(inner_type) = &t.inner_type {
write!(
w,
"<h2 id=\"aliased-type\" class=\"small-section-header\">\
"<h2 id=\"aliased-type\" class=\"section-header\">\
Aliased Type<a href=\"#aliased-type\" class=\"anchor\">§</a></h2>"
);

Expand Down Expand Up @@ -1685,7 +1685,7 @@ fn item_variants(
let tcx = cx.tcx();
write!(
w,
"<h2 id=\"variants\" class=\"variants small-section-header\">\
"<h2 id=\"variants\" class=\"variants section-header\">\
Variants{}<a href=\"#variants\" class=\"anchor\">§</a>\
</h2>\
{}\
Expand Down Expand Up @@ -1772,7 +1772,7 @@ fn item_variants(
write!(
w,
"<div class=\"sub-variant-field\">\
<span id=\"{id}\" class=\"small-section-header\">\
<span id=\"{id}\" class=\"section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{f}: {t}</code>\
</span>",
Expand Down Expand Up @@ -1929,7 +1929,7 @@ fn item_fields(
if fields.peek().is_some() {
write!(
w,
"<h2 id=\"fields\" class=\"fields small-section-header\">\
"<h2 id=\"fields\" class=\"fields section-header\">\
{}{}<a href=\"#fields\" class=\"anchor\">§</a>\
</h2>\
{}",
Expand All @@ -1943,7 +1943,7 @@ fn item_fields(
let id = cx.derive_id(format!("{typ}.{field_name}", typ = ItemType::StructField));
write!(
w,
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
"<span id=\"{id}\" class=\"{item_type} section-header\">\
<a href=\"#{id}\" class=\"anchor field\">§</a>\
<code>{field_name}: {ty}</code>\
</span>",
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ul.all-items {

#toggle-all-docs,
a.anchor,
.small-section-header a,
.section-header a,
#src-sidebar a,
.rust a,
.sidebar h2 a,
Expand Down Expand Up @@ -742,13 +742,13 @@ nav.sub {
margin: 0 0 15px 0;
}

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

.small-section-header:hover > .anchor, .impl:hover > .anchor,
.section-header:hover > .anchor, .impl:hover > .anchor,
.trait-impl:hover > .anchor, .variant:hover > .anchor {
display: initial;
}
Expand All @@ -761,11 +761,11 @@ nav.sub {
.anchor.field {
left: -5px;
}
.small-section-header > .anchor {
.section-header > .anchor {
left: -15px;
padding-right: 8px;
}
h2.small-section-header > .anchor {
h2.section-header > .anchor {
padding-right: 6px;
}

Expand Down
Loading

0 comments on commit 1670ff6

Please sign in to comment.