Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize the type Self resolves to in an impl #58757

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment so that we know we do this to normalize e.g. any unevaluated constants into their evaluated counterpart if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would '// Try to evaluate any associated constants' be an accurate way of phrasing it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really associated constants. Maybe

// Try to evaluate array length constants

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

}
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() {
}