Skip to content

Commit d3789c4

Browse files
author
Alexander Regueiro
committed
Disallow multi-trait objects via trait aliases.
1 parent 4632cf2 commit d3789c4

File tree

15 files changed

+247
-154
lines changed

15 files changed

+247
-154
lines changed

src/liballoc/slice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ pub use core::slice::{RChunks, RChunksMut, RChunksExact, RChunksExactMut};
133133
////////////////////////////////////////////////////////////////////////////////
134134

135135
// HACK(japaric) needed for the implementation of `vec!` macro during testing
136-
// NB see the hack module in this file for more details
136+
// N.B., see the `hack` module in this file for more details.
137137
#[cfg(test)]
138138
pub use self::hack::into_vec;
139139

140140
// HACK(japaric) needed for the implementation of `Vec::clone` during testing
141-
// NB see the hack module in this file for more details
141+
// N.B., see the `hack` module in this file for more details.
142142
#[cfg(test)]
143143
pub use self::hack::to_vec;
144144

@@ -383,7 +383,7 @@ impl<T> [T] {
383383
pub fn to_vec(&self) -> Vec<T>
384384
where T: Clone
385385
{
386-
// NB see hack module in this file
386+
// N.B., see the `hack` module in this file for more details.
387387
hack::to_vec(self)
388388
}
389389

@@ -404,7 +404,7 @@ impl<T> [T] {
404404
#[stable(feature = "rust1", since = "1.0.0")]
405405
#[inline]
406406
pub fn into_vec(self: Box<Self>) -> Vec<T> {
407-
// NB see hack module in this file
407+
// N.B., see the `hack` module in this file for more details.
408408
hack::into_vec(self)
409409
}
410410

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ impl<'hir> Map<'hir> {
815815
}
816816
}
817817

818-
/// Returns the name associated with the given NodeId's AST.
818+
/// Returns the name associated with the given `NodeId`'s AST.
819819
pub fn name(&self, id: NodeId) -> Name {
820820
match self.get(id) {
821821
Node::Item(i) => i.name,

src/librustc/hir/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl Lifetime {
297297
}
298298
}
299299

300-
/// A "Path" is essentially Rust's notion of a name; for instance:
300+
/// A `Path` is essentially Rust's notion of a name; for instance:
301301
/// `std::cmp::PartialEq`. It's represented as a sequence of identifiers,
302302
/// along with a bunch of supporting information.
303303
#[derive(Clone, RustcEncodable, RustcDecodable)]
@@ -2039,12 +2039,12 @@ pub enum UseKind {
20392039
ListStem,
20402040
}
20412041

2042-
/// TraitRef's appear in impls.
2042+
/// `TraitRef` are references to traits in impls.
20432043
///
2044-
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
2045-
/// that the ref_id is for. Note that ref_id's value is not the NodeId of the
2046-
/// trait being referred to but just a unique NodeId that serves as a key
2047-
/// within the DefMap.
2044+
/// `resolve` maps each `TraitRef`'s `ref_id` to its defining trait; that's all
2045+
/// that the `ref_id` is for. Note that `ref_id`'s value is not the `NodeId` of the
2046+
/// trait being referred to but just a unique `NodeId` that serves as a key
2047+
/// within the `DefMap`.
20482048
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
20492049
pub struct TraitRef {
20502050
pub path: Path,
@@ -2054,10 +2054,10 @@ pub struct TraitRef {
20542054

20552055
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
20562056
pub struct PolyTraitRef {
2057-
/// The `'a` in `<'a> Foo<&'a T>`
2057+
/// The `'a` in `<'a> Foo<&'a T>`.
20582058
pub bound_generic_params: HirVec<GenericParam>,
20592059

2060-
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
2060+
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`.
20612061
pub trait_ref: TraitRef,
20622062

20632063
pub span: Span,

src/librustc/infer/outlives/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
151151
}
152152

153153
fn recursive_type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
154-
let mut bounds = ty.walk_shallow()
154+
let mut bounds: Vec<_> = ty.walk_shallow()
155155
.map(|subty| self.type_bound(subty))
156-
.collect::<Vec<_>>();
156+
.collect();
157157

158158
let mut regions = smallvec![];
159159
ty.push_regions(&mut regions);

src/librustc/traits/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ pub use self::specialize::{OverlapError, specialization_graph, translate_substs}
5151
pub use self::specialize::find_associated_item;
5252
pub use self::engine::{TraitEngine, TraitEngineExt};
5353
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
54-
pub use self::util::{supertraits, supertrait_def_ids, Supertraits, SupertraitDefIds};
55-
pub use self::util::transitive_bounds;
54+
pub use self::util::{supertraits, supertrait_def_ids, transitive_bounds,
55+
Supertraits, SupertraitDefIds};
56+
pub use self::util::{expand_trait_refs, TraitRefExpander};
5657

5758
#[allow(dead_code)]
5859
pub mod auto_trait;
@@ -1017,7 +1018,7 @@ fn vtable_methods<'a, 'tcx>(
10171018
)
10181019
}
10191020

1020-
impl<'tcx,O> Obligation<'tcx,O> {
1021+
impl<'tcx, O> Obligation<'tcx,O> {
10211022
pub fn new(cause: ObligationCause<'tcx>,
10221023
param_env: ty::ParamEnv<'tcx>,
10231024
predicate: O)

src/librustc/traits/select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use super::{
3838
};
3939

4040
use dep_graph::{DepKind, DepNodeIndex};
41+
use hir;
4142
use hir::def_id::DefId;
4243
use infer;
4344
use infer::{InferCtxt, InferOk, TypeFreshener};
@@ -47,8 +48,6 @@ use ty::fast_reject;
4748
use ty::relate::TypeRelation;
4849
use ty::subst::{Subst, Substs};
4950
use ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
50-
51-
use hir;
5251
use rustc_data_structures::bit_set::GrowableBitSet;
5352
use rustc_data_structures::sync::Lock;
5453
use rustc_target::spec::abi::Abi;
@@ -1759,7 +1758,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17591758
bounds
17601759
);
17611760

1762-
let matching_bound = util::elaborate_predicates(self.tcx(), bounds.predicates)
1761+
let elaborated_predicates = util::elaborate_predicates(self.tcx(), bounds.predicates);
1762+
let matching_bound = elaborated_predicates
17631763
.filter_to_traits()
17641764
.find(|bound| {
17651765
self.probe(|this, _| {

0 commit comments

Comments
 (0)