Skip to content

Commit e702b75

Browse files
authored
Rollup merge of rust-lang#42409 - bjorn3:patch-3, r=frewsxcv
Better docs Working on more doc improvements Edit: done for today
2 parents 76242ae + 949b2a3 commit e702b75

File tree

5 files changed

+118
-110
lines changed

5 files changed

+118
-110
lines changed

src/librustc/hir/def.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use hir;
1717

1818
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1919
pub enum CtorKind {
20-
// Constructor function automatically created by a tuple struct/variant.
20+
/// Constructor function automatically created by a tuple struct/variant.
2121
Fn,
22-
// Constructor constant automatically created by a unit struct/variant.
22+
/// Constructor constant automatically created by a unit struct/variant.
2323
Const,
24-
// Unusable name in value namespace created by a struct variant.
24+
/// Unusable name in value namespace created by a struct variant.
2525
Fictive,
2626
}
2727

@@ -109,17 +109,21 @@ impl PathResolution {
109109
}
110110
}
111111

112-
// Definition mapping
112+
/// Definition mapping
113113
pub type DefMap = NodeMap<PathResolution>;
114-
// This is the replacement export map. It maps a module to all of the exports
115-
// within.
114+
115+
/// This is the replacement export map. It maps a module to all of the exports
116+
/// within.
116117
pub type ExportMap = NodeMap<Vec<Export>>;
117118

118119
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
119120
pub struct Export {
120-
pub ident: ast::Ident, // The name of the target.
121-
pub def: Def, // The definition of the target.
122-
pub span: Span, // The span of the target definition.
121+
/// The name of the target.
122+
pub ident: ast::Ident,
123+
/// The definition of the target.
124+
pub def: Def,
125+
/// The span of the target definition.
126+
pub span: Span,
123127
}
124128

125129
impl CtorKind {
@@ -160,6 +164,7 @@ impl Def {
160164
}
161165
}
162166

