]> git.lizzy.rs Git - rust.git/commitdiff
use `diagnostic_item` and modify wording
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 23 Jan 2020 19:51:56 +0000 (11:51 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 23 Jan 2020 19:51:56 +0000 (11:51 -0800)
src/libcore/option.rs
src/libcore/result.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/test/ui/suggestions/for-i-in-vec.stderr

index a471b174534aa4e11d16781ecb1d1731d00ace64..cb4247d98745eb8e52af0fd9e2de8de382cd54b0 100644 (file)
 
 /// The `Option` type. See [the module level documentation](index.html) for more.
 #[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
+#[rustc_diagnostic_item = "option_type"]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum Option<T> {
     /// No value
index c657ce33f60adccb380b82001affb7dfd59606ae..bc70dbd62eb52720bfd95e94849ec1af71749bd9 100644 (file)
 /// [`Err`]: enum.Result.html#variant.Err
 #[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
 #[must_use = "this `Result` may be an `Err` variant, which should be handled"]
+#[rustc_diagnostic_item = "result_type"]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum Result<T, E> {
     /// Contains the success value
index c016cc90b1b8679b0369aacf43dc5c44ca2501b3..43121b38da01a1160e3794ef18321dfec4bccd63 100644 (file)
@@ -2,7 +2,7 @@
 use rustc::ty;
 use rustc_errors::{Applicability, DiagnosticBuilder};
 use rustc_span::source_map::DesugaringKind;
-use rustc_span::Span;
+use rustc_span::{Span, Symbol};
 
 use crate::borrow_check::diagnostics::UseSpans;
 use crate::borrow_check::prefixes::PrefixSet;
@@ -384,10 +384,20 @@ fn report_cannot_move_from_borrowed_content(
                 }
             }
         };
-        let move_ty = format!("{:?}", move_place.ty(*self.body, self.infcx.tcx).ty,);
         if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
-            let is_option = move_ty.starts_with("std::option::Option");
-            let is_result = move_ty.starts_with("std::result::Result");
+            let def_id = match move_place.ty(*self.body, self.infcx.tcx).ty.kind {
+                ty::Adt(self_def, _) => self_def.did,
+                ty::Foreign(def_id)
+                | ty::FnDef(def_id, _)
+                | ty::Closure(def_id, _)
+                | ty::Generator(def_id, ..)
+                | ty::Opaque(def_id, _) => def_id,
+                _ => return err,
+            };
+            let is_option =
+                self.infcx.tcx.is_diagnostic_item(Symbol::intern("option_type"), def_id);
+            let is_result =
+                self.infcx.tcx.is_diagnostic_item(Symbol::intern("result_type"), def_id);
             if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) {
                 err.span_suggestion(
                     span,
@@ -399,12 +409,12 @@ fn report_cannot_move_from_borrowed_content(
                     Applicability::MaybeIncorrect,
                 );
             } else if span.is_desugaring(DesugaringKind::ForLoop)
-                && move_ty.starts_with("std::vec::Vec")
+                && self.infcx.tcx.is_diagnostic_item(Symbol::intern("vec_type"), def_id)
             {
                 // FIXME: suggest for anything that implements `IntoIterator`.
                 err.span_suggestion(
                     span,
-                    "consider iterating over a slice of the `Vec`'s content",
+                    "consider iterating over a slice of the `Vec<_>`'s content",
                     format!("&{}", snippet),
                     Applicability::MaybeIncorrect,
                 );
index 0fd10489bd0dfb4a392bd8f6b344e28dd41ea166..576a7cc2f6043b8e31250830cf7fbffb53c14f8a 100644 (file)
@@ -5,7 +5,7 @@ LL |         for _ in self.v {
    |                  ^^^^^^
    |                  |
    |                  move occurs because `self.v` has type `std::vec::Vec<u32>`, which does not implement the `Copy` trait
-   |                  help: consider iterating over a slice of the `Vec`'s content: `&self.v`
+   |                  help: consider iterating over a slice of the `Vec<_>`'s content: `&self.v`
 
 error: aborting due to previous error