rustc_hir: nix rustc_errors dep
This commit is contained in:
parent
f07802c0de
commit
b60d732efe
|
@ -3730,7 +3730,6 @@ dependencies = [
|
|||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_span",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue