Skip to content

Commit 6a6a262

Browse files
committed
Auto merge of rust-lang#109010 - compiler-errors:rtn, r=eholk
Initial support for return type notation (RTN) See: https://smallcultfollowing.com/babysteps/blog/2023/02/13/return-type-notation-send-bounds-part-2/ 1. Only supports `T: Trait<method(): Send>` style bounds, not `<T as Trait>::method(): Send`. Checking validity and injecting an implicit binder for all of the late-bound method generics is harder to do for the latter. * I'd add this in a follow-up. 3. ~Doesn't support RTN in general type position, i.e. no `let x: <T as Trait>::method() = ...`~ * I don't think we actually want this. 5. Doesn't add syntax for "eliding" the function args -- i.e. for now, we write `method(): Send` instead of `method(..): Send`. * May be a hazard if we try to add it in the future. I'll probably add it in a follow-up later, with a structured suggestion to change `method()` to `method(..)` once we add it. 7. ~I'm not in love with the feature gate name 😺~ * I renamed it to `return_type_notation` ✔️ Follow-up PRs will probably add support for `where T::method(): Send` bounds. I'm not sure if we ever want to support return-type-notation in arbitrary type positions. I may also make the bounds require `..` in the args list later. r? `@ghost`
2 parents 3c964ea + fc6262f commit 6a6a262

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

clippy_lints/src/ref_option_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::last_path_segment;
33
use clippy_utils::source::snippet;
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
6-
use rustc_hir::{GenericArg, Mutability, Ty, TyKind};
6+
use rustc_hir::{GenericArg, GenericArgsParentheses, Mutability, Ty, TyKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::symbol::sym;
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
4747

4848
if cx.tcx.is_diagnostic_item(sym::Option, def_id);
4949
if let Some(params) = last_path_segment(qpath).args ;
50-
if !params.parenthesized;
50+
if params.parenthesized == GenericArgsParentheses::No;
5151
if let Some(inner_ty) = params.args.iter().find_map(|arg| match arg {
5252
GenericArg::Type(inner_ty) => Some(inner_ty),
5353
_ => None,

clippy_lints/src/types/borrowed_box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
2020
if let QPath::Resolved(None, path) = *qpath;
2121
if let [ref bx] = *path.segments;
2222
if let Some(params) = bx.args;
23-
if !params.parenthesized;
23+
if params.parenthesized == hir::GenericArgsParentheses::No;
2424
if let Some(inner) = params.args.iter().find_map(|arg| match arg {
2525
GenericArg::Type(ty) => Some(ty),
2626
_ => None,

clippy_lints/src/types/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use clippy_utils::last_path_segment;
22
use if_chain::if_chain;
3-
use rustc_hir::{GenericArg, QPath, TyKind};
3+
use rustc_hir::{GenericArg, GenericArgsParentheses, QPath, TyKind};
44
use rustc_lint::LateContext;
55
use rustc_span::source_map::Span;
66

77
pub(super) fn match_borrows_parameter(_cx: &LateContext<'_>, qpath: &QPath<'_>) -> Option<Span> {
88
let last = last_path_segment(qpath);
99
if_chain! {
1010
if let Some(params) = last.args;
11-
if !params.parenthesized;
11+
if params.parenthesized == GenericArgsParentheses::No;
1212
if let Some(ty) = params.args.iter().find_map(|arg| match arg {
1313
GenericArg::Type(ty) => Some(ty),
1414
_ => None,

clippy_lints/src/use_self.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{
1010
def::{CtorOf, DefKind, Res},
1111
def_id::LocalDefId,
1212
intravisit::{walk_inf, walk_ty, Visitor},
13-
Expr, ExprKind, FnRetTy, FnSig, GenericArg, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item,
13+
Expr, ExprKind, FnRetTy, FnSig, GenericArg, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item,
1414
ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind,
1515
};
1616
use rustc_hir_analysis::hir_ty_to_ty;
@@ -100,7 +100,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
100100
if let TyKind::Path(QPath::Resolved(_, item_path)) = self_ty.kind;
101101
let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).args;
102102
if parameters.as_ref().map_or(true, |params| {
103-
!params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
103+
params.parenthesized == GenericArgsParentheses::No
104+
&& !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
104105
});
105106
if !item.span.from_expansion();
106107
if !is_from_proc_macro(cx, item); // expensive, should be last check

clippy_utils/src/hir_utils.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,9 @@ impl HirEqInterExpr<'_, '_, '_> {
401401
}
402402

403403
fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool {
404-
if !(left.parenthesized || right.parenthesized) {
404+
if left.parenthesized == right.parenthesized {
405405
over(left.args, right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
406406
&& over(left.bindings, right.bindings, |l, r| self.eq_type_binding(l, r))
407-
} else if left.parenthesized && right.parenthesized {
408-
over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r))
409-
&& both(&Some(&left.bindings[0].ty()), &Some(&right.bindings[0].ty()), |l, r| {
410-
self.eq_ty(l, r)
411-
})
412407
} else {
413408
false
414409
}

0 commit comments

Comments
 (0)