Skip to content

Commit 2b3cef8

Browse files
committed
Auto merge of rust-lang#137651 - fmease:rollup-s3s7m6f, r=fmease
Rollup of 14 pull requests Successful merges: - rust-lang#136576 (pass optimization level to llvm-bitcode-linker) - rust-lang#137154 (Add UTF-8 validation fast paths in `Wtf8Buf`) - rust-lang#137311 (Enable `f16` for MIPS) - rust-lang#137320 (fix(rustdoc): Fixed stability version in rustdoc) - rust-lang#137529 (remove few unused args) - rust-lang#137544 (tests: Add regression test for derive token invalidation (rust-lang#81099)) - rust-lang#137559 (run some tests on emscripten again) - rust-lang#137601 (ssa/mono: deduplicate `type_has_metadata`) - rust-lang#137603 (codegen_llvm: avoid `Deref` impls w/ extern type) - rust-lang#137604 (trait_sel: resolve vars in host effects) - rust-lang#137609 (Complete the list of resources used in rustdoc output) - rust-lang#137613 (hir_analysis: skip self type of host effect preds in variances_of) - rust-lang#137614 (fix doc in library/core/src/pin.rs) - rust-lang#137622 (fix attribute-related ICE when parsing macro on the rhs of a name-value attribute) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a46c755 + 1bb4319 commit 2b3cef8

File tree

48 files changed

+487
-119
lines changed

Some content is hidden

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

48 files changed

+487
-119
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ impl<'sess> AttributeParser<'sess> {
333333
{
334334
lit
335335
} else {
336-
let guar = self.dcx().has_errors().unwrap();
336+
let guar = self.dcx().span_delayed_bug(
337+
args.span().unwrap_or(DUMMY_SP),
338+
"expr in place where literal is expected (builtin attr parsing)",
339+
);
337340
ast::MetaItemLit {
338341
symbol: kw::Empty,
339342
suffix: None,

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
1313
use rustc_errors::DiagCtxtHandle;
1414
use rustc_hir::{self as hir, AttrPath};
1515
use rustc_span::symbol::{Ident, kw};
16-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol};
16+
use rustc_span::{ErrorGuaranteed, Span, Symbol};
1717

1818
pub struct SegmentIterator<'a> {
1919
offset: usize,
@@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> {
127127
}
128128
AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
129129
eq_span: *eq_span,
130-
value: expr_to_lit(dcx, &expr),
130+
value: expr_to_lit(dcx, &expr, *eq_span),
131131
value_span: expr.span,
132132
}),
133133
}
@@ -348,16 +348,19 @@ impl NameValueParser {
348348
}
349349
}
350350

