Skip to content

Commit 370c911

Browse files
committed
Auto merge of rust-lang#118723 - matthiaskrgr:rollup-409e9u1, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#116420 (discard invalid spans in external blocks) - rust-lang#118686 (Only check principal trait ref for object safety) - rust-lang#118688 (Add method to get type of an Rvalue in StableMIR) - rust-lang#118707 (Ping GuillaumeGomez for changes in rustc_codegen_gcc) - rust-lang#118712 (targets: remove not-added {i386,i486}-unknown-linux-gnu) - rust-lang#118719 (CFI: Add char to CFI integer normalization) Failed merges: - rust-lang#117586 (Uplift the (new solver) canonicalizer into `rustc_next_trait_solver`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 503e129 + 71812d7 commit 370c911

File tree

15 files changed

+310
-97
lines changed

15 files changed

+310
-97
lines changed

compiler/rustc_parse/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ pub(crate) struct ExternItemCannotBeConst {
17331733
#[primary_span]
17341734
pub ident_span: Span,
17351735
#[suggestion(code = "static ", applicability = "machine-applicable")]
1736-
pub const_span: Span,
1736+
pub const_span: Option<Span>,
17371737
}
17381738

17391739
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/item.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,11 @@ impl<'a> Parser<'a> {
11391139
Ok(kind) => kind,
11401140
Err(kind) => match kind {
11411141
ItemKind::Const(box ConstItem { ty, expr, .. }) => {
1142+
let const_span = Some(span.with_hi(ident.span.lo()))
1143+
.filter(|span| span.can_be_used_for_suggestions());
11421144
self.sess.emit_err(errors::ExternItemCannotBeConst {
11431145
ident_span: ident.span,
1144-
const_span: span.with_hi(ident.span.lo()),
1146+
const_span,
11451147
});
11461148
ForeignItemKind::Static(ty, Mutability::Not, expr)
11471149
}

compiler/rustc_smir/src/rustc_smir/context.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
250250
tables.tcx.mk_ty_from_kind(internal_kind).stable(&mut *tables)
251251
}
252252

253+
#[allow(rustc::usage_of_qualified_ty)]
254+
fn new_box_ty(&self, ty: stable_mir::ty::Ty) -> stable_mir::ty::Ty {
255+
let mut tables = self.0.borrow_mut();
256+
let inner = ty.internal(&mut *tables);
257+
ty::Ty::new_box(tables.tcx, inner).stable(&mut *tables)
258+
}
259+
253260
fn def_ty(&self, item: stable_mir::DefId) -> stable_mir::ty::Ty {
254261
let mut tables = self.0.borrow_mut();
255262
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
@@ -276,6 +283,13 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
276283
tables.types[ty].kind().stable(&mut *tables)
277284
}
278285

286+
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> stable_mir::ty::Ty {
287+
let mut tables = self.0.borrow_mut();
288+
let internal_kind = ty.internal(&mut *tables);
289+
let internal_ty = tables.tcx.mk_ty_from_kind(internal_kind);
290+
internal_ty.discriminant_ty(tables.tcx).stable(&mut *tables)
291+
}
292+
279293
fn instance_body(&self, def: InstanceDef) -> Option<Body> {
280294
let mut tables = self.0.borrow_mut();
281295
let instance = tables.instances[def];
@@ -308,9 +322,9 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
308322
matches!(instance.def, ty::InstanceDef::DropGlue(_, None))
309323
}
310324

311-
fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
325+
fn mono_instance(&self, def_id: stable_mir::DefId) -> stable_mir::mir::mono::Instance {
312326
let mut tables = self.0.borrow_mut();
313-
let def_id = tables[item.0];
327+
let def_id = tables[def_id];
314328
Instance::mono(tables.tcx, def_id).stable(&mut *tables)
315329
}
316330

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
773773
let mut ty = ty;
774774

775775
match ty.kind() {
776-
ty::Float(..)
777-
| ty::Char
778-
| ty::Str
779-
| ty::Never
780-
| ty::Foreign(..)
781-
| ty::CoroutineWitness(..) => {}
776+
ty::Float(..) | ty::Str | ty::Never | ty::Foreign(..) | ty::CoroutineWitness(..) => {}
782777

783778
ty::Bool => {
784779
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -792,6 +787,14 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
792787
}
793788
}
794789

790+
ty::Char => {
791+
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
792+
// Since #118032, char is guaranteed to have the same size, alignment, and function
793+
// call ABI as u32 on all platforms.
794+
ty = tcx.types.u32;
795+
}
796+
}
797+
795798
ty::Int(..) | ty::Uint(..) => {
796799
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
797800
// Note: C99 7.18.2.4 requires uintptr_t and intptr_t to be at least 16-bit wide.

compiler/rustc_target/src/spec/targets/i386_unknown_linux_gnu.rs

-8
This file was deleted.

compiler/rustc_target/src/spec/targets/i486_unknown_linux_gnu.rs

-8
This file was deleted.

compiler/rustc_trait_selection/src/traits/wf.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,15 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
761761
let defer_to_coercion = self.tcx().features().object_safe_for_dispatch;
762762

763763
if !defer_to_coercion {
764-
let cause = self.cause(traits::WellFormed(None));
765-
let component_traits = data.auto_traits().chain(data.principal_def_id());
766-
let tcx = self.tcx();
767-
self.out.extend(component_traits.map(|did| {
768-
traits::Obligation::with_depth(
769-
tcx,
770-
cause.clone(),
764+
if let Some(principal) = data.principal_def_id() {
765+
self.out.push(traits::Obligation::with_depth(
766+
self.tcx(),
767+
self.cause(traits::WellFormed(None)),
771768
depth,
772769
param_env,
773-
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(did)),
774-
)
775-
}));
770+
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
771+
));
772+
}
776773
}
777774
}
778775

