Skip to content

Commit c9c0756

Browse files
committed
Auto merge of rust-lang#136388 - matthiaskrgr:rollup-rsoi815, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#130514 (Implement MIR lowering for unsafe binders) - rust-lang#135684 (docs: Documented Send and Sync requirements for Mutex + MutexGuard) - rust-lang#135760 (Add `unchecked_disjoint_bitor` per ACP373) - rust-lang#136154 (Use +secure-plt for powerpc-unknown-linux-gnu{,spe}) - rust-lang#136309 (set rustc dylib on manually constructed rustc command) - rust-lang#136339 (CompileTest: Add Directives to Ignore `arm-unknown-*` Targets) - rust-lang#136368 (Make comma separated lists of anything easier to make for errors) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e08cd3c + e644717 commit c9c0756

File tree

83 files changed

+912
-258
lines changed

Some content is hidden

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

83 files changed

+912
-258
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ impl GenBlockKind {
16571657
}
16581658

16591659
/// Whether we're unwrapping or wrapping an unsafe binder
1660-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1660+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
16611661
#[derive(Encodable, Decodable, HashStable_Generic)]
16621662
pub enum UnsafeBinderCastKind {
16631663
// e.g. `&i32` -> `unsafe<'a> &'a i32`

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
39153915
ProjectionElem::ConstantIndex { .. }
39163916
| ProjectionElem::Subslice { .. }
39173917
| ProjectionElem::Subtype(_)
3918-
| ProjectionElem::Index(_) => kind,
3918+
| ProjectionElem::Index(_)
3919+
| ProjectionElem::UnwrapUnsafeBinder(_) => kind,
39193920
},
39203921
place_ty.projection_ty(tcx, elem),
39213922
)

compiler/rustc_borrowck/src/diagnostics/mod.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::BTreeMap;
44

55
use rustc_abi::{FieldIdx, VariantIdx};
66
use rustc_data_structures::fx::FxIndexMap;
7-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan};
7+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
88
use rustc_hir::def::{CtorKind, Namespace};
99
use rustc_hir::{self as hir, CoroutineKind, LangItem};
1010
use rustc_index::IndexSlice;
@@ -29,7 +29,7 @@ use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2929
use rustc_trait_selection::error_reporting::traits::call_kind::{CallDesugaringKind, call_kind};
3030
use rustc_trait_selection::infer::InferCtxtExt;
3131
use rustc_trait_selection::traits::{
32-
FulfillmentErrorCode, type_known_to_meet_bound_modulo_regions,
32+
FulfillmentError, FulfillmentErrorCode, type_known_to_meet_bound_modulo_regions,
3333
};
3434
use tracing::debug;
3535

@@ -370,6 +370,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
370370
ProjectionElem::Downcast(..) => (),
371371
ProjectionElem::OpaqueCast(..) => (),
372372
ProjectionElem::Subtype(..) => (),
373+
ProjectionElem::UnwrapUnsafeBinder(_) => (),
373374
ProjectionElem::Field(field, _ty) => {
374375
// FIXME(project-rfc_2229#36): print capture precisely here.
375376
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -450,9 +451,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
450451
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
451452
}
452453
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
453-
ProjectionElem::Subtype(ty) | ProjectionElem::OpaqueCast(ty) => {
454-
PlaceTy::from_ty(*ty)
455-
}
454+
ProjectionElem::Subtype(ty)
455+
| ProjectionElem::OpaqueCast(ty)
456+
| ProjectionElem::UnwrapUnsafeBinder(ty) => PlaceTy::from_ty(*ty),
456457
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
457458
},
458459
};
@@ -1433,17 +1434,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14331434
error.obligation.predicate,
14341435
)
14351436
}
1436-
[errors @ .., last] => {
1437+
_ => {
14371438
format!(
14381439
"you could `clone` the value and consume it, if the \
1439-
following trait bounds could be satisfied: \
1440-
{} and `{}`",
1441-
errors
1442-
.iter()
1443-
.map(|e| format!("`{}`", e.obligation.predicate))
1444-
.collect::<Vec<_>>()
1445-
.join(", "),
1446-
last.obligation.predicate,
1440+
following trait bounds could be satisfied: {}",
1441+
listify(&errors, |e: &FulfillmentError<'tcx>| format!(
1442+
"`{}`",
1443+
e.obligation.predicate
1444+
))
1445+
.unwrap(),
14471446
)
14481447
}
14491448
};

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
167167
| ProjectionElem::ConstantIndex { .. }
168168
| ProjectionElem::OpaqueCast { .. }
169169
| ProjectionElem::Subslice { .. }
170-
| ProjectionElem::Downcast(..),
170+
| ProjectionElem::Downcast(..)
171+
| ProjectionElem::UnwrapUnsafeBinder(_),
171172
],
172173
} => bug!("Unexpected immutable place."),
173174
}

