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
don't emit a type error if autoderef ends in an inference variable, a…
…s long as we went through a raw pointer

This avoids a break in backward compatibility in the following case:

```
let ptr = std::ptr::null();
let _ = &data as *const *const ();
if data.null() {}
```
  • Loading branch information
mikeyhew committed Dec 17, 2017
commit e7d1542a52dd04b58058d5d170a7a9b09f528f8c
10 changes: 7 additions & 3 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// a real method lookup, this is a hard error (it's an
// ambiguity and we can't make progress).
if !is_suggestion.0 {
let t = self.structurally_resolved_type(span, final_ty);
assert_eq!(t, self.tcx.types.err);
return None
// don't report a type error if we dereferenced a raw pointer,
Copy link
Contributor

@arielb1 arielb1 Dec 12, 2017

Choose a reason for hiding this comment

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

Is that really a problem in practice?

If then, I think we might want a warning cycle here. This looks like a sort of expected inference breakage, so it should remain an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It broke something in libstd:

let mut data = ptr::null();

Here's a minimal reproduction:

fn main() {
    let data = std::ptr::null();
    let _ = &data as *const *const ();
    if data.is_null() {}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I get that. I think we should probably make this a future-compat warning, or an error with the arbitrary_self_types feature flag set.

// because that would break backwards compatibility in certain cases
if !reached_raw_pointer {
let t = self.structurally_resolved_type(span, final_ty);
assert_eq!(t, self.tcx.types.err);
return None
}
} else {
// If we're just looking for suggestions,
// though, ambiguity is no big thing, we can
Expand Down