167+
/// A human readable kind name
163168
pub fn kind_name(&self) -> &'static str {
164169
match *self {
165170
Def::Fn(..) => "function",

src/librustc/hir/def_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl fmt::Debug for DefId {
187187

188188

189189
impl DefId {
190+
/// Make a local `DefId` with the given index.
190191
pub fn local(index: DefIndex) -> DefId {
191192
DefId { krate: LOCAL_CRATE, index: index }
192193
}

src/librustc/hir/lowering.rs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,37 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Lowers the AST to the HIR.
12-
//
13-
// Since the AST and HIR are fairly similar, this is mostly a simple procedure,
14-
// much like a fold. Where lowering involves a bit more work things get more
15-
// interesting and there are some invariants you should know about. These mostly
16-
// concern spans and ids.
17-
//
18-
// Spans are assigned to AST nodes during parsing and then are modified during
19-
// expansion to indicate the origin of a node and the process it went through
20-
// being expanded. Ids are assigned to AST nodes just before lowering.
21-
//
22-
// For the simpler lowering steps, ids and spans should be preserved. Unlike
23-
// expansion we do not preserve the process of lowering in the spans, so spans
24-
// should not be modified here. When creating a new node (as opposed to
25-
// 'folding' an existing one), then you create a new id using `next_id()`.
26-
//
27-
// You must ensure that ids are unique. That means that you should only use the
28-
// id from an AST node in a single HIR node (you can assume that AST node ids
29-
// are unique). Every new node must have a unique id. Avoid cloning HIR nodes.
30-
// If you do, you must then set the new node's id to a fresh one.
31-
//
32-
// Spans are used for error messages and for tools to map semantics back to
33-
// source code. It is therefore not as important with spans as ids to be strict
34-
// about use (you can't break the compiler by screwing up a span). Obviously, a
35-
// HIR node can only have a single span. But multiple nodes can have the same
36-
// span and spans don't need to be kept in order, etc. Where code is preserved
37-
// by lowering, it should have the same span as in the AST. Where HIR nodes are
38-
// new it is probably best to give a span for the whole AST node being lowered.
39-
// All nodes should have real spans, don't use dummy spans. Tools are likely to
40-
// get confused if the spans from leaf AST nodes occur in multiple places
41-
// in the HIR, especially for multiple identifiers.
11+
//! Lowers the AST to the HIR.
12+
//!
13+
//! Since the AST and HIR are fairly similar, this is mostly a simple procedure,
14+
//! much like a fold. Where lowering involves a bit more work things get more
15+
//! interesting and there are some invariants you should know about. These mostly
16+
//! concern spans and ids.
17+
//!
18+
//! Spans are assigned to AST nodes during parsing and then are modified during
19+
//! expansion to indicate the origin of a node and the process it went through
20+
//! being expanded. Ids are assigned to AST nodes just before lowering.
21+
//!
22+
//! For the simpler lowering steps, ids and spans should be preserved. Unlike
23+
//! expansion we do not preserve the process of lowering in the spans, so spans
24+
//! should not be modified here. When creating a new node (as opposed to
25+
//! 'folding' an existing one), then you create a new id using `next_id()`.
26+
//!
27+
//! You must ensure that ids are unique. That means that you should only use the
28+
//! id from an AST node in a single HIR node (you can assume that AST node ids
29+
//! are unique). Every new node must have a unique id. Avoid cloning HIR nodes.
30+
//! If you do, you must then set the new node's id to a fresh one.
31+
//!
32+
//! Spans are used for error messages and for tools to map semantics back to
33+
//! source code. It is therefore not as important with spans as ids to be strict
34+
//! about use (you can't break the compiler by screwing up a span). Obviously, a
35+
//! HIR node can only have a single span. But multiple nodes can have the same
36+
//! span and spans don't need to be kept in order, etc. Where code is preserved
37+
//! by lowering, it should have the same span as in the AST. Where HIR nodes are
38+
//! new it is probably best to give a span for the whole AST node being lowered.
39+
//! All nodes should have real spans, don't use dummy spans. Tools are likely to
40+
//! get confused if the spans from leaf AST nodes occur in multiple places
41+
//! in the HIR, especially for multiple identifiers.
4242
4343
use hir;
4444
use hir::map::{Definitions, DefKey, REGULAR_SPACE};
@@ -70,8 +70,10 @@ const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
7070

7171
pub struct LoweringContext<'a> {
7272
crate_root: Option<&'static str>,
73+
7374
// Use to assign ids to hir nodes that do not directly correspond to an ast node
7475
sess: &'a Session,
76+
7577
// As we walk the AST we must keep track of the current 'parent' def id (in
7678
// the form of a DefIndex) so that if we create a new node which introduces
7779
// a definition, then we can properly create the def id.
@@ -102,14 +104,14 @@ pub struct LoweringContext<'a> {
102104
}
103105

104106
pub trait Resolver {
105-
// Resolve a hir path generated by the lowerer when expanding `for`, `if let`, etc.
107+
/// Resolve a hir path generated by the lowerer when expanding `for`, `if let`, etc.
106108
fn resolve_hir_path(&mut self, path: &mut hir::Path, is_value: bool);
107109

108-
// Obtain the resolution for a node id
110+
/// Obtain the resolution for a node id
109111
fn get_resolution(&mut self, id: NodeId) -> Option<PathResolution>;
110112

111-
// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
112-
// This should only return `None` during testing.
113+
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
114+
/// This should only return `None` during testing.
113115
fn definitions(&mut self) -> &mut Definitions;
114116
}
115117

src/librustc/infer/region_inference/graphviz.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ enum Node {
133133
Region(ty::RegionKind),
134134
}
135135

136-
// type Edge = Constraint;
137136
#[derive(Clone, PartialEq, Eq, Debug, Copy)]
138137
enum Edge<'tcx> {
139138
Constraint(Constraint<'tcx>),

src/librustc/infer/region_inference/mod.rs

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ use std::u32;
3535

3636
mod graphviz;
3737

38-
// A constraint that influences the inference process.
38+
/// A constraint that influences the inference process.
3939
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
4040
pub enum Constraint<'tcx> {
41-
// One region variable is subregion of another
41+
/// One region variable is subregion of another
4242
ConstrainVarSubVar(RegionVid, RegionVid),
4343

44-
// Concrete region is subregion of region variable
44+
/// Concrete region is subregion of region variable
4545
ConstrainRegSubVar(Region<'tcx>, RegionVid),
4646

47-
// Region variable is subregion of concrete region. This does not
48-
// directly affect inference, but instead is checked after
49-
// inference is complete.
47+
/// Region variable is subregion of concrete region. This does not
48+
/// directly affect inference, but instead is checked after
49+
/// inference is complete.
5050
ConstrainVarSubReg(RegionVid, Region<'tcx>),
5151

52-
// A constraint where neither side is a variable. This does not
53-
// directly affect inference, but instead is checked after
54-
// inference is complete.
52+
/// A constraint where neither side is a variable. This does not
53+
/// directly affect inference, but instead is checked after
54+
/// inference is complete.
5555
ConstrainRegSubReg(Region<'tcx>, Region<'tcx>),
5656
}
5757

58-
// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
59-
// associated type) must outlive the region `R`. `T` is known to
60-
// outlive `RS`. Therefore verify that `R <= RS[i]` for some
61-
// `i`. Inference variables may be involved (but this verification
62-
// step doesn't influence inference).
58+
/// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
59+
/// associated type) must outlive the region `R`. `T` is known to
60+
/// outlive `RS`. Therefore verify that `R <= RS[i]` for some
61+
/// `i`. Inference variables may be involved (but this verification
62+
/// step doesn't influence inference).
6363
#[derive(Debug)]
6464
pub struct Verify<'tcx> {
6565
kind: GenericKind<'tcx>,
@@ -74,29 +74,29 @@ pub enum GenericKind<'tcx> {
7474
Projection(ty::ProjectionTy<'tcx>),
7575
}
7676

77-
// When we introduce a verification step, we wish to test that a
78-
// particular region (let's call it `'min`) meets some bound.
79-
// The bound is described the by the following grammar:
77+
/// When we introduce a verification step, we wish to test that a
78+
/// particular region (let's call it `'min`) meets some bound.
79+
/// The bound is described the by the following grammar:
8080
#[derive(Debug)]
8181
pub enum VerifyBound<'tcx> {
82-
// B = exists {R} --> some 'r in {R} must outlive 'min
83-
//
84-
// Put another way, the subject value is known to outlive all
85-
// regions in {R}, so if any of those outlives 'min, then the
86-
// bound is met.
82+
/// B = exists {R} --> some 'r in {R} must outlive 'min
83+
///
84+
/// Put another way, the subject value is known to outlive all
85+
/// regions in {R}, so if any of those outlives 'min, then the
86+
/// bound is met.
8787
AnyRegion(Vec<Region<'tcx>>),
8888

89-
// B = forall {R} --> all 'r in {R} must outlive 'min
90-
//
91-
// Put another way, the subject value is known to outlive some
92-
// region in {R}, so if all of those outlives 'min, then the bound
93-
// is met.
89+
/// B = forall {R} --> all 'r in {R} must outlive 'min
90+
///
91+
/// Put another way, the subject value is known to outlive some
92+
/// region in {R}, so if all of those outlives 'min, then the bound
93+
/// is met.
9494
AllRegions(Vec<Region<'tcx>>),
9595

96-
// B = exists {B} --> 'min must meet some bound b in {B}
96+
/// B = exists {B} --> 'min must meet some bound b in {B}
9797
AnyBound(Vec<VerifyBound<'tcx>>),
9898

99-
// B = forall {B} --> 'min must meet all bounds b in {B}
99+
/// B = forall {B} --> 'min must meet all bounds b in {B}
100100
AllBounds(Vec<VerifyBound<'tcx>>),
101101
}
102102

@@ -183,56 +183,57 @@ pub struct RegionVarBindings<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
183183
tcx: TyCtxt<'a, 'gcx, 'tcx>,
184184
var_origins: RefCell<Vec<RegionVariableOrigin>>,
185185

186-
// Constraints of the form `A <= B` introduced by the region
187-
// checker. Here at least one of `A` and `B` must be a region
188-
// variable.
186+
/// Constraints of the form `A <= B` introduced by the region
187+
/// checker. Here at least one of `A` and `B` must be a region
188+
/// variable.
189189
constraints: RefCell<FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>>,
190190

191-
// A "verify" is something that we need to verify after inference is
192-
// done, but which does not directly affect inference in any way.
193-
//
194-
// An example is a `A <= B` where neither `A` nor `B` are
195-
// inference variables.
191+
/// A "verify" is something that we need to verify after inference is
192+
/// done, but which does not directly affect inference in any way.
193+
///
194+
/// An example is a `A <= B` where neither `A` nor `B` are
195+
/// inference variables.
196196
verifys: RefCell<Vec<Verify<'tcx>>>,
197197

198-
// A "given" is a relationship that is known to hold. In particular,
199-
// we often know from closure fn signatures that a particular free
200-
// region must be a subregion of a region variable:
201-
//
202-
// foo.iter().filter(<'a> |x: &'a &'b T| ...)
203-
//
204-
// In situations like this, `'b` is in fact a region variable
205-
// introduced by the call to `iter()`, and `'a` is a bound region
206-
// on the closure (as indicated by the `<'a>` prefix). If we are
207-
// naive, we wind up inferring that `'b` must be `'static`,
208-
// because we require that it be greater than `'a` and we do not
209-
// know what `'a` is precisely.
210-
//
211-
// This hashmap is used to avoid that naive scenario. Basically we
212-
// record the fact that `'a <= 'b` is implied by the fn signature,
213-
// and then ignore the constraint when solving equations. This is
214-
// a bit of a hack but seems to work.
198+
/// A "given" is a relationship that is known to hold. In particular,
199+
/// we often know from closure fn signatures that a particular free
200+
/// region must be a subregion of a region variable:
201+
///
202+
/// foo.iter().filter(<'a> |x: &'a &'b T| ...)
203+
///
204+
/// In situations like this, `'b` is in fact a region variable
205+
/// introduced by the call to `iter()`, and `'a` is a bound region
206+
/// on the closure (as indicated by the `<'a>` prefix). If we are
207+
/// naive, we wind up inferring that `'b` must be `'static`,
208+
/// because we require that it be greater than `'a` and we do not
209+
/// know what `'a` is precisely.
210+
///
211+
/// This hashmap is used to avoid that naive scenario. Basically we
212+
/// record the fact that `'a <= 'b` is implied by the fn signature,
213+
/// and then ignore the constraint when solving equations. This is
214+
/// a bit of a hack but seems to work.
215215
givens: RefCell<FxHashSet<(Region<'tcx>, ty::RegionVid)>>,
216216

217217
lubs: RefCell<CombineMap<'tcx>>,
218218
glbs: RefCell<CombineMap<'tcx>>,
219219
skolemization_count: Cell<u32>,
220220
bound_count: Cell<u32>,
221221

222-
// The undo log records actions that might later be undone.
223-
//
224-
// Note: when the undo_log is empty, we are not actively
225-
// snapshotting. When the `start_snapshot()` method is called, we
226-
// push an OpenSnapshot entry onto the list to indicate that we
227-
// are now actively snapshotting. The reason for this is that
228-
// otherwise we end up adding entries for things like the lower
229-
// bound on a variable and so forth, which can never be rolled
230-
// back.
222+
/// The undo log records actions that might later be undone.
223+
///
224+
/// Note: when the undo_log is empty, we are not actively
225+
/// snapshotting. When the `start_snapshot()` method is called, we
226+
/// push an OpenSnapshot entry onto the list to indicate that we
227+
/// are now actively snapshotting. The reason for this is that
228+
/// otherwise we end up adding entries for things like the lower
229+
/// bound on a variable and so forth, which can never be rolled
230+
/// back.
231231
undo_log: RefCell<Vec<UndoLogEntry<'tcx>>>,
232+
232233
unification_table: RefCell<UnificationTable<ty::RegionVid>>,
233234

234-
// This contains the results of inference. It begins as an empty
235-
// option and only acquires a value after inference is complete.
235+
/// This contains the results of inference. It begins as an empty
236+
/// option and only acquires a value after inference is complete.
236237
values: RefCell<Option<Vec<VarValue<'tcx>>>>,
237238
}
238239

0 commit comments

Comments
 (0)