Skip to content

Commit 2b3cef8

Browse files
committed
Auto merge of #137651 - fmease:rollup-s3s7m6f, r=fmease
Rollup of 14 pull requests Successful merges: - #136576 (pass optimization level to llvm-bitcode-linker) - #137154 (Add UTF-8 validation fast paths in `Wtf8Buf`) - #137311 (Enable `f16` for MIPS) - #137320 (fix(rustdoc): Fixed stability version in rustdoc) - #137529 (remove few unused args) - #137544 (tests: Add regression test for derive token invalidation (#81099)) - #137559 (run some tests on emscripten again) - #137601 (ssa/mono: deduplicate `type_has_metadata`) - #137603 (codegen_llvm: avoid `Deref` impls w/ extern type) - #137604 (trait_sel: resolve vars in host effects) - #137609 (Complete the list of resources used in rustdoc output) - #137613 (hir_analysis: skip self type of host effect preds in variances_of) - #137614 (fix doc in library/core/src/pin.rs) - #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

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

+4-1
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

+8-5
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

+2-2
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

+4-2
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

+5-6
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

+3-3
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

+3-3
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

+1-1
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

+1-1
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

+10-11
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,

compiler/rustc_codegen_llvm/src/llvm_util.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<S
331331
if let Some(feat) = to_llvm_features(sess, feature) {
332332
for llvm_feature in feat {
333333
let cstr = SmallCStr::new(llvm_feature);
334-
if !unsafe { llvm::LLVMRustHasFeature(&target_machine, cstr.as_ptr()) } {
334+
if !unsafe { llvm::LLVMRustHasFeature(target_machine.raw(), cstr.as_ptr()) }
335+
{
335336
return false;
336337
}
337338
}
@@ -453,8 +454,8 @@ pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) {
453454
require_inited();
454455
let tm = create_informational_target_machine(sess, false);
455456
match req.kind {
456-
PrintKind::TargetCPUs => print_target_cpus(sess, &tm, out),
457-
PrintKind::TargetFeatures => print_target_features(sess, &tm, out),
457+
PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out),
458+
PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out),
458459
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
459460
}
460461
}

compiler/rustc_codegen_ssa/src/back/linker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1939,14 +1939,14 @@ impl<'a> Linker for LlbcLinker<'a> {
19391939
}
19401940

19411941
fn optimize(&mut self) {
1942-
match self.sess.opts.optimize {
1942+
self.link_arg(match self.sess.opts.optimize {
19431943
OptLevel::No => "-O0",
19441944
OptLevel::Less => "-O1",
19451945
OptLevel::More => "-O2",
19461946
OptLevel::Aggressive => "-O3",
19471947
OptLevel::Size => "-Os",
19481948
OptLevel::SizeMin => "-Oz",
1949-
};
1949+
});
19501950
}
19511951

19521952
fn full_relro(&mut self) {}

compiler/rustc_codegen_ssa/src/mir/place.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_abi::Primitive::{Int, Pointer};
22
use rustc_abi::{Align, BackendRepr, FieldsShape, Size, TagEncoding, VariantIdx, Variants};
33
use rustc_middle::mir::PlaceTy;
44
use rustc_middle::mir::interpret::Scalar;
5-
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
5+
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
66
use rustc_middle::ty::{self, Ty};
77
use rustc_middle::{bug, mir};
88
use tracing::{debug, instrument};
@@ -168,7 +168,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
168168
};
169169
let val = PlaceValue {
170170
llval,
171-
llextra: if bx.cx().type_has_metadata(field.ty) { self.val.llextra } else { None },
171+
llextra: if bx.cx().tcx().type_has_metadata(field.ty, bx.cx().typing_env()) {
172+
self.val.llextra
173+
} else {
174+
None
175+
},
172176
align: effective_field_align,
173177
};
174178
val.with_type(field)

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::assert_matches::assert_matches;
33
use arrayvec::ArrayVec;
44
use rustc_abi::{self as abi, FIRST_VARIANT, FieldIdx};
55
use rustc_middle::ty::adjustment::PointerCoercion;
6-
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
6+
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
77
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
88
use rustc_middle::{bug, mir, span_bug};
99
use rustc_session::config::OptLevel;
@@ -878,7 +878,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
878878

