about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2022-10-17 08:32:08 +0800
committeryukang <moorekang@gmail.com>2022-10-17 08:32:08 +0800
commit151001c1cb1c054d7f259e90ed44b31c25ba2db7 (patch)
tree977ad8ceac89669861d6e9780437f39485283910
parente747201ad83d384a418dc2b31bf3d3024e2c2a3c (diff)
downloadrust-151001c1cb1c054d7f259e90ed44b31c25ba2db7.tar.gz
rust-151001c1cb1c054d7f259e90ed44b31c25ba2db7.zip
trivial fix for comments feedback
-rw-r--r--compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl2
-rw-r--r--compiler/rustc_hir_analysis/src/check/method/suggest.rs26
-rw-r--r--src/test/ui/methods/issues/issue-90315.stderr20
3 files changed, 28 insertions, 20 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
index 5a7aee9c1c1..357c6900a70 100644
--- a/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
@@ -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_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
diff --git a/compiler/rustc_hir_analysis/src/check/method/suggest.rs b/compiler/rustc_hir_analysis/src/check/method/suggest.rs
index 9aa1b2e2c0a..6e9ea5d7f52 100644
--- a/compiler/rustc_hir_analysis/src/check/method/suggest.rs
+++ b/compiler/rustc_hir_analysis/src/check/method/suggest.rs
@@ -272,11 +272,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     }
                 };
 
-                if self.suggest_range_for_iter(tcx, actual, source, span, item_name, &ty_str)
-                    || self.suggest_constraining_numerical_ty(
-                        tcx, actual, source, span, item_kind, item_name, &ty_str,
-                    )
-                {
+                if self.suggest_wrapping_range_with_parens(
+                    tcx, actual, source, span, item_name, &ty_str,
+                ) || self.suggest_constraining_numerical_ty(
+                    tcx, actual, source, span, item_kind, item_name, &ty_str,
+                ) {
                     return None;
                 }
 
@@ -1204,7 +1204,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         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,
         tcx: TyCtxt<'tcx>,
         actual: Ty<'tcx>,
@@ -1252,13 +1254,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         continue;
                     }
 
-                    debug!("lang_item: {:?}", lang_item);
                     let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
                     let range_ty =
                         self.tcx.bound_type_of(range_def_id).subst(self.tcx, &[actual.into()]);
 
-                    let pick =
-                        self.lookup_probe(span, item_name, range_ty, expr, ProbeScope::AllTraits);
+                    let pick = self.probe_for_name(
+                        span,
+                        Mode::MethodCall,
+                        item_name,
+                        IsSuggestion(true),
+                        range_ty,
+                        expr.hir_id,
+                        ProbeScope::AllTraits,
+                    );
                     if pick.is_ok() {
                         let range_span = parent_expr.span.with_hi(expr.span.hi());
                         tcx.sess.emit_err(errors::MissingParentheseInRange {
diff --git a/src/test/ui/methods/issues/issue-90315.stderr b/src/test/ui/methods/issues/issue-90315.stderr
index 581d6fb4fc9..070cd305436 100644
--- a/src/test/ui/methods/issues/issue-90315.stderr
+++ b/src/test/ui/methods/issues/issue-90315.stderr
@@ -4,7 +4,7 @@ error[E0689]: can't call method `rev` on type `usize`
 LL |     for _i in 0..arr.len().rev() {
    |                            ^^^ 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() {
    |               +            +
@@ -15,7 +15,7 @@ error[E0689]: can't call method `rev` on type `{integer}`
 LL |     for i in 1..11.rev() {
    |                    ^^^ 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() {
    |              +     +
@@ -26,7 +26,7 @@ error[E0689]: can't call method `rev` on type `usize`
 LL |     for i in 1..end.rev() {
    |                     ^^^ 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() {
    |              +      +
@@ -37,7 +37,7 @@ error[E0689]: can't call method `rev` on type `usize`
 LL |     for i in 1..(end + 1).rev() {
    |                           ^^^ 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() {
    |              +            +
@@ -48,7 +48,7 @@ error[E0689]: can't call method `is_empty` on type `usize`
 LL |     if 1..(end + 1).is_empty() {
    |                     ^^^^^^^^ 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() {
    |        +            +
@@ -68,7 +68,7 @@ error[E0689]: can't call method `is_sorted` on type `usize`
 LL |     if 1..(end + 1).is_sorted() {
    |                     ^^^^^^^^^ 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() {
    |        +            +
@@ -88,7 +88,7 @@ error[E0689]: can't call method `take` on type `{integer}`
 LL |     let _res: i32 = 3..6.take(2).sum();
    |                          ^^^^ 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();
    |                     +    +
@@ -110,7 +110,7 @@ error[E0689]: can't call method `sum` on type `{integer}`
 LL |     let _sum: i32 = 3..6.sum();
    |                          ^^^ 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();
    |                     +    +
@@ -132,7 +132,7 @@ error[E0689]: can't call method `rev` on type `usize`
 LL |     for _a in a..=b.rev() {
    |                     ^^^ 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() {
    |               +     +
@@ -143,7 +143,7 @@ error[E0689]: can't call method `contains` on type `{integer}`
 LL |     let _res = ..10.contains(3);
    |                     ^^^^^^^^ 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);
    |                +    +