Skip to content

Commit 2ebb126

Browse files
committed
Auto merge of #146666 - Zalathar:rollup-m2b8low, r=Zalathar
Rollup of 14 pull requests Successful merges: - #142807 (libtest: expose --fail-fast as an unstable command-line option) - #144871 (Stabilize `btree_entry_insert` feature) - #145071 (Update the minimum external LLVM to 20) - #145181 (remove FIXME block from `has_significant_drop`, it never encounters inference variables) - #145660 (initial implementation of the darwin_objc unstable feature) - #145838 (don't apply temporary lifetime extension rules to non-extended `super let`) - #146259 (Suggest removing Box::new instead of unboxing it) - #146410 (Iterator repeat: no infinite loop for `last` and `count`) - #146460 (Add tidy readme) - #146552 (StateTransform: Do not renumber resume local.) - #146564 (Remove Rvalue::Len again.) - #146581 (Detect attempt to use var-args in closure) - #146588 (tests/run-make: Update list of statically linked musl targets) - #146631 (cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 3)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ba4b643 + 4e6640b commit 2ebb126

File tree

181 files changed

+4238
-1385
lines changed

Some content is hidden

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

181 files changed

+4238
-1385
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ attr_parsing_null_on_export = `export_name` may not contain null characters
122122
123123
attr_parsing_null_on_link_section = `link_section` may not contain null characters
124124
125+
attr_parsing_null_on_objc_class = `objc::class!` may not contain null characters
126+
127+
attr_parsing_null_on_objc_selector = `objc::selector!` may not contain null characters
128+
129+
attr_parsing_objc_class_expected_string_literal = `objc::class!` expected a string literal
130+
131+
attr_parsing_objc_selector_expected_string_literal = `objc::selector!` expected a string literal
132+
125133
attr_parsing_repr_ident =
126134
meta item in `repr` must be an identifier
127135

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use rustc_hir::attrs::{CoverageAttrKind, OptimizeAttr, SanitizerSet, UsedBy};
22
use rustc_session::parse::feature_err;
33

44
use super::prelude::*;
5-
use crate::session_diagnostics::{NakedFunctionIncompatibleAttribute, NullOnExport};
5+
use crate::session_diagnostics::{
6+
NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass, NullOnObjcSelector,
7+
ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral,
8+
};
69

710
pub(crate) struct OptimizeParser;
811

@@ -150,6 +153,70 @@ impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
150153
}
151154
}
152155

