about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-15 15:24:54 +0000
committerbors <bors@rust-lang.org>2021-03-15 15:24:54 +0000
commit2ccf06302c08d7d4911aad40e66a9a3ee731c6f9 (patch)
tree407134d0127b6a7d759851a2a032f5b172ca845a /compiler/rustc_resolve/src
parent7a7bbdb3abfa72ca717ef54ffc4f307d0d44de67 (diff)
parent2816c110e01846dd737207f19ba3db11a20b887d (diff)
downloadrust-2ccf06302c08d7d4911aad40e66a9a3ee731c6f9.tar.gz
rust-2ccf06302c08d7d4911aad40e66a9a3ee731c6f9.zip
Auto merge of #83149 - Dylan-DPC:rollup-ov70c5v, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #82989 (Custom error on literal names from other languages)
 - #83054 (Validate rustc_layout_scalar_valid_range_{start,end} attributes)
 - #83098 (Find more invalid doc attributes)
 - #83108 (Remove unused `opt_local_def_id_to_hir_id` function)
 - #83110 (Fix typos in `library/core/src/ptr/mod.rs` and `library/std/src/sys_common/thread_local_dtor.rs`)
 - #83113 (Minor refactoring in try_index_step)
 - #83127 (Introduce `proc_macro_back_compat` lint, and emit for `time-macros-impl`)
 - #83132 (Don't encode file information for span with a dummy location)
 - #83141 (:arrow_up: rust-analyzer)
 - #83144 (Introduce `rustc_interface::interface::Config::parse_sess_created` callback)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index e7b3d459766..e85d78db22c 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -563,6 +563,15 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
                         }
                     }
                 }
+            } else if err_code == &rustc_errors::error_code!(E0412) {
+                if let Some(correct) = Self::likely_rust_type(path) {
+                    err.span_suggestion(
+                        span,
+                        "perhaps you intended to use this type",
+                        correct.to_string(),
+                        Applicability::MaybeIncorrect,
+                    );
+                }
             }
         }
 
@@ -1243,6 +1252,23 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
         }
     }
 
+    // Returns the name of the Rust type approximately corresponding to
+    // a type name in another programming language.
+    fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {
+        let name = path[path.len() - 1].ident.as_str();
+        // Common Java types
+        Some(match &*name {
+            "byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes.
+            "short" => sym::i16,
+            "boolean" => sym::bool,
+            "int" => sym::i32,
+            "long" => sym::i64,
+            "float" => sym::f32,
+            "double" => sym::f64,
+            _ => return None,
+        })
+    }
+
     /// Only used in a specific case of type ascription suggestions
     fn get_colon_suggestion_span(&self, start: Span) -> Span {
         let sm = self.r.session.source_map();