trivial fix for comments feedback
This commit is contained in:
parent
e747201ad8
commit
151001c1cb
@ -136,4 +136,4 @@ hir_analysis_expected_used_symbol = expected `used`, `used(compiler)` or `used(l
|
|||||||
|
|
||||||
hir_analysis_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
|
hir_analysis_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
|
||||||
|
|
||||||
hir_analysis_add_missing_parentheses_in_range = you must surround the range in parentheses to call the `{$func_name}` function
|
hir_analysis_add_missing_parentheses_in_range = you must surround the range in parentheses to call its `{$func_name}` function
|
||||||
|
@ -272,11 +272,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.suggest_range_for_iter(tcx, actual, source, span, item_name, &ty_str)
|
if self.suggest_wrapping_range_with_parens(
|
||||||
|| self.suggest_constraining_numerical_ty(
|
tcx, actual, source, span, item_name, &ty_str,
|
||||||
tcx, actual, source, span, item_kind, item_name, &ty_str,
|
) || self.suggest_constraining_numerical_ty(
|
||||||
)
|
tcx, actual, source, span, item_kind, item_name, &ty_str,
|
||||||
{
|
) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,7 +1204,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_range_for_iter(
|
/// Suggest possible range with adding parentheses, for example:
|
||||||
|
/// when encountering `0..1.map(|i| i + 1)` suggest `(0..1).map(|i| i + 1)`.
|
||||||
|
fn suggest_wrapping_range_with_parens(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
@ -1252,13 +1254,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("lang_item: {:?}", lang_item);
|
|
||||||
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
|
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
|
||||||
let range_ty =
|
let range_ty =
|
||||||
self.tcx.bound_type_of(range_def_id).subst(self.tcx, &[actual.into()]);
|
self.tcx.bound_type_of(range_def_id).subst(self.tcx, &[actual.into()]);
|
||||||
|
|
||||||
let pick =
|
let pick = self.probe_for_name(
|
||||||
self.lookup_probe(span, item_name, range_ty, expr, ProbeScope::AllTraits);
|
span,
|
||||||
|
Mode::MethodCall,
|
||||||
|
item_name,
|
||||||
|
IsSuggestion(true),
|
||||||
|
range_ty,
|
||||||
|
expr.hir_id,
|
||||||
|
ProbeScope::AllTraits,
|
||||||
|
);
|
||||||
if pick.is_ok() {
|
if pick.is_ok() {
|
||||||
let range_span = parent_expr.span.with_hi(expr.span.hi());
|
let range_span = parent_expr.span.with_hi(expr.span.hi());
|
||||||
tcx.sess.emit_err(errors::MissingParentheseInRange {
|
tcx.sess.emit_err(errors::MissingParentheseInRange {
|
||||||
|
@ -4,7 +4,7 @@ error[E0689]: can't call method `rev` on type `usize`
|
|||||||
LL | for _i in 0..arr.len().rev() {
|
LL | for _i in 0..arr.len().rev() {
|
||||||
| ^^^ can't call method `rev` on type `usize`
|
| ^^^ can't call method `rev` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `rev` function
|
help: you must surround the range in parentheses to call its `rev` function
|
||||||
|
|
|
|
||||||
LL | for _i in (0..arr.len()).rev() {
|
LL | for _i in (0..arr.len()).rev() {
|
||||||
| + +
|
| + +
|
||||||
@ -15,7 +15,7 @@ error[E0689]: can't call method `rev` on type `{integer}`
|
|||||||
LL | for i in 1..11.rev() {
|
LL | for i in 1..11.rev() {
|
||||||
| ^^^ can't call method `rev` on type `{integer}`
|
| ^^^ can't call method `rev` on type `{integer}`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `rev` function
|
help: you must surround the range in parentheses to call its `rev` function
|
||||||
|
|
|
|
||||||
LL | for i in (1..11).rev() {
|
LL | for i in (1..11).rev() {
|
||||||
| + +
|
| + +
|
||||||
@ -26,7 +26,7 @@ error[E0689]: can't call method `rev` on type `usize`
|
|||||||
LL | for i in 1..end.rev() {
|
LL | for i in 1..end.rev() {
|
||||||
| ^^^ can't call method `rev` on type `usize`
|
| ^^^ can't call method `rev` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `rev` function
|
help: you must surround the range in parentheses to call its `rev` function
|
||||||
|
|
|
|
||||||
LL | for i in (1..end).rev() {
|
LL | for i in (1..end).rev() {
|
||||||
| + +
|
| + +
|
||||||
@ -37,7 +37,7 @@ error[E0689]: can't call method `rev` on type `usize`
|
|||||||
LL | for i in 1..(end + 1).rev() {
|
LL | for i in 1..(end + 1).rev() {
|
||||||
| ^^^ can't call method `rev` on type `usize`
|
| ^^^ can't call method `rev` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `rev` function
|
help: you must surround the range in parentheses to call its `rev` function
|
||||||
|
|
|
|
||||||
LL | for i in (1..(end + 1)).rev() {
|
LL | for i in (1..(end + 1)).rev() {
|
||||||
| + +
|
| + +
|
||||||
@ -48,7 +48,7 @@ error[E0689]: can't call method `is_empty` on type `usize`
|
|||||||
LL | if 1..(end + 1).is_empty() {
|
LL | if 1..(end + 1).is_empty() {
|
||||||
| ^^^^^^^^ can't call method `is_empty` on type `usize`
|
| ^^^^^^^^ can't call method `is_empty` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `is_empty` function
|
help: you must surround the range in parentheses to call its `is_empty` function
|
||||||
|
|
|
|
||||||
LL | if (1..(end + 1)).is_empty() {
|
LL | if (1..(end + 1)).is_empty() {
|
||||||
| + +
|
| + +
|
||||||
@ -68,7 +68,7 @@ error[E0689]: can't call method `is_sorted` on type `usize`
|
|||||||
LL | if 1..(end + 1).is_sorted() {
|
LL | if 1..(end + 1).is_sorted() {
|
||||||
| ^^^^^^^^^ can't call method `is_sorted` on type `usize`
|
| ^^^^^^^^^ can't call method `is_sorted` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `is_sorted` function
|
help: you must surround the range in parentheses to call its `is_sorted` function
|
||||||
|
|
|
|
||||||
LL | if (1..(end + 1)).is_sorted() {
|
LL | if (1..(end + 1)).is_sorted() {
|
||||||
| + +
|
| + +
|
||||||
@ -88,7 +88,7 @@ error[E0689]: can't call method `take` on type `{integer}`
|
|||||||
LL | let _res: i32 = 3..6.take(2).sum();
|
LL | let _res: i32 = 3..6.take(2).sum();
|
||||||
| ^^^^ can't call method `take` on type `{integer}`
|
| ^^^^ can't call method `take` on type `{integer}`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `take` function
|
help: you must surround the range in parentheses to call its `take` function
|
||||||
|
|
|
|
||||||
LL | let _res: i32 = (3..6).take(2).sum();
|
LL | let _res: i32 = (3..6).take(2).sum();
|
||||||
| + +
|
| + +
|
||||||
@ -110,7 +110,7 @@ error[E0689]: can't call method `sum` on type `{integer}`
|
|||||||
LL | let _sum: i32 = 3..6.sum();
|
LL | let _sum: i32 = 3..6.sum();
|
||||||
| ^^^ can't call method `sum` on type `{integer}`
|
| ^^^ can't call method `sum` on type `{integer}`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `sum` function
|
help: you must surround the range in parentheses to call its `sum` function
|
||||||
|
|
|
|
||||||
LL | let _sum: i32 = (3..6).sum();
|
LL | let _sum: i32 = (3..6).sum();
|
||||||
| + +
|
| + +
|
||||||
@ -132,7 +132,7 @@ error[E0689]: can't call method `rev` on type `usize`
|
|||||||
LL | for _a in a..=b.rev() {
|
LL | for _a in a..=b.rev() {
|
||||||
| ^^^ can't call method `rev` on type `usize`
|
| ^^^ can't call method `rev` on type `usize`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `rev` function
|
help: you must surround the range in parentheses to call its `rev` function
|
||||||
|
|
|
|
||||||
LL | for _a in (a..=b).rev() {
|
LL | for _a in (a..=b).rev() {
|
||||||
| + +
|
| + +
|
||||||
@ -143,7 +143,7 @@ error[E0689]: can't call method `contains` on type `{integer}`
|
|||||||
LL | let _res = ..10.contains(3);
|
LL | let _res = ..10.contains(3);
|
||||||
| ^^^^^^^^ can't call method `contains` on type `{integer}`
|
| ^^^^^^^^ can't call method `contains` on type `{integer}`
|
||||||
|
|
|
|
||||||
help: you must surround the range in parentheses to call the `contains` function
|
help: you must surround the range in parentheses to call its `contains` function
|
||||||
|
|
|
|
||||||
LL | let _res = (..10).contains(3);
|
LL | let _res = (..10).contains(3);
|
||||||
| + +
|
| + +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user