Skip to content

Commit 8ebf042

Browse files
committed
Auto merge of rust-lang#112198 - compiler-errors:rollup-o2xe4of, r=compiler-errors
Rollup of 7 pull requests Successful merges: - rust-lang#111670 (Require that const param tys implement `ConstParamTy`) - rust-lang#111914 (CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi…) - rust-lang#112030 (Migrate `item_trait_alias` to Askama) - rust-lang#112150 (Support 128-bit atomics on all x86_64 Apple targets) - rust-lang#112174 (Fix broken link) - rust-lang#112190 (Improve comments on `TyCtxt` and `GlobalCtxt`.) - rust-lang#112193 (Check tuple elements are `Sized` in `offset_of`) Failed merges: - rust-lang#112071 (Group rfcs tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 33c3d10 + ebb7f64 commit 8ebf042

File tree

78 files changed

+717
-349
lines changed

Some content is hidden

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

78 files changed

+717
-349
lines changed

Diff for: compiler/rustc_error_codes/src/error_codes/E0741.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ struct A;
1010
struct B<const X: A>; // error!
1111
```
1212

13-
Only structural-match types (that is, types that derive `PartialEq` and `Eq`)
14-
may be used as the types of const generic parameters.
13+
Only structural-match types, which are types that derive `PartialEq` and `Eq`
14+
and implement `ConstParamTy`, may be used as the types of const generic
15+
parameters.
1516

16-
To fix the previous code example, we derive `PartialEq` and `Eq`:
17+
To fix the previous code example, we derive `PartialEq`, `Eq`, and
18+
`ConstParamTy`:
1719

1820
```
1921
#![feature(adt_const_params)]
2022
21-
#[derive(PartialEq, Eq)] // We derive both traits here.
23+
use std::marker::ConstParamTy;
24+
25+
#[derive(PartialEq, Eq, ConstParamTy)] // We derive both traits here.
2226
struct A;
2327
2428
struct B<const X: A>; // ok!

Diff for: compiler/rustc_errors/src/diagnostic_builder.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,22 @@ pub trait EmissionGuarantee: Sized {
115115
) -> DiagnosticBuilder<'_, Self>;
116116
}
117117

118-
/// Private module for sealing the `IsError` helper trait.
119-
mod sealed_level_is_error {
120-
use crate::Level;
121-
122-
/// Sealed helper trait for statically checking that a `Level` is an error.
123-
pub(crate) trait IsError<const L: Level> {}
124-
125-
impl IsError<{ Level::Bug }> for () {}
126-
impl IsError<{ Level::DelayedBug }> for () {}
127-
impl IsError<{ Level::Fatal }> for () {}
128-
// NOTE(eddyb) `Level::Error { lint: true }` is also an error, but lints
129-
// don't need error guarantees, as their levels are always dynamic.
130-
impl IsError<{ Level::Error { lint: false } }> for () {}
131-
}
132-
133118
impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> {
134119
/// Convenience function for internal use, clients should use one of the
135120
/// `struct_*` methods on [`Handler`].
136121
#[track_caller]
137-
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>, const L: Level>(
122+
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>>(
138123
handler: &'a Handler,
139124
message: M,
140-
) -> Self
141-
where
142-
(): sealed_level_is_error::IsError<L>,
143-
{
125+
) -> Self {
144126
Self {
145127
inner: DiagnosticBuilderInner {
146128
state: DiagnosticBuilderState::Emittable(handler),
147-
diagnostic: Box::new(Diagnostic::new_with_code(L, None, message)),
129+
diagnostic: Box::new(Diagnostic::new_with_code(
130+
Level::Error { lint: false },
131+
None,
132+
message,
133+
)),
148134
},
149135
_marker: PhantomData,
150136
}
@@ -203,9 +189,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
203189
handler: &Handler,
204190
msg: impl Into<DiagnosticMessage>,
205191
) -> DiagnosticBuilder<'_, Self> {
206-
DiagnosticBuilder::new_guaranteeing_error::<_, { Level::Error { lint: false } }>(
207-
handler, msg,
208-
)
192+
DiagnosticBuilder::new_guaranteeing_error(handler, msg)
209193
}
210194
}
211195

Diff for: compiler/rustc_errors/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![feature(array_windows)]
77
#![feature(drain_filter)]
88
#![feature(if_let_guard)]
9-
#![feature(adt_const_params)]
109
#![feature(let_chains)]
1110
#![feature(never_type)]
1211
#![feature(result_option_inspect)]
@@ -845,7 +844,7 @@ impl Handler {
845844
&self,
846845
msg: impl Into<DiagnosticMessage>,
847846
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
848-
DiagnosticBuilder::new_guaranteeing_error::<_, { Level::Error { lint: false } }>(self, msg)
847+
DiagnosticBuilder::new_guaranteeing_error(self, msg)
849848
}
850849

851850
/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+14-77
Original file line numberDiff line numberDiff line change
@@ -829,83 +829,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
829829
let ty = tcx.type_of(param.def_id).subst_identity();
830830

