-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Remove duplicated errors for closure type mismatch #41760
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ use super::project; | |
use super::project::{normalize_with_depth, Normalized}; | ||
use super::{PredicateObligation, TraitObligation, ObligationCause}; | ||
use super::{ObligationCauseCode, BuiltinDerivedObligation, ImplDerivedObligation}; | ||
use super::{SelectionError, Unimplemented, OutputTypeParameterMismatch}; | ||
use super::{SelectionError, Unimplemented, ParameterCountMismatch, OutputTypeParameterMismatch}; | ||
use super::{ObjectCastObligation, Obligation}; | ||
use super::Reveal; | ||
use super::TraitNotObjectSafe; | ||
|
@@ -39,6 +39,7 @@ use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable}; | |
use traits; | ||
use ty::fast_reject; | ||
use ty::relate::TypeRelation; | ||
use ty::error::TypeError::{TupleSize, Sorts}; | ||
use middle::lang_items; | ||
|
||
use rustc_data_structures::bitvec::BitVector; | ||
|
@@ -2425,7 +2426,42 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { | |
expected_trait_ref.clone(), | ||
obligation_trait_ref.clone()) | ||
.map(|InferOk { obligations, .. }| self.inferred_obligations.extend(obligations)) | ||
.map_err(|e| OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e)) | ||
.map_err(|e| { | ||
let self_ty = expected_trait_ref.self_ty(); | ||
match (&self_ty.sty, &e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please just compare the # of parameters in the fn sig vs. the # of parameters in the obligation (that's |
||
(&ty::TyClosure(def_id, ..), &TupleSize(expected_found)) | | ||
(&ty::TyFnDef(def_id, ..), &TupleSize(expected_found)) => { | ||
// Expected `fn(x)`/`|x| { }`, found `fn(x, y)`/`|x, y| { }` | ||
ParameterCountMismatch(expected_found, self_ty, def_id) | ||
} | ||
(&ty::TyClosure(def_id, ..), &Sorts(expected_found)) | | ||
(&ty::TyFnDef(def_id, ..), &Sorts(expected_found)) => { | ||
// Expected `|| { }`, found `|x, y| { }` | ||
// Expected `fn(x)`, found `|| { }` | ||
let expected = if let ty::TyTuple(tys, _) = expected_found.expected.sty { | ||
tys.len() | ||
} else { | ||
1 | ||
}; | ||
let found = if let ty::TyTuple(tys, _) = expected_found.found.sty { | ||
tys.len() | ||
} else { | ||
1 | ||
}; | ||
|
||
if expected != found { | ||
let expected_found = ty::error::ExpectedFound { | ||
expected: expected, | ||
found: found, | ||
}; | ||
ParameterCountMismatch(expected_found, self_ty, def_id) | ||
} else { | ||
OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e) | ||
} | ||
} | ||
_ => OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e), | ||
} | ||
}) | ||
} | ||
|
||
fn confirm_builtin_unsize_candidate(&mut self, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,4 @@ fn main() { | |
|
||
needs_fn(1); | ||
//~^ ERROR : std::ops::Fn<(isize,)>` | ||
//~| ERROR : std::ops::FnOnce<(isize,)>` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,4 @@ | |
fn main() { | ||
"".chars().fold(|_, _| (), ()); | ||
//~^ ERROR E0277 | ||
//~| ERROR E0277 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds overly excessive. Outside of closures all trait errors are
Unimplemented
, so you are only showing 1 error per span.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was surprising to me how many tests were affected by this. I'll think of a different way to deduplicate these errors...
Originally I was trying to get to the point where only one of
FnMut
andFnOnce
were required, which feels like the correct way to accomplish this, but could not find where to tackle that (even pouring through the code and with full debugging output on :-/ ).