Skip to content

Commit

Permalink
Auto merge of rust-lang#112198 - compiler-errors:rollup-o2xe4of, r=co…
Browse files Browse the repository at this point in the history
…mpiler-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
  • Loading branch information
bors committed Jun 2, 2023
2 parents 33c3d10 + ebb7f64 commit 8ebf042
Show file tree
Hide file tree
Showing 78 changed files with 717 additions and 349 deletions.
12 changes: 8 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0741.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ struct A;
struct B<const X: A>; // error!
```

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

To fix the previous code example, we derive `PartialEq` and `Eq`:
To fix the previous code example, we derive `PartialEq`, `Eq`, and
`ConstParamTy`:

```
#![feature(adt_const_params)]
#[derive(PartialEq, Eq)] // We derive both traits here.
use std::marker::ConstParamTy;
#[derive(PartialEq, Eq, ConstParamTy)] // We derive both traits here.
struct A;
struct B<const X: A>; // ok!
Expand Down
32 changes: 8 additions & 24 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,22 @@ pub trait EmissionGuarantee: Sized {
) -> DiagnosticBuilder<'_, Self>;
}

/// Private module for sealing the `IsError` helper trait.
mod sealed_level_is_error {
use crate::Level;

/// Sealed helper trait for statically checking that a `Level` is an error.
pub(crate) trait IsError<const L: Level> {}

impl IsError<{ Level::Bug }> for () {}
impl IsError<{ Level::DelayedBug }> for () {}
impl IsError<{ Level::Fatal }> for () {}
// NOTE(eddyb) `Level::Error { lint: true }` is also an error, but lints
// don't need error guarantees, as their levels are always dynamic.
impl IsError<{ Level::Error { lint: false } }> for () {}
}

