Skip to content

Commit 151001c

Browse files
committed
trivial fix for comments feedback
1 parent e747201 commit 151001c

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ hir_analysis_expected_used_symbol = expected `used`, `used(compiler)` or `used(l
136136
137137
hir_analysis_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
138138
139-
hir_analysis_add_missing_parentheses_in_range = you must surround the range in parentheses to call the `{$func_name}` function
139+
hir_analysis_add_missing_parentheses_in_range = you must surround the range in parentheses to call its `{$func_name}` function

compiler/rustc_hir_analysis/src/check/method/suggest.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
272272
}
273273
};
274274

275-
if self.suggest_range_for_iter(tcx, actual, source, span, item_name, &ty_str)
276-
|| self.suggest_constraining_numerical_ty(
277-
tcx, actual, source, span, item_kind, item_name, &ty_str,
278-
)
279-
{
275+
if self.suggest_wrapping_range_with_parens(
276+
tcx, actual, source, span, item_name, &ty_str,
277+
) || self.suggest_constraining_numerical_ty(
278+
tcx, actual, source, span, item_kind, item_name, &ty_str,
279+
) {
280280
return None;
281281
}
282282

@@ -1204,7 +1204,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12041204
false
12051205
}
12061206

1207-
fn suggest_range_for_iter(
1207+
/// Suggest possible range with adding parentheses, for example:
1208+
/// when encountering `0..1.map(|i| i + 1)` suggest `(0..1).map(|i| i + 1)`.
1209+
fn suggest_wrapping_range_with_parens(
12081210
&self,
12091211
tcx: TyCtxt<'tcx>,
12101212
actual: Ty<'tcx>,
@@ -1252,13 +1254,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12521254
continue;
12531255
}
12541256

1255-
debug!("lang_item: {:?}", lang_item);
12561257
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
12571258
let range_ty =
12581259
self.tcx.bound_type_of(range_def_id).subst(self.tcx, &[actual.into()]);
12591260

1260-
let pick =
1261-
self.lookup_probe(span, item_name, range_ty, expr, ProbeScope::AllTraits);
1261+
let pick = self.probe_for_name(
1262+
span,
1263+
Mode::MethodCall,
1264+
item_name,
1265+
IsSuggestion(true),
1266+
range_ty,
1267+
expr.hir_id,
1268+
ProbeScope::AllTraits,
1269+
);
12621270
if pick.is_ok() {
12631271
let range_span = parent_expr.span.with_hi(expr.span.hi());
12641272
tcx.sess.emit_err(errors::MissingParentheseInRange {

src/test/ui/methods/issues/issue-90315.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0689]: can't call method `rev` on type `usize`
44
LL | for _i in 0..arr.len().rev() {
55
| ^^^ can't call method `rev` on type `usize`
66
|
7-
help: you must surround the range in parentheses to call the `rev` function
7+
help: you must surround the range in parentheses to call its `rev` function
88
|
99
LL | for _i in (0..arr.len()).rev() {
1010
| + +
@@ -15,7 +15,7 @@ error[E0689]: can't call method `rev` on type `{integer}`
1515
LL | for i in 1..11.rev() {
1616
| ^^^ can't call method `rev` on type `{integer}`
1717
|
18-
help: you must surround the range in parentheses to call the `rev` function
18+
help: you must surround the range in parentheses to call its `rev` function
1919
|
2020
LL | for i in (1..11).rev() {
2121
| + +
@@ -26,7 +26,7 @@ error[E0689]: can't call method `rev` on type `usize`
2626
LL | for i in 1..end.rev() {
2727
| ^^^ can't call method `rev` on type `usize`
2828
|
29-
help: you must surround the range in parentheses to call the `rev` function
29+
help: you must surround the range in parentheses to call its `rev` function
3030
|
3131
LL | for i in (1..end).rev() {
3232
| + +
@@ -37,7 +37,7 @@ error[E0689]: can't call method `rev` on type `usize`
3737
LL | for i in 1..(end + 1).rev() {
3838
| ^^^ can't call method `rev` on type `usize`
3939
|
40-
help: you must surround the range in parentheses to call the `rev` function
40+
help: you must surround the range in parentheses to call its `rev` function
4141
|
4242
LL | for i in (1..(end + 1)).rev() {
4343
| + +
@@ -48,7 +48,7 @@ error[E0689]: can't call method `is_empty` on type `usize`
4848
LL | if 1..(end + 1).is_empty() {
4949
| ^^^^^^^^ can't call method `is_empty` on type `usize`
5050
|
51-
help: you must surround the range in parentheses to call the `is_empty` function
51+
help: you must surround the range in parentheses to call its `is_empty` function
5252
|
5353
LL | if (1..(end + 1)).is_empty() {
5454
| + +
@@ -68,7 +68,7 @@ error[E0689]: can't call method `is_sorted` on type `usize`
6868
LL | if 1..(end + 1).is_sorted() {
6969
| ^^^^^^^^^ can't call method `is_sorted` on type `usize`
7070
|
71-
help: you must surround the range in parentheses to call the `is_sorted` function
71+
help: you must surround the range in parentheses to call its `is_sorted` function
7272
|
7373
LL | if (1..(end + 1)).is_sorted() {
7474
| + +
@@ -88,7 +88,7 @@ error[E0689]: can't call method `take` on type `{integer}`
8888
LL | let _res: i32 = 3..6.take(2).sum();
8989
| ^^^^ can't call method `take` on type `{integer}`
9090
|
91-
help: you must surround the range in parentheses to call the `take` function
91+
help: you must surround the range in parentheses to call its `take` function
9292
|
9393
LL | let _res: i32 = (3..6).take(2).sum();
9494
| + +
@@ -110,7 +110,7 @@ error[E0689]: can't call method `sum` on type `{integer}`
110110
LL | let _sum: i32 = 3..6.sum();
111111
| ^^^ can't call method `sum` on type `{integer}`
112112
|
113-
help: you must surround the range in parentheses to call the `sum` function
113+
help: you must surround the range in parentheses to call its `sum` function
114114
|
115115
LL | let _sum: i32 = (3..6).sum();
116116
| + +
@@ -132,7 +132,7 @@ error[E0689]: can't call method `rev` on type `usize`
132132
LL | for _a in a..=b.rev() {
133133
| ^^^ can't call method `rev` on type `usize`
134134
|
135-
help: you must surround the range in parentheses to call the `rev` function
135+
help: you must surround the range in parentheses to call its `rev` function
136136
|
137137
LL | for _a in (a..=b).rev() {
138138
| + +
@@ -143,7 +143,7 @@ error[E0689]: can't call method `contains` on type `{integer}`
143143
LL | let _res = ..10.contains(3);
144144
| ^^^^^^^^ can't call method `contains` on type `{integer}`
145145
|
146-
help: you must surround the range in parentheses to call the `contains` function
146+
help: you must surround the range in parentheses to call its `contains` function
147147
|
148148
LL | let _res = (..10).contains(3);
149149
| + +

0 commit comments

Comments
 (0)