Skip to content

Commit 740668d

Browse files
committed
Auto merge of #57428 - alexreg:associated_type_bounds, r=nikomatsakis,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
2 parents 1bec46c + ee89033 commit 740668d

File tree

116 files changed

+4847
-1055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4847
-1055
lines changed

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ impl<'b> BorrowRefMut<'b> {
13511351
}
13521352
}
13531353

1354-
// Clone a `BorrowRefMut`.
1354+
// Clones a `BorrowRefMut`.
13551355
//
13561356
// This is only valid if each `BorrowRefMut` is used to track a mutable
13571357
// reference to a distinct, nonoverlapping range of the original object.

src/libcore/ops/unsize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
7171

7272
/// This is used for object safety, to check that a method's receiver type can be dispatched on.
7373
///
74-
/// example impl:
74+
/// An example implementation of the trait:
7575
///
7676
/// ```
7777
/// # #![feature(dispatch_from_dyn, unsize)]

src/librustc/hir/intravisit.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,14 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
674674
type_binding: &'v TypeBinding) {
675675
visitor.visit_id(type_binding.hir_id);
676676
visitor.visit_ident(type_binding.ident);
677-
visitor.visit_ty(&type_binding.ty);
677+
match type_binding.kind {
678+
TypeBindingKind::Equality { ref ty } => {
679+
visitor.visit_ty(ty);
680+
}
681+
TypeBindingKind::Constraint { ref bounds } => {
682+
walk_list!(visitor, visit_param_bound, bounds);
683+
}
684+
}
678685
}
679686

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

937-
938944
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) {
939945
if let Some(ctor_hir_id) = struct_definition.ctor_hir_id() {
940946
visitor.visit_id(ctor_hir_id);

src/librustc/hir/lowering.rs

+266-119
Large diffs are not rendered by default.

src/librustc/hir/map/collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::iter::repeat;
1919
use crate::ich::StableHashingContext;
2020
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
2121

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

4646
hcx: StableHashingContext<'a>,
4747

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

110110
let mut hir_body_nodes = Vec::new();
111111

112-
// Allocate DepNodes for the root module
112+
// Allocate `DepNode`s for the root module.
113113
let (root_mod_sig_dep_index, root_mod_full_dep_index) = {
114114
let Crate {
115115
ref module,

src/librustc/hir/map/definitions.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl DefPath {
239239
"{}[{}]",
240240
component.data.as_interned_str(),
241241
component.disambiguator)
242-
.unwrap();
242+
.unwrap();
243243
}
244244
}
245245

@@ -263,7 +263,7 @@ impl DefPath {
263263
"{}[{}]",
264264
component.data.as_interned_str(),
265265
component.disambiguator)
266-
.unwrap();
266+
.unwrap();
267267
}
268268
}
269269
s
@@ -276,7 +276,7 @@ pub enum DefPathData {
276276
// they are treated specially by the `def_path` function.
277277
/// The crate root (marker)
278278
CrateRoot,
279-
// Catch-all for random DefId things like DUMMY_NODE_ID
279+
// Catch-all for random DefId things like `DUMMY_NODE_ID`
280280
Misc,
281281
// Different kinds of items and item-like things:
282282
/// An impl
@@ -298,9 +298,9 @@ pub enum DefPathData {
298298
AnonConst,
299299
/// An `impl Trait` type node
300300
ImplTrait,
301-
/// GlobalMetaData identifies a piece of crate metadata that is global to
302-
/// a whole crate (as opposed to just one item). GlobalMetaData components
303-
/// are only supposed to show up right below the crate root.
301+
/// Identifies a piece of crate metadata that is global to a whole crate
302+
/// (as opposed to just one item). `GlobalMetaData` components are only
303+
/// supposed to show up right below the crate root.
304304
GlobalMetaData(InternedString),
305305
}
306306

@@ -397,6 +397,11 @@ impl Definitions {
397397
self.node_to_hir_id[node_id]
398398
}
399399

400+
#[inline]
401+
pub fn def_index_to_node_id(&self, def_index: DefIndex) -> ast::NodeId {
402+
self.as_local_node_id(DefId::local(def_index)).unwrap()
403+
}
404+
400405
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate, the span exists
401406
/// and it's not `DUMMY_SP`.
402407
#[inline]
@@ -442,7 +447,7 @@ impl Definitions {
442447
root_index
443448
}
444449

445-
/// Add a definition with a parent definition.
450+
/// Adds a definition with a parent definition.
446451
pub fn create_def_with_parent(&mut self,
447452
parent: DefIndex,
448453
node_id: ast::NodeId,
@@ -559,7 +564,7 @@ impl DefPathData {
559564
GlobalMetaData(name) => {
560565
return name
561566
}
562-
// note that this does not show up in user printouts
567+
// Note that this does not show up in user print-outs.
563568
CrateRoot => sym::double_braced_crate,
564569
Impl => sym::double_braced_impl,
565570
Misc => sym::double_braced_misc,

0 commit comments

Comments
 (0)