-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
9 - Make more use of let_chains
#94498
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 |
---|---|---|
|
@@ -891,23 +891,20 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
} | ||
if let Some(typeck_results) = | ||
self.in_progress_typeck_results.map(|t| t.borrow()) | ||
&& let ty = typeck_results.expr_ty_adjusted(base) | ||
&& let ty::FnDef(def_id, _substs) = ty.kind() | ||
&& let Some(hir::Node::Item(hir::Item { span, ident, .. })) = | ||
hir.get_if_local(*def_id) | ||
{ | ||
let ty = typeck_results.expr_ty_adjusted(base); | ||
if let ty::FnDef(def_id, _substs) = ty.kind() { | ||
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) = | ||
hir.get_if_local(*def_id) | ||
{ | ||
err.span_suggestion_verbose( | ||
span.shrink_to_lo(), | ||
&format!( | ||
"alternatively, consider making `fn {}` asynchronous", | ||
ident | ||
), | ||
"async ".to_string(), | ||
Applicability::MaybeIncorrect, | ||
); | ||
} | ||
} | ||
err.span_suggestion_verbose( | ||
span.shrink_to_lo(), | ||
&format!( | ||
"alternatively, consider making `fn {}` asynchronous", | ||
ident | ||
), | ||
"async ".to_string(), | ||
Applicability::MaybeIncorrect, | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -1000,34 +997,24 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
span: Span, | ||
trait_pred: ty::PolyTraitPredicate<'tcx>, | ||
) { | ||
let is_empty_tuple = | ||
|ty: ty::Binder<'tcx, Ty<'_>>| *ty.skip_binder().kind() == ty::Tuple(ty::List::empty()); | ||
|
||
let hir = self.tcx.hir(); | ||
let parent_node = hir.get_parent_node(obligation.cause.body_id); | ||
let node = hir.find(parent_node); | ||
if let Some(hir::Node::Item(hir::Item { | ||
kind: hir::ItemKind::Fn(sig, _, body_id), .. | ||
})) = node | ||
if let Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, _, body_id), .. })) = node | ||
&& let body = hir.body(*body_id) | ||
&& let hir::ExprKind::Block(blk, _) = &body.value.kind | ||
&& sig.decl.output.span().overlaps(span) | ||
&& blk.expr.is_none() | ||
&& *trait_pred.self_ty().skip_binder().kind() == ty::Tuple(ty::List::empty()) | ||
// FIXME(estebank): When encountering a method with a trait | ||
// bound not satisfied in the return type with a body that has | ||
// no return, suggest removal of semicolon on last statement. | ||
// Once that is added, close #54771. | ||
&& let Some(stmt) = blk.stmts.last() | ||
&& let hir::StmtKind::Semi(_) = stmt.kind | ||
{ | ||
let body = hir.body(*body_id); | ||
if let hir::ExprKind::Block(blk, _) = &body.value.kind { | ||
if sig.decl.output.span().overlaps(span) | ||
&& blk.expr.is_none() | ||
&& is_empty_tuple(trait_pred.self_ty()) | ||
{ | ||
// FIXME(estebank): When encountering a method with a trait | ||
// bound not satisfied in the return type with a body that has | ||
// no return, suggest removal of semicolon on last statement. | ||
// Once that is added, close #54771. | ||
if let Some(ref stmt) = blk.stmts.last() { | ||
if let hir::StmtKind::Semi(_) = stmt.kind { | ||
let sp = self.tcx.sess.source_map().end_point(stmt.span); | ||
err.span_label(sp, "consider removing this semicolon"); | ||
} | ||
} | ||
} | ||
} | ||
let sp = self.tcx.sess.source_map().end_point(stmt.span); | ||
err.span_label(sp, "consider removing this semicolon"); | ||
Comment on lines
+1003
to
+1017
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. |
||
} | ||
} | ||
|
||
|
@@ -2481,17 +2468,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | |
debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation); | ||
if self.predicate_may_hold(&try_obligation) | ||
&& impls_future.must_apply_modulo_regions() | ||
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) | ||
&& snippet.ends_with('?') | ||
{ | ||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { | ||
if snippet.ends_with('?') { | ||
err.span_suggestion_verbose( | ||
span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), | ||
"consider `await`ing on the `Future`", | ||
".await".to_string(), | ||
Applicability::MaybeIncorrect, | ||
); | ||
} | ||
} | ||
err.span_suggestion_verbose( | ||
span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), | ||
"consider `await`ing on the `Future`", | ||
".await".to_string(), | ||
Applicability::MaybeIncorrect, | ||
); | ||
} | ||
} | ||
} | ||
|
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.
Alphabetical order