summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos Oikonomopoulos <a.oikonomopoulos@vu.nl>2019-02-26 16:48:12 +0100
committerAngelos Oikonomopoulos <a.oikonomopoulos@vu.nl>2019-02-26 17:22:13 +0100
commit9b4055b30200caf366d387624fd5bbb03de8da13 (patch)
tree509075113b03725d220b8f8a2bfeeca5ea706df6
parentea43c3c688980edd6f09a4cb632c9eb996c4f2af (diff)
downloadrust-9b4055b30200caf366d387624fd5bbb03de8da13.tar.gz
Normalize the type Self resolves to in an impl
This is required at the very least in order to evaluate associated constants for arrays (see #58212).
-rw-r--r--src/librustc_typeck/astconv.rs3
-rw-r--r--src/test/run-pass/issues/issue-58212.rs13
2 files changed, 15 insertions, 1 deletions
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index db63f2aafbc..c52ff8bf650 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -1700,7 +1700,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
// `Self` in impl (we know the concrete type).
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
- tcx.at(span).type_of(def_id)
+ // Try to evaluate any array length constants
+ self.normalize_ty(span, tcx.at(span).type_of(def_id))
}
Def::SelfTy(Some(_), None) => {
// `Self` in trait.
diff --git a/src/test/run-pass/issues/issue-58212.rs b/src/test/run-pass/issues/issue-58212.rs
new file mode 100644
index 00000000000..76437630309
--- /dev/null
+++ b/src/test/run-pass/issues/issue-58212.rs
@@ -0,0 +1,13 @@
+trait FromUnchecked {
+ unsafe fn from_unchecked();
+}
+
+impl FromUnchecked for [u8; 1] {
+ unsafe fn from_unchecked() {
+ let mut array: Self = std::mem::uninitialized();
+ let _ptr = &mut array as *mut [u8] as *mut u8;
+ }
+}
+
+fn main() {
+}