compiler/rustc_borrowck/src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
13981398
self.consume_operand(location, (operand, span), state);
13991399
}
14001400
}
1401+
1402+
Rvalue::WrapUnsafeBinder(op, _) => {
1403+
self.consume_operand(location, (op, span), state);
1404+
}
14011405
}
14021406
}
14031407

@@ -1770,7 +1774,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
17701774
// So it's safe to skip these.
17711775
ProjectionElem::OpaqueCast(_)
17721776
| ProjectionElem::Subtype(_)
1773-
| ProjectionElem::Downcast(_, _) => (),
1777+
| ProjectionElem::Downcast(_, _)
1778+
| ProjectionElem::UnwrapUnsafeBinder(_) => (),
17741779
}
17751780

17761781
place_ty = place_ty.projection_ty(tcx, elem);
@@ -2004,6 +2009,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20042009
// FIXME: is this true even if P is an adt with a dtor?
20052010
{ }
20062011

2012+
ProjectionElem::UnwrapUnsafeBinder(_) => {
2013+
check_parent_of_field(self, location, place_base, span, state);
2014+
}
2015+
20072016
// assigning to (*P) requires P to be initialized
20082017
ProjectionElem::Deref => {
20092018
self.check_if_full_path_is_moved(
@@ -2384,7 +2393,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23842393
| ProjectionElem::Subslice { .. }
23852394
| ProjectionElem::Subtype(..)
23862395
| ProjectionElem::OpaqueCast { .. }
2387-
| ProjectionElem::Downcast(..) => {
2396+
| ProjectionElem::Downcast(..)
2397+
| ProjectionElem::UnwrapUnsafeBinder(_) => {
23882398
let upvar_field_projection = self.is_upvar_field_projection(place);
23892399
if let Some(field) = upvar_field_projection {
23902400
let upvar = &self.upvars[field.index()];

compiler/rustc_borrowck/src/places_conflict.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ fn place_components_conflict<'tcx>(
250250
| (ProjectionElem::Subslice { .. }, _, _)
251251
| (ProjectionElem::OpaqueCast { .. }, _, _)
252252
| (ProjectionElem::Subtype(_), _, _)
253-
| (ProjectionElem::Downcast { .. }, _, _) => {
253+
| (ProjectionElem::Downcast { .. }, _, _)
254+
| (ProjectionElem::UnwrapUnsafeBinder(_), _, _) => {
254255
// Recursive case. This can still be disjoint on a
255256
// further iteration if this a shallow access and
256257
// there's a deref later on, e.g., a borrow
@@ -519,5 +520,9 @@ fn place_projection_conflict<'tcx>(
519520
pi1_elem,
520521
pi2_elem
521522
),
523+
524+
(ProjectionElem::UnwrapUnsafeBinder(_), _) => {
525+
todo!()
526+
}
522527
}
523528
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
325325
self.consume_operand(location, operand);
326326
}
327327
}
328+
329+
Rvalue::WrapUnsafeBinder(op, _) => {
330+
self.consume_operand(location, op);
331+
}
328332
}
329333
}
330334

compiler/rustc_borrowck/src/prefixes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ impl<'tcx> Iterator for Prefixes<'tcx> {
6666
self.next = Some(cursor_base);
6767
return Some(cursor);
6868
}
69+
ProjectionElem::UnwrapUnsafeBinder(_) => {
70+
self.next = Some(cursor_base);
71+
return Some(cursor);
72+
}
6973
ProjectionElem::Downcast(..)
7074
| ProjectionElem::Subslice { .. }
7175
| ProjectionElem::OpaqueCast { .. }

compiler/rustc_borrowck/src/type_check/mod.rs

+44-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
302302
)
303303
.unwrap();
304304
}
305+
ProjectionElem::UnwrapUnsafeBinder(ty) => {
306+
let ty::UnsafeBinder(binder_ty) = *base_ty.ty.kind() else {
307+
unreachable!();
308+
};
309+
let found_ty = self.typeck.infcx.instantiate_binder_with_fresh_vars(
310+
self.body().source_info(location).span,
311+
BoundRegionConversionTime::HigherRankedType,
312+
binder_ty.into(),
313+
);
314+
self.typeck
315+
.relate_types(
316+
ty,
317+
context.ambient_variance(),
318+
found_ty,
319+
location.to_locations(),
320+
ConstraintCategory::Boring,
321+
)
322+
.unwrap();
323+
}
305324
ProjectionElem::Subtype(_) => {
306325
bug!("ProjectionElem::Subtype shouldn't exist in borrowck")
307326
}
@@ -2233,6 +2252,27 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22332252
self.check_operand(right, location);
22342253
}
22352254