compiler/stable_mir/src/compiler_interface.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub trait Context {
8787
/// Create a new type from the given kind.
8888
fn new_rigid_ty(&self, kind: RigidTy) -> Ty;
8989

90+
/// Create a new box type, `Box<T>`, for the given inner type `T`.
91+
fn new_box_ty(&self, ty: Ty) -> Ty;
92+
9093
/// Returns the type of given crate item.
9194
fn def_ty(&self, item: DefId) -> Ty;
9295

@@ -102,6 +105,9 @@ pub trait Context {
102105
/// Obtain the representation of a type.
103106
fn ty_kind(&self, ty: Ty) -> TyKind;
104107

108+
// Get the discriminant Ty for this Ty if there's one.
109+
fn rigid_ty_discriminant_ty(&self, ty: &RigidTy) -> Ty;
110+
105111
/// Get the body of an Instance which is already monomorphized.
106112
fn instance_body(&self, instance: InstanceDef) -> Option<Body>;
107113

@@ -119,7 +125,7 @@ pub trait Context {
119125

120126
/// Convert a non-generic crate item into an instance.
121127
/// This function will panic if the item is generic.
122-
fn mono_instance(&self, item: CrateItem) -> Instance;
128+
fn mono_instance(&self, def_id: DefId) -> Instance;
123129

124130
/// Item requires monomorphization.
125131
fn requires_monomorphization(&self, def_id: DefId) -> bool;

compiler/stable_mir/src/mir/body.rs

+100
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,38 @@ pub enum BinOp {
274274
Offset,
275275
}
276276

277+
impl BinOp {
278+
/// Return the type of this operation for the given input Ty.
279+
/// This function does not perform type checking, and it currently doesn't handle SIMD.
280+
pub fn ty(&self, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
281+
assert!(lhs_ty.kind().is_primitive());
282+
assert!(rhs_ty.kind().is_primitive());
283+
match self {
284+
BinOp::Add
285+
| BinOp::AddUnchecked
286+
| BinOp::Sub
287+
| BinOp::SubUnchecked
288+
| BinOp::Mul
289+
| BinOp::MulUnchecked
290+
| BinOp::Div
291+
| BinOp::Rem
292+
| BinOp::BitXor
293+
| BinOp::BitAnd
294+
| BinOp::BitOr => {
295+
assert_eq!(lhs_ty, rhs_ty);
296+
lhs_ty
297+
}
298+
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked | BinOp::Offset => {
299+
lhs_ty
300+
}
301+
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
302+
assert_eq!(lhs_ty, rhs_ty);
303+
Ty::bool_ty()
304+
}
305+
}
306+
}
307+
}
308+
277309
#[derive(Clone, Debug, Eq, PartialEq)]
278310
pub enum UnOp {
279311
Not,
@@ -475,6 +507,63 @@ pub enum Rvalue {
475507
Use(Operand),
476508
}
477509

510+
impl Rvalue {
511+
pub fn ty(&self, locals: &[LocalDecl]) -> Result<Ty, Error> {
512+
match self {
513+
Rvalue::Use(operand) => operand.ty(locals),
514+
Rvalue::Repeat(operand, count) => {
515+
Ok(Ty::new_array_with_const_len(operand.ty(locals)?, count.clone()))
516+
}
517+
Rvalue::ThreadLocalRef(did) => Ok(did.ty()),
518+
Rvalue::Ref(reg, bk, place) => {
519+
let place_ty = place.ty(locals)?;
520+
Ok(Ty::new_ref(reg.clone(), place_ty, bk.to_mutable_lossy()))
521+
}
522+
Rvalue::AddressOf(mutability, place) => {
523+
let place_ty = place.ty(locals)?;
524+
Ok(Ty::new_ptr(place_ty, *mutability))
525+
}
526+
Rvalue::Len(..) => Ok(Ty::usize_ty()),
527+
Rvalue::Cast(.., ty) => Ok(*ty),
528+
Rvalue::BinaryOp(op, lhs, rhs) => {
529+
let lhs_ty = lhs.ty(locals)?;
530+
let rhs_ty = rhs.ty(locals)?;
531+
Ok(op.ty(lhs_ty, rhs_ty))
532+
}
533+
Rvalue::CheckedBinaryOp(op, lhs, rhs) => {
534+
let lhs_ty = lhs.ty(locals)?;
535+
let rhs_ty = rhs.ty(locals)?;
536+
let ty = op.ty(lhs_ty, rhs_ty);
537+
Ok(Ty::new_tuple(&[ty, Ty::bool_ty()]))
538+
}
539+
Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, operand) => operand.ty(locals),
540+
Rvalue::Discriminant(place) => {
541+
let place_ty = place.ty(locals)?;
542+
place_ty
543+
.kind()
544+
.discriminant_ty()
545+
.ok_or_else(|| error!("Expected a `RigidTy` but found: {place_ty:?}"))
546+
}
547+
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf | NullOp::OffsetOf(..), _) => {
548+
Ok(Ty::usize_ty())
549+
}
550+
Rvalue::Aggregate(ak, ops) => match *ak {
551+
AggregateKind::Array(ty) => Ty::try_new_array(ty, ops.len() as u64),
552+
AggregateKind::Tuple => Ok(Ty::new_tuple(
553+
&ops.iter().map(|op| op.ty(locals)).collect::<Result<Vec<_>, _>>()?,
554+
)),
555+
AggregateKind::Adt(def, _, ref args, _, _) => Ok(def.ty_with_args(args)),
556+
AggregateKind::Closure(def, ref args) => Ok(Ty::new_closure(def, args.clone())),
557+
AggregateKind::Coroutine(def, ref args, mov) => {
558+
Ok(Ty::new_coroutine(def, args.clone(), mov))
559+
}
560+
},
561+
Rvalue::ShallowInitBox(_, ty) => Ok(Ty::new_box(*ty)),
562+
Rvalue::CopyForDeref(place) => place.ty(locals),
563+
}
564+
}
565+
}
566+
478567
#[derive(Clone, Debug, Eq, PartialEq)]
479568
pub enum AggregateKind {
480569
Array(Ty),
@@ -725,6 +814,17 @@ pub enum BorrowKind {
725814
},
726815
}
727816

817+
impl BorrowKind {
818+
pub fn to_mutable_lossy(self) -> Mutability {
819+
match self {
820+
BorrowKind::Mut { .. } => Mutability::Mut,
821+
BorrowKind::Shared => Mutability::Not,
822+
// FIXME: There's no type corresponding to a shallow borrow, so use `&` as an approximation.
823+
BorrowKind::Fake => Mutability::Not,
824+
}
825+
}
826+
}
827+
728828
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
729829
pub enum MutBorrowKind {
730830
Default,

compiler/stable_mir/src/mir/mono.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ impl TryFrom<CrateItem> for Instance {
150150

151151
fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
152152
with(|context| {
153-
if !context.requires_monomorphization(item.0) {
154-
Ok(context.mono_instance(item))
153+
let def_id = item.def_id();
154+
if !context.requires_monomorphization(def_id) {
155+
Ok(context.mono_instance(def_id))
155156
} else {
156157
Err(Error::new("Item requires monomorphization".to_string()))
157158
}
@@ -219,6 +220,21 @@ impl TryFrom<CrateItem> for StaticDef {
219220
}
220221
}
221222

223+
impl TryFrom<Instance> for StaticDef {
224+
type Error = crate::Error;
225+
226+
fn try_from(value: Instance) -> Result<Self, Self::Error> {
227+
StaticDef::try_from(CrateItem::try_from(value)?)
228+
}
229+
}
230+
231+
impl From<StaticDef> for Instance {
232+
fn from(value: StaticDef) -> Self {
233+
// A static definition should always be convertible to an instance.
234+
with(|cx| cx.mono_instance(value.def_id()))
235+
}
236+
}
237+
222238
impl StaticDef {
223239
/// Return the type of this static definition.
224240
pub fn ty(&self) -> Ty {

0 commit comments

Comments
 (0)