-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
librustc: Implement the syntax in the RFC for unboxed closure sugar. #17041
Merged
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1427,7 +1427,8 @@ pub fn instantiate_unboxed_fn_ty<'tcx,AC>(this: &AC, | |
let param_ty = param_ty.to_ty(this.tcx()); | ||
Rc::new(astconv::trait_ref_for_unboxed_function(this, | ||
&rscope, | ||
unboxed_function, | ||
unboxed_function.kind, | ||
&*unboxed_function.decl, | ||
Some(param_ty))) | ||
} | ||
|
||
|
@@ -2165,9 +2166,42 @@ fn conv_param_bounds<'tcx,AC>(this: &AC, | |
region_bounds, | ||
unboxed_fn_ty_bounds } = | ||
astconv::partition_bounds(this.tcx(), span, all_bounds.as_slice()); | ||
let unboxed_fn_ty_bounds = | ||
unboxed_fn_ty_bounds.into_iter() | ||
.map(|b| instantiate_unboxed_fn_ty(this, b, param_ty)); | ||
|
||
let unboxed_fn_ty_bounds = unboxed_fn_ty_bounds.move_iter().map(|b| { | ||
let trait_id = this.tcx().def_map.borrow().get(&b.ref_id).def_id(); | ||
let mut kind = None; | ||
for &(lang_item, this_kind) in [ | ||
(this.tcx().lang_items.fn_trait(), ast::FnUnboxedClosureKind), | ||
(this.tcx().lang_items.fn_mut_trait(), | ||
ast::FnMutUnboxedClosureKind), | ||
(this.tcx().lang_items.fn_once_trait(), | ||
ast::FnOnceUnboxedClosureKind) | ||
].iter() { | ||
if Some(trait_id) == lang_item { | ||
kind = Some(this_kind); | ||
break | ||
} | ||
} | ||
|
||
let kind = match kind { | ||
Some(kind) => kind, | ||
None => { | ||
this.tcx().sess.span_err(b.path.span, | ||
"unboxed function trait must be one \ | ||
of `Fn`, `FnMut`, or `FnOnce`"); | ||
ast::FnMutUnboxedClosureKind | ||
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 add a test for this error? |
||
} | ||
}; | ||
|
||
let rscope = ExplicitRscope; | ||
let param_ty = param_ty.to_ty(this.tcx()); | ||
Rc::new(astconv::trait_ref_for_unboxed_function(this, | ||
&rscope, | ||
kind, | ||
&*b.decl, | ||
Some(param_ty))) | ||
}); | ||
|
||
let trait_bounds: Vec<Rc<ty::TraitRef>> = | ||
trait_bounds.into_iter() | ||
.map(|b| { | ||
|
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.
Could you also add tests for these two errors?