351-
fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
351+
fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit {
352352
// In valid code the value always ends up as a single literal. Otherwise, a dummy
353353
// literal suffices because the error is handled elsewhere.
354354
if let ExprKind::Lit(token_lit) = expr.kind
355355
&& let Ok(lit) = MetaItemLit::from_token_lit(token_lit, expr.span)
356356
{
357357
lit
358358
} else {
359-
let guar = dcx.has_errors().unwrap();
360-
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span: DUMMY_SP }
359+
let guar = dcx.span_delayed_bug(
360+
span,
361+
"expr in place where literal is expected (builtin attr parsing)",
362+
);
363+
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span }
361364
}
362365
}
363366

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl<'a, 'tcx> ResultsVisitor<'a, 'tcx, Borrowck<'a, 'tcx>> for MirBorrowckCtxt<
648648
| StatementKind::StorageLive(..) => {}
649649
// This does not affect borrowck
650650
StatementKind::BackwardIncompatibleDropHint { place, reason: BackwardIncompatibleDropReason::Edition2024 } => {
651-
self.check_backward_incompatible_drop(location, (**place, span), state);
651+
self.check_backward_incompatible_drop(location, **place, state);
652652
}
653653
StatementKind::StorageDead(local) => {
654654
self.access_place(
@@ -1174,7 +1174,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
11741174
fn check_backward_incompatible_drop(
11751175
&mut self,
11761176
location: Location,
1177-
(place, place_span): (Place<'tcx>, Span),
1177+
place: Place<'tcx>,
11781178
state: &BorrowckDomain,
11791179
) {
11801180
let tcx = self.infcx.tcx;

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,9 @@ pub(crate) unsafe fn optimize_thin_module(
793793
{
794794
let _timer =
795795
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
796-
unsafe { llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) };
796+
unsafe {
797+
llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target.raw())
798+
};
797799
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
798800
}
799801

@@ -823,7 +825,7 @@ pub(crate) unsafe fn optimize_thin_module(
823825
let _timer =
824826
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
825827
if unsafe {
826-
!llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target)
828+
!llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target.raw())
827829
} {
828830
return Err(write::llvm_err(dcx, LlvmError::PrepareThinLtoModule));
829831
}

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::ffi::{CStr, c_char};
22
use std::marker::PhantomData;
3-
use std::ops::Deref;
43
use std::ptr::NonNull;
54

65
use rustc_data_structures::small_c_str::SmallCStr;
@@ -80,12 +79,12 @@ impl OwnedTargetMachine {
8079
.map(|tm_unique| Self { tm_unique, phantom: PhantomData })
8180
.ok_or_else(|| LlvmError::CreateTargetMachine { triple: SmallCStr::from(triple) })
8281
}
83-
}
84-
85-
impl Deref for OwnedTargetMachine {
86-
type Target = llvm::TargetMachine;
8782

88-
fn deref(&self) -> &Self::Target {
83+
/// Returns inner `llvm::TargetMachine` type.
84+
///
85+
/// This could be a `Deref` implementation, but `llvm::TargetMachine` is an extern type and
86+
/// `Deref::Target: ?Sized`.
87+
pub fn raw(&self) -> &llvm::TargetMachine {
8988
// SAFETY: constructing ensures we have a valid pointer created by
9089
// llvm::LLVMRustCreateTargetMachine.
9190
unsafe { self.tm_unique.as_ref() }

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub(crate) unsafe fn llvm_optimize(
637637
let result = unsafe {
638638
llvm::LLVMRustOptimize(
639639
module.module_llvm.llmod(),
640-
&*module.module_llvm.tm,
640+
&*module.module_llvm.tm.raw(),
641641
to_pass_builder_opt_level(opt_level),
642642
opt_stage,
643643
cgcx.opts.cg.linker_plugin_lto.enabled(),
@@ -875,7 +875,7 @@ pub(crate) unsafe fn codegen(
875875
};
876876
write_output_file(
877877
dcx,
878-
tm,
878+
tm.raw(),
879879
config.no_builtins,
880880
llmod,
881881
&path,
@@ -909,7 +909,7 @@ pub(crate) unsafe fn codegen(
909909

910910
write_output_file(
911911
dcx,
912-
tm,
912+
tm.raw(),
913913
config.no_builtins,
914914
llmod,
915915
&obj_out,

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
405405

406406
// Emit KCFI operand bundle
407407
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
408-
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
408+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
409409
bundles.push(kcfi_bundle);
410410
}
411411

@@ -1433,7 +1433,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14331433

14341434
// Emit KCFI operand bundle
14351435
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1436-
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
1436+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
14371437
bundles.push(kcfi_bundle);
14381438
}
14391439

@@ -1782,7 +1782,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17821782

17831783
// Emit KCFI operand bundle
17841784
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1785-
if let Some(kcfi_bundle) = kcfi_bundle.as_deref() {
1785+
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.raw()) {
17861786
bundles.push(kcfi_bundle);
17871787
}
17881788

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'ll> Funclet<'ll> {
7777
}
7878

7979
pub(crate) fn bundle(&self) -> &llvm::OperandBundle<'ll> {
80-
&self.operand
80+
self.operand.raw()
8181
}
8282
}
8383

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub(crate) unsafe fn create_module<'ll>(
205205
{
206206
let tm = crate::back::write::create_informational_target_machine(tcx.sess, false);
207207
unsafe {
208-
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
208+
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm.raw());
209209
}
210210

211211
let llvm_data_layout = unsafe { llvm::LLVMGetDataLayoutStr(llmod) };

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(non_snake_case)]
22

33
use std::ffi::{CStr, CString};
4-
use std::ops::Deref;
54
use std::ptr;
65
use std::str::FromStr;
76
use std::string::FromUtf8Error;
@@ -355,6 +354,16 @@ impl<'a> OperandBundleOwned<'a> {
355354
};
356355
OperandBundleOwned { raw: ptr::NonNull::new(raw).unwrap() }
357356
}
357+
358+
/// Returns inner `OperandBundle` type.
359+
///
360+
/// This could be a `Deref` implementation, but `OperandBundle` contains an extern type and
361+
/// `Deref::Target: ?Sized`.
362+
pub(crate) fn raw(&self) -> &OperandBundle<'a> {
363+
// SAFETY: The returned reference is opaque and can only used for FFI.
364+
// It is valid for as long as `&self` is.
365+
unsafe { self.raw.as_ref() }
366+
}
358367
}
359368

360369
impl Drop for OperandBundleOwned<'_> {
@@ -365,16 +374,6 @@ impl Drop for OperandBundleOwned<'_> {
365374
}
366375
}
367376

368-
impl<'a> Deref for OperandBundleOwned<'a> {
369-
type Target = OperandBundle<'a>;
370-
371-
fn deref(&self) -> &Self::Target {
372-
// SAFETY: The returned reference is opaque and can only used for FFI.
373-
// It is valid for as long as `&self` is.
374-
unsafe { self.raw.as_ref() }
375-
}
376-
}
377-
378377
pub(crate) fn add_module_flag_u32(
379378
module: &Module,
380379
merge_behavior: ModuleFlagMergeBehavior,

0 commit comments

Comments
 (0)