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

Correct regression in type-inference #27258

Merged
merged 1 commit into from Jul 25, 2015

Conversation

Projects
None yet
5 participants
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 24, 2015

Correct regression in type-inference caused by failing to reconfirm that
the object trait matches the required trait during trait selection. The
existing code was checking that the object trait WOULD match (in a
probe), but never executing the match outside of a probe.

This corrects various regressions observed in the wild, including
issue #26952. Fixes #26952.

r? @eddyb
cc @frankmcsherry

let upcast_trait_refs: Vec<_> = util::supertraits(self.tcx(), poly_trait_ref).collect();

// Find the first one that matches; this is what we are upcasting to.
let index =

This comment has been minimized.

@arielb1

arielb1 Jul 24, 2015

Contributor

nit: I think this iterator salad would actually be clearer as a for-loop

@@ -1367,11 +1367,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// correct trait, but also the correct type parameters.
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
// but `Foo` is declared as `trait Foo : Bar<u32>`.
let upcast_trait_refs = util::supertraits(self.tcx(), poly_trait_ref)

This comment has been minimized.

@arielb1

arielb1 Jul 24, 2015

Contributor

Just a reformatting?

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 24, 2015

r+ modulo nit

let mut upcast_trait_ref = None;
let mut vtable_base = 0;
// Collect the full set of supertraitrefs.
let upcast_trait_refs: Vec<_> = util::supertraits(self.tcx(), poly_trait_ref).collect();

This comment has been minimized.

@eddyb

eddyb Jul 24, 2015

Member

Couldn't this be done without collecting?

// Now that we found the correct trait ref, we have to match again outside
// the probe to confirm the effects.
let upcast_trait_ref = upcast_trait_refs[index].clone();
self.match_poly_trait_ref(obligation, upcast_trait_ref.clone()).unwrap();

This comment has been minimized.

@eddyb

eddyb Jul 24, 2015

Member

I think it would be enough to just add this and keep the non-allocating loop.

Correct regression in type-inference caused by failing to reconfirm that
the object trait matches the required trait during trait selection.  The
existing code was checking that the object trait WOULD match (in a
probe), but never executing the match outside of a probe.

This corrects various regressions observed in the wild, including
issue #26952. Fixes #26952.

@nikomatsakis nikomatsakis force-pushed the nikomatsakis:issue-26952 branch from 93e7295 to 4726bb4 Jul 24, 2015

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Jul 24, 2015

@eddyb updated

@@ -1898,7 +1898,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
/// erase, or otherwise "discharge" these bound regions, we change the
/// type from `Binder<T>` to just `T` (see
/// e.g. `liberate_late_bound_regions`).
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Binder<T>(pub T);

This comment has been minimized.

@eddyb

eddyb Jul 24, 2015

Member

Time to remove a thousand clone calls :P.
@huonw @Manishearth How about a lint against calling .clone() on a Copy type?

This comment has been minimized.

@Manishearth

Manishearth Jul 24, 2015

Member

Sounds good to me.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Jul 24, 2015

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 24, 2015

📌 Commit 4726bb4 has been approved by eddyb

Manishearth added a commit to Manishearth/rust that referenced this pull request Jul 24, 2015

Rollup merge of rust-lang#27258 - nikomatsakis:issue-26952, r=eddyb
Correct regression in type-inference caused by failing to reconfirm that
the object trait matches the required trait during trait selection.  The
existing code was checking that the object trait WOULD match (in a
probe), but never executing the match outside of a probe.

This corrects various regressions observed in the wild, including
issue rust-lang#26952. Fixes rust-lang#26952.

r? @eddyb 
cc @frankmcsherry

bors added a commit that referenced this pull request Jul 24, 2015

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 25, 2015

⌛️ Testing commit 4726bb4 with merge 7276d8b...

bors added a commit that referenced this pull request Jul 25, 2015

Auto merge of #27258 - nikomatsakis:issue-26952, r=eddyb
Correct regression in type-inference caused by failing to reconfirm that
the object trait matches the required trait during trait selection.  The
existing code was checking that the object trait WOULD match (in a
probe), but never executing the match outside of a probe.

This corrects various regressions observed in the wild, including
issue #26952. Fixes #26952.

r? @eddyb 
cc @frankmcsherry

@bors bors merged commit 4726bb4 into rust-lang:master Jul 25, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@nikomatsakis nikomatsakis deleted the nikomatsakis:issue-26952 branch Mar 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.