diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 4489a424c0d5..11afd359e5ad 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -710,6 +710,12 @@ impl Pat {
}
}
+impl From
> for Pat {
+ fn from(value: P) -> Self {
+ *value
+ }
+}
+
/// A single field in a struct pattern.
///
/// Patterns like the fields of `Foo { x, ref y, ref mut z }`
@@ -1553,17 +1559,23 @@ impl Expr {
)
}
- /// Creates a dummy `P`.
+ /// Creates a dummy `Expr`.
///
/// Should only be used when it will be replaced afterwards or as a return value when an error was encountered.
- pub fn dummy() -> P {
- P(Expr {
+ pub fn dummy() -> Expr {
+ Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Dummy,
span: DUMMY_SP,
attrs: ThinVec::new(),
tokens: None,
- })
+ }
+ }
+}
+
+impl From> for Expr {
+ fn from(value: P) -> Self {
+ *value
}
}
@@ -2374,6 +2386,12 @@ impl Clone for Ty {
}
}
+impl From> for Ty {
+ fn from(value: P) -> Self {
+ *value
+ }
+}
+
impl Ty {
pub fn peel_refs(&self) -> &Self {
let mut final_ty = self;
diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs
index 71a47dcfcba2..07fbe8045fc2 100644
--- a/compiler/rustc_ast/src/mut_visit.rs
+++ b/compiler/rustc_ast/src/mut_visit.rs
@@ -168,7 +168,7 @@ pub trait MutVisitor: Sized + MutVisitorResult {
walk_flat_map_arm(self, arm)
}
- fn visit_pat(&mut self, p: &mut P) {
+ fn visit_pat(&mut self, p: &mut Pat) {
walk_pat(self, p);
}
@@ -176,7 +176,7 @@ pub trait MutVisitor: Sized + MutVisitorResult {
walk_anon_const(self, c);
}
- fn visit_expr(&mut self, e: &mut P) {
+ fn visit_expr(&mut self, e: &mut Expr) {
walk_expr(self, e);
}
@@ -194,7 +194,7 @@ pub trait MutVisitor: Sized + MutVisitorResult {
walk_generic_arg(self, arg);
}
- fn visit_ty(&mut self, t: &mut P) {
+ fn visit_ty(&mut self, t: &mut Ty) {
walk_ty(self, t);
}
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs
index 54781e8235e2..9b4535dcfbce 100644
--- a/compiler/rustc_ast/src/token.rs
+++ b/compiler/rustc_ast/src/token.rs
@@ -1085,6 +1085,7 @@ pub enum NtExprKind {
Expr2021 { inferred: bool },
}
+/// A macro nonterminal, known in documentation as a fragment specifier.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
pub enum NonterminalKind {
Item,
diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs
index 1449a4a5fb30..bd2ab34bfc19 100644
--- a/compiler/rustc_ast/src/visit.rs
+++ b/compiler/rustc_ast/src/visit.rs
@@ -884,7 +884,7 @@ macro_rules! common_visitor_and_walkers {
TyKind::BareFn(function_declaration) => {
let BareFnTy { safety, ext: _, generic_params, decl, decl_span } =
&$($mut)? **function_declaration;
- visit_safety(vis, safety);
+ try_visit!(visit_safety(vis, safety));
try_visit!(visit_generic_params(vis, generic_params));
try_visit!(vis.visit_fn_decl(decl));
try_visit!(visit_span(vis, decl_span));
@@ -1235,7 +1235,7 @@ macro_rules! common_visitor_and_walkers {
bounds,
bound_generic_params,
}) => {
- visit_generic_params(vis, bound_generic_params);
+ try_visit!(visit_generic_params(vis, bound_generic_params));
try_visit!(vis.visit_ty(bounded_ty));
walk_list!(vis, visit_param_bound, bounds, BoundKind::Bound);
}
@@ -1420,7 +1420,7 @@ macro_rules! common_visitor_and_walkers {
let StructExpr { qself, path, fields, rest } = &$($mut)?**se;
try_visit!(vis.visit_qself(qself));
try_visit!(vis.visit_path(path));
- visit_expr_fields(vis, fields);
+ try_visit!(visit_expr_fields(vis, fields));
match rest {
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
StructRest::Rest(_span) => {}
diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl
index 5ef76fb64aaf..50eb7c7ae99b 100644
--- a/compiler/rustc_ast_lowering/messages.ftl
+++ b/compiler/rustc_ast_lowering/messages.ftl
@@ -179,6 +179,8 @@ ast_lowering_underscore_expr_lhs_assign =
in expressions, `_` can only be used on the left-hand side of an assignment
.label = `_` not allowed here
+ast_lowering_union_default_field_values = unions cannot have default field values
+
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
using both label and output operands for inline assembly is unstable
diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs
index 576fa9731e90..b444324ef914 100644
--- a/compiler/rustc_ast_lowering/src/errors.rs
+++ b/compiler/rustc_ast_lowering/src/errors.rs
@@ -475,3 +475,10 @@ pub(crate) struct UseConstGenericArg {
#[suggestion_part(code = "{other_args}")]
pub call_args: Span,
}
+
+#[derive(Diagnostic)]
+#[diag(ast_lowering_union_default_field_values)]
+pub(crate) struct UnionWithDefault {
+ #[primary_span]
+ pub span: Span,
+}
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index 49110c93954a..ef27d0ef69b1 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -17,6 +17,7 @@ use tracing::instrument;
use super::errors::{
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
+ UnionWithDefault,
};
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
@@ -316,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.arena.alloc_from_iter(
- enum_definition.variants.iter().map(|x| this.lower_variant(x)),
+ enum_definition.variants.iter().map(|x| this.lower_variant(i, x)),
)
},
);
@@ -328,7 +329,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
- |this| this.lower_variant_data(hir_id, struct_def),
+ |this| this.lower_variant_data(hir_id, i, struct_def),
);
hir::ItemKind::Struct(ident, generics, struct_def)
}
@@ -338,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
id,
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
- |this| this.lower_variant_data(hir_id, vdata),
+ |this| this.lower_variant_data(hir_id, i, vdata),
);
hir::ItemKind::Union(ident, generics, vdata)
}
@@ -714,13 +715,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
- fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
+ fn lower_variant(&mut self, item_kind: &ItemKind, v: &Variant) -> hir::Variant<'hir> {
let hir_id = self.lower_node_id(v.id);
self.lower_attrs(hir_id, &v.attrs, v.span);
hir::Variant {
hir_id,
def_id: self.local_def_id(v.id),
- data: self.lower_variant_data(hir_id, &v.data),
+ data: self.lower_variant_data(hir_id, item_kind, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const_to_anon_const(e)),
ident: self.lower_ident(v.ident),
span: self.lower_span(v.span),
@@ -730,15 +731,36 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_variant_data(
&mut self,
parent_id: hir::HirId,
+ item_kind: &ItemKind,
vdata: &VariantData,
) -> hir::VariantData<'hir> {
match vdata {
- VariantData::Struct { fields, recovered } => hir::VariantData::Struct {
- fields: self
+ VariantData::Struct { fields, recovered } => {
+ let fields = self
.arena
- .alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
- recovered: *recovered,
- },
+ .alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f)));
+
+ if let ItemKind::Union(..) = item_kind {
+ for field in &fields[..] {
+ if let Some(default) = field.default {
+ // Unions cannot derive `Default`, and it's not clear how to use default
+ // field values of unions if that was supported. Therefore, blanket reject
+ // trying to use field values with unions.
+ if self.tcx.features().default_field_values() {
+ self.dcx().emit_err(UnionWithDefault { span: default.span });
+ } else {
+ let _ = self.dcx().span_delayed_bug(
+ default.span,
+ "expected union default field values feature gate error but none \
+ was produced",
+ );
+ }
+ }
+ }
+ }
+
+ hir::VariantData::Struct { fields, recovered: *recovered }
+ }
VariantData::Tuple(fields, id) => {
let ctor_id = self.lower_node_id(*id);
self.alias_attrs(ctor_id, parent_id);
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 018887d0e8ea..b69a91e2f5f8 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -224,20 +224,6 @@ impl<'a> AstValidator<'a> {
}
}
- fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
- if let Some(ref ident) = field.ident
- && ident.name == kw::Underscore
- {
- self.visit_vis(&field.vis);
- self.visit_ident(ident);
- self.visit_ty_common(&field.ty);
- self.walk_ty(&field.ty);
- walk_list!(self, visit_attribute, &field.attrs);
- } else {
- self.visit_field_def(field);
- }
- }
-
fn dcx(&self) -> DiagCtxtHandle<'a> {
self.sess.dcx()
}
@@ -1135,8 +1121,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
- // Permit `Anon{Struct,Union}` as field type.
- walk_list!(self, visit_struct_field_def, fields);
+ walk_list!(self, visit_field_def, fields);
}
_ => visit::walk_item(self, item),
},
@@ -1148,8 +1133,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
VariantData::Struct { fields, .. } => {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.visit_generics(generics);
- // Permit `Anon{Struct,Union}` as field type.
- walk_list!(self, visit_struct_field_def, fields);
+ walk_list!(self, visit_field_def, fields);
}
_ => visit::walk_item(self, item),
}
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
index c4b0f503664e..095c0df98acc 100644
--- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
@@ -342,10 +342,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
}
}
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
- let sp = info
- .span
- .find_ancestor_in_same_ctxt(local_decl.source_info.span)
- .unwrap_or(info.span);
+ let sp = info.span.find_oldest_ancestor_in_same_ctxt();
if info.tail_result_is_ignored {
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs
index da01e3e9607b..fe44350863c9 100644
--- a/compiler/rustc_builtin_macros/src/cfg_eval.rs
+++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs
@@ -155,7 +155,7 @@ impl CfgEval<'_> {
impl MutVisitor for CfgEval<'_> {
#[instrument(level = "trace", skip(self))]
- fn visit_expr(&mut self, expr: &mut P) {
+ fn visit_expr(&mut self, expr: &mut ast::Expr) {
self.0.configure_expr(expr, false);
mut_visit::walk_expr(self, expr);
}
diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
index 0794192621a9..3a20b39798d7 100644
--- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs
@@ -1,5 +1,4 @@
use ast::HasAttrs;
-use ast::ptr::P;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::visit::BoundKind;
use rustc_ast::{
@@ -378,11 +377,11 @@ struct TypeSubstitution<'a> {
}
impl<'a> ast::mut_visit::MutVisitor for TypeSubstitution<'a> {
- fn visit_ty(&mut self, ty: &mut P) {
+ fn visit_ty(&mut self, ty: &mut ast::Ty) {
if let Some(name) = ty.kind.is_simple_path()
&& name == self.from_name
{
- **ty = self.to_ty.clone();
+ *ty = self.to_ty.clone();
self.rewritten = true;
} else {
ast::mut_visit::walk_ty(self, ty);
diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs
index 012e4dbc3ec9..524ebde1c743 100644
--- a/compiler/rustc_codegen_cranelift/example/mini_core.rs
+++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs
@@ -14,8 +14,14 @@
#![no_core]
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
+#[lang = "pointee_sized"]
+pub trait PointeeSized {}
+
+#[lang = "meta_sized"]
+pub trait MetaSized: PointeeSized {}
+
#[lang = "sized"]
-pub trait Sized {}
+pub trait Sized: MetaSized {}
#[lang = "destruct"]
pub trait Destruct {}
@@ -24,35 +30,35 @@ pub trait Destruct {}
pub trait Tuple {}
#[lang = "unsize"]
-pub trait Unsize {}
+pub trait Unsize: PointeeSized {}
#[lang = "coerce_unsized"]
pub trait CoerceUnsized {}
-impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
-impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
-impl, U: ?Sized> CoerceUnsized<*const U> for *const T {}
-impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
+impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
+impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
+impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
#[lang = "dispatch_from_dyn"]
pub trait DispatchFromDyn {}
// &T -> &U
-impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
-impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
-impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
+impl, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
-impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
-impl, U: ?Sized> DispatchFromDyn> for Box {}
+impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
+impl, U: MetaSized> DispatchFromDyn> for Box {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}
-impl LegacyReceiver for &T {}
-impl LegacyReceiver for &mut T {}
-impl LegacyReceiver for Box {}
+impl LegacyReceiver for &T {}
+impl LegacyReceiver for &mut T {}
+impl LegacyReceiver for Box {}
#[lang = "copy"]
pub trait Copy {}
@@ -74,9 +80,9 @@ impl Copy for isize {}
impl Copy for f32 {}
impl Copy for f64 {}
impl Copy for char {}
-impl<'a, T: ?Sized> Copy for &'a T {}
-impl Copy for *const T {}
-impl Copy for *mut T {}
+impl<'a, T: PointeeSized> Copy for &'a T {}
+impl Copy for *const T {}
+impl Copy for *mut T {}
impl Copy for Option {}
#[lang = "sync"]
@@ -94,17 +100,17 @@ unsafe impl Sync for i32 {}
unsafe impl Sync for isize {}
unsafe impl Sync for char {}
unsafe impl Sync for f32 {}
-unsafe impl<'a, T: ?Sized> Sync for &'a T {}
+unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
unsafe impl Sync for [T; N] {}
#[lang = "freeze"]
unsafe auto trait Freeze {}
-unsafe impl Freeze for PhantomData {}
-unsafe impl Freeze for *const T {}
-unsafe impl Freeze for *mut T {}
-unsafe impl Freeze for &T {}
-unsafe impl Freeze for &mut T {}
+unsafe impl Freeze for PhantomData {}
+unsafe impl Freeze for *const T {}
+unsafe impl Freeze for *mut T {}
+unsafe impl Freeze for &T {}
+unsafe impl Freeze for &mut T {}
#[lang = "structural_peq"]
pub trait StructuralPartialEq {}
@@ -443,7 +449,7 @@ pub enum Option {
pub use Option::*;
#[lang = "phantom_data"]
-pub struct PhantomData;
+pub struct PhantomData;
#[lang = "fn_once"]
#[rustc_paren_sugar]
@@ -564,18 +570,18 @@ pub trait Deref {
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
-pub struct NonNull(pub *const T);
+pub struct NonNull(pub *const T);
-impl CoerceUnsized> for NonNull where T: Unsize {}
-impl DispatchFromDyn> for NonNull where T: Unsize {}
+impl CoerceUnsized> for NonNull where T: Unsize {}
+impl DispatchFromDyn> for NonNull where T: Unsize {}
-pub struct Unique {
+pub struct Unique {
pub pointer: NonNull,
pub _marker: PhantomData,
}
-impl CoerceUnsized> for Unique where T: Unsize {}
-impl DispatchFromDyn> for Unique where T: Unsize {}
+impl CoerceUnsized> for Unique where T: Unsize {}
+impl DispatchFromDyn> for Unique where T: Unsize {}
#[lang = "global_alloc_ty"]
pub struct Global;
diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs
index aca1f0080efd..9dfb12be2436 100644
--- a/compiler/rustc_codegen_gcc/example/mini_core.rs
+++ b/compiler/rustc_codegen_gcc/example/mini_core.rs
@@ -19,8 +19,14 @@ unsafe extern "C" fn _Unwind_Resume() {
intrinsics::unreachable();
}
+#[lang = "pointee_sized"]
+pub trait PointeeSized {}
+
+#[lang = "meta_sized"]
+pub trait MetaSized: PointeeSized {}
+
#[lang = "sized"]
-pub trait Sized {}
+pub trait Sized: MetaSized {}
#[lang = "destruct"]
pub trait Destruct {}
@@ -29,35 +35,35 @@ pub trait Destruct {}
pub trait Tuple {}
#[lang = "unsize"]
-pub trait Unsize {}
+pub trait Unsize: PointeeSized {}
#[lang = "coerce_unsized"]
pub trait CoerceUnsized {}
-impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
-impl<'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
-impl, U: ?Sized> CoerceUnsized<*const U> for *const T {}
-impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
+impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
+impl, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
+impl, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
#[lang = "dispatch_from_dyn"]
pub trait DispatchFromDyn {}
// &T -> &U
-impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
-impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
+impl<'a, T: PointeeSized + Unsize, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
-impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
+impl, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
-impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
-impl, U: ?Sized> DispatchFromDyn> for Box {}
+impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
+impl, U: MetaSized> DispatchFromDyn> for Box {}
#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}
-impl LegacyReceiver for &T {}
-impl LegacyReceiver for &mut T {}
-impl LegacyReceiver for Box {}
+impl LegacyReceiver for &T {}
+impl LegacyReceiver for &mut T {}
+impl LegacyReceiver for Box {}
#[lang = "receiver"]
trait Receiver {}
@@ -84,9 +90,9 @@ impl Copy for i128 {}
impl Copy for f32 {}
impl Copy for f64 {}
impl Copy for char {}
-impl<'a, T: ?Sized> Copy for &'a T {}
-impl Copy for *const T {}
-impl Copy for *mut T {}
+impl<'a, T: PointeeSized> Copy for &'a T {}
+impl Copy for *const T {}
+impl Copy for *mut T {}
#[lang = "sync"]
pub unsafe trait Sync {}
@@ -102,17 +108,17 @@ unsafe impl Sync for i16 {}
unsafe impl Sync for i32 {}
unsafe impl Sync for isize {}
unsafe impl Sync for char {}
-unsafe impl<'a, T: ?Sized> Sync for &'a T {}
+unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
unsafe impl Sync for [u8; 16] {}
#[lang = "freeze"]
unsafe auto trait Freeze {}
-unsafe impl Freeze for PhantomData {}
-unsafe impl Freeze for *const T {}
-unsafe impl Freeze for *mut T {}
-unsafe impl Freeze for &T {}
-unsafe impl Freeze for &mut T {}
+unsafe impl Freeze for PhantomData {}
+unsafe impl Freeze for *const T {}
+unsafe impl Freeze for *mut T {}
+unsafe impl Freeze for &T {}
+unsafe impl Freeze for &mut T {}
#[lang = "structural_peq"]
pub trait StructuralPartialEq {}
@@ -456,7 +462,7 @@ pub enum Option {
pub use Option::*;
#[lang = "phantom_data"]
-pub struct PhantomData;
+pub struct PhantomData;
#[lang = "fn_once"]
#[rustc_paren_sugar]
@@ -576,18 +582,18 @@ impl Allocator for Global {}
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
-pub struct NonNull(pub *const T);
+pub struct NonNull(pub *const T);
-impl CoerceUnsized> for NonNull where T: Unsize {}
-impl DispatchFromDyn> for NonNull where T: Unsize {}
+impl CoerceUnsized> for NonNull where T: Unsize {}
+impl DispatchFromDyn> for NonNull where T: Unsize {}
-pub struct Unique {
+pub struct Unique {
pub pointer: NonNull,
pub _marker: PhantomData,
}
-impl CoerceUnsized> for Unique where T: Unsize {}
-impl DispatchFromDyn> for Unique where T: Unsize {}
+impl CoerceUnsized> for Unique where T: Unsize {}
+impl DispatchFromDyn> for Unique where T: Unsize {}
#[lang = "owned_box"]
pub struct Box(Unique, A);
diff --git a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
index c5c13ac097a2..b07d9a5cfca8 100644
--- a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
+++ b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs
@@ -114,7 +114,7 @@ fn match_args_from_caller_to_enzyme<'ll>(
let mul = unsafe {
llvm::LLVMBuildMul(
builder.llbuilder,
- cx.get_const_i64(elem_bytes_size),
+ cx.get_const_int(cx.type_i64(), elem_bytes_size),
next_outer_arg,
UNNAMED,
)
@@ -385,7 +385,7 @@ fn generate_enzyme_call<'ll>(
if attrs.width > 1 {
let enzyme_width = cx.create_metadata("enzyme_width".to_string()).unwrap();
args.push(cx.get_metadata_value(enzyme_width));
- args.push(cx.get_const_i64(attrs.width as u64));
+ args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
}
let has_sret = has_sret(outer_fn);
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs
index 3cfa96393e92..ae5add59322f 100644
--- a/compiler/rustc_codegen_llvm/src/common.rs
+++ b/compiler/rustc_codegen_llvm/src/common.rs
@@ -99,14 +99,14 @@ impl<'ll, CX: Borrow>> BackendTypes for GenericCx<'ll, CX> {
type DIVariable = &'ll llvm::debuginfo::DIVariable;
}
-impl<'ll> CodegenCx<'ll, '_> {
+impl<'ll, CX: Borrow>> GenericCx<'ll, CX> {
pub(crate) fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
let len = u64::try_from(elts.len()).expect("LLVMConstArray2 elements len overflow");
unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) }
}
pub(crate) fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
- bytes_in_context(self.llcx, bytes)
+ bytes_in_context(self.llcx(), bytes)
}
pub(crate) fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs
index bff95ea46fa7..0324dff6ff25 100644
--- a/compiler/rustc_codegen_llvm/src/context.rs
+++ b/compiler/rustc_codegen_llvm/src/context.rs
@@ -679,11 +679,8 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> {
llvm::LLVMMetadataAsValue(self.llcx(), metadata)
}
- // FIXME(autodiff): We should split `ConstCodegenMethods` to pull the reusable parts
- // onto a trait that is also implemented for GenericCx.
- pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value {
- let ty = unsafe { llvm::LLVMInt64TypeInContext(self.llcx()) };
- unsafe { llvm::LLVMConstInt(ty, n, llvm::False) }
+ pub(crate) fn get_const_int(&self, ty: &'ll Type, val: u64) -> &'ll Value {
+ unsafe { llvm::LLVMConstInt(ty, val, llvm::False) }
}
pub(crate) fn get_function(&self, name: &str) -> Option<&'ll Value> {
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 8c52ed6ed123..8882ba359b77 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -69,23 +69,6 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
}
}
-fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) {
- let print_native_static_libs =
- sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
- let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib);
- if print_native_static_libs {
- if !has_staticlib {
- sess.dcx()
- .warn(format!("cannot output linkage information without staticlib crate-type"));
- sess.dcx()
- .note(format!("consider `--crate-type staticlib` to print linkage information"));
- } else if !sess.opts.output_types.should_link() {
- sess.dcx()
- .warn(format!("cannot output linkage information when --emit link is not passed"));
- }
- }
-}
-
/// Performs the linkage portion of the compilation phase. This will generate all
/// of the requested outputs for this compilation session.
pub fn link_binary(
@@ -208,8 +191,6 @@ pub fn link_binary(
}
}
- check_link_info_print_request(sess, &codegen_results.crate_info.crate_types);
-
// Remove the temporary object file and metadata if we aren't saving temps.
sess.time("link_binary_remove_temps", || {
// If the user requests that temporaries are saved, don't delete any.
diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index a16862c41ee5..d091c46d9c18 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -379,6 +379,24 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
};
e_flags
}
+ Architecture::PowerPc64 => {
+ const EF_PPC64_ABI_UNKNOWN: u32 = 0;
+ const EF_PPC64_ABI_ELF_V1: u32 = 1;
+ const EF_PPC64_ABI_ELF_V2: u32 = 2;
+
+ match sess.target.options.llvm_abiname.as_ref() {
+ // If the flags do not correctly indicate the ABI,
+ // linkers such as ld.lld assume that the ppc64 object files are always ELFv2
+ // which leads to broken binaries if ELFv1 is used for the object files.
+ "elfv1" => EF_PPC64_ABI_ELF_V1,
+ "elfv2" => EF_PPC64_ABI_ELF_V2,
+ "" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
+ bug!("No ABI specified for this PPC64 ELF target");
+ }
+ // Fall back
+ _ => EF_PPC64_ABI_UNKNOWN,
+ }
+ }
_ => 0,
}
}
diff --git a/compiler/rustc_data_structures/src/aligned.rs b/compiler/rustc_data_structures/src/aligned.rs
index a636d09fcae2..111740e55092 100644
--- a/compiler/rustc_data_structures/src/aligned.rs
+++ b/compiler/rustc_data_structures/src/aligned.rs
@@ -1,5 +1,7 @@
use std::ptr::Alignment;
+use rustc_serialize::PointeeSized;
+
/// Returns the ABI-required minimum alignment of a type in bytes.
///
/// This is equivalent to [`align_of`], but also works for some unsized
@@ -17,7 +19,7 @@ pub const fn align_of() -> Alignment {
/// example `[T]` has alignment of `T`.
///
/// [`align_of::()`]: align_of
-pub unsafe trait Aligned {
+pub unsafe trait Aligned: PointeeSized {
/// Alignment of `Self`.
const ALIGN: Alignment;
}
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index eb3817a80a72..0431182e9e2a 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -12,6 +12,7 @@
#![allow(rustc::potential_query_instability)]
#![cfg_attr(bootstrap, feature(cfg_match))]
#![cfg_attr(not(bootstrap), feature(cfg_select))]
+#![cfg_attr(not(bootstrap), feature(sized_hierarchy))]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
@@ -43,6 +44,9 @@ use std::fmt;
pub use atomic_ref::AtomicRef;
pub use ena::{snapshot_vec, undo_log, unify};
pub use rustc_index::static_assert_size;
+// re-exported for `rustc_smir`
+// FIXME(sized_hierarchy): remove with `cfg(bootstrap)`, see `rustc_serialize/src/lib.rs`
+pub use rustc_serialize::PointeeSized;
pub mod aligned;
pub mod base_n;
diff --git a/compiler/rustc_data_structures/src/marker.rs b/compiler/rustc_data_structures/src/marker.rs
index e0df1b232e13..4846bc997f13 100644
--- a/compiler/rustc_data_structures/src/marker.rs
+++ b/compiler/rustc_data_structures/src/marker.rs
@@ -1,5 +1,7 @@
use std::alloc::Allocator;
+use rustc_serialize::PointeeSized;
+
#[diagnostic::on_unimplemented(message = "`{Self}` doesn't implement `DynSend`. \
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`")]
// This is an auto trait for types which can be sent across threads if `sync::is_dyn_thread_safe()`
@@ -15,7 +17,7 @@ pub unsafe auto trait DynSend {}
pub unsafe auto trait DynSync {}
// Same with `Sync` and `Send`.
-unsafe impl DynSend for &T {}
+unsafe impl DynSend for &T {}
macro_rules! impls_dyn_send_neg {
($([$t1: ty $(where $($generics1: tt)*)?])*) => {
@@ -27,9 +29,9 @@ macro_rules! impls_dyn_send_neg {
impls_dyn_send_neg!(
[std::env::Args]
[std::env::ArgsOs]
- [*const T where T: ?Sized]
- [*mut T where T: ?Sized]
- [std::ptr::NonNull where T: ?Sized]
+ [*const T where T: ?Sized + PointeeSized]
+ [*mut T where T: ?Sized + PointeeSized]
+ [std::ptr::NonNull where T: ?Sized + PointeeSized]
[std::rc::Rc where T: ?Sized, A: Allocator]
[std::rc::Weak where T: ?Sized, A: Allocator]
[std::sync::MutexGuard<'_, T> where T: ?Sized]
@@ -100,12 +102,12 @@ macro_rules! impls_dyn_sync_neg {
impls_dyn_sync_neg!(
[std::env::Args]
[std::env::ArgsOs]
- [*const T where T: ?Sized]
- [*mut T where T: ?Sized]
+ [*const T where T: ?Sized + PointeeSized]
+ [*mut T where T: ?Sized + PointeeSized]
[std::cell::Cell where T: ?Sized]
[std::cell::RefCell where T: ?Sized]
[std::cell::UnsafeCell where T: ?Sized]
- [std::ptr::NonNull where T: ?Sized]
+ [std::ptr::NonNull where T: ?Sized + PointeeSized]
[std::rc::Rc where T: ?Sized, A: Allocator]
[std::rc::Weak where T: ?Sized, A: Allocator]
[std::cell::OnceCell where T]
@@ -175,10 +177,10 @@ impl_dyn_sync!(
[thin_vec::ThinVec where T: DynSync]
);
-pub fn assert_dyn_sync() {}
-pub fn assert_dyn_send() {}
-pub fn assert_dyn_send_val(_t: &T) {}
-pub fn assert_dyn_send_sync_val(_t: &T) {}
+pub fn assert_dyn_sync() {}
+pub fn assert_dyn_send() {}
+pub fn assert_dyn_send_val(_t: &T) {}
+pub fn assert_dyn_send_sync_val(_t: &T) {}
#[derive(Copy, Clone)]
pub struct FromDyn(T);
@@ -231,10 +233,10 @@ impl std::ops::DerefMut for FromDyn {
// an instance of `DynSend` and `DynSync`, since the compiler cannot infer
// it automatically in some cases. (e.g. Box)
#[derive(Copy, Clone)]
-pub struct IntoDynSyncSend(pub T);
+pub struct IntoDynSyncSend(pub T);
-unsafe impl DynSend for IntoDynSyncSend {}
-unsafe impl DynSync for IntoDynSyncSend {}
+unsafe impl DynSend for IntoDynSyncSend {}
+unsafe impl DynSync for IntoDynSyncSend {}
impl std::ops::Deref for IntoDynSyncSend {
type Target = T;
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index ec0af67c0463..b697f2049bd8 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -444,7 +444,7 @@ pub(crate) struct InvalidFragmentSpecifier {
#[primary_span]
pub span: Span,
pub fragment: Ident,
- pub help: String,
+ pub help: &'static str,
}
#[derive(Diagnostic)]
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 3cfeb01ea477..9fd524ef45cd 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -1768,7 +1768,7 @@ impl InvocationCollectorNode for ast::Crate {
}
}
-impl InvocationCollectorNode for P {
+impl InvocationCollectorNode for ast::Ty {
type OutputTy = P;
const KIND: AstFragmentKind = AstFragmentKind::Ty;
fn to_annotatable(self) -> Annotatable {
@@ -1791,7 +1791,7 @@ impl InvocationCollectorNode for P {
}
}
-impl InvocationCollectorNode for P {
+impl InvocationCollectorNode for ast::Pat {
type OutputTy = P;
const KIND: AstFragmentKind = AstFragmentKind::Pat;
fn to_annotatable(self) -> Annotatable {
@@ -1814,11 +1814,11 @@ impl InvocationCollectorNode for P {
}
}
-impl InvocationCollectorNode for P