impl<'a> DiagnosticBuilder<'a, ErrorGuaranteed> {
/// Convenience function for internal use, clients should use one of the
/// `struct_*` methods on [`Handler`].
#[track_caller]
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>, const L: Level>(
pub(crate) fn new_guaranteeing_error<M: Into<DiagnosticMessage>>(
handler: &'a Handler,
message: M,
) -> Self
where
(): sealed_level_is_error::IsError<L>,
{
) -> Self {
Self {
inner: DiagnosticBuilderInner {
state: DiagnosticBuilderState::Emittable(handler),
diagnostic: Box::new(Diagnostic::new_with_code(L, None, message)),
diagnostic: Box::new(Diagnostic::new_with_code(
Level::Error { lint: false },
None,
message,
)),
},
_marker: PhantomData,
}
Expand Down Expand Up @@ -203,9 +189,7 @@ impl EmissionGuarantee for ErrorGuaranteed {
handler: &Handler,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, Self> {
DiagnosticBuilder::new_guaranteeing_error::<_, { Level::Error { lint: false } }>(
handler, msg,
)
DiagnosticBuilder::new_guaranteeing_error(handler, msg)
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#![feature(array_windows)]
#![feature(drain_filter)]
#![feature(if_let_guard)]
#![feature(adt_const_params)]
#![feature(let_chains)]
#![feature(never_type)]
#![feature(result_option_inspect)]
Expand Down Expand Up @@ -845,7 +844,7 @@ impl Handler {
&self,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
DiagnosticBuilder::new_guaranteeing_error::<_, { Level::Error { lint: false } }>(self, msg)
DiagnosticBuilder::new_guaranteeing_error(self, msg)
}

/// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors.
Expand Down
91 changes: 14 additions & 77 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,83 +829,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
let ty = tcx.type_of(param.def_id).subst_identity();

if tcx.features().adt_const_params {
if let Some(non_structural_match_ty) =
traits::search_for_adt_const_param_violation(param.span, tcx, ty)
{
// We use the same error code in both branches, because this is really the same
// issue: we just special-case the message for type parameters to make it
// clearer.
match non_structural_match_ty.kind() {
ty::Param(_) => {
// Const parameters may not have type parameters as their types,
// because we cannot be sure that the type parameter derives `PartialEq`
// and `Eq` (just implementing them is not enough for `structural_match`).
struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"`{ty}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
used as the type of a const parameter",
)
.span_label(
hir_ty.span,
format!("`{ty}` may not derive both `PartialEq` and `Eq`"),
)
.note(
"it is not currently possible to use a type parameter as the type of a \
const parameter",
)
.emit();
}
ty::Float(_) => {
struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"`{ty}` is forbidden as the type of a const generic parameter",
)
.note("floats do not derive `Eq` or `Ord`, which are required for const parameters")
.emit();
}
ty::FnPtr(_) => {
struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"using function pointers as const generic parameters is forbidden",
)
.emit();
}
ty::RawPtr(_) => {
struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"using raw pointers as const generic parameters is forbidden",
)
.emit();
}
_ => {
let mut diag = struct_span_err!(
tcx.sess,
hir_ty.span,
E0741,
"`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
the type of a const parameter",
non_structural_match_ty,
);

if ty == non_structural_match_ty {
diag.span_label(
hir_ty.span,
format!("`{ty}` doesn't derive both `PartialEq` and `Eq`"),
);
}

diag.emit();
}
}
}
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
let trait_def_id =
tcx.require_lang_item(LangItem::ConstParamTy, Some(hir_ty.span));
wfcx.register_bound(
ObligationCause::new(
hir_ty.span,
param.def_id,
ObligationCauseCode::ConstParam(ty),
),
wfcx.param_env,
ty,
trait_def_id,
);
});
} else {
let err_ty_str;
let mut is_ptr = true;
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3117,16 +3117,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
ty::Tuple(tys) => {
let fstr = field.as_str();

if let Ok(index) = fstr.parse::<usize>() {
if fstr == index.to_string() {
if let Some(&field_ty) = tys.get(index) {
field_indices.push(index.into());
current_container = field_ty;
if let Ok(index) = field.as_str().parse::<usize>()
&& field.name == sym::integer(index)
{
for ty in tys.iter().take(index + 1) {
self.require_type_is_sized(ty, expr.span, traits::MiscObligation);
}
if let Some(&field_ty) = tys.get(index) {
field_indices.push(index.into());
current_container = field_ty;

continue;
}
continue;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ pub enum ObligationCauseCode<'tcx> {
/// Obligations to prove that a `std::ops::Drop` impl is not stronger than
/// the ADT it's being implemented for.
DropImpl,

/// Requirement for a `const N: Ty` to implement `Ty: ConstParamTy`
ConstParam(Ty<'tcx>),
}

/// The 'location' at which we try to perform HIR-based wf checking.
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
/// [rustc dev guide] for more details.
///
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/ty.html
///
/// An implementation detail: `TyCtxt` is a wrapper type for [GlobalCtxt],
/// which is the struct that actually holds all the data. `TyCtxt` derefs to
/// `GlobalCtxt`, and in practice `TyCtxt` is passed around everywhere, and all
/// operations are done via `TyCtxt`. A `TyCtxt` is obtained for a `GlobalCtxt`
/// by calling `enter` with a closure `f`. That function creates both the
/// `TyCtxt`, and an `ImplicitCtxt` around it that is put into TLS. Within `f`:
/// - The `ImplicitCtxt` is available implicitly via TLS.
/// - The `TyCtxt` is available explicitly via the `tcx` parameter, and also
/// implicitly within the `ImplicitCtxt`. Explicit access is preferred when
/// possible.
#[derive(Copy, Clone)]
#[rustc_diagnostic_item = "TyCtxt"]
#[rustc_pass_by_value]
Expand All @@ -493,6 +504,7 @@ impl<'tcx> Deref for TyCtxt<'tcx> {
}
}

/// See [TyCtxt] for details about this type.
pub struct GlobalCtxt<'tcx> {
pub arena: &'tcx WorkerLocal<Arena<'tcx>>,
pub hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,7 @@ fn encode_ty<'tcx>(
}

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

ty::Generator(def_id, substs, ..) => {
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
// as vendor extended type.
let mut s = String::new();
let name = encode_ty_name(tcx, *def_id);
let _ = write!(s, "u{}{}", name.len(), &name);
// Encode parent substs only
s.push_str(&encode_substs(
tcx,
tcx.mk_substs(substs.as_generator().parent_substs()),
dict,
options,
));
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
typeid.push_str(&s);
}

// Pointer types
ty::Ref(region, ty0, ..) => {
// [U3mut]u3refI<element-type>E as vendor extended type qualifier and type
Expand Down Expand Up @@ -740,7 +755,12 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
let mut ty = ty;

match ty.kind() {
ty::Float(..) | ty::Char | ty::Str | ty::Never | ty::Foreign(..) => {}
ty::Float(..)
| ty::Char
| ty::Str
| ty::Never
| ty::Foreign(..)
| ty::GeneratorWitness(..) => {}

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

ty::Bound(..)
| ty::Error(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Infer(..)
| ty::Alias(..)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/abi/call/x86_64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// The classification code for the x86_64 ABI is taken from the clay language
// https://github.com/jckarter/clay/blob/master/compiler/src/externals.cpp
// https://github.com/jckarter/clay/blob/db0bd2702ab0b6e48965cd85f8859bbd5f60e48e/compiler/externals.cpp

use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind};
use crate::abi::{self, Abi, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/x86_64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn target() -> Target {
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
..base
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/x86_64_apple_ios_macabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn target() -> Target {
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
..base
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/x86_64_apple_tvos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn target() -> Target {
data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
..opts("tvos", arch)
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
.into(),
arch: arch.target_arch(),
options: TargetOptions {
max_atomic_width: Some(64),
max_atomic_width: Some(128),
stack_probes: StackProbeType::X86,
forces_embed_bitcode: true,
// Taken from a clang build on Xcode 11.4.1.
Expand Down
Loading

0 comments on commit 8ebf042

Please sign in to comment.