about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias KrΓΌger <matthias.krueger@famsik.de>2022-10-06 07:07:36 +0200
committerGitHub <noreply@github.com>2022-10-06 07:07:36 +0200
commita9b3441c178191b4d33f9fe6b8e937894baff7c4 (patch)
treefef3634ad1b6696f98e620986ac6f26f8486bd14
parent6d8cea63db8761d8a7e5549e407e5bd60b5c3eb1 (diff)
parentea3837072c44aaafd4156755fde5c4b43b8f3558 (diff)
downloadrust-a9b3441c178191b4d33f9fe6b8e937894baff7c4.tar.gz
rust-a9b3441c178191b4d33f9fe6b8e937894baff7c4.zip
Rollup merge of #102694 - compiler-errors:fn-to-method, r=davidtwco
Suggest calling method if fn does not exist

I tried to split this up into two commits, the first where we stash the resolution error until typeck (which causes a bunch of diagnostics changes because the ordering of error messages change), then the second commit is the actual logic that actually implements the suggestion.

I am not in love with the presentation of the suggestion, so I could use some advice for how to format the actual messaging.

r? diagnostics

Fixes #102518
-rw-r--r--compiler/rustc_errors/src/lib.rs1
-rw-r--r--compiler/rustc_hir_analysis/src/check/callee.rs142
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs10
-rw-r--r--compiler/rustc_resolve/src/late.rs2
-rw-r--r--compiler/rustc_resolve/src/lib.rs2
-rw-r--r--src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr16
-rw-r--r--src/test/ui/empty/empty-struct-braces-expr.stderr46
-rw-r--r--src/test/ui/error-codes/E0423.stderr22
-rw-r--r--src/test/ui/issues/issue-58022.stderr12
-rw-r--r--src/test/ui/lang-items/issue-83471.stderr12
-rw-r--r--src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr44
-rw-r--r--src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr24
-rw-r--r--src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr24
-rw-r--r--src/test/ui/parser/emoji-identifiers.stderr18
-rw-r--r--src/test/ui/parser/parser-recovery-1.stderr12
-rw-r--r--src/test/ui/parser/parser-recovery-2.stderr12
-rw-r--r--src/test/ui/parser/unmatched-langle-1.stderr12
-rw-r--r--src/test/ui/proc-macro/keep-expr-tokens.stderr12
-rw-r--r--src/test/ui/resolve/bad-env-capture.stderr12
-rw-r--r--src/test/ui/resolve/bad-env-capture2.stderr12
-rw-r--r--src/test/ui/resolve/bad-env-capture3.stderr12
-rw-r--r--src/test/ui/resolve/bad-expr-path.stderr12
-rw-r--r--src/test/ui/resolve/bad-expr-path2.stderr12
-rw-r--r--src/test/ui/resolve/issue-14254.stderr86
-rw-r--r--src/test/ui/resolve/issue-2356.stderr90
-rw-r--r--src/test/ui/resolve/issue-42944.stderr24
-rw-r--r--src/test/ui/resolve/issue-73427.stderr40
-rw-r--r--src/test/ui/resolve/levenshtein.stderr18
-rw-r--r--src/test/ui/resolve/resolve-hint-macro.stderr22
-rw-r--r--src/test/ui/resolve/resolve-speculative-adjustment.stderr12
-rw-r--r--src/test/ui/resolve/tuple-struct-alias.stderr16
-rw-r--r--src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr36
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/struct.stderr12
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr12
-rw-r--r--src/test/ui/suggestions/assoc_fn_without_self.stderr12
-rw-r--r--src/test/ui/suggestions/fn-to-method.rs19
-rw-r--r--src/test/ui/suggestions/fn-to-method.stderr38
37 files changed, 559 insertions, 361 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 7c312da6279..94a493992e5 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -460,6 +460,7 @@ pub enum StashKey {
     ItemNoType,
     UnderscoreForArrayLengths,
     EarlySyntaxWarning,
+    CallIntoMethod,
 }
 
 fn default_track_diagnostic(_: &Diagnostic) {}
diff --git a/compiler/rustc_hir_analysis/src/check/callee.rs b/compiler/rustc_hir_analysis/src/check/callee.rs
index 080771844a4..f0a7c910906 100644
--- a/compiler/rustc_hir_analysis/src/check/callee.rs
+++ b/compiler/rustc_hir_analysis/src/check/callee.rs
@@ -1,8 +1,10 @@
+use super::method::probe::{IsSuggestion, Mode, ProbeScope};
 use super::method::MethodCallee;
 use super::{DefIdOrName, Expectation, FnCtxt, TupleArgumentsFlag};
 use crate::type_error_struct;
 
-use rustc_errors::{struct_span_err, Applicability, Diagnostic};
+use rustc_ast::util::parser::PREC_POSTFIX;
+use rustc_errors::{struct_span_err, Applicability, Diagnostic, StashKey};
 use rustc_hir as hir;
 use rustc_hir::def::{self, Namespace, Res};
 use rustc_hir::def_id::DefId;
@@ -60,6 +62,7 @@ pub fn check_legal_trait_for_method_call(
     }
 }
 
+#[derive(Debug)]
 enum CallStep<'tcx> {
     Builtin(Ty<'tcx>),
     DeferredClosure(LocalDefId, ty::FnSig<'tcx>),
@@ -188,6 +191,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 return None;
             }
 
+            ty::Error(_) => {
+                return None;
+            }
+
             _ => {}
         }
 
@@ -394,6 +401,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             }
             ty::FnPtr(sig) => (sig, None),
             _ => {
+                if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &callee_expr.kind
+                    && let [segment] = path.segments
+                    && let Some(mut diag) = self
+                        .tcx
+                        .sess
+                        .diagnostic()
+                        .steal_diagnostic(segment.ident.span, StashKey::CallIntoMethod)
+                {
+                    // Try suggesting `foo(a)` -> `a.foo()` if possible.
+                    if let Some(ty) =
+                        self.suggest_call_as_method(
+                            &mut diag,
+                            segment,
+                            arg_exprs,
+                            call_expr,
+                            expected
+                        )
+                    {
+                        diag.emit();
+                        return ty;
+                    } else {
+                        diag.emit();
+                    }
+                }
+
                 self.report_invalid_callee(call_expr, callee_expr, callee_ty, arg_exprs);
 
                 // This is the "default" function signature, used in case of error.
@@ -441,6 +473,105 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         fn_sig.output()
     }
 
