Skip to content

Commit

Permalink
Auto merge of #57428 - alexreg:associated_type_bounds, r=nikomatsakis…
Browse files Browse the repository at this point in the history
…,Centril

Implementation of RFC 2289 (associated_type_bounds)

This PR implements the [`asociated_type_bounds` feature](https://github.com/rust-lang/rfcs/blob/master/text/2289-associated-type-bounds.md).

Associated type bounds are implemented in:
   - function/method arguments and return types
   - structs, enums, unions
   - associated items in traits
   - type aliases
   - type parameter defaults
   - trait objects
   - let bindings

CC @nikomatsakis @Centril
  • Loading branch information
bors committed Jun 6, 2019
2 parents 1bec46c + ee89033 commit 740668d
Show file tree
Hide file tree
Showing 116 changed files with 4,847 additions and 1,055 deletions.
2 changes: 1 addition & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ impl<'b> BorrowRefMut<'b> {
}
}

// Clone a `BorrowRefMut`.
// Clones a `BorrowRefMut`.
//
// This is only valid if each `BorrowRefMut` is used to track a mutable
// reference to a distinct, nonoverlapping range of the original object.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/ops/unsize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}

/// This is used for object safety, to check that a method's receiver type can be dispatched on.
///
/// example impl:
/// An example implementation of the trait:
///
/// ```
/// # #![feature(dispatch_from_dyn, unsize)]
Expand Down
10 changes: 8 additions & 2 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,14 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
type_binding: &'v TypeBinding) {
visitor.visit_id(type_binding.hir_id);
visitor.visit_ident(type_binding.ident);
visitor.visit_ty(&type_binding.ty);
match type_binding.kind {
TypeBindingKind::Equality { ref ty } => {
visitor.visit_ty(ty);
}
TypeBindingKind::Constraint { ref bounds } => {
walk_list!(visitor, visit_param_bound, bounds);
}
}
}

pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
Expand Down Expand Up @@ -934,7 +941,6 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'
visitor.visit_defaultness(defaultness);
}


pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) {
if let Some(ctor_hir_id) = struct_definition.ctor_hir_id() {
visitor.visit_id(ctor_hir_id);
Expand Down
385 changes: 266 additions & 119 deletions src/librustc/hir/lowering.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::iter::repeat;
use crate::ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};

/// A Visitor that walks over the HIR and collects Nodes into a HIR map
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
pub(super) struct NodeCollector<'a, 'hir> {
/// The crate
krate: &'hir Crate,
Expand All @@ -45,7 +45,7 @@ pub(super) struct NodeCollector<'a, 'hir> {

hcx: StableHashingContext<'a>,

// We are collecting DepNode::HirBody hashes here so we can compute the
// We are collecting `DepNode::HirBody` hashes here so we can compute the
// crate hash from then later on.
hir_body_nodes: Vec<(DefPathHash, Fingerprint)>,
}
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {

let mut hir_body_nodes = Vec::new();

// Allocate DepNodes for the root module
// Allocate `DepNode`s for the root module.
let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
let Crate {
ref module,
Expand Down
21 changes: 13 additions & 8 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl DefPath {
"{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
.unwrap();
}
}

Expand All @@ -263,7 +263,7 @@ impl DefPath {
"{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
.unwrap();
}
}
s
Expand All @@ -276,7 +276,7 @@ pub enum DefPathData {
// they are treated specially by the `def_path` function.
/// The crate root (marker)
CrateRoot,
// Catch-all for random DefId things like DUMMY_NODE_ID
// Catch-all for random DefId things like `DUMMY_NODE_ID`
Misc,
// Different kinds of items and item-like things:
/// An impl
Expand All @@ -298,9 +298,9 @@ pub enum DefPathData {
AnonConst,
/// An `impl Trait` type node
ImplTrait,
/// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components
/// are only supposed to show up right below the crate root.
/// Identifies a piece of crate metadata that is global to a whole crate
/// (as opposed to just one item). `GlobalMetaData` components are only
/// supposed to show up right below the crate root.
GlobalMetaData(InternedString),
}

Expand Down Expand Up @@ -397,6 +397,11 @@ impl Definitions {
self.node_to_hir_id[node_id]
}

#[inline]
pub fn def_index_to_node_id(&self, def_index: DefIndex) -> ast::NodeId {
self.as_local_node_id(DefId::local(def_index)).unwrap()
}

/// Retrieves the span of the given `DefId` if `DefId` is in the local crate, the span exists
/// and it's not `DUMMY_SP`.
#[inline]
Expand Down Expand Up @@ -442,7 +447,7 @@ impl Definitions {
root_index
}

/// Add a definition with a parent definition.
/// Adds a definition with a parent definition.
pub fn create_def_with_parent(&mut self,
parent: DefIndex,
node_id: ast::NodeId,
Expand Down Expand Up @@ -559,7 +564,7 @@ impl DefPathData {
GlobalMetaData(name) => {
return name
}
// note that this does not show up in user printouts
// Note that this does not show up in user print-outs.
CrateRoot => sym::double_braced_crate,
Impl => sym::double_braced_impl,
Misc => sym::double_braced_misc,
Expand Down
Loading

0 comments on commit 740668d

Please sign in to comment.