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

arbitrary_self_types: add support for raw pointer self types #46664

Merged
merged 14 commits into from
Dec 19, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
changed some stuff in probe.rs and it broke libstd
  • Loading branch information
mikeyhew committed Dec 17, 2017
commit 083635eab2c146a35d734ab40c5a3ba5df720786
25 changes: 22 additions & 3 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ impl<'a, 'gcx, 'tcx> Deref for ProbeContext<'a, 'gcx, 'tcx> {
struct CandidateStep<'tcx> {
self_ty: Ty<'tcx>,
autoderefs: usize,
// true if the type results from a dereference of a raw pointer.
// when assembling candidates, we include these steps, but not when
// picking methods. This so that if we have `foo: *const Foo` and `Foo` has methods
// `fn by_raw_ptr(self: *const Self)` and `fn by_ref(&self)`, then
// `foo.by_raw_ptr()` will work and `foo.by_ref()` won't.
from_unsafe_deref: bool,
unsize: bool,
}

Expand Down Expand Up @@ -257,6 +263,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
vec![CandidateStep {
self_ty,
autoderefs: 0,
from_unsafe_deref: false,
unsize: false,
}]
};
Expand Down Expand Up @@ -289,14 +296,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
-> Option<Vec<CandidateStep<'tcx>>> {
// FIXME: we don't need to create the entire steps in one pass

let mut autoderef = self.autoderef(span, self_ty);
let mut autoderef = self.autoderef(span, self_ty).include_raw_pointers();
let mut reached_raw_pointer = false;
let mut steps: Vec<_> = autoderef.by_ref()
.map(|(ty, d)| {
CandidateStep {
let step = CandidateStep {
self_ty: ty,
autoderefs: d,
from_unsafe_deref: reached_raw_pointer,
unsize: false,
};
if let ty::TyRawPtr(_) = ty.sty {
// all the subsequent steps will be from_unsafe_deref
reached_raw_pointer = true;
}
step
})
.collect();

Expand All @@ -322,6 +336,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
steps.push(CandidateStep {
self_ty: self.tcx.mk_slice(elem_ty),
autoderefs: dereferences,
// this could be from an unsafe deref if we had
// a *mut/const [T; N]
from_unsafe_deref: reached_raw_pointer,
unsize: true,
});
}
Expand Down Expand Up @@ -830,7 +847,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
.iter()
.filter(|step| {
debug!("pick_core: step={:?}", step);
!step.self_ty.references_error()
// skip types that are from a type error or that would require dereferencing
// a raw pointer
!step.self_ty.references_error() && !step.from_unsafe_deref
}).flat_map(|step| {
self.pick_by_value_method(step).or_else(|| {
self.pick_autorefd_method(step, hir::MutImmutable).or_else(|| {
Expand Down