diff options
Diffstat (limited to 'src/librustc/traits')
| -rw-r--r-- | src/librustc/traits/auto_trait.rs | 10 | ||||
| -rw-r--r-- | src/librustc/traits/coherence.rs | 10 | ||||
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 2 | ||||
| -rw-r--r-- | src/librustc/traits/mod.rs | 64 | ||||
| -rw-r--r-- | src/librustc/traits/object_safety.rs | 12 | ||||
| -rw-r--r-- | src/librustc/traits/project.rs | 8 | ||||
| -rw-r--r-- | src/librustc/traits/select.rs | 32 | ||||
| -rw-r--r-- | src/librustc/traits/specialize/mod.rs | 30 | ||||
| -rw-r--r-- | src/librustc/traits/specialize/specialization_graph.rs | 27 | ||||
| -rw-r--r-- | src/librustc/traits/util.rs | 5 |
10 files changed, 100 insertions, 100 deletions
diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index a0237348ea6..fff77816e75 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -138,7 +138,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { // the first evaluate_predicates call. // // The problem is this: most of rustc, including SelectionContext and traits::project, - // are designed to work with a concrete usage of a type (e.g. Vec<u8> + // are designed to work with a concrete usage of a type (e.g., Vec<u8> // fn<T>() { Vec<T> }. This information will generally never change - given // the 'T' in fn<T>() { ... }, we'll never know anything else about 'T'. // If we're unable to prove that 'T' implements a particular trait, we're done - @@ -289,7 +289,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { // // One additional consideration is supertrait bounds. Normally, a ParamEnv is only ever // constructed once for a given type. As part of the construction process, the ParamEnv will - // have any supertrait bounds normalized - e.g. if we have a type 'struct Foo<T: Copy>', the + // have any supertrait bounds normalized - e.g., if we have a type 'struct Foo<T: Copy>', the // ParamEnv will contain 'T: Copy' and 'T: Clone', since 'Copy: Clone'. When we construct our // own ParamEnv, we need to do this ourselves, through traits::elaborate_predicates, or else // SelectionContext will choke on the missing predicates. However, this should never show up in @@ -343,7 +343,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { match &result { &Ok(Some(ref vtable)) => { - // If we see an explicit negative impl (e.g. 'impl !Send for MyStruct'), + // If we see an explicit negative impl (e.g., 'impl !Send for MyStruct'), // we immediately bail out, since it's impossible for us to continue. match vtable { Vtable::VtableImpl(VtableImplData { impl_def_id, .. }) => { @@ -432,11 +432,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { // If we put both of these predicates in our computed ParamEnv, we'll // confuse SelectionContext, since it will (correctly) view both as being applicable. // - // To solve this, we pick the 'more strict' lifetime bound - i.e. the HRTB + // To solve this, we pick the 'more strict' lifetime bound - i.e., the HRTB // Our end goal is to generate a user-visible description of the conditions // under which a type implements an auto trait. A trait predicate involving // a HRTB means that the type needs to work with any choice of lifetime, - // not just one specific lifetime (e.g. 'static). + // not just one specific lifetime (e.g., 'static). fn add_user_pred<'c>( &self, user_computed_preds: &mut FxHashSet<ty::Predicate<'c>>, diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 4bf8ba0d6d1..f10f523e2b4 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -256,12 +256,12 @@ pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// The current rule is that a trait-ref orphan checks in a crate C: /// /// 1. Order the parameters in the trait-ref in subst order - Self first, -/// others linearly (e.g. `<U as Foo<V, W>>` is U < V < W). +/// others linearly (e.g., `<U as Foo<V, W>>` is U < V < W). /// 2. Of these type parameters, there is at least one type parameter /// in which, walking the type as a tree, you can reach a type local /// to C where all types in-between are fundamental types. Call the /// first such parameter the "local key parameter". -/// - e.g. `Box<LocalType>` is OK, because you can visit LocalType +/// - e.g., `Box<LocalType>` is OK, because you can visit LocalType /// going through `Box`, which is fundamental. /// - similarly, `FundamentalPair<Vec<()>, Box<LocalType>>` is OK for /// the same reason. @@ -269,7 +269,7 @@ pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// not local), `Vec<LocalType>` is bad, because `Vec<->` is between /// the local type and the type parameter. /// 3. Every type parameter before the local key parameter is fully known in C. -/// - e.g. `impl<T> T: Trait<LocalType>` is bad, because `T` might be +/// - e.g., `impl<T> T: Trait<LocalType>` is bad, because `T` might be /// an unknown type. /// - but `impl<T> LocalType: Trait<T>` is OK, because `LocalType` /// occurs before `T`. @@ -277,7 +277,7 @@ pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// through the parameter's type tree, must appear only as a subtree of /// a type local to C, with only fundamental types between the type /// local to C and the local key parameter. -/// - e.g. `Vec<LocalType<T>>>` (or equivalently `Box<Vec<LocalType<T>>>`) +/// - e.g., `Vec<LocalType<T>>>` (or equivalently `Box<Vec<LocalType<T>>>`) /// is bad, because the only local type with `T` as a subtree is /// `LocalType<T>`, and `Vec<->` is between it and the type parameter. /// - similarly, `FundamentalPair<LocalType<T>, T>` is bad, because @@ -288,7 +288,7 @@ pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, /// /// The orphan rules actually serve several different purposes: /// -/// 1. They enable link-safety - i.e. 2 mutually-unknowing crates (where +/// 1. They enable link-safety - i.e., 2 mutually-unknowing crates (where /// every type local to one crate is unknown in the other) can't implement /// the same trait-ref. This follows because it can be seen that no such /// type can orphan-check in 2 such crates. diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 80634aa3066..4ef4f457105 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -128,7 +128,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } - // returns if `cond` not occurring implies that `error` does not occur - i.e. that + // returns if `cond` not occurring implies that `error` does not occur - i.e., that // `error` occurring implies that `cond` occurs. fn error_implies(&self, cond: &ty::Predicate<'tcx>, diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index ab2fa68ab5f..b259ee011da 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -8,34 +8,46 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Trait Resolution. See [rustc guide] for more info on how this works. +//! Trait Resolution. See the [rustc guide] for more information on how this works. //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html -pub use self::SelectionError::*; -pub use self::FulfillmentErrorCode::*; -pub use self::Vtable::*; -pub use self::ObligationCauseCode::*; +#[allow(dead_code)] +pub mod auto_trait; +mod coherence; +pub mod error_reporting; +mod engine; +mod fulfill; +mod project; +mod object_safety; +mod on_unimplemented; +mod select; +mod specialize; +mod structural_impls; +pub mod codegen; +mod util; +pub mod query; use chalk_engine; use hir; use hir::def_id::DefId; -use infer::SuppressRegionErrors; +use infer::{InferCtxt, SuppressRegionErrors}; use infer::outlives::env::OutlivesEnvironment; use middle::region; use mir::interpret::ErrorHandled; +use rustc_data_structures::sync::Lrc; +use syntax::ast; +use syntax_pos::{Span, DUMMY_SP}; use ty::subst::Substs; use ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use ty::error::{ExpectedFound, TypeError}; use ty::fold::{TypeFolder, TypeFoldable, TypeVisitor}; -use infer::{InferCtxt}; use util::common::ErrorReported; -use rustc_data_structures::sync::Lrc; -use std::fmt::Debug; -use std::rc::Rc; -use syntax::ast; -use syntax_pos::{Span, DUMMY_SP}; +pub use self::SelectionError::*; +pub use self::FulfillmentErrorCode::*; +pub use self::Vtable::*; +pub use self::ObligationCauseCode::*; pub use self::coherence::{orphan_check, overlapping_impls, OrphanCheckErr, OverlapResult}; pub use self::fulfill::{FulfillmentContext, PendingPredicateObligation}; @@ -51,25 +63,13 @@ pub use self::specialize::{OverlapError, specialization_graph, translate_substs} pub use self::specialize::find_associated_item; pub use self::engine::{TraitEngine, TraitEngineExt}; pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs}; -pub use self::util::{supertraits, supertrait_def_ids, Supertraits, SupertraitDefIds}; -pub use self::util::transitive_bounds; - -#[allow(dead_code)] -pub mod auto_trait; -mod coherence; -pub mod error_reporting; -mod engine; -mod fulfill; -mod project; -mod object_safety; -mod on_unimplemented; -mod select; -mod specialize; -mod structural_impls; -pub mod codegen; -mod util; +pub use self::util::{supertraits, supertrait_def_ids, transitive_bounds, + Supertraits, SupertraitDefIds}; -pub mod query; +pub use self::ObligationCauseCode::*; +pub use self::FulfillmentErrorCode::*; +pub use self::SelectionError::*; +pub use self::Vtable::*; // Whether to enable bug compatibility with issue #43355 #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -91,7 +91,7 @@ pub enum TraitQueryMode { Canonical, } -/// An `Obligation` represents some trait reference (e.g. `int:Eq`) for +/// An `Obligation` represents some trait reference (e.g., `int:Eq`) for /// which the vtable must be found. The process of finding a vtable is /// called "resolving" the `Obligation`. This process consists of /// either identifying an `impl` (e.g., `impl Eq for int`) that @@ -955,7 +955,7 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx /// Given a trait `trait_ref`, iterates the vtable entries /// that come from `trait_ref`, including its supertraits. -#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait. +#[inline] // FIXME(#35870): avoid closures being unexported due to `impl Trait`. fn vtable_methods<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 2909daf22b3..4b2f817cfa9 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -36,7 +36,7 @@ pub enum ObjectSafetyViolation { SizedSelf, /// Supertrait reference references `Self` an in illegal location - /// (e.g. `trait Foo : Bar<Self>`) + /// (e.g., `trait Foo : Bar<Self>`) SupertraitSelf, /// Method has something illegal @@ -81,7 +81,7 @@ pub enum MethodViolationCode { /// e.g., `fn foo(&self, x: Self)` or `fn foo(&self) -> Self` ReferencesSelf, - /// e.g. `fn foo(&self) where Self: Clone` + /// e.g., `fn foo(&self) where Self: Clone` WhereClauseReferencesSelf(Span), /// e.g., `fn foo<A>()` @@ -343,7 +343,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { } }; - // e.g. Rc<()> + // e.g., Rc<()> let unit_receiver_ty = self.receiver_for_self_ty( receiver_ty, self.mk_unit(), method.def_id ); @@ -357,7 +357,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { trait_def_id, self.mk_region(ty::ReStatic) ); - // e.g. Rc<dyn Trait> + // e.g., Rc<dyn Trait> let trait_object_receiver = self.receiver_for_self_ty( receiver_ty, trait_object_ty, method.def_id ); @@ -376,7 +376,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { } /// performs a type substitution to produce the version of receiver_ty when `Self = self_ty` - /// e.g. for receiver_ty = `Rc<Self>` and self_ty = `Foo`, returns `Rc<Foo>` + /// e.g., for receiver_ty = `Rc<Self>` and self_ty = `Foo`, returns `Rc<Foo>` fn receiver_for_self_ty( self, receiver_ty: Ty<'tcx>, self_ty: Ty<'tcx>, method_def_id: DefId ) -> Ty<'tcx> { @@ -451,7 +451,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { /// /// The only case where the receiver is not dispatchable, but is still a valid receiver /// type (just not object-safe), is when there is more than one level of pointer indirection. - /// e.g. `self: &&Self`, `self: &Rc<Self>`, `self: Box<Box<Self>>`. In these cases, there + /// e.g., `self: &&Self`, `self: &Rc<Self>`, `self: Box<Box<Self>>`. In these cases, there /// is no way, or at least no inexpensive way, to coerce the receiver from the version where /// `Self = dyn Trait` to the version where `Self = T`, where `T` is the unknown erased type /// contained by the trait object, because the object that needs to be coerced is behind diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 1d3d66e82f1..5717a76f1cf 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -70,7 +70,7 @@ pub enum Reveal { /// be observable directly by the user, `Reveal::All` /// should not be used by checks which may expose /// type equality or type contents to the user. - /// There are some exceptions, e.g. around OIBITS and + /// There are some exceptions, e.g., around OIBITS and /// transmute-checking, which expose some details, but /// not the whole concrete type of the `impl Trait`. All, @@ -608,7 +608,7 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>( // created (and hence the new ones will quickly be // discarded as duplicated). But when doing trait // evaluation this is not the case, and dropping the trait - // evaluations can causes ICEs (e.g. #43132). + // evaluations can causes ICEs (e.g., #43132). debug!("opt_normalize_projection_type: \ found normalized ty `{:?}`", ty); @@ -1589,7 +1589,7 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>( /// When working with a fulfillment context, the derived obligations of each /// projection cache entry will be registered on the fulfillcx, so any users /// that can wait for a fulfillcx fixed point need not care about this. However, -/// users that don't wait for a fixed point (e.g. trait evaluation) have to +/// users that don't wait for a fixed point (e.g., trait evaluation) have to /// resolve the obligations themselves to make sure the projected result is /// ok and avoid issues like #43132. /// @@ -1637,7 +1637,7 @@ enum ProjectionCacheEntry<'tcx> { NormalizedTy(NormalizedTy<'tcx>), } -// NB: intentionally not Clone +// N.B., intentionally not Clone pub struct ProjectionCacheSnapshot { snapshot: Snapshot, } diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index fb4c9f3bad7..c438542106c 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! See [rustc guide] for more info on how this works. +//! Candidate selection. See the [rustc guide] for more information on how this works. //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html#selection @@ -69,10 +69,10 @@ pub struct SelectionContext<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> { /// require themselves. freshener: TypeFreshener<'cx, 'gcx, 'tcx>, - /// If true, indicates that the evaluation should be conservative + /// If `true`, indicates that the evaluation should be conservative /// and consider the possibility of types outside this crate. /// This comes up primarily when resolving ambiguity. Imagine - /// there is some trait reference `$0 : Bar` where `$0` is an + /// there is some trait reference `$0: Bar` where `$0` is an /// inference variable. If `intercrate` is true, then we can never /// say for sure that this reference is not implemented, even if /// there are *no impls at all for `Bar`*, because `$0` could be @@ -80,7 +80,7 @@ pub struct SelectionContext<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> { /// `Bar`. This is the suitable mode for coherence. Elsewhere, /// though, we set this to false, because we are only interested /// in types that the user could actually have written --- in - /// other words, we consider `$0 : Bar` to be unimplemented if + /// other words, we consider `$0: Bar` to be unimplemented if /// there is no type that the user could *actually name* that /// would satisfy it. This avoids crippling inference, basically. intercrate: Option<IntercrateMode>, @@ -1170,7 +1170,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // // The selection process begins by examining all in-scope impls, // caller obligations, and so forth and assembling a list of - // candidates. See [rustc guide] for more details. + // candidates. See the [rustc guide] for more details. // // [rustc guide]: // https://rust-lang.github.io/rustc-guide/traits/resolution.html#candidate-assembly @@ -1615,7 +1615,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { }; if obligation.predicate.skip_binder().self_ty().is_ty_var() { - // Self is a type variable (e.g. `_: AsRef<str>`). + // Self is a type variable (e.g., `_: AsRef<str>`). // // This is somewhat problematic, as the current scheme can't really // handle it turning to be a projection. This does end up as truly @@ -1664,7 +1664,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { self.assemble_candidates_for_unsizing(obligation, &mut candidates); } else { if lang_items.clone_trait() == Some(def_id) { - // Same builtin conditions as `Copy`, i.e. every type which has builtin support + // Same builtin conditions as `Copy`, i.e., every type which has builtin support // for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone` // types have builtin support for `Clone`. let clone_conditions = self.copy_clone_conditions(obligation); @@ -2023,7 +2023,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { { candidates.vec.push(ImplCandidate(impl_def_id)); - // NB: we can safely drop the placeholder map + // N.B., we can safely drop the placeholder map // since we are in a probe. mem::drop(placeholder_map); } @@ -2069,7 +2069,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // that this obligation holds. That could be a // where-clause or, in the case of an object type, // it could be that the object type lists the - // trait (e.g. `Foo+Send : Send`). See + // trait (e.g., `Foo+Send : Send`). See // `compile-fail/typeck-default-trait-impl-send-param.rs` // for an example of a test case that exercises // this path. @@ -2097,7 +2097,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { ); self.probe(|this, _snapshot| { - // the code below doesn't care about regions, and the + // The code below doesn't care about regions, and the // self-ty here doesn't escape this probe, so just erase // any LBR. let self_ty = this.tcx().erase_late_bound_regions(&obligation.self_ty()); @@ -2145,7 +2145,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { .count(); if upcast_trait_refs > 1 { - // can be upcast in many ways; need more type information + // Can be upcast in many ways; need more type information. candidates.ambiguous = true; } else if upcast_trait_refs == 1 { candidates.vec.push(ObjectCandidate); @@ -2197,8 +2197,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => { // Upcasts permit two things: // - // 1. Dropping builtin bounds, e.g. `Foo+Send` to `Foo` - // 2. Tightening the region bound, e.g. `Foo+'a` to `Foo+'b` if `'a : 'b` + // 1. Dropping builtin bounds, e.g., `Foo+Send` to `Foo` + // 2. Tightening the region bound, e.g., `Foo+'a` to `Foo+'b` if `'a : 'b` // // Note that neither of these changes requires any // change at runtime. Eventually this will be @@ -2354,7 +2354,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { ImplCandidate(other_def) => { // See if we can toss out `victim` based on specialization. // This requires us to know *for sure* that the `other` impl applies - // i.e. EvaluatedToOk: + // i.e., EvaluatedToOk: if other.evaluation == EvaluatedToOk { match victim.candidate { ImplCandidate(victim_def) => { @@ -2717,7 +2717,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // // Confirmation unifies the output type parameters of the trait // with the values found in the obligation, possibly yielding a - // type error. See [rustc guide] for more details. + // type error. See the [rustc guide] for more details. // // [rustc guide]: // https://rust-lang.github.io/rustc-guide/traits/resolution.html#confirmation @@ -3003,7 +3003,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // are sufficient to determine the impl substs, without // relying on projections in the impl-trait-ref. // - // e.g. `impl<U: Tr, V: Iterator<Item=U>> Foo<<U as Tr>::T> for V` + // e.g., `impl<U: Tr, V: Iterator<Item=U>> Foo<<U as Tr>::T> for V` impl_obligations.append(&mut substs.obligations); VtableImplData { diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 50d2179c412..96bb545f25c 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -19,22 +19,21 @@ //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/specialization.html -use super::{SelectionContext, FulfillmentContext}; -use super::util::impl_trait_ref_and_oblig; +pub mod specialization_graph; -use rustc_data_structures::fx::FxHashSet; use hir::def_id::DefId; use infer::{InferCtxt, InferOk}; -use ty::subst::{Subst, Substs}; +use lint; +use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::sync::Lrc; +use syntax_pos::DUMMY_SP; use traits::{self, ObligationCause, TraitEngine}; use traits::select::IntercrateAmbiguityCause; use ty::{self, TyCtxt, TypeFoldable}; -use syntax_pos::DUMMY_SP; -use rustc_data_structures::sync::Lrc; - -use lint; +use ty::subst::{Subst, Substs}; -pub mod specialization_graph; +use super::{SelectionContext, FulfillmentContext}; +use super::util::impl_trait_ref_and_oblig; /// Information pertinent to an overlapping impl error. pub struct OverlapError { @@ -184,7 +183,7 @@ pub(super) fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // // See RFC 1210 for more details and justification. - // Currently we do not allow e.g. a negative impl to specialize a positive one + // Currently we do not allow e.g., a negative impl to specialize a positive one if tcx.impl_polarity(impl1_def_id) != tcx.impl_polarity(impl2_def_id) { return false; } @@ -295,17 +294,18 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, } // Query provider for `specialization_graph_of`. -pub(super) fn specialization_graph_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - trait_id: DefId) - -> Lrc<specialization_graph::Graph> { +pub(super) fn specialization_graph_provider<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + trait_id: DefId, +) -> Lrc<specialization_graph::Graph> { let mut sg = specialization_graph::Graph::new(); let mut trait_impls = tcx.all_impls(trait_id); // The coherence checking implementation seems to rely on impls being // iterated over (roughly) in definition order, so we are sorting by - // negated CrateNum (so remote definitions are visited first) and then - // by a flattened version of the DefIndex. + // negated `CrateNum` (so remote definitions are visited first) and then + // by a flattened version of the `DefIndex`. trait_impls.sort_unstable_by_key(|def_id| { (-(def_id.krate.as_u32() as i64), def_id.index.address_space().index(), diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index db0302f3a90..22221e0a3d9 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -29,7 +29,7 @@ use util::nodemap::{DefIdMap, FxHashMap}; /// /// The graph provides two key services: /// -/// - Construction, which implicitly checks for overlapping impls (i.e., impls +/// - Construction. This implicitly checks for overlapping impls (i.e., impls /// that overlap but where neither specializes the other -- an artifact of the /// simple "chain" rule. /// @@ -39,11 +39,11 @@ use util::nodemap::{DefIdMap, FxHashMap}; /// has at most one parent. #[derive(RustcEncodable, RustcDecodable)] pub struct Graph { - // all impls have a parent; the "root" impls have as their parent the def_id - // of the trait + // All impls have a parent; the "root" impls have as their parent the `def_id` + // of the trait. parent: DefIdMap<DefId>, - // the "root" impls are found by looking up the trait's def_id. + // The "root" impls are found by looking up the trait's def_id. children: DefIdMap<Children>, } @@ -81,7 +81,7 @@ enum Inserted { } impl<'a, 'gcx, 'tcx> Children { - /// Insert an impl into this set of children without comparing to any existing impls + /// Insert an impl into this set of children without comparing to any existing impls. fn insert_blindly(&mut self, tcx: TyCtxt<'a, 'gcx, 'tcx>, impl_def_id: DefId) { @@ -144,13 +144,13 @@ impl<'a, 'gcx, 'tcx> Children { ); let overlap_error = |overlap: traits::coherence::OverlapResult<'_>| { - // overlap, but no specialization; error out + // Found overlap, but no specialization; error out. let trait_ref = overlap.impl_header.trait_ref.unwrap(); let self_ty = trait_ref.self_ty(); OverlapError { with_impl: possible_sibling, trait_desc: trait_ref.to_string(), - // only report the Self type if it has at least + // Only report the `Self` type if it has at least // some outer concrete shell; otherwise, it's // not adding much information. self_desc: if self_ty.has_concrete_skeleton() { @@ -189,7 +189,7 @@ impl<'a, 'gcx, 'tcx> Children { debug!("descending as child of TraitRef {:?}", tcx.impl_trait_ref(possible_sibling).unwrap()); - // the impl specializes possible_sibling + // The impl specializes `possible_sibling`. return Ok(Inserted::ShouldRecurseOn(possible_sibling)); } else if ge && !le { debug!("placing as parent of TraitRef {:?}", @@ -216,7 +216,7 @@ impl<'a, 'gcx, 'tcx> Children { return Ok(Inserted::ReplaceChildren(replace_children)); } - // no overlap with any potential siblings, so add as a new sibling + // No overlap with any potential siblings, so add as a new sibling. debug!("placing as new sibling"); self.insert_blindly(tcx, impl_def_id); Ok(Inserted::BecameNewSibling(last_lint)) @@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> Graph { debug!("insert({:?}): inserting TraitRef {:?} into specialization graph", impl_def_id, trait_ref); - // if the reference itself contains an earlier error (e.g., due to a + // If the reference itself contains an earlier error (e.g., due to a // resolution failure), then we just insert the impl at the top level of // the graph and claim that there's no overlap (in order to suppress // bogus errors). @@ -275,7 +275,7 @@ impl<'a, 'gcx, 'tcx> Graph { let mut last_lint = None; let simplified = fast_reject::simplify_type(tcx, trait_ref.self_ty(), false); - // Descend the specialization tree, where `parent` is the current parent node + // Descend the specialization tree, where `parent` is the current parent node. loop { use self::Inserted::*; @@ -313,7 +313,7 @@ impl<'a, 'gcx, 'tcx> Graph { siblings.insert_blindly(tcx, impl_def_id); } - // Set G's parent to N and N's parent to P + // Set G's parent to N and N's parent to P. for &grand_child_to_be in &grand_children_to_be { self.parent.insert(grand_child_to_be, impl_def_id); } @@ -429,7 +429,8 @@ impl<T> NodeItem<T> { impl<'a, 'gcx, 'tcx> Ancestors { /// Search the items from the given ancestors, returning each definition /// with the given name and the given kind. - #[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait. + // FIXME(#35870): avoid closures being unexported due to `impl Trait`. + #[inline] pub fn defs( self, tcx: TyCtxt<'a, 'gcx, 'tcx>, diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 6d3fc0d4fe4..80d8a1d6e5c 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -9,12 +9,11 @@ // except according to those terms. use hir::def_id::DefId; -use ty::subst::{Kind, Subst, Substs}; +use traits::specialize::specialization_graph::NodeItem; use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef}; use ty::outlives::Component; +use ty::subst::{Kind, Subst}; use util::nodemap::FxHashSet; -use hir::{self}; -use traits::specialize::specialization_graph::NodeItem; use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized}; |