879879
let ty = cg_place.layout.ty;
880880
assert!(
881-
if bx.cx().type_has_metadata(ty) {
881+
if bx.cx().tcx().type_has_metadata(ty, bx.cx().typing_env()) {
882882
matches!(val, OperandValue::Pair(..))
883883
} else {
884884
matches!(val, OperandValue::Immediate(..))

compiler/rustc_codegen_ssa/src/traits/type_.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_abi::{AddressSpace, Float, Integer, Reg};
22
use rustc_middle::bug;
3+
use rustc_middle::ty::Ty;
34
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, TyAndLayout};
4-
use rustc_middle::ty::{self, Ty};
55
use rustc_target::callconv::{ArgAbi, CastTarget, FnAbi};
66

77
use super::BackendTypes;
@@ -84,19 +84,6 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
8484
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
8585
ty.is_freeze(self.tcx(), self.typing_env())
8686
}
87-
88-
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
89-
if ty.is_sized(self.tcx(), self.typing_env()) {
90-
return false;
91-
}
92-
93-
let tail = self.tcx().struct_tail_for_codegen(ty, self.typing_env());
94-
match tail.kind() {
95-
ty::Foreign(..) => false,
96-
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
97-
_ => bug!("unexpected unsized tail: {:?}", tail),
98-
}
99-
}
10087
}
10188

10289
impl<'tcx, T> DerivedTypeCodegenMethods<'tcx> for T where

compiler/rustc_hir_analysis/src/collect.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,6 @@ fn lower_variant<'tcx>(
10741074
def.ctor().map(|(kind, _, def_id)| (kind, def_id.to_def_id())),
10751075
discr,
10761076
fields,
1077-
adt_kind,
10781077
parent_did.to_def_id(),
10791078
recovered,
10801079
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive)

compiler/rustc_hir_analysis/src/variance/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ fn variance_of_opaque(
198198
ty::ClauseKind::Trait(ty::TraitPredicate {
199199
trait_ref: ty::TraitRef { def_id: _, args, .. },
200200
polarity: _,
201+
})
202+
| ty::ClauseKind::HostEffect(ty::HostEffectPredicate {
203+
trait_ref: ty::TraitRef { def_id: _, args, .. },
204+
constness: _,
201205
}) => {
202206
for arg in &args[1..] {
203207
arg.visit_with(&mut collector);

compiler/rustc_metadata/src/rmeta/decoder.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,6 @@ impl<'a> CrateMetadataRef<'a> {
11161116
value: self.get_default_field(did.index),
11171117
})
11181118
.collect(),
1119-
adt_kind,
11201119
parent_did,
11211120
None,
11221121
data.is_non_exhaustive,

compiler/rustc_middle/src/ty/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1184,23 +1184,17 @@ impl VariantDef {
11841184
///
11851185
/// If someone speeds up attribute loading to not be a performance concern, they can
11861186
/// remove this hack and use the constructor `DefId` everywhere.
1187+
#[instrument(level = "debug")]
11871188
pub fn new(
11881189
name: Symbol,
11891190
variant_did: Option<DefId>,
11901191
ctor: Option<(CtorKind, DefId)>,
11911192
discr: VariantDiscr,
11921193
fields: IndexVec<FieldIdx, FieldDef>,
1193-
adt_kind: AdtKind,
11941194
parent_did: DefId,
11951195
recover_tainted: Option<ErrorGuaranteed>,
11961196
is_field_list_non_exhaustive: bool,
11971197
) -> Self {
1198-
debug!(
1199-
"VariantDef::new(name = {:?}, variant_did = {:?}, ctor = {:?}, discr = {:?},
1200-
fields = {:?}, adt_kind = {:?}, parent_did = {:?})",
1201-
name, variant_did, ctor, discr, fields, adt_kind, parent_did,
1202-
);
1203-
12041198
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
12051199
if is_field_list_non_exhaustive {
12061200
flags |= VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;

0 commit comments

Comments
 (0)