+    /// Attempts to reinterpret `method(rcvr, args...)` as `rcvr.method(args...)`
+    /// and suggesting the fix if the method probe is successful.
+    fn suggest_call_as_method(
+        &self,
+        diag: &mut Diagnostic,
+        segment: &'tcx hir::PathSegment<'tcx>,
+        arg_exprs: &'tcx [hir::Expr<'tcx>],
+        call_expr: &'tcx hir::Expr<'tcx>,
+        expected: Expectation<'tcx>,
+    ) -> Option<Ty<'tcx>> {
+        if let [callee_expr, rest @ ..] = arg_exprs {
+            let callee_ty = self.check_expr(callee_expr);
+            // First, do a probe with `IsSuggestion(true)` to avoid emitting
+            // any strange errors. If it's successful, then we'll do a true
+            // method lookup.
+            let Ok(pick) = self
+            .probe_for_name(
+                call_expr.span,
+                Mode::MethodCall,
+                segment.ident,
+                IsSuggestion(true),
+                callee_ty,
+                call_expr.hir_id,
+                // We didn't record the in scope traits during late resolution
+                // so we need to probe AllTraits unfortunately
+                ProbeScope::AllTraits,
+            ) else {
+                return None;
+            };
+
+            let pick = self.confirm_method(
+                call_expr.span,
+                callee_expr,
+                call_expr,
+                callee_ty,
+                pick,
+                segment,
+            );
+            if pick.illegal_sized_bound.is_some() {
+                return None;
+            }
+
+            let up_to_rcvr_span = segment.ident.span.until(callee_expr.span);
+            let rest_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
+            let rest_snippet = if let Some(first) = rest.first() {
+                self.tcx
+                    .sess
+                    .source_map()
+                    .span_to_snippet(first.span.to(call_expr.span.shrink_to_hi()))
+            } else {
+                Ok(")".to_string())
+            };
+
+            if let Ok(rest_snippet) = rest_snippet {
+                let sugg = if callee_expr.precedence().order() >= PREC_POSTFIX {
+                    vec![
+                        (up_to_rcvr_span, "".to_string()),
+                        (rest_span, format!(".{}({rest_snippet}", segment.ident)),
+                    ]
+                } else {
+                    vec![
+                        (up_to_rcvr_span, "(".to_string()),
+                        (rest_span, format!(").{}({rest_snippet}", segment.ident)),
+                    ]
+                };
+                let self_ty = self.resolve_vars_if_possible(pick.callee.sig.inputs()[0]);
+                diag.multipart_suggestion(
+                    format!(
+                        "use the `.` operator to call the method `{}{}` on `{self_ty}`",
+                        self.tcx
+                            .associated_item(pick.callee.def_id)
+                            .trait_container(self.tcx)
+                            .map_or_else(
+                                || String::new(),
+                                |trait_def_id| self.tcx.def_path_str(trait_def_id) + "::"
+                            ),
+                        segment.ident
+                    ),
+                    sugg,
+                    Applicability::MaybeIncorrect,
+                );
+
+                // Let's check the method fully now
+                let return_ty = self.check_method_argument_types(
+                    segment.ident.span,
+                    call_expr,
+                    Ok(pick.callee),
+                    rest,
+                    TupleArgumentsFlag::DontTupleArguments,
+                    expected,
+                );
+
+                return Some(return_ty);
+            }
+        }
+
+        None
+    }
+
     fn report_invalid_callee(
         &self,
         call_expr: &'tcx hir::Expr<'tcx>,
@@ -459,10 +590,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 def::CtorOf::Struct => "struct",
                 def::CtorOf::Variant => "enum variant",
             };
-            let removal_span =
-                callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
-            unit_variant =
-                Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
+            let removal_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
+            unit_variant = Some((removal_span, descr, rustc_hir_pretty::qpath_to_string(qpath)));
         }
 
         let callee_ty = self.resolve_vars_if_possible(callee_ty);
@@ -525,7 +654,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         };
 
         if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
-            if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_expr, callee_ty)
+            if let Some((maybe_def, output_ty, _)) =
+                self.extract_callable_info(callee_expr, callee_ty)
                 && !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
             {
                 let descr = match maybe_def {
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index b6778804a99..98982240af2 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -120,7 +120,7 @@ impl<'a> Resolver<'a> {
     }
 
     fn report_with_use_injections(&mut self, krate: &Crate) {
-        for UseError { mut err, candidates, def_id, instead, suggestion, path } in
+        for UseError { mut err, candidates, def_id, instead, suggestion, path, is_call } in
             self.use_injections.drain(..)
         {
             let (span, found_use) = if let Some(def_id) = def_id.as_local() {
@@ -128,6 +128,7 @@ impl<'a> Resolver<'a> {
             } else {
                 (None, FoundUse::No)
             };
+
             if !candidates.is_empty() {
                 show_candidates(
                     &self.session,
@@ -140,10 +141,15 @@ impl<'a> Resolver<'a> {
                     IsPattern::No,
                     path,
                 );
+                err.emit();
             } else if let Some((span, msg, sugg, appl)) = suggestion {
                 err.span_suggestion(span, msg, sugg, appl);
+                err.emit();
+            } else if let [segment] = path.as_slice() && is_call {
+                err.stash(segment.ident.span, rustc_errors::StashKey::CallIntoMethod);
+            } else {
+                err.emit();
             }
-            err.emit();
         }
     }
 
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 72029488cb1..431507e8e0f 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -3263,6 +3263,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
                     instead,
                     suggestion,
                     path: path.into(),
+                    is_call: source.is_call(),
                 });
             }
 
@@ -3327,6 +3328,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
                     instead: false,
                     suggestion: None,
                     path: path.into(),
+                    is_call: source.is_call(),
                 });
             } else {
                 err.cancel();
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index 9b52decd9c7..9173c3692ce 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -674,6 +674,8 @@ struct UseError<'a> {
     /// Path `Segment`s at the place of use that failed. Used for accurate suggestion after telling
     /// the user to import the item directly.
     path: Vec<Segment>,
+    /// Whether the expected source is a call
+    is_call: bool,
 }
 
 #[derive(Clone, Copy, PartialEq, Debug)]
diff --git a/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr b/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
index bca493e67d5..9dde5b3ebe3 100644
--- a/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
+++ b/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
@@ -1,11 +1,3 @@
-error[E0423]: expected function, tuple struct or tuple variant, found enum `Option`
-  --> $DIR/issue-43871-enum-instead-of-variant.rs:19:13
-   |
-LL |     let x = Option(1);
-   |             ^^^^^^ help: try to construct one of the enum's variants: `std::option::Option::Some`
-   |
-   = help: you might have meant to construct the enum's non-tuple variant
-
 error[E0532]: expected tuple struct or tuple variant, found enum `Option`
   --> $DIR/issue-43871-enum-instead-of-variant.rs:21:12
    |
@@ -27,6 +19,14 @@ note: the enum is defined here
 LL | enum Example { Ex(String), NotEx }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+error[E0423]: expected function, tuple struct or tuple variant, found enum `Option`
+  --> $DIR/issue-43871-enum-instead-of-variant.rs:19:13
+   |
+LL |     let x = Option(1);
+   |             ^^^^^^ help: try to construct one of the enum's variants: `std::option::Option::Some`
+   |
+   = help: you might have meant to construct the enum's non-tuple variant
+
 error[E0423]: expected function, tuple struct or tuple variant, found enum `Void`
   --> $DIR/issue-43871-enum-instead-of-variant.rs:31:13
    |
diff --git a/src/test/ui/empty/empty-struct-braces-expr.stderr b/src/test/ui/empty/empty-struct-braces-expr.stderr
index 5fc0a916a09..5b0ca613fc4 100644
--- a/src/test/ui/empty/empty-struct-braces-expr.stderr
+++ b/src/test/ui/empty/empty-struct-braces-expr.stderr
@@ -21,29 +21,6 @@ help: a unit struct with a similar name exists
 LL |     let e1 = XEmpty2;
    |              ~~~~~~~
 
-error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
-  --> $DIR/empty-struct-braces-expr.rs:16:14
-   |
-LL | struct Empty1 {}
-   | ---------------- `Empty1` defined here
-...
-LL |     let e1 = Empty1();
-   |              ^^^^^^^^
-   |
-  ::: $DIR/auxiliary/empty-struct.rs:2:1
-   |
-LL | pub struct XEmpty2;
-   | ------------------ similarly named unit struct `XEmpty2` defined here
-   |
-help: use struct literal syntax instead
-   |
-LL |     let e1 = Empty1 {};
-   |              ~~~~~~~~~
-help: a unit struct with a similar name exists
-   |
-LL |     let e1 = XEmpty2();
-   |              ~~~~~~~
-
 error[E0423]: expected value, found struct variant `E::Empty3`
   --> $DIR/empty-struct-braces-expr.rs:18:14
    |
@@ -84,6 +61,29 @@ help: a unit struct with a similar name exists
 LL |     let xe1 = XEmpty2;
    |               ~~~~~~~
 
+error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
+  --> $DIR/empty-struct-braces-expr.rs:16:14
+   |
+LL | struct Empty1 {}
+   | ---------------- `Empty1` defined here
+...
+LL |     let e1 = Empty1();
+   |              ^^^^^^^^
+   |
+  ::: $DIR/auxiliary/empty-struct.rs:2:1
+   |
+LL | pub struct XEmpty2;
+   | ------------------ similarly named unit struct `XEmpty2` defined here
+   |
+help: use struct literal syntax instead
+   |
+LL |     let e1 = Empty1 {};
+   |              ~~~~~~~~~
+help: a unit struct with a similar name exists
+   |
+LL |     let e1 = XEmpty2();
+   |              ~~~~~~~
+
 error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1`
   --> $DIR/empty-struct-braces-expr.rs:23:15
    |
diff --git a/src/test/ui/error-codes/E0423.stderr b/src/test/ui/error-codes/E0423.stderr
index 8f2ef8c8e6b..ac70d905d35 100644
--- a/src/test/ui/error-codes/E0423.stderr
+++ b/src/test/ui/error-codes/E0423.stderr
@@ -26,6 +26,17 @@ help: surround the struct literal with parentheses
 LL |     for _ in (std::ops::Range { start: 0, end: 10 }) {}
    |              +                                     +
 
+error[E0423]: expected value, found struct `T`
+  --> $DIR/E0423.rs:14:8
+   |
+LL |     if T {} == T {} { println!("Ok"); }
+   |        ^ not a value
+   |
+help: surround the struct literal with parentheses
+   |
+LL |     if (T {}) == T {} { println!("Ok"); }
+   |        +    +
+
 error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
   --> $DIR/E0423.rs:4:13
    |
@@ -47,17 +58,6 @@ help: a function with a similar name exists
 LL |     let f = foo();
    |             ~~~
 
-error[E0423]: expected value, found struct `T`
-  --> $DIR/E0423.rs:14:8
-   |
-LL |     if T {} == T {} { println!("Ok"); }
-   |        ^ not a value
-   |
-help: surround the struct literal with parentheses
-   |
-LL |     if (T {}) == T {} { println!("Ok"); }
-   |        +    +
-
 error: aborting due to 5 previous errors
 
 For more information about this error, try `rustc --explain E0423`.
diff --git a/src/test/ui/issues/issue-58022.stderr b/src/test/ui/issues/issue-58022.stderr
index 6d24209ad3c..56d85c066a8 100644
--- a/src/test/ui/issues/issue-58022.stderr
+++ b/src/test/ui/issues/issue-58022.stderr
@@ -1,9 +1,3 @@
-error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo`
-  --> $DIR/issue-58022.rs:14:9
-   |
-LL |         Foo(Box::new(*slice))
-   |         ^^^ not a function, tuple struct or tuple variant
-
 error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type
   --> $DIR/issue-58022.rs:4:25
    |
@@ -13,6 +7,12 @@ LL |
 LL |     fn new(slice: &[u8; Foo::SIZE]) -> Self;
    |                         ^^^^^^^^^ cannot refer to the associated constant of trait
 