831831
if tcx.features().adt_const_params {
832-
if let Some(non_structural_match_ty) =
833-
traits::search_for_adt_const_param_violation(param.span, tcx, ty)
834-
{
835-
// We use the same error code in both branches, because this is really the same
836-
// issue: we just special-case the message for type parameters to make it
837-
// clearer.
838-
match non_structural_match_ty.kind() {
839-
ty::Param(_) => {
840-
// Const parameters may not have type parameters as their types,
841-
// because we cannot be sure that the type parameter derives `PartialEq`
842-
// and `Eq` (just implementing them is not enough for `structural_match`).
843-
struct_span_err!(
844-
tcx.sess,
845-
hir_ty.span,
846-
E0741,
847-
"`{ty}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
848-
used as the type of a const parameter",
849-
)
850-
.span_label(
851-
hir_ty.span,
852-
format!("`{ty}` may not derive both `PartialEq` and `Eq`"),
853-
)
854-
.note(
855-
"it is not currently possible to use a type parameter as the type of a \
856-
const parameter",
857-
)
858-
.emit();
859-
}
860-
ty::Float(_) => {
861-
struct_span_err!(
862-
tcx.sess,
863-
hir_ty.span,
864-
E0741,
865-
"`{ty}` is forbidden as the type of a const generic parameter",
866-
)
867-
.note("floats do not derive `Eq` or `Ord`, which are required for const parameters")
868-
.emit();
869-
}
870-
ty::FnPtr(_) => {
871-
struct_span_err!(
872-
tcx.sess,
873-
hir_ty.span,
874-
E0741,
875-
"using function pointers as const generic parameters is forbidden",
876-
)
877-
.emit();
878-
}
879-
ty::RawPtr(_) => {
880-
struct_span_err!(
881-
tcx.sess,
882-
hir_ty.span,
883-
E0741,
884-
"using raw pointers as const generic parameters is forbidden",
885-
)
886-
.emit();
887-
}
888-
_ => {
889-
let mut diag = struct_span_err!(
890-
tcx.sess,
891-
hir_ty.span,
892-
E0741,
893-
"`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
894-
the type of a const parameter",
895-
non_structural_match_ty,
896-
);
897-
898-
if ty == non_structural_match_ty {
899-
diag.span_label(
900-
hir_ty.span,
901-
format!("`{ty}` doesn't derive both `PartialEq` and `Eq`"),
902-
);
903-
}
904-
905-
diag.emit();
906-
}
907-
}
908-
}
832+
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
833+
let trait_def_id =
834+
tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span));
835+
wfcx.register_bound(
836+
ObligationCause::new(
837+
hir_ty.span,
838+
param.def_id,
839+
ObligationCauseCode::ConstParam(ty),
840+
),
841+
wfcx.param_env,
842+
ty,
843+
trait_def_id,
844+
);
845+
});
909846
} else {
910847
let err_ty_str;
911848
let mut is_ptr = true;

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -3117,16 +3117,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31173117
}
31183118
}
31193119
ty::Tuple(tys) => {
3120-
let fstr = field.as_str();
3121-
3122-
if let Ok(index) = fstr.parse::<usize>() {
3123-
if fstr == index.to_string() {
3124-
if let Some(&field_ty) = tys.get(index) {
3125-
field_indices.push(index.into());
3126-
current_container = field_ty;
3120+
if let Ok(index) = field.as_str().parse::<usize>()
3121+
&& field.name == sym::integer(index)
3122+
{
3123+
for ty in tys.iter().take(index + 1) {
3124+
self.require_type_is_sized(ty, expr.span, traits::MiscObligation);
3125+
}
3126+
if let Some(&field_ty) = tys.get(index) {
3127+
field_indices.push(index.into());
3128+
current_container = field_ty;
31273129

3128-
continue;
3129-
}
3130+
continue;
31303131
}
31313132
}
31323133
}

Diff for: compiler/rustc_middle/src/traits/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ pub enum ObligationCauseCode<'tcx> {
445445
/// Obligations to prove that a `std::ops::Drop` impl is not stronger than
446446
/// the ADT it's being implemented for.
447447
DropImpl,
448+
449+
/// Requirement for a `const N: Ty` to implement `Ty: ConstParamTy`
450+
ConstParam(Ty<'tcx>),
448451
}
449452

450453
/// The 'location' at which we try to perform HIR-based wf checking.

Diff for: compiler/rustc_middle/src/ty/context.rs

+12
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
478478
/// [rustc dev guide] for more details.
479479
///
480480
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/ty.html
481+
///
482+
/// An implementation detail: `TyCtxt` is a wrapper type for [GlobalCtxt],
483+
/// which is the struct that actually holds all the data. `TyCtxt` derefs to
484+
/// `GlobalCtxt`, and in practice `TyCtxt` is passed around everywhere, and all
485+
/// operations are done via `TyCtxt`. A `TyCtxt` is obtained for a `GlobalCtxt`
486+
/// by calling `enter` with a closure `f`. That function creates both the
487+
/// `TyCtxt`, and an `ImplicitCtxt` around it that is put into TLS. Within `f`:
488+
/// - The `ImplicitCtxt` is available implicitly via TLS.
489+
/// - The `TyCtxt` is available explicitly via the `tcx` parameter, and also
490+
/// implicitly within the `ImplicitCtxt`. Explicit access is preferred when
491+
/// possible.
481492
#[derive(Copy, Clone)]
482493
#[rustc_diagnostic_item = "TyCtxt"]
483494
#[rustc_pass_by_value]
@@ -493,6 +504,7 @@ impl<'tcx> Deref for TyCtxt<'tcx> {
493504
}
494505
}
495506

507+
/// See [TyCtxt] for details about this type.
496508
pub struct GlobalCtxt<'tcx> {
497509
pub arena: &'tcx WorkerLocal<Arena<'tcx>>,
498510
pub hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,

Diff for: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ fn encode_ty<'tcx>(
609609
}
610610

