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

Replace consider_unification_despite_ambiguity with new obligation variant #32780

Merged
merged 2 commits into from
Apr 13, 2016

Conversation

soltanmm
Copy link

@soltanmm soltanmm commented Apr 6, 2016

Is work towards #32730. Addresses part one of #32286. Addresses #24210 and #26046 to some degree.

r? @nikomatsakis

@soltanmm
Copy link
Author

soltanmm commented Apr 7, 2016

w.r.t. the Travis failure: s'what I get for not running stage 2 tests locally, I guess.

@nikomatsakis
Copy link
Contributor

Hmm, the error is unexpected. I did not anticipate that this would affect anything like that (and it's interesting that this outdated help text still exists, too).

@@ -179,6 +179,9 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
ty::Predicate::TypeOutlives(..) => None,
ty::Predicate::WellFormed(..) => None,
ty::Predicate::ObjectSafe(..) => None,
ty::Predicate::ClosureKind(_closure_def_id, kind) => {
return Some(kind);
Copy link
Author

Choose a reason for hiding this comment

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

@nikomatsakis a note: changing this to expressing None (as opposed to returning) causes the stage 2 librustc_typeck compile to go through without adversely affecting tests. Not sure if that's 'right' though.

@nikomatsakis
Copy link
Contributor

@soltanmm I did some investigation. This fixes the problem, I believe:

diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index 84c277a..ed58070 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -47,7 +47,8 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
                           expected_sig: Option<ty::FnSig<'tcx>>) {
     let expr_def_id = fcx.tcx().map.local_def_id(expr.id);

-    debug!("check_closure opt_kind={:?} expected_sig={:?}",
+    debug!("check_closure expr.id={:?} opt_kind={:?} expected_sig={:?}",
+           expr.id,
            opt_kind,
            expected_sig);

@@ -179,9 +180,16 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
                 ty::Predicate::TypeOutlives(..) => None,
                 ty::Predicate::WellFormed(..) => None,
                 ty::Predicate::ObjectSafe(..) => None,
-                ty::Predicate::ClosureKind(_closure_def_id, kind) => {
-                    return Some(kind);
-                }
+
+                // NB: This predicate is created by breaking down a
+                // `ClosureType: FnFoo()` predicate, where
+                // `ClosureType` represents some `TyClosure`. It can't
+                // possibly be referring to the current closure,
+                // because we haven't produced the `TyClosure` for
+                // this closure yet; this is exactly why the other
+                // code is looking for a self type of a unresolved
+                // inference variable.
+                ty::Predicate::ClosureKind(..) => None,
             };
             opt_trait_ref
                 .and_then(|trait_ref| self_type_matches_expected_vid(fcx, trait_ref, expected_vid))

@nikomatsakis
Copy link
Contributor

Heh, oh, I see you already found that :)

@nikomatsakis
Copy link
Contributor

@soltanmm I think that's the right fix, see my code for a comment as to why (which we might as well include in the code)

let closure_span = infcx.tcx.map.span_if_local(closure_def_id).unwrap();
let mut err = struct_span_err!(
infcx.tcx.sess, closure_span, E0524,
"the closure implements `{}` but not `{}`",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think you should say something like "expected a closure that implements the {} trait, but this closure only implement {}". This fits our usual "expected, found" order better, and helps clarify that FnMut (etc) is a trait.

@nikomatsakis
Copy link
Contributor

@soltanmm sorry for dropping off the notifications grid for a few days, had to finish up a few things, but anyway ping me when you have a revision that addresses the nit and which changes the Some to None

@nikomatsakis
Copy link
Contributor

@soltanmm I'd like very much to see this land -- do you have time to rebase/fix? I could also do it for you.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Apr 13, 2016

📌 Commit de82fc4 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 13, 2016

⌛ Testing commit de82fc4 with merge 35dca7f...

bors added a commit that referenced this pull request Apr 13, 2016
Replace consider_unification_despite_ambiguity with new obligation variant

Is work towards #32730. Addresses part one of #32286. Addresses #24210 and #26046 to some degree.

r? @nikomatsakis
@bors bors merged commit de82fc4 into rust-lang:master Apr 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants