about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-23 23:44:49 +0000
committerbors <bors@rust-lang.org>2021-04-23 23:44:49 +0000
commit8ad0821b035e35aed07ec252c2dd831c15a4e26e (patch)
treea5b32fe60523876762c5a1064c7db4e084c06e7b /compiler/rustc_resolve/src
parentbb491ed23937aef876622e4beb68ae95938b3bf9 (diff)
parenteea27b81366a6a91a5b05153cd9ab6207d7f11bc (diff)
downloadrust-8ad0821b035e35aed07ec252c2dd831c15a4e26e.tar.gz
rust-8ad0821b035e35aed07ec252c2dd831c15a4e26e.zip
Auto merge of #83729 - JohnTitor:issue-43913, r=estebank
Add a suggestion when using a type alias instead of trait alias

Fixes #43913

r? `@estebank`
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index 6fae6921fc9..e33c374f562 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -930,7 +930,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
                     let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
                                `type` alias";
                     if let Some(span) = self.def_span(def_id) {
-                        err.span_help(span, msg);
+                        if let Ok(snip) = self.r.session.source_map().span_to_snippet(span) {
+                            // The span contains a type alias so we should be able to
+                            // replace `type` with `trait`.
+                            let snip = snip.replacen("type", "trait", 1);
+                            err.span_suggestion(span, msg, snip, Applicability::MaybeIncorrect);
+                        } else {
+                            err.span_help(span, msg);
+                        }
                     } else {
                         err.help(msg);
                     }