2255+
Rvalue::WrapUnsafeBinder(op, ty) => {
2256+
self.check_operand(op, location);
2257+
let operand_ty = op.ty(self.body, self.tcx());
2258+
2259+
let ty::UnsafeBinder(binder_ty) = *ty.kind() else {
2260+
unreachable!();
2261+
};
2262+
let expected_ty = self.infcx.instantiate_binder_with_fresh_vars(
2263+
self.body().source_info(location).span,
2264+
BoundRegionConversionTime::HigherRankedType,
2265+
binder_ty.into(),
2266+
);
2267+
self.sub_types(
2268+
operand_ty,
2269+
expected_ty,
2270+
location.to_locations(),
2271+
ConstraintCategory::Boring,
2272+
)
2273+
.unwrap();
2274+
}
2275+
22362276
Rvalue::RawPtr(..)
22372277
| Rvalue::ThreadLocalRef(..)
22382278
| Rvalue::Len(..)
@@ -2258,7 +2298,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
22582298
| Rvalue::NullaryOp(..)
22592299
| Rvalue::CopyForDeref(..)
22602300
| Rvalue::UnaryOp(..)
2261-
| Rvalue::Discriminant(..) => None,
2301+
| Rvalue::Discriminant(..)
2302+
| Rvalue::WrapUnsafeBinder(..) => None,
22622303

22632304
Rvalue::Aggregate(aggregate, _) => match **aggregate {
22642305
AggregateKind::Adt(_, _, _, user_ty, _) => user_ty,
@@ -2450,7 +2491,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24502491
| ProjectionElem::OpaqueCast(..)
24512492
| ProjectionElem::Index(..)
24522493
| ProjectionElem::ConstantIndex { .. }
2453-
| ProjectionElem::Subslice { .. } => {
2494+
| ProjectionElem::Subslice { .. }
2495+
| ProjectionElem::UnwrapUnsafeBinder(_) => {
24542496
// other field access
24552497
}
24562498
ProjectionElem::Subtype(_) => {

compiler/rustc_builtin_macros/src/format.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_ast::{
88
token,
99
};
1010
use rustc_data_structures::fx::FxHashSet;
11-
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
11+
use rustc_errors::{
12+
Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans, listify, pluralize,
13+
};
1214
use rustc_expand::base::*;
1315
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
1416
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId};
@@ -975,15 +977,11 @@ fn report_invalid_references(
975977
} else {
976978
MultiSpan::from_spans(invalid_refs.iter().filter_map(|&(_, span, _, _)| span).collect())
977979
};
978-
let arg_list = if let &[index] = &indexes[..] {
979-
format!("argument {index}")
980-
} else {
981-
let tail = indexes.pop().unwrap();
982-
format!(
983-
"arguments {head} and {tail}",
984-
head = indexes.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", ")
985-
)
986-
};
980+
let arg_list = format!(
981+
"argument{} {}",
982+
pluralize!(indexes.len()),
983+
listify(&indexes, |i: &usize| i.to_string()).unwrap_or_default()
984+
);
987985
e = ecx.dcx().struct_span_err(
988986
span,
989987
format!("invalid reference to positional {arg_list} ({num_args_desc})"),

compiler/rustc_codegen_cranelift/src/base.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,10 @@ fn codegen_stmt<'tcx>(
925925
}
926926
crate::discriminant::codegen_set_discriminant(fx, lval, variant_index);
927927
}
928+
Rvalue::WrapUnsafeBinder(ref operand, _to_ty) => {
929+
let operand = codegen_operand(fx, operand);
930+
lval.write_cvalue_transmute(fx, operand);
931+
}
928932
}
929933
}
930934
StatementKind::StorageLive(_)
@@ -993,7 +997,9 @@ pub(crate) fn codegen_place<'tcx>(
993997
cplace = cplace.place_deref(fx);
994998
}
995999
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
996-
PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)),
1000+
PlaceElem::Subtype(ty) | PlaceElem::UnwrapUnsafeBinder(ty) => {
1001+
cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty));
1002+
}
9971003
PlaceElem::Field(field, _ty) => {
9981004
cplace = cplace.place_field(fx, field);
9991005
}

