]> git.lizzy.rs Git - rust.git/commitdiff
rustc_hir: nix rustc_errors dep
authorMazdak Farrokhzad <twingoow@gmail.com>
Mon, 23 Mar 2020 19:27:59 +0000 (20:27 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 24 Mar 2020 05:22:27 +0000 (06:22 +0100)
Cargo.lock
src/librustc_hir/Cargo.toml
src/librustc_hir/hir.rs
src/librustc_hir/lib.rs
src/librustc_trait_selection/traits/error_reporting/mod.rs
src/librustc_trait_selection/traits/object_safety.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/method/suggest.rs

index 22a06151353bada202aa083bf39d34c2cab1d293..94305401ee9f82c05e69306974811b08b5a90fae 100644 (file)
@@ -3730,7 +3730,6 @@ dependencies = [
  "rustc_ast",
  "rustc_ast_pretty",
  "rustc_data_structures",
- "rustc_errors",
  "rustc_index",
  "rustc_macros",
  "rustc_span",
index b3682ea5a807cac6560659eecc24bff1096c78ca..98598c4bcb5afa0b1696cc5c36ed5cae047e724e 100644 (file)
@@ -16,7 +16,6 @@ rustc_macros = { path = "../librustc_macros" }
 rustc_data_structures = { path = "../librustc_data_structures" }
 rustc_index = { path = "../librustc_index" }
 rustc_span = { path = "../librustc_span" }
-rustc_errors = { path = "../librustc_errors" }
 rustc_serialize = { path = "../libserialize", package = "serialize" }
 rustc_ast = { path = "../librustc_ast" }
 lazy_static = "1"
index 2d11bc3dd978435b85d03e46d854313c7fec1957..2054759933f3ce6044fed0b3c1282974d8ee2a28 100644 (file)
@@ -11,7 +11,6 @@
 use rustc_ast::util::parser::ExprPrecedence;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
-use rustc_errors::FatalError;
 use rustc_macros::HashStable_Generic;
 use rustc_span::source_map::{SourceMap, Spanned};
 use rustc_span::symbol::{kw, sym, Symbol};
@@ -366,9 +365,9 @@ pub enum GenericBound<'hir> {
 }
 
 impl GenericBound<'_> {
-    pub fn trait_def_id(&self) -> Option<DefId> {
+    pub fn trait_ref(&self) -> Option<&TraitRef<'_>> {
         match self {
-            GenericBound::Trait(data, _) => Some(data.trait_ref.trait_def_id()),
+            GenericBound::Trait(data, _) => Some(&data.trait_ref),
             _ => None,
         }
     }
@@ -2204,13 +2203,10 @@ pub struct TraitRef<'hir> {
 
 impl TraitRef<'_> {
     /// Gets the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
-    pub fn trait_def_id(&self) -> DefId {
+    pub fn trait_def_id(&self) -> Option<DefId> {
         match self.path.res {
-            Res::Def(DefKind::Trait, did) => did,
-            Res::Def(DefKind::TraitAlias, did) => did,
-            Res::Err => {
-                FatalError.raise();
-            }
+            Res::Def(DefKind::Trait | DefKind::TraitAlias, did) => Some(did),
+            Res::Err => None,
             _ => unreachable!(),
         }
     }
index fbb3d6b2af37ca9f3ce065b4d76a62a83f4ced6f..5888bde919d4c49c2141bbf7ebf8bb1dcbd1ffa5 100644 (file)
@@ -7,6 +7,7 @@
 #![feature(const_fn)] // For the unsizing cast on `&[]`
 #![feature(const_panic)]
 #![feature(in_band_lifetimes)]
+#![feature(or_patterns)]
 #![feature(specialization)]
 #![recursion_limit = "256"]
 
index b9ee991aa0226de1041b7086d346889287775fd5..52df6d7271b9600215defeab0ec46576115814c1 100644 (file)
@@ -1582,7 +1582,8 @@ fn suggest_unsized_bound_if_applicable(
                 for param in generics.params {
                     if param.span == *span
                         && !param.bounds.iter().any(|bound| {
-                            bound.trait_def_id() == self.tcx.lang_items().sized_trait()
+                            bound.trait_ref().and_then(|trait_ref| trait_ref.trait_def_id())
+                                == self.tcx.lang_items().sized_trait()
                         })
                     {
                         let (span, separator) = match param.bounds {
index 5cc1da045fc371e42bae948300efb33a0c08507d..ebeb0e968b0a15a0e91fc935ed8b8764134cd364 100644 (file)
@@ -15,7 +15,7 @@
 use crate::traits::{self, Obligation, ObligationCause};
 use rustc::ty::subst::{InternalSubsts, Subst};
 use rustc::ty::{self, Predicate, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
-use rustc_errors::Applicability;
+use rustc_errors::{Applicability, FatalError};
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
 use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
@@ -170,6 +170,24 @@ fn object_safety_violations_for_trait(
     violations
 }
 
+fn trait_bound_spans<'tcx>(
+    tcx: TyCtxt<'tcx>,
+    bounds: hir::GenericBounds<'tcx>,
+) -> impl 'tcx + Iterator<Item = Span> {
+    bounds.iter().filter_map(move |b| match b {
+        hir::GenericBound::Trait(trait_ref, hir::TraitBoundModifier::None)
+            if trait_has_sized_self(
+                tcx,
+                trait_ref.trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
+            ) =>
+        {
+            // Fetch spans for supertraits that are `Sized`: `trait T: Super`
+            Some(trait_ref.span)
+        }
+        _ => None,
+    })
+}
+
 fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> {
     tcx.hir()
         .get_if_local(trait_def_id)
@@ -189,33 +207,14 @@ fn object_safety_violations_for_trait(
                             {
                                 // Fetch spans for trait bounds that are Sized:
                                 // `trait T where Self: Pred`
-                                Some(pred.bounds.iter().filter_map(|b| match b {
-                                    hir::GenericBound::Trait(
-                                        trait_ref,
-                                        hir::TraitBoundModifier::None,
-                                    ) if trait_has_sized_self(
-                                        tcx,
-                                        trait_ref.trait_ref.trait_def_id(),
-                                    ) =>
-                                    {
-                                        Some(trait_ref.span)
-                                    }
-                                    _ => None,
-                                }))
+                                Some(trait_bound_spans(tcx, pred.bounds))
                             }
                             _ => None,
                         }
                     })
                     .flatten()
-                    .chain(bounds.iter().filter_map(|b| match b {
-                        hir::GenericBound::Trait(trait_ref, hir::TraitBoundModifier::None)
-                            if trait_has_sized_self(tcx, trait_ref.trait_ref.trait_def_id()) =>
-                        {
-                            // Fetch spans for supertraits that are `Sized`: `trait T: Super`
-                            Some(trait_ref.span)
-                        }
-                        _ => None,
-                    }))
+                    // Fetch spans for supertraits that are `Sized`: `trait T: Super`.
+                    .chain(trait_bound_spans(tcx, bounds))
                     .collect::<SmallVec<[Span; 1]>>(),
             ),
             _ => None,
index 6f558ec9b9508a4578bbd5d6e977fb33dbdba322..86737a819a7aff56c8ef2b66c160e8348acf5177 100644 (file)
@@ -16,7 +16,7 @@
 use rustc_ast::ast;
 use rustc_ast::util::lev_distance::find_best_match_for_name;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId};
+use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, FatalError};
 use rustc_hir as hir;
 use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
 use rustc_hir::def_id::DefId;
@@ -991,7 +991,7 @@ pub fn instantiate_mono_trait_ref(
 
         self.ast_path_to_mono_trait_ref(
             trait_ref.path.span,
-            trait_ref.trait_def_id(),
+            trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
             self_ty,
             trait_ref.path.segments.last().unwrap(),
         )
@@ -1007,7 +1007,7 @@ pub(super) fn instantiate_poly_trait_ref_inner(
         bounds: &mut Bounds<'tcx>,
         speculative: bool,
     ) -> Result<(), GenericArgCountMismatch> {
-        let trait_def_id = trait_ref.trait_def_id();
+        let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
 
         debug!("instantiate_poly_trait_ref({:?}, def_id={:?})", trait_ref, trait_def_id);
 
index 33fc18b4b6e689ed5aa36b804ed4007318df67c5..2dc2a48ecbce82f2fdfae9d657ad761d5fe2503b 100644 (file)
@@ -1402,9 +1402,12 @@ fn add_impl_trait_explanation<'a>(
                     {
                         // Are of this `impl Trait`'s traits object safe?
                         is_object_safe = bounds.iter().all(|bound| {
-                            bound.trait_def_id().map_or(false, |def_id| {
-                                fcx.tcx.object_safety_violations(def_id).is_empty()
-                            })
+                            bound
+                                .trait_ref()
+                                .and_then(|t| t.trait_def_id())
+                                .map_or(false, |def_id| {
+                                    fcx.tcx.object_safety_violations(def_id).is_empty()
+                                })
                         })
                     }
                 }
index 68996f5aaf973c68aaa4e6c3c3a3aea357347f3e..8a3dc9e8f0279346e5c75a55c537a8276c3d106b 100644 (file)
@@ -1057,7 +1057,7 @@ fn suggest_traits_to_import<'b>(
                                 let trait_def_ids: FxHashSet<DefId> = param
                                     .bounds
                                     .iter()
-                                    .filter_map(|bound| bound.trait_def_id())
+                                    .filter_map(|bound| Some(bound.trait_ref()?.trait_def_id()?))
                                     .collect();
                                 if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
                                     err.span_suggestions(