156+
pub(crate) struct ObjcClassParser;
157+
158+
impl<S: Stage> SingleAttributeParser<S> for ObjcClassParser {
159+
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_class];
160+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
161+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
162+
const ALLOWED_TARGETS: AllowedTargets =
163+
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
164+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "ClassName");
165+
166+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
167+
let Some(nv) = args.name_value() else {
168+
cx.expected_name_value(cx.attr_span, None);
169+
return None;
170+
};
171+
let Some(classname) = nv.value_as_str() else {
172+
// `#[rustc_objc_class = ...]` is expected to be used as an implementatioin detail
173+
// inside a standard library macro, but `cx.expected_string_literal` exposes too much.
174+
// Use a custom error message instead.
175+
cx.emit_err(ObjcClassExpectedStringLiteral { span: nv.value_span });
176+
return None;
177+
};
178+
if classname.as_str().contains('\0') {
179+
// `#[rustc_objc_class = ...]` will be converted to a null-terminated string,
180+
// so it may not contain any null characters.
181+
cx.emit_err(NullOnObjcClass { span: nv.value_span });
182+
return None;
183+
}
184+
Some(AttributeKind::ObjcClass { classname, span: cx.attr_span })
185+
}
186+
}
187+
188+
pub(crate) struct ObjcSelectorParser;
189+
190+
impl<S: Stage> SingleAttributeParser<S> for ObjcSelectorParser {
191+
const PATH: &[rustc_span::Symbol] = &[sym::rustc_objc_selector];
192+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
193+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
194+
const ALLOWED_TARGETS: AllowedTargets =
195+
AllowedTargets::AllowList(&[Allow(Target::ForeignStatic)]);
196+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "methodName");
197+
198+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
199+
let Some(nv) = args.name_value() else {
200+
cx.expected_name_value(cx.attr_span, None);
201+
return None;
202+
};
203+
let Some(methname) = nv.value_as_str() else {
204+
// `#[rustc_objc_selector = ...]` is expected to be used as an implementatioin detail
205+
// inside a standard library macro, but `cx.expected_string_literal` exposes too much.
206+
// Use a custom error message instead.
207+
cx.emit_err(ObjcSelectorExpectedStringLiteral { span: nv.value_span });
208+
return None;
209+
};
210+
if methname.as_str().contains('\0') {
211+
// `#[rustc_objc_selector = ...]` will be converted to a null-terminated string,
212+
// so it may not contain any null characters.
213+
cx.emit_err(NullOnObjcSelector { span: nv.value_span });
214+
return None;
215+
}
216+
Some(AttributeKind::ObjcSelector { methname, span: cx.attr_span })
217+
}
218+
}
219+
153220
#[derive(Default)]
154221
pub(crate) struct NakedParser {
155222
span: Option<Span>,

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::attributes::allow_unstable::{
2020
use crate::attributes::body::CoroutineParser;
2121
use crate::attributes::codegen_attrs::{
2222
ColdParser, CoverageParser, ExportNameParser, ForceTargetFeatureParser, NakedParser,
23-
NoMangleParser, OptimizeParser, SanitizeParser, TargetFeatureParser, TrackCallerParser,
24-
UsedParser,
23+
NoMangleParser, ObjcClassParser, ObjcSelectorParser, OptimizeParser, SanitizeParser,
24+
TargetFeatureParser, TrackCallerParser, UsedParser,
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
2727
use crate::attributes::crate_level::{
@@ -185,6 +185,8 @@ attribute_parsers!(
185185
Single<LinkageParser>,
186186
Single<MoveSizeLimitParser>,
187187
Single<MustUseParser>,
188+
Single<ObjcClassParser>,
189+
Single<ObjcSelectorParser>,
188190
Single<OptimizeParser>,
189191
Single<PathAttributeParser>,
190192
Single<PatternComplexityLimitParser>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,34 @@ pub(crate) struct NullOnLinkSection {
459459
pub span: Span,
460460
}
461461

462+
#[derive(Diagnostic)]
463+
#[diag(attr_parsing_null_on_objc_class)]
464+
pub(crate) struct NullOnObjcClass {
465+
#[primary_span]
466+
pub span: Span,
467+
}
468+
469+
#[derive(Diagnostic)]
470+
#[diag(attr_parsing_null_on_objc_selector)]
471+
pub(crate) struct NullOnObjcSelector {
472+
#[primary_span]
473+
pub span: Span,
474+
}
475+
476+
#[derive(Diagnostic)]
477+
#[diag(attr_parsing_objc_class_expected_string_literal)]
478+
pub(crate) struct ObjcClassExpectedStringLiteral {
479+
#[primary_span]
480+
pub span: Span,
481+
}
482+
483+
#[derive(Diagnostic)]
484+
#[diag(attr_parsing_objc_selector_expected_string_literal)]
485+
pub(crate) struct ObjcSelectorExpectedStringLiteral {
486+
#[primary_span]
487+
pub span: Span,
488+
}
489+
462490
#[derive(Diagnostic)]
463491
#[diag(attr_parsing_stability_outside_std, code = E0734)]
464492
pub(crate) struct StabilityOutsideStd {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
15571557
);
15581558
}
15591559

1560-
&(Rvalue::Len(place) | Rvalue::Discriminant(place)) => {
1560+
&Rvalue::Discriminant(place) => {
15611561
let af = match *rvalue {
1562-
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),
15631562
Rvalue::Discriminant(..) => None,
15641563
_ => unreachable!(),
15651564
};

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,11 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
306306
self.consume_operand(location, op);
307307
}
308308

309-
&(Rvalue::Len(place) | Rvalue::Discriminant(place)) => {
310-
let af = match rvalue {
311-
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),
312-
Rvalue::Discriminant(..) => None,
313-
_ => unreachable!(),
314-
};
309+
&Rvalue::Discriminant(place) => {
315310
self.access_place(
316311
location,
317312
place,
318-
(Shallow(af), Read(ReadKind::Copy)),
313+
(Shallow(None), Read(ReadKind::Copy)),
319314
LocalMutationIsAllowed::No,
320315
);
321316
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
16311631
| Rvalue::BinaryOp(..)
16321632
| Rvalue::RawPtr(..)
16331633
| Rvalue::ThreadLocalRef(..)
1634-
| Rvalue::Len(..)
16351634
| Rvalue::Discriminant(..)
16361635
| Rvalue::NullaryOp(NullOp::OffsetOf(..), _) => {}
16371636
}
@@ -2201,7 +2200,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22012200
| Rvalue::Repeat(..)
22022201
| Rvalue::Ref(..)
22032202
| Rvalue::RawPtr(..)
2204-
| Rvalue::Len(..)
22052203
| Rvalue::Cast(..)
22062204
| Rvalue::ShallowInitBox(..)
22072205
| Rvalue::BinaryOp(..)

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
834834
fx.bcx.ins().nop();
835835
}
836836
}
837-
Rvalue::Len(place) => {
838-
let place = codegen_place(fx, place);
839-
let usize_layout = fx.layout_of(fx.tcx.types.usize);
840-
let len = codegen_array_len(fx, place);
841-
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
842-
}
843837
Rvalue::ShallowInitBox(ref operand, content_ty) => {
844838
let content_ty = fx.monomorphize(content_ty);
845839
let box_layout = fx.layout_of(Ty::new_box(fx.tcx, content_ty));

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,36 @@ pub(crate) fn compile_codegen_unit(
109109
attributes::apply_to_llfn(entry, llvm::AttributePlace::Function, &attrs);
110110
}
111111

112+
// Define Objective-C module info and module flags. Note, the module info will
113+
// also be added to the `llvm.compiler.used` variable, created later.
114+
//
115+
// These are only necessary when we need the linker to do its Objective-C-specific
116+
// magic. We could theoretically do it unconditionally, but at a slight cost to linker
117+
// performance in the common case where it's unnecessary.
118+
if !cx.objc_classrefs.borrow().is_empty() || !cx.objc_selrefs.borrow().is_empty() {
119+
if cx.objc_abi_version() == 1 {
120+
cx.define_objc_module_info();
121+
}
122+
cx.add_objc_module_flags();
123+
}
124+
112125
// Finalize code coverage by injecting the coverage map. Note, the coverage map will
113126
// also be added to the `llvm.compiler.used` variable, created next.
114127
if cx.sess().instrument_coverage() {
115128
cx.coverageinfo_finalize();
116129
}
117130

118-
// Create the llvm.used and llvm.compiler.used variables.
131+
// Create the llvm.used variable.
119132
if !cx.used_statics.is_empty() {
120133
cx.create_used_variable_impl(c"llvm.used", &cx.used_statics);
121134
}
122-
if !cx.compiler_used_statics.is_empty() {
123-
cx.create_used_variable_impl(c"llvm.compiler.used", &cx.compiler_used_statics);
135+
136+
// Create the llvm.compiler.used variable.
137+
{
138+
let compiler_used_statics = cx.compiler_used_statics.borrow();
139+
if !compiler_used_statics.is_empty() {
140+
cx.create_used_variable_impl(c"llvm.compiler.used", &compiler_used_statics);
141+
}
124142
}
125143

126144
// Run replace-all-uses-with for statics that need it. This must

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,16 +1091,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10911091
ty: Ty<'tcx>,
10921092
lhs: Self::Value,
10931093
rhs: Self::Value,
1094-
) -> Option<Self::Value> {
1095-
// FIXME: See comment on the definition of `three_way_compare`.
1096-
if crate::llvm_util::get_version() < (20, 0, 0) {
1097-
return None;
1098-
}
1099-
1094+
) -> Self::Value {
11001095
let size = ty.primitive_size(self.tcx);
11011096
let name = if ty.is_signed() { "llvm.scmp" } else { "llvm.ucmp" };
11021097

1103-
Some(self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], &[lhs, rhs]))
1098+
self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], &[lhs, rhs])
11041099
}
11051100

11061101
/* Miscellaneous instructions */

0 commit comments

Comments
 (0)