Skip to content

Commit

Permalink
Rollup merge of rust-lang#58757 - aoikonomopoulos:issue-58212, r=oli-obk
Browse files Browse the repository at this point in the history
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
  • Loading branch information
Centril authored Feb 27, 2019
2 parents 30e20a3 + 9b4055b commit 2055bff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/test/run-pass/issues/issue-58212.rs
Original file line number Diff line number Diff line change
@@ -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() {
}

0 comments on commit 2055bff

Please sign in to comment.