+error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo`
+  --> $DIR/issue-58022.rs:14:9
+   |
+LL |         Foo(Box::new(*slice))
+   |         ^^^ not a function, tuple struct or tuple variant
+
 error: aborting due to 2 previous errors
 
 Some errors have detailed explanations: E0423, E0790.
diff --git a/src/test/ui/lang-items/issue-83471.stderr b/src/test/ui/lang-items/issue-83471.stderr
index fc9ab293f99..b315df179d0 100644
--- a/src/test/ui/lang-items/issue-83471.stderr
+++ b/src/test/ui/lang-items/issue-83471.stderr
@@ -4,12 +4,6 @@ error[E0573]: expected type, found built-in attribute `export_name`
 LL |     fn call(export_name);
    |             ^^^^^^^^^^^ not a type
 
-error[E0425]: cannot find function `a` in this scope
-  --> $DIR/issue-83471.rs:21:5
-   |
-LL |     a()
-   |     ^ not found in this scope
-
 error[E0658]: language items are subject to change
   --> $DIR/issue-83471.rs:7:1
    |
@@ -45,6 +39,12 @@ LL | #[lang = "fn"]
 LL | trait Fn {
    |         - this trait has 0 generic arguments
 
+error[E0425]: cannot find function `a` in this scope
+  --> $DIR/issue-83471.rs:21:5
+   |
+LL |     a()
+   |     ^ not found in this scope
+
 error: aborting due to 5 previous errors; 1 warning emitted
 
 Some errors have detailed explanations: E0425, E0573, E0658, E0718.
diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr b/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
index 0188938a30e..a6cff95fd91 100644
--- a/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
+++ b/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
@@ -319,11 +319,11 @@ LL |     unknown_metavar!(a);
    |
    = note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0425]: cannot find function `count` in this scope
-  --> $DIR/syntax-errors.rs:29:30
+error[E0425]: cannot find value `i` in this scope
+  --> $DIR/syntax-errors.rs:29:36
    |
 LL |     ( $( $i:ident ),* ) => { count(i) };
-   |                              ^^^^^ not found in this scope
+   |                                    ^ not found in this scope
 ...
 LL |     no_curly__no_rhs_dollar__round!(a, b, c);
    |     ---------------------------------------- in this macro invocation
@@ -331,10 +331,27 @@ LL |     no_curly__no_rhs_dollar__round!(a, b, c);
    = note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0425]: cannot find value `i` in this scope
-  --> $DIR/syntax-errors.rs:29:36
+  --> $DIR/syntax-errors.rs:35:29
+   |
+LL |     ( $i:ident ) => { count(i) };
+   |                             ^ not found in this scope
+...
+LL |     no_curly__no_rhs_dollar__no_round!(a);
+   |     ------------------------------------- in this macro invocation
+   |
+   = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0425]: cannot find value `a` in this scope
+  --> $DIR/syntax-errors.rs:153:37
+   |
+LL |     no_curly__rhs_dollar__no_round!(a);
+   |                                     ^ not found in this scope
+
+error[E0425]: cannot find function `count` in this scope
+  --> $DIR/syntax-errors.rs:29:30
    |
 LL |     ( $( $i:ident ),* ) => { count(i) };
-   |                                    ^ not found in this scope
+   |                              ^^^^^ not found in this scope
 ...
 LL |     no_curly__no_rhs_dollar__round!(a, b, c);
    |     ---------------------------------------- in this macro invocation
@@ -352,17 +369,6 @@ LL |     no_curly__no_rhs_dollar__no_round!(a);
    |
    = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0425]: cannot find value `i` in this scope
-  --> $DIR/syntax-errors.rs:35:29
-   |
-LL |     ( $i:ident ) => { count(i) };
-   |                             ^ not found in this scope
-...
-LL |     no_curly__no_rhs_dollar__no_round!(a);
-   |     ------------------------------------- in this macro invocation
-   |
-   = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
-
 error[E0425]: cannot find function `count` in this scope
   --> $DIR/syntax-errors.rs:46:23
    |
@@ -374,12 +380,6 @@ LL |     no_curly__rhs_dollar__no_round!(a);
    |
    = note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0425]: cannot find value `a` in this scope
-  --> $DIR/syntax-errors.rs:153:37
-   |
-LL |     no_curly__rhs_dollar__no_round!(a);
-   |                                     ^ not found in this scope
-
 error: aborting due to 40 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
index f3dbcc2d7b2..227d30282b1 100644
--- a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
+++ b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
@@ -1,27 +1,27 @@
-error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:11:5
-   |
-LL |     foo();
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find function `foo` in module `m`
   --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:12:8
    |
 LL |     m::foo();
    |        ^^^ not found in `m`
 
-error[E0425]: cannot find function `bar` in this scope
-  --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:13:5
-   |
-LL |     bar();
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find function `bar` in module `m`
   --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:14:8
    |
 LL |     m::bar();
    |        ^^^ not found in `m`
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:11:5
+   |
+LL |     foo();
+   |     ^^^ not found in this scope
+
+error[E0425]: cannot find function `bar` in this scope
+  --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:13:5
+   |
+LL |     bar();
+   |     ^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
index 98784de8e59..111ac7ab0f0 100644
--- a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
+++ b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
@@ -1,27 +1,27 @@
-error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/namespaced-enum-glob-import-no-impls.rs:21:5
-   |
-LL |     foo();
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find function `foo` in module `m`
   --> $DIR/namespaced-enum-glob-import-no-impls.rs:22:8
    |
 LL |     m::foo();
    |        ^^^ not found in `m`
 
-error[E0425]: cannot find function `bar` in this scope
-  --> $DIR/namespaced-enum-glob-import-no-impls.rs:23:5
-   |
-LL |     bar();
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find function `bar` in module `m`
   --> $DIR/namespaced-enum-glob-import-no-impls.rs:24:8
    |
 LL |     m::bar();
    |        ^^^ not found in `m`
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/namespaced-enum-glob-import-no-impls.rs:21:5
+   |
+LL |     foo();
+   |     ^^^ not found in this scope
+
+error[E0425]: cannot find function `bar` in this scope
+  --> $DIR/namespaced-enum-glob-import-no-impls.rs:23:5
+   |
+LL |     bar();
+   |     ^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/emoji-identifiers.stderr b/src/test/ui/parser/emoji-identifiers.stderr
index 2550dc3d321..e645b68ba87 100644
--- a/src/test/ui/parser/emoji-identifiers.stderr
+++ b/src/test/ui/parser/emoji-identifiers.stderr
@@ -9,15 +9,6 @@ help: Unicode character 'βž–' (Heavy Minus Sign) looks like '-' (Minus/Hyphen),
 LL |     let _ = i_like_to_πŸ˜„_a_lot() - 4;
    |                                  ~
 
-error[E0425]: cannot find function `i_like_to_πŸ˜„_a_lot` in this scope
-  --> $DIR/emoji-identifiers.rs:13:13
-   |
-LL | fn i_like_to_πŸ˜…_a_lot() -> πŸ‘€ {
-   | ----------------------------- similarly named function `i_like_to_πŸ˜…_a_lot` defined here
-...
-LL |     let _ = i_like_to_πŸ˜„_a_lot() βž– 4;
-   |             ^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `i_like_to_πŸ˜…_a_lot`
-
 error: Ferris cannot be used as an identifier
   --> $DIR/emoji-identifiers.rs:17:9
    |
@@ -85,6 +76,15 @@ LL |     πŸ‘€::full_of✨()
    |         function or associated item not found in `πŸ‘€`
    |         help: there is an associated function with a similar name: `full_of_✨`
 
+error[E0425]: cannot find function `i_like_to_πŸ˜„_a_lot` in this scope
+  --> $DIR/emoji-identifiers.rs:13:13
+   |
+LL | fn i_like_to_πŸ˜…_a_lot() -> πŸ‘€ {
+   | ----------------------------- similarly named function `i_like_to_πŸ˜…_a_lot` defined here
+...
+LL |     let _ = i_like_to_πŸ˜„_a_lot() βž– 4;
+   |             ^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `i_like_to_πŸ˜…_a_lot`
+
 error: aborting due to 10 previous errors
 
 Some errors have detailed explanations: E0425, E0599.
diff --git a/src/test/ui/parser/parser-recovery-1.stderr b/src/test/ui/parser/parser-recovery-1.stderr
index f56060c3e35..0cb771ea39c 100644
--- a/src/test/ui/parser/parser-recovery-1.stderr
+++ b/src/test/ui/parser/parser-recovery-1.stderr
@@ -18,18 +18,18 @@ error: unexpected token: `;`
 LL |     let x = y.;
    |               ^
 
-error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/parser-recovery-1.rs:5:17
-   |
-LL |         let x = foo();
-   |                 ^^^ not found in this scope
-
 error[E0425]: cannot find value `y` in this scope
   --> $DIR/parser-recovery-1.rs:10:13
    |
 LL |     let x = y.;
    |             ^ not found in this scope
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/parser-recovery-1.rs:5:17
+   |
+LL |         let x = foo();
+   |                 ^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/parser-recovery-2.stderr b/src/test/ui/parser/parser-recovery-2.stderr
index 0980d033fe7..8829cf4c1e1 100644
--- a/src/test/ui/parser/parser-recovery-2.stderr
+++ b/src/test/ui/parser/parser-recovery-2.stderr
@@ -13,18 +13,18 @@ LL |         let x = foo();
 LL |     )
    |     ^ mismatched closing delimiter
 
-error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/parser-recovery-2.rs:5:17
-   |
-LL |         let x = foo();
-   |                 ^^^ not found in this scope
-
 error[E0425]: cannot find value `y` in this scope
   --> $DIR/parser-recovery-2.rs:10:13
    |
 LL |     let x = y.;
    |             ^ not found in this scope
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/parser-recovery-2.rs:5:17
+   |
+LL |         let x = foo();
+   |                 ^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/unmatched-langle-1.stderr b/src/test/ui/parser/unmatched-langle-1.stderr
index c8072b4c59a..cdf74bdedc2 100644
--- a/src/test/ui/parser/unmatched-langle-1.stderr
+++ b/src/test/ui/parser/unmatched-langle-1.stderr
@@ -4,18 +4,18 @@ error: unmatched angle brackets
 LL |     foo::<<<<Ty<i32>>();
    |          ^^^ help: remove extra angle brackets
 
-error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/unmatched-langle-1.rs:5:5
-   |
-LL |     foo::<<<<Ty<i32>>();
-   |     ^^^ not found in this scope
-
 error[E0412]: cannot find type `Ty` in this scope
   --> $DIR/unmatched-langle-1.rs:5:14
    |
 LL |     foo::<<<<Ty<i32>>();
    |              ^^ not found in this scope
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/unmatched-langle-1.rs:5:5
+   |
+LL |     foo::<<<<Ty<i32>>();
+   |     ^^^ not found in this scope
+
 error: aborting due to 3 previous errors
 
 Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/proc-macro/keep-expr-tokens.stderr b/src/test/ui/proc-macro/keep-expr-tokens.stderr
index 11052d11c25..1a1f83cc156 100644
--- a/src/test/ui/proc-macro/keep-expr-tokens.stderr
+++ b/src/test/ui/proc-macro/keep-expr-tokens.stderr
@@ -1,15 +1,15 @@
-error[E0425]: cannot find function `missing_fn` in this scope
-  --> $DIR/keep-expr-tokens.rs:17:17
-   |
-LL |     for item in missing_fn() {}
-   |                 ^^^^^^^^^^ not found in this scope
-
 error[E0425]: cannot find value `bad` in this scope
   --> $DIR/keep-expr-tokens.rs:19:62
    |
 LL |     (#[recollect_attr] #[recollect_attr] ((#[recollect_attr] bad)));
    |                                                              ^^^ not found in this scope
 
+error[E0425]: cannot find function `missing_fn` in this scope
+  --> $DIR/keep-expr-tokens.rs:17:17
+   |
+LL |     for item in missing_fn() {}
+   |                 ^^^^^^^^^^ not found in this scope
+
 error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/resolve/bad-env-capture.stderr b/src/test/ui/resolve/bad-env-capture.stderr
index f78a38a3dd4..59b1fabfd7c 100644
--- a/src/test/ui/resolve/bad-env-capture.stderr
+++ b/src/test/ui/resolve/bad-env-capture.stderr
@@ -6,18 +6,18 @@ LL |     fn bar() { log(debug, x); }
    |
    = help: use the `|| { ... }` closure form instead
 
-error[E0425]: cannot find function `log` in this scope
-  --> $DIR/bad-env-capture.rs:4:16
-   |
-LL |     fn bar() { log(debug, x); }
-   |                ^^^ not found in this scope
-
 error[E0425]: cannot find value `debug` in this scope
   --> $DIR/bad-env-capture.rs:4:20
    |
 LL |     fn bar() { log(debug, x); }
    |                    ^^^^^ not found in this scope
 
+error[E0425]: cannot find function `log` in this scope
+  --> $DIR/bad-env-capture.rs:4:16
+   |
+LL |     fn bar() { log(debug, x); }
+   |                ^^^ not found in this scope
+
 error: aborting due to 3 previous errors
 
 Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-env-capture2.stderr b/src/test/ui/resolve/bad-env-capture2.stderr
index 57c807fd7df..811c259de6b 100644
--- a/src/test/ui/resolve/bad-env-capture2.stderr
+++ b/src/test/ui/resolve/bad-env-capture2.stderr
@@ -6,18 +6,18 @@ LL |     fn bar() { log(debug, x); }
    |
    = help: use the `|| { ... }` closure form instead
 
-error[E0425]: cannot find function `log` in this scope
-  --> $DIR/bad-env-capture2.rs:3:16
-   |
-LL |     fn bar() { log(debug, x); }
-   |                ^^^ not found in this scope
-
 error[E0425]: cannot find value `debug` in this scope
   --> $DIR/bad-env-capture2.rs:3:20
    |
 LL |     fn bar() { log(debug, x); }
    |                    ^^^^^ not found in this scope
 
+error[E0425]: cannot find function `log` in this scope
+  --> $DIR/bad-env-capture2.rs:3:16
+   |
+LL |     fn bar() { log(debug, x); }
+   |                ^^^ not found in this scope
+
 error: aborting due to 3 previous errors
 
 Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-env-capture3.stderr b/src/test/ui/resolve/bad-env-capture3.stderr
index d6eb4f86e11..eab37fde96e 100644
--- a/src/test/ui/resolve/bad-env-capture3.stderr
+++ b/src/test/ui/resolve/bad-env-capture3.stderr
@@ -6,18 +6,18 @@ LL |         fn bar() { log(debug, x); }
    |
    = help: use the `|| { ... }` closure form instead
 
-error[E0425]: cannot find function `log` in this scope
-  --> $DIR/bad-env-capture3.rs:4:20
-   |
-LL |         fn bar() { log(debug, x); }
-   |                    ^^^ not found in this scope
-
 error[E0425]: cannot find value `debug` in this scope
   --> $DIR/bad-env-capture3.rs:4:24
    |
 LL |         fn bar() { log(debug, x); }
    |                        ^^^^^ not found in this scope
 
+error[E0425]: cannot find function `log` in this scope
+  --> $DIR/bad-env-capture3.rs:4:20
+   |
+LL |         fn bar() { log(debug, x); }
+   |                    ^^^ not found in this scope
+
 error: aborting due to 3 previous errors
 
 Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-expr-path.stderr b/src/test/ui/resolve/bad-expr-path.stderr
index 77c48c951ac..8261e8e53b0 100644
--- a/src/test/ui/resolve/bad-expr-path.stderr
+++ b/src/test/ui/resolve/bad-expr-path.stderr
@@ -1,9 +1,3 @@
-error[E0425]: cannot find function `log` in this scope
-  --> $DIR/bad-expr-path.rs:4:5
-   |
-LL |     log(debug, m1::arguments);
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find value `debug` in this scope
   --> $DIR/bad-expr-path.rs:4:9
    |
@@ -16,6 +10,12 @@ error[E0425]: cannot find value `arguments` in module `m1`
 LL |     log(debug, m1::arguments);
    |                    ^^^^^^^^^ not found in `m1`
 
+error[E0425]: cannot find function `log` in this scope
+  --> $DIR/bad-expr-path.rs:4:5
+   |
+LL |     log(debug, m1::arguments);
+   |     ^^^ not found in this scope
+
 error[E0580]: `main` function has wrong type
   --> $DIR/bad-expr-path.rs:3:1
    |
diff --git a/src/test/ui/resolve/bad-expr-path2.stderr b/src/test/ui/resolve/bad-expr-path2.stderr
index d06e1027179..6e11296d9fc 100644
--- a/src/test/ui/resolve/bad-expr-path2.stderr
+++ b/src/test/ui/resolve/bad-expr-path2.stderr
@@ -1,9 +1,3 @@
-error[E0425]: cannot find function `log` in this scope
-  --> $DIR/bad-expr-path2.rs:6:5
-   |
-LL |     log(debug, m1::arguments);
-   |     ^^^ not found in this scope
-
 error[E0425]: cannot find value `debug` in this scope
   --> $DIR/bad-expr-path2.rs:6:9
    |
@@ -16,6 +10,12 @@ error[E0423]: expected value, found module `m1::arguments`
 LL |     log(debug, m1::arguments);
    |                ^^^^^^^^^^^^^ not a value
 
+error[E0425]: cannot find function `log` in this scope
+  --> $DIR/bad-expr-path2.rs:6:5
+   |
+LL |     log(debug, m1::arguments);
+   |     ^^^ not found in this scope
+
 error[E0580]: `main` function has wrong type
   --> $DIR/bad-expr-path2.rs:5:1
    |
diff --git a/src/test/ui/resolve/issue-14254.stderr b/src/test/ui/resolve/issue-14254.stderr
index b1f45adb8b7..c848014ad8f 100644
--- a/src/test/ui/resolve/issue-14254.stderr
+++ b/src/test/ui/resolve/issue-14254.stderr
@@ -1,21 +1,9 @@
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:19:9
-   |
-LL |         baz();
-   |         ^^^ help: you might have meant to call the method: `self.baz`
-
 error[E0425]: cannot find value `a` in this scope
   --> $DIR/issue-14254.rs:21:9
    |
 LL |         a;
    |         ^ not found in this scope
 
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:28:9
-   |
-LL |         baz();
-   |         ^^^ help: you might have meant to call the method: `self.baz`
-
 error[E0425]: cannot find value `x` in this scope
   --> $DIR/issue-14254.rs:30:9
    |
@@ -46,12 +34,6 @@ error[E0425]: cannot find value `b` in this scope
 LL |         b;
    |         ^ not found in this scope
 
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:45:9
-   |
-LL |         baz();
-   |         ^^^ help: you might have meant to call the method: `self.baz`
-
 error[E0425]: cannot find value `x` in this scope
   --> $DIR/issue-14254.rs:47:9
    |
@@ -82,65 +64,83 @@ error[E0425]: cannot find value `b` in this scope
 LL |         b;
    |         ^ not found in this scope
 
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:62:9
+error[E0425]: cannot find value `bah` in this scope
+  --> $DIR/issue-14254.rs:64:9
    |
-LL |         baz();
-   |         ^^^ help: you might have meant to call the method: `self.baz`
+LL |         bah;
+   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
 
 error[E0425]: cannot find value `bah` in this scope
-  --> $DIR/issue-14254.rs:64:9
+  --> $DIR/issue-14254.rs:73:9
    |
 LL |         bah;
    |         ^^^ help: you might have meant to call the associated function: `Self::bah`
 
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:71:9
+error[E0425]: cannot find value `bah` in this scope
+  --> $DIR/issue-14254.rs:82:9
    |
-LL |         baz();
-   |         ^^^ help: you might have meant to call the method: `self.baz`
+LL |         bah;
+   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
 
 error[E0425]: cannot find value `bah` in this scope
-  --> $DIR/issue-14254.rs:73:9
+  --> $DIR/issue-14254.rs:91:9
+   |
+LL |         bah;
+   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
+
+error[E0425]: cannot find value `bah` in this scope
+  --> $DIR/issue-14254.rs:100:9
    |
 LL |         bah;
    |         ^^^ help: you might have meant to call the associated function: `Self::bah`
 
 error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:80:9
+  --> $DIR/issue-14254.rs:19:9
    |
 LL |         baz();
    |         ^^^ help: you might have meant to call the method: `self.baz`
 
-error[E0425]: cannot find value `bah` in this scope
-  --> $DIR/issue-14254.rs:82:9
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/issue-14254.rs:28:9
    |
-LL |         bah;
-   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL |         baz();
+   |         ^^^ help: you might have meant to call the method: `self.baz`
 
 error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:89:9
+  --> $DIR/issue-14254.rs:45:9
    |
 LL |         baz();
    |         ^^^ help: you might have meant to call the method: `self.baz`
 
-error[E0425]: cannot find value `bah` in this scope
-  --> $DIR/issue-14254.rs:91:9
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/issue-14254.rs:62:9
    |
-LL |         bah;
-   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL |         baz();
+   |         ^^^ help: you might have meant to call the method: `self.baz`
 
 error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/issue-14254.rs:98:9
+  --> $DIR/issue-14254.rs:71:9
    |
 LL |         baz();
    |         ^^^ help: you might have meant to call the method: `self.baz`
 
-error[E0425]: cannot find value `bah` in this scope
-  --> $DIR/issue-14254.rs:100:9
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/issue-14254.rs:80:9
    |
-LL |         bah;
-   |         ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL |         baz();
+   |         ^^^ help: you might have meant to call the method: `self.baz`
+
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/issue-14254.rs:89:9
+   |
+LL |         baz();
+   |         ^^^ help: you might have meant to call the method: `self.baz`
+
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/issue-14254.rs:98:9
+   |
+LL |         baz();
+   |         ^^^ help: you might have meant to call the method: `self.baz`
 
 error: aborting due to 24 previous errors
 
diff --git a/src/test/ui/resolve/issue-2356.stderr b/src/test/ui/resolve/issue-2356.stderr
index b8d528efc15..e7c53ff44e6 100644
--- a/src/test/ui/resolve/issue-2356.stderr
+++ b/src/test/ui/resolve/issue-2356.stderr
@@ -1,15 +1,3 @@
-error[E0425]: cannot find function `shave` in this scope
-  --> $DIR/issue-2356.rs:17:5
-   |
-LL |     shave();
-   |     ^^^^^ not found in this scope
-
-error[E0425]: cannot find function `clone` in this scope
-  --> $DIR/issue-2356.rs:24:5
-   |
-LL |     clone();
-   |     ^^^^^ help: you might have meant to call the method: `self.clone`
-
 error[E0425]: cannot find function `default` in this scope
   --> $DIR/issue-2356.rs:31:5
    |
@@ -31,6 +19,51 @@ error[E0425]: cannot find value `whiskers` in this scope
 LL |     whiskers -= other;
    |     ^^^^^^^^ a field by this name exists in `Self`
 
+error[E0424]: expected value, found module `self`
+  --> $DIR/issue-2356.rs:65:8
+   |
+LL |   fn meow() {
+   |      ---- this function doesn't have a `self` parameter
+LL |     if self.whiskers > 3 {
+   |        ^^^^ `self` value is a keyword only available in methods with a `self` parameter
+   |
+help: add a `self` receiver parameter to make the associated `fn` a method
+   |
+LL |   fn meow(&self) {
+   |           +++++
+
+error[E0425]: cannot find value `whiskers` in this scope
+  --> $DIR/issue-2356.rs:79:5
+   |
+LL |     whiskers = 0;
+   |     ^^^^^^^^ help: you might have meant to use the available field: `self.whiskers`
+
+error[E0425]: cannot find value `whiskers` in this scope
+  --> $DIR/issue-2356.rs:84:5
+   |
+LL |     whiskers = 4;
+   |     ^^^^^^^^ a field by this name exists in `Self`
+
+error[E0424]: expected value, found module `self`
+  --> $DIR/issue-2356.rs:92:5
+   |
+LL | fn main() {
+   |    ---- this function can't have a `self` parameter
+LL |     self += 1;
+   |     ^^^^ `self` value is a keyword only available in methods with a `self` parameter
+
+error[E0425]: cannot find function `shave` in this scope
+  --> $DIR/issue-2356.rs:17:5
+   |
+LL |     shave();
+   |     ^^^^^ not found in this scope
+
+error[E0425]: cannot find function `clone` in this scope
+  --> $DIR/issue-2356.rs:24:5
+   |
+LL |     clone();
+   |     ^^^^^ help: you might have meant to call the method: `self.clone`
+
 error[E0425]: cannot find function `shave` in this scope
   --> $DIR/issue-2356.rs:41:5
    |
@@ -72,19 +105,6 @@ error[E0425]: cannot find function `purr` in this scope
 LL |         purr();
    |         ^^^^ not found in this scope
 
-error[E0424]: expected value, found module `self`
-  --> $DIR/issue-2356.rs:65:8
-   |
-LL |   fn meow() {
-   |      ---- this function doesn't have a `self` parameter
-LL |     if self.whiskers > 3 {
-   |        ^^^^ `self` value is a keyword only available in methods with a `self` parameter
-   |
-help: add a `self` receiver parameter to make the associated `fn` a method
-   |
-LL |   fn meow(&self) {
-   |           +++++
-
 error[E0425]: cannot find function `grow_older` in this scope
   --> $DIR/issue-2356.rs:72:5
    |
@@ -102,32 +122,12 @@ error[E0425]: cannot find function `shave` in this scope
 LL |     shave();
    |     ^^^^^ not found in this scope
 
-error[E0425]: cannot find value `whiskers` in this scope
-  --> $DIR/issue-2356.rs:79:5
-   |
-LL |     whiskers = 0;
-   |     ^^^^^^^^ help: you might have meant to use the available field: `self.whiskers`
-
-error[E0425]: cannot find value `whiskers` in this scope
-  --> $DIR/issue-2356.rs:84:5
-   |
-LL |     whiskers = 4;
-   |     ^^^^^^^^ a field by this name exists in `Self`
-
 error[E0425]: cannot find function `purr_louder` in this scope
   --> $DIR/issue-2356.rs:86:5
    |
 LL |     purr_louder();
    |     ^^^^^^^^^^^ not found in this scope
 
-error[E0424]: expected value, found module `self`
-  --> $DIR/issue-2356.rs:92:5
-   |
-LL | fn main() {
-   |    ---- this function can't have a `self` parameter
-LL |     self += 1;
-   |     ^^^^ `self` value is a keyword only available in methods with a `self` parameter
-
 error: aborting due to 17 previous errors
 
 Some errors have detailed explanations: E0424, E0425.
diff --git a/src/test/ui/resolve/issue-42944.stderr b/src/test/ui/resolve/issue-42944.stderr
index cad3ccc4a0e..0ee9fd391fe 100644
--- a/src/test/ui/resolve/issue-42944.stderr
+++ b/src/test/ui/resolve/issue-42944.stderr
@@ -1,15 +1,3 @@
-error[E0423]: cannot initialize a tuple struct which contains private fields
-  --> $DIR/issue-42944.rs:9:9
-   |
-LL |         Bx(());
-   |         ^^
-   |
-note: constructor is not visible here due to private fields
-  --> $DIR/issue-42944.rs:2:19
-   |
-LL |     pub struct Bx(());
-   |                   ^^ private field
-
 error[E0425]: cannot find function, tuple struct or tuple variant `Bx` in this scope
   --> $DIR/issue-42944.rs:16:9
    |
@@ -22,6 +10,18 @@ note: tuple struct `foo::Bx` exists but is inaccessible
 LL |     pub struct Bx(());
    |     ^^^^^^^^^^^^^^^^^^ not accessible
 
+error[E0423]: cannot initialize a tuple struct which contains private fields
+  --> $DIR/issue-42944.rs:9:9
+   |
+LL |         Bx(());
+   |         ^^
+   |
+note: constructor is not visible here due to private fields
+  --> $DIR/issue-42944.rs:2:19
+   |
+LL |     pub struct Bx(());
+   |                   ^^ private field
+
 error: aborting due to 2 previous errors
 
 Some errors have detailed explanations: E0423, E0425.
diff --git a/src/test/ui/resolve/issue-73427.stderr b/src/test/ui/resolve/issue-73427.stderr
index a2ca46f0ce9..d31c5e47775 100644
--- a/src/test/ui/resolve/issue-73427.stderr
+++ b/src/test/ui/resolve/issue-73427.stderr
@@ -124,13 +124,13 @@ LL | use std::f32::consts::E;
 LL | use std::f64::consts::E;
    |
 
-error[E0423]: expected function, tuple struct or tuple variant, found enum `A`
-  --> $DIR/issue-73427.rs:46:13
+error[E0532]: expected tuple struct or tuple variant, found enum `A`
+  --> $DIR/issue-73427.rs:48:12
    |
-LL |     let x = A(3);
-   |             ^
+LL |     if let A(3) = x { }
+   |            ^
    |
-   = help: you might have meant to construct one of the enum's non-tuple variants
+   = help: you might have meant to match against one of the enum's non-tuple variants
 note: the enum is defined here
   --> $DIR/issue-73427.rs:1:1
    |
@@ -142,20 +142,20 @@ LL | |     Tuple(),
 LL | |     Unit,
 LL | | }
    | |_^
-help: try to construct one of the enum's variants
+help: try to match against one of the enum's variants
    |
-LL |     let x = A::Tuple(3);
-   |             ~~~~~~~~
-LL |     let x = A::TupleWithFields(3);
-   |             ~~~~~~~~~~~~~~~~~~
+LL |     if let A::Tuple(3) = x { }
+   |            ~~~~~~~~
+LL |     if let A::TupleWithFields(3) = x { }
+   |            ~~~~~~~~~~~~~~~~~~
 
-error[E0532]: expected tuple struct or tuple variant, found enum `A`
-  --> $DIR/issue-73427.rs:48:12
+error[E0423]: expected function, tuple struct or tuple variant, found enum `A`
+  --> $DIR/issue-73427.rs:46:13
    |
-LL |     if let A(3) = x { }
-   |            ^
+LL |     let x = A(3);
+   |             ^
    |
-   = help: you might have meant to match against one of the enum's non-tuple variants
+   = help: you might have meant to construct one of the enum's non-tuple variants
 note: the enum is defined here
   --> $DIR/issue-73427.rs:1:1
    |
@@ -167,12 +167,12 @@ LL | |     Tuple(),
 LL | |     Unit,
 LL | | }
    | |_^
-help: try to match against one of the enum's variants
+help: try to construct one of the enum's variants
    |
-LL |     if let A::Tuple(3) = x { }
-   |            ~~~~~~~~
-LL |     if let A::TupleWithFields(3) = x { }
-   |            ~~~~~~~~~~~~~~~~~~
+LL |     let x = A::Tuple(3);
+   |             ~~~~~~~~
+LL |     let x = A::TupleWithFields(3);
+   |             ~~~~~~~~~~~~~~~~~~
 
 error: aborting due to 7 previous errors
 
diff --git a/src/test/ui/resolve/levenshtein.stderr b/src/test/ui/resolve/levenshtein.stderr
index 249a7e53d45..9a2d61ea405 100644
--- a/src/test/ui/resolve/levenshtein.stderr
+++ b/src/test/ui/resolve/levenshtein.stderr
@@ -39,15 +39,6 @@ LL | const MAX_ITEM: usize = 10;
 LL |     let v = [0u32; MAXITEM]; // Misspelled constant name.
    |                    ^^^^^^^ help: a constant with a similar name exists: `MAX_ITEM`
 
-error[E0425]: cannot find function `foobar` in this scope
-  --> $DIR/levenshtein.rs:26:5
-   |
-LL | fn foo_bar() {}
-   | ------------ similarly named function `foo_bar` defined here
-...
-LL |     foobar(); // Misspelled function name.
-   |     ^^^^^^ help: a function with a similar name exists: `foo_bar`
-
 error[E0412]: cannot find type `first` in module `m`
   --> $DIR/levenshtein.rs:28:15
    |
@@ -66,6 +57,15 @@ LL |     pub struct Second;
 LL |     let b: m::first = m::second; // Misspelled item in module.
    |                          ^^^^^^ help: a unit struct with a similar name exists (notice the capitalization): `Second`
 
+error[E0425]: cannot find function `foobar` in this scope
+  --> $DIR/levenshtein.rs:26:5
+   |
+LL | fn foo_bar() {}
+   | ------------ similarly named function `foo_bar` defined here
+...
+LL |     foobar(); // Misspelled function name.
+   |     ^^^^^^ help: a function with a similar name exists: `foo_bar`
+
 error: aborting due to 8 previous errors
 
 Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/resolve/resolve-hint-macro.stderr b/src/test/ui/resolve/resolve-hint-macro.stderr
index bc69ddd8ffe..1e7ab48ef90 100644
--- a/src/test/ui/resolve/resolve-hint-macro.stderr
+++ b/src/test/ui/resolve/resolve-hint-macro.stderr
@@ -14,17 +14,6 @@ LL |     assert_eq { 1, 1 };
    |     |
    |     while parsing this struct
 
-error[E0423]: expected function, found macro `assert_eq`
-  --> $DIR/resolve-hint-macro.rs:3:5
-   |
-LL |     assert_eq(1, 1);
-   |     ^^^^^^^^^ not a function
-   |
-help: use `!` to invoke the macro
-   |
-LL |     assert_eq!(1, 1);
-   |              +
-
 error[E0574]: expected struct, variant or union type, found macro `assert_eq`
   --> $DIR/resolve-hint-macro.rs:5:5
    |
@@ -47,6 +36,17 @@ help: use `!` to invoke the macro
 LL |     assert![true];
    |           +
 
+error[E0423]: expected function, found macro `assert_eq`
+  --> $DIR/resolve-hint-macro.rs:3:5
+   |
+LL |     assert_eq(1, 1);
+   |     ^^^^^^^^^ not a function
+   |
+help: use `!` to invoke the macro
+   |
+LL |     assert_eq!(1, 1);
+   |              +
+
 error: aborting due to 5 previous errors
 
 Some errors have detailed explanations: E0423, E0574.
diff --git a/src/test/ui/resolve/resolve-speculative-adjustment.stderr b/src/test/ui/resolve/resolve-speculative-adjustment.stderr
index 1c34af6d0ff..be11a7ebeca 100644
--- a/src/test/ui/resolve/resolve-speculative-adjustment.stderr
+++ b/src/test/ui/resolve/resolve-speculative-adjustment.stderr
@@ -4,12 +4,6 @@ error[E0425]: cannot find value `field` in this scope
 LL |             field;
    |             ^^^^^ not found in this scope
 
-error[E0425]: cannot find function `method` in this scope
-  --> $DIR/resolve-speculative-adjustment.rs:19:13
-   |
-LL |             method();
-   |             ^^^^^^ not found in this scope
-
 error[E0425]: cannot find value `field` in this scope
   --> $DIR/resolve-speculative-adjustment.rs:23:9
    |
@@ -22,6 +16,12 @@ error[E0425]: cannot find function `method` in this scope
 LL |         method();
    |         ^^^^^^ help: you might have meant to call the method: `self.method`
 
+error[E0425]: cannot find function `method` in this scope
+  --> $DIR/resolve-speculative-adjustment.rs:19:13
+   |
+LL |             method();
+   |             ^^^^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/resolve/tuple-struct-alias.stderr b/src/test/ui/resolve/tuple-struct-alias.stderr
index 5a7873301c8..a739ea43eed 100644
--- a/src/test/ui/resolve/tuple-struct-alias.stderr
+++ b/src/test/ui/resolve/tuple-struct-alias.stderr
@@ -1,22 +1,22 @@
-error[E0423]: expected function, tuple struct or tuple variant, found type alias `A`
-  --> $DIR/tuple-struct-alias.rs:5:13
+error[E0532]: expected tuple struct or tuple variant, found type alias `A`
+  --> $DIR/tuple-struct-alias.rs:7:9
    |
 LL | struct S(u8, u16);
    | ------------------ similarly named tuple struct `S` defined here
 ...
-LL |     let s = A(0, 1);
-   |             ^ help: a tuple struct with a similar name exists: `S`
+LL |         A(..) => {}
+   |         ^ help: a tuple struct with a similar name exists: `S`
    |
    = note: can't use a type alias as a constructor
 
-error[E0532]: expected tuple struct or tuple variant, found type alias `A`
-  --> $DIR/tuple-struct-alias.rs:7:9
+error[E0423]: expected function, tuple struct or tuple variant, found type alias `A`
+  --> $DIR/tuple-struct-alias.rs:5:13
    |
 LL | struct S(u8, u16);
    | ------------------ similarly named tuple struct `S` defined here
 ...
-LL |         A(..) => {}
-   |         ^ help: a tuple struct with a similar name exists: `S`
+LL |     let s = A(0, 1);
+   |             ^ help: a tuple struct with a similar name exists: `S`
    |
    = note: can't use a type alias as a constructor
 
diff --git a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
index 0b0a37f246c..2764e1f8132 100644
--- a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
+++ b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
@@ -31,24 +31,6 @@ help: a local variable with a similar name exists
 LL |         println!("{cofig}");
    |                    ~~~~~
 
-error[E0425]: cannot find function `baz` in this scope
-  --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
-   |
-LL |         baz();
-   |         ^^^
-...
-LL | fn ba() {}
-   | ------- similarly named function `ba` defined here
-   |
-help: you might have meant to call the method
-   |
-LL |         self.baz();
-   |         ~~~~~~~~
-help: a function with a similar name exists
-   |
-LL |         ba();
-   |         ~~
-
 error[E0425]: cannot find value `bah` in this scope
   --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:33:9
    |
@@ -103,6 +85,24 @@ help: a type alias with a similar name exists
 LL |         let foo: Bar = "".to_string();
    |                  ~~~
 
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
+   |
+LL |         baz();
+   |         ^^^
+...
+LL | fn ba() {}
+   | ------- similarly named function `ba` defined here
+   |
+help: you might have meant to call the method
+   |
+LL |         self.baz();
+   |         ~~~~~~~~
+help: a function with a similar name exists
+   |
+LL |         ba();
+   |         ~~
+
 error: aborting due to 7 previous errors
 
 Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/rfc-2008-non-exhaustive/struct.stderr b/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
index 2b34d071179..2cb9ba0d1d1 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
+++ b/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
@@ -1,9 +1,3 @@
-error[E0423]: cannot initialize a tuple struct which contains private fields
-  --> $DIR/struct.rs:20:14
-   |
-LL |     let ts = TupleStruct(640, 480);
-   |              ^^^^^^^^^^^
-
 error[E0423]: expected value, found struct `UnitStruct`
   --> $DIR/struct.rs:29:14
    |
@@ -68,6 +62,12 @@ help: add `..` at the end of the field list to ignore all other fields
 LL |     let NormalStruct { first_field, second_field , .. } = ns;
    |                                                  ~~~~~~
 
+error[E0423]: cannot initialize a tuple struct which contains private fields
+  --> $DIR/struct.rs:20:14
+   |
+LL |     let ts = TupleStruct(640, 480);
+   |              ^^^^^^^^^^^
+
 error[E0638]: `..` required with struct marked as non-exhaustive
   --> $DIR/struct.rs:26:9
    |
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
index ee72a0c65c8..386385165f6 100644
--- a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
@@ -25,12 +25,6 @@ LL | trait C{async fn new(val: T) {}
    = help: pass `--edition 2021` to `rustc`
    = note: for more on editions, read https://doc.rust-lang.org/edition-guide
 
-error[E0423]: expected function, found module `crate`
-  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
-   |
-LL |     crate(move || {} ).await
-   |     ^^^^^ not a function
-
 error[E0412]: cannot find type `T` in this scope
   --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:27
    |
@@ -53,6 +47,12 @@ LL | trait C{async fn new(val: T) {}
    = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
    = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
 
+error[E0423]: expected function, found module `crate`
+  --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
+   |
+LL |     crate(move || {} ).await
+   |     ^^^^^ not a function
+
 warning: changes to closure capture in Rust 2021 will affect drop order
   --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:57
    |
diff --git a/src/test/ui/suggestions/assoc_fn_without_self.stderr b/src/test/ui/suggestions/assoc_fn_without_self.stderr
index 4a0e62e7309..88920b85290 100644
--- a/src/test/ui/suggestions/assoc_fn_without_self.stderr
+++ b/src/test/ui/suggestions/assoc_fn_without_self.stderr
@@ -1,10 +1,4 @@
 error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/assoc_fn_without_self.rs:14:13
-   |
-LL |             foo();
-   |             ^^^ not found in this scope
-
-error[E0425]: cannot find function `foo` in this scope
   --> $DIR/assoc_fn_without_self.rs:16:9
    |
 LL |         foo();
@@ -32,6 +26,12 @@ help: consider using the associated function
 LL |         Self::baz(2, 3);
    |         ~~~~~~~~~
 
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/assoc_fn_without_self.rs:14:13
+   |
+LL |             foo();
+   |             ^^^ not found in this scope
+
 error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/suggestions/fn-to-method.rs b/src/test/ui/suggestions/fn-to-method.rs
new file mode 100644
index 00000000000..9a35c3efc41
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method.rs
@@ -0,0 +1,19 @@
+struct Foo;
+
+impl Foo {
+    fn bar(self) {}
+}
+
+fn main() {
+    let x = cmp(&1, &2);
+    //~^ ERROR cannot find function `cmp` in this scope
+    //~| HELP use the `.` operator to call the method `Ord::cmp` on `&{integer}`
+
+    let y = len([1, 2, 3]);
+    //~^ ERROR cannot find function `len` in this scope
+    //~| HELP use the `.` operator to call the method `len` on `&[{integer}]`
+
+    let z = bar(Foo);
+    //~^ ERROR cannot find function `bar` in this scope
+    //~| HELP use the `.` operator to call the method `bar` on `Foo`
+}
diff --git a/src/test/ui/suggestions/fn-to-method.stderr b/src/test/ui/suggestions/fn-to-method.stderr
new file mode 100644
index 00000000000..36c17e60d35
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method.stderr
@@ -0,0 +1,38 @@
+error[E0425]: cannot find function `cmp` in this scope
+  --> $DIR/fn-to-method.rs:8:13
+   |
+LL |     let x = cmp(&1, &2);
+   |             ^^^ not found in this scope
+   |
+help: use the `.` operator to call the method `Ord::cmp` on `&{integer}`
+   |
+LL |     let x = (&1).cmp(&2);
+   |             ~  ~~~~~~~~~
+
+error[E0425]: cannot find function `len` in this scope
+  --> $DIR/fn-to-method.rs:12:13
+   |
+LL |     let y = len([1, 2, 3]);
+   |             ^^^ not found in this scope
+   |
+help: use the `.` operator to call the method `len` on `&[{integer}]`
+   |
+LL -     let y = len([1, 2, 3]);
+LL +     let y = [1, 2, 3].len();
+   |
+
+error[E0425]: cannot find function `bar` in this scope
+  --> $DIR/fn-to-method.rs:16:13
+   |
+LL |     let z = bar(Foo);
+   |             ^^^ not found in this scope
+   |
+help: use the `.` operator to call the method `bar` on `Foo`
+   |
+LL -     let z = bar(Foo);
+LL +     let z = Foo.bar();
+   |
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0425`.