compiler/rustc_codegen_llvm/src/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
421421
unchecked_umul(x, y) => LLVMBuildNUWMul,
422422
}
423423

424+
fn or_disjoint(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value {
425+
unsafe {
426+
let or = llvm::LLVMBuildOr(self.llbuilder, a, b, UNNAMED);
427+
llvm::LLVMSetIsDisjoint(or, True);
428+
or
429+
}
430+
}
431+
424432
set_math_builder_methods! {
425433
fadd_fast(x, y) => (LLVMBuildFAdd, LLVMRustSetFastMath),
426434
fsub_fast(x, y) => (LLVMBuildFSub, LLVMRustSetFastMath),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,9 @@ unsafe extern "C" {
13801380
pub fn LLVMBuildFNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
13811381
pub fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
13821382

1383+
// Extra flags on arithmetic
1384+
pub fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);
1385+
13831386
// Memory
13841387
pub fn LLVMBuildAlloca<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
13851388
pub fn LLVMBuildArrayAlloca<'a>(

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+5
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
225225
args[1].val.unaligned_volatile_store(bx, dst);
226226
return Ok(());
227227
}
228+
sym::disjoint_bitor => {
229+
let a = args[0].immediate();
230+
let b = args[1].immediate();
231+
bx.or_disjoint(a, b)
232+
}
228233
sym::exact_div => {
229234
let ty = arg_tys[0];
230235
match int_type_width_signed(ty, bx.tcx()) {

compiler/rustc_codegen_ssa/src/mir/place.rs

+3
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
502502
bug!("encountered OpaqueCast({ty}) in codegen")
503503
}
504504
mir::ProjectionElem::Subtype(ty) => cg_base.project_type(bx, self.monomorphize(ty)),
505+
mir::ProjectionElem::UnwrapUnsafeBinder(ty) => {
506+
cg_base.project_type(bx, self.monomorphize(ty))
507+
}
505508
mir::ProjectionElem::Index(index) => {
506509
let index = &mir::Operand::Copy(mir::Place::from(index));
507510
let index = self.codegen_operand(bx, index);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
823823

824824
OperandRef { val: OperandValue::Immediate(val), layout: box_layout }
825825
}
826+
mir::Rvalue::WrapUnsafeBinder(ref operand, binder_ty) => {
827+
let operand = self.codegen_operand(bx, operand);
828+
let binder_ty = self.monomorphize(binder_ty);
829+
let layout = bx.cx().layout_of(binder_ty);
830+
OperandRef { val: operand.val, layout }
831+
}
826832
}
827833
}
828834

@@ -1123,7 +1129,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11231129
mir::Rvalue::Discriminant(..) |
11241130
mir::Rvalue::NullaryOp(..) |
11251131
mir::Rvalue::ThreadLocalRef(_) |
1126-
mir::Rvalue::Use(..) => // (*)
1132+
mir::Rvalue::Use(..) |
1133+
mir::Rvalue::WrapUnsafeBinder(..) => // (*)
11271134
true,
11281135
// Arrays are always aggregates, so it's not worth checking anything here.
11291136
// (If it's really `[(); N]` or `[T; 0]` and we use the place path, fine.)

compiler/rustc_codegen_ssa/src/traits/builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ pub trait BuilderMethods<'a, 'tcx>:
167167
fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
168168
fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
169169
fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
170+
/// Defaults to [`Self::or`], but guarantees `(lhs & rhs) == 0` so some backends
171+
/// can emit something more helpful for optimizations.
172+
fn or_disjoint(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value {
173+
self.or(lhs, rhs)
174+
}
170175
fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
171176
fn neg(&mut self, v: Self::Value) -> Self::Value;
172177
fn fneg(&mut self, v: Self::Value) -> Self::Value;

compiler/rustc_const_eval/src/check_consts/check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
728728
);
729729
}
730730
}
731+
732+
Rvalue::WrapUnsafeBinder(..) => {
733+
// Unsafe binders are always trivial to create.
734+
}
731735
}
732736
}
733737

0 commit comments

Comments
 (0)