diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-23 20:27:59 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-24 06:22:27 +0100 |
| commit | b60d732efe924931f377e1f552ce6290b2ba8393 (patch) | |
| tree | 4a807c56cf3aef86bc1f7965ee70689a943b6b8b | |
| parent | f07802c0de9091a1f4c728c6b4ee1eca5a49b275 (diff) | |
| download | rust-b60d732efe924931f377e1f552ce6290b2ba8393.tar.gz rust-b60d732efe924931f377e1f552ce6290b2ba8393.zip | |
rustc_hir: nix rustc_errors dep
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | src/librustc_hir/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_hir/hir.rs | 14 | ||||
| -rw-r--r-- | src/librustc_hir/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_trait_selection/traits/error_reporting/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustc_trait_selection/traits/object_safety.rs | 45 | ||||
| -rw-r--r-- | src/librustc_typeck/astconv.rs | 6 | ||||
| -rw-r--r-- | src/librustc_typeck/check/coercion.rs | 9 | ||||
| -rw-r--r-- | src/librustc_typeck/check/method/suggest.rs | 2 |
9 files changed, 40 insertions, 42 deletions
diff --git a/Cargo.lock b/Cargo.lock index 22a06151353..94305401ee9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3730,7 +3730,6 @@ dependencies = [ "rustc_ast", "rustc_ast_pretty", "rustc_data_structures", - "rustc_errors", "rustc_index", "rustc_macros", "rustc_span", diff --git a/src/librustc_hir/Cargo.toml b/src/librustc_hir/Cargo.toml index b3682ea5a80..98598c4bcb5 100644 --- a/src/librustc_hir/Cargo.toml +++ b/src/librustc_hir/Cargo.toml @@ -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" diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 2d11bc3dd97..2054759933f 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -11,7 +11,6 @@ use rustc_ast::node_id::NodeMap; 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!(), } } diff --git a/src/librustc_hir/lib.rs b/src/librustc_hir/lib.rs index fbb3d6b2af3..5888bde919d 100644 --- a/src/librustc_hir/lib.rs +++ b/src/librustc_hir/lib.rs @@ -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"] diff --git a/src/librustc_trait_selection/traits/error_reporting/mod.rs b/src/librustc_trait_selection/traits/error_reporting/mod.rs index b9ee991aa02..52df6d7271b 100644 --- a/src/librustc_trait_selection/traits/error_reporting/mod.rs +++ b/src/librustc_trait_selection/traits/error_reporting/mod.rs @@ -1582,7 +1582,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { 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 { diff --git a/src/librustc_trait_selection/traits/object_safety.rs b/src/librustc_trait_selection/traits/object_safety.rs index 5cc1da045fc..ebeb0e968b0 100644 --- a/src/librustc_trait_selection/traits/object_safety.rs +++ b/src/librustc_trait_selection/traits/object_safety.rs @@ -15,7 +15,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt; 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 get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> { // 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, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6f558ec9b95..86737a819a7 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -16,7 +16,7 @@ use rustc::ty::{GenericParamDef, GenericParamDefKind}; 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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { 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 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { 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); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 33fc18b4b6e..2dc2a48ecbc 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1402,9 +1402,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { { // 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() + }) }) } } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 68996f5aaf9..8a3dc9e8f02 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -1057,7 +1057,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { 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( |
