+where [();N/2]:,
+{
+ type R = Self;
+ fn func(self)->Self::R {
+ self
+ }
+}
+
+fn sample(p:P,f:Convert) -> i32
+where
+ P:Trait,Convert:Fn(P::R)->i32
+{
+ f(p.func())
+}
+
+fn main() {
+ let t = TraitImpl::<10>(4);
+ sample(t,|x|x.0);
+}
diff --git a/src/test/ui/associated-types/issue-91234.rs b/src/test/ui/associated-types/issue-91234.rs
new file mode 100644
index 0000000000000..2f6c2d3aebd0a
--- /dev/null
+++ b/src/test/ui/associated-types/issue-91234.rs
@@ -0,0 +1,13 @@
+// check-pass
+
+struct Struct;
+
+trait Trait {
+ type Type;
+}
+
+enum Enum<'a> where &'a Struct: Trait {
+ Variant(<&'a Struct as Trait>::Type)
+}
+
+fn main() {}
From a040b4189d326b25559041bd2c6452bfe0c9cfa7 Mon Sep 17 00:00:00 2001
From: b-naber
Date: Fri, 26 Nov 2021 23:37:24 +0100
Subject: [PATCH 3/7] more fixed issues
---
src/librustdoc/html/render/print_item.rs | 7 +++++++
src/test/ui/associated-types/issue-85103.rs | 9 +++++++++
src/test/ui/associated-types/issue-85103.stderr | 8 ++++++++
src/test/ui/associated-types/issue-91231.rs | 17 +++++++++++++++++
4 files changed, 41 insertions(+)
create mode 100644 src/test/ui/associated-types/issue-85103.rs
create mode 100644 src/test/ui/associated-types/issue-85103.stderr
create mode 100644 src/test/ui/associated-types/issue-91231.rs
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index d3738cfa3e781..48dd69155cea9 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -1769,6 +1769,13 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
the type was too big.
"
);
}
+ Err(LayoutError::NormalizationFailure(_, _)) => {
+ writeln!(
+ w,
+ "Note: Encountered an error during type layout; \
+ the type was not normalizable.
"
+ )
+ }
}
writeln!(w, "");
diff --git a/src/test/ui/associated-types/issue-85103.rs b/src/test/ui/associated-types/issue-85103.rs
new file mode 100644
index 0000000000000..c5e13856178de
--- /dev/null
+++ b/src/test/ui/associated-types/issue-85103.rs
@@ -0,0 +1,9 @@
+#![feature(rustc_attrs)]
+
+use std::borrow::Cow;
+
+#[rustc_layout(debug)]
+type Edges<'a, E> = Cow<'a, [E]>;
+//~^ ERROR layout error: NormalizationFailure
+
+fn main() {}
diff --git a/src/test/ui/associated-types/issue-85103.stderr b/src/test/ui/associated-types/issue-85103.stderr
new file mode 100644
index 0000000000000..142f3c411ec5c
--- /dev/null
+++ b/src/test/ui/associated-types/issue-85103.stderr
@@ -0,0 +1,8 @@
+error: layout error: NormalizationFailure(<[E] as std::borrow::ToOwned>::Owned, Type(<[E] as std::borrow::ToOwned>::Owned))
+ --> $DIR/issue-85103.rs:6:1
+ |
+LL | type Edges<'a, E> = Cow<'a, [E]>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/associated-types/issue-91231.rs b/src/test/ui/associated-types/issue-91231.rs
new file mode 100644
index 0000000000000..3c1cb81f09756
--- /dev/null
+++ b/src/test/ui/associated-types/issue-91231.rs
@@ -0,0 +1,17 @@
+// check-pass
+
+#![feature(extern_types)]
+#![allow(dead_code)]
+
+extern {
+ type Extern;
+}
+
+trait Trait {
+ type Type;
+}
+
+#[inline]
+fn f<'a>(_: <&'a Extern as Trait>::Type) where &'a Extern: Trait {}
+
+fn main() {}
From 0b32cf3a8d5bda2fb2599e658102e2d7bd70a07f Mon Sep 17 00:00:00 2001
From: b-naber
Date: Fri, 26 Nov 2021 23:39:48 +0100
Subject: [PATCH 4/7] remove static_assert_size on InterpError
---
compiler/rustc_middle/src/mir/interpret/error.rs | 3 ---
1 file changed, 3 deletions(-)
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index 3e307979f2d0a..8e4a17bfa65cb 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -492,9 +492,6 @@ impl dyn MachineStopType {
}
}
-#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
-static_assert_size!(InterpError<'_>, 88);
-
pub enum InterpError<'tcx> {
/// The program caused undefined behavior.
UndefinedBehavior(UndefinedBehaviorInfo<'tcx>),
From 84bcd40927d0547d36df8f6419b4d060c8c5a840 Mon Sep 17 00:00:00 2001
From: b-naber
Date: Fri, 26 Nov 2021 23:41:22 +0100
Subject: [PATCH 5/7] fix query description
---
compiler/rustc_middle/src/query/mod.rs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 12665be335492..8c1ffa1be3af5 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -1662,14 +1662,14 @@ rustc_queries! {
query try_normalize_generic_arg_after_erasing_regions(
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
) -> Result, NoSolution> {
- desc { "trying to normalize `{}`", goal.value }
+ desc { "normalizing `{}`", goal.value }
}
/// Do not call this query directly: invoke `try_normalize_erasing_regions` instead.
query try_normalize_mir_const_after_erasing_regions(
goal: ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
) -> Result, NoSolution> {
- desc { "trying to normalize `{}`", goal.value }
+ desc { "normalizing `{}`", goal.value }
}
query implied_outlives_bounds(
From 4d9a0bf21b5429c9e3d08b4a735c40d60114ba5f Mon Sep 17 00:00:00 2001
From: b-naber
Date: Wed, 1 Dec 2021 00:20:57 +0100
Subject: [PATCH 6/7] address review
---
compiler/rustc_middle/src/query/mod.rs | 5 +++++
compiler/rustc_middle/src/ty/layout.rs | 4 ++++
src/librustdoc/html/render/print_item.rs | 2 +-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 8c1ffa1be3af5..8667a6bea11f6 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -1644,6 +1644,11 @@ rustc_queries! {
desc { "normalizing `{:?}`", goal }
}
+ // FIXME: Implement `normalize_generic_arg_after_erasing_regions` and
+ // `normalize_mir_const_after_erasing_regions` in terms of
+ // `try_normalize_generic_arg_after_erasing_regions` and
+ // `try_normalize_mir_const_after_erasing_regions`, respectively.
+
/// Do not call this query directly: invoke `normalize_erasing_regions` instead.
query normalize_generic_arg_after_erasing_regions(
goal: ParamEnvAnd<'tcx, GenericArg<'tcx>>
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index 9c1407de812f5..57506bc68345b 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -240,6 +240,10 @@ fn layout_of<'tcx>(
let param_env = param_env.with_reveal_all_normalized(tcx);
let unnormalized_ty = ty;
+ // FIXME: We might want to have two different versions of `layout_of`:
+ // One that can be called after typecheck has completed and can use
+ // `normalize_erasing_regions` here and another one that can be called
+ // before typecheck has completed and uses `try_normalize_erasing_regions`.
let ty = match tcx.try_normalize_erasing_regions(param_env, ty) {
Ok(t) => t,
Err(normalization_error) => {
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 48dd69155cea9..62fdec15af420 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -1773,7 +1773,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
writeln!(
w,
"Note: Encountered an error during type layout; \
- the type was not normalizable.
"
+ the type failed to be normalized.