611611
// Function types
612-
ty::FnDef(def_id, substs)
613-
| ty::Closure(def_id, substs)
614-
| ty::Generator(def_id, substs, ..) => {
612+
ty::FnDef(def_id, substs) | ty::Closure(def_id, substs) => {
615613
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
616614
// as vendor extended type.
617615
let mut s = String::new();
@@ -622,6 +620,23 @@ fn encode_ty<'tcx>(
622620
typeid.push_str(&s);
623621
}
624622

623+
ty::Generator(def_id, substs, ..) => {
624+
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
625+
// as vendor extended type.
626+
let mut s = String::new();
627+
let name = encode_ty_name(tcx, *def_id);
628+
let _ = write!(s, "u{}{}", name.len(), &name);
629+
// Encode parent substs only
630+
s.push_str(&encode_substs(
631+
tcx,
632+
tcx.mk_substs(substs.as_generator().parent_substs()),
633+
dict,
634+
options,
635+
));
636+
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
637+
typeid.push_str(&s);
638+
}
639+
625640
// Pointer types
626641
ty::Ref(region, ty0, ..) => {
627642
// [U3mut]u3refI<element-type>E as vendor extended type qualifier and type
@@ -740,7 +755,12 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
740755
let mut ty = ty;
741756

742757
match ty.kind() {
743-
ty::Float(..) | ty::Char | ty::Str | ty::Never | ty::Foreign(..) => {}
758+
ty::Float(..)
759+
| ty::Char
760+
| ty::Str
761+
| ty::Never
762+
| ty::Foreign(..)
763+
| ty::GeneratorWitness(..) => {}
744764

745765
ty::Bool => {
746766
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -928,7 +948,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
928948

929949
ty::Bound(..)
930950
| ty::Error(..)
931-
| ty::GeneratorWitness(..)
932951
| ty::GeneratorWitnessMIR(..)
933952
| ty::Infer(..)
934953
| ty::Alias(..)

Diff for: compiler/rustc_target/src/abi/call/x86_64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// The classification code for the x86_64 ABI is taken from the clay language
2-
// https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp
2+
// https://github.com/jckarter/clay/blob/db0bd2702ab0b6e48965cd85f8859bbd5f60e48e/compiler/externals.cpp
33

44
use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind};
55
use crate::abi::{self, Abi, HasDataLayout, Size, TyAbiInterface, TyAndLayout};

Diff for: compiler/rustc_target/src/spec/x86_64_apple_ios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn target() -> Target {
1313
.into(),
1414
arch: arch.target_arch(),
1515
options: TargetOptions {
16-
max_atomic_width: Some(64),
16+
max_atomic_width: Some(128),
1717
stack_probes: StackProbeType::X86,
1818
..base
1919
},

Diff for: compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn target() -> Target {
1515
.into(),
1616
arch: arch.target_arch(),
1717
options: TargetOptions {
18-
max_atomic_width: Some(64),
18+
max_atomic_width: Some(128),
1919
stack_probes: StackProbeType::X86,
2020
..base
2121
},

Diff for: compiler/rustc_target/src/spec/x86_64_apple_tvos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn target() -> Target {
99
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(),
1010
arch: arch.target_arch(),
1111
options: TargetOptions {
12-
max_atomic_width: Some(64),
12+
max_atomic_width: Some(128),
1313
stack_probes: StackProbeType::X86,
1414
..opts("tvos", arch)
1515
},

Diff for: compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn target() -> Target {
1010
.into(),
1111
arch: arch.target_arch(),
1212
options: TargetOptions {
13-
max_atomic_width: Some(64),
13+
max_atomic_width: Some(128),
1414
stack_probes: StackProbeType::X86,
1515
forces_embed_bitcode: true,
1616
// Taken from a clang build on Xcode 11.4.1.

0 commit comments

Comments
 (0)