Skip to content

Commit 2d4e94a

Browse files
committed
Auto merge of #31385 - oli-obk:doc/mir, r=nagisa
I didn't change any content, just added another slash so we can see those comments in the docs r? @steveklabnik
2 parents db6f888 + 4e44ef1 commit 2d4e94a

File tree

3 files changed

+92
-86
lines changed

3 files changed

+92
-86
lines changed

src/librustc/mir/repr.rs

+59-55
Original file line numberDiff line numberDiff line change
@@ -144,33 +144,33 @@ pub enum BorrowKind {
144144
///////////////////////////////////////////////////////////////////////////
145145
// Variables and temps
146146

147-
// A "variable" is a binding declared by the user as part of the fn
148-
// decl, a let, etc.
147+
/// A "variable" is a binding declared by the user as part of the fn
148+
/// decl, a let, etc.
149149
#[derive(Clone, RustcEncodable, RustcDecodable)]
150150
pub struct VarDecl<'tcx> {
151151
pub mutability: Mutability,
152152
pub name: Name,
153153
pub ty: Ty<'tcx>,
154154
}
155155

156-
// A "temp" is a temporary that we place on the stack. They are
157-
// anonymous, always mutable, and have only a type.
156+
/// A "temp" is a temporary that we place on the stack. They are
157+
/// anonymous, always mutable, and have only a type.
158158
#[derive(Clone, RustcEncodable, RustcDecodable)]
159159
pub struct TempDecl<'tcx> {
160160
pub ty: Ty<'tcx>,
161161
}
162162

163-
// A "arg" is one of the function's formal arguments. These are
164-
// anonymous and distinct from the bindings that the user declares.
165-
//
166-
// For example, in this function:
167-
//
168-
// ```
169-
// fn foo((x, y): (i32, u32)) { ... }
170-
// ```
171-
//
172-
// there is only one argument, of type `(i32, u32)`, but two bindings
173-
// (`x` and `y`).
163+
/// A "arg" is one of the function's formal arguments. These are
164+
/// anonymous and distinct from the bindings that the user declares.
165+
///
166+
/// For example, in this function:
167+
///
168+
/// ```
169+
/// fn foo((x, y): (i32, u32)) { ... }
170+
/// ```
171+
///
172+
/// there is only one argument, of type `(i32, u32)`, but two bindings
173+
/// (`x` and `y`).
174174
#[derive(Clone, RustcEncodable, RustcDecodable)]
175175
pub struct ArgDecl<'tcx> {
176176
pub ty: Ty<'tcx>,
@@ -495,7 +495,8 @@ pub enum StatementKind<'tcx> {
495495

496496
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
497497
pub enum DropKind {
498-
Free, // free a partially constructed box, should go away eventually
498+
/// free a partially constructed box, should go away eventually
499+
Free,
499500
Deep
500501
}
501502

@@ -552,24 +553,27 @@ pub enum ProjectionElem<'tcx, V> {
552553
Field(Field),
553554
Index(V),
554555

555-
// These indices are generated by slice patterns. Easiest to explain
556-
// by example:
557-
//
558-
// ```
559-
// [X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false },
560-
// [_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false },
561-
// [_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true },
562-
// [_, _, .._, _, X] => { offset: 1, min_length: 4, from_end: true },
563-
// ```
556+
/// These indices are generated by slice patterns. Easiest to explain
557+
/// by example:
558+
///
559+
/// ```
560+
/// [X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false },
561+
/// [_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false },
562+
/// [_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true },
563+
/// [_, _, .._, _, X] => { offset: 1, min_length: 4, from_end: true },
564+
/// ```
564565
ConstantIndex {
565-
offset: u32, // index or -index (in Python terms), depending on from_end
566-
min_length: u32, // thing being indexed must be at least this long
567-
from_end: bool, // counting backwards from end?
566+
/// index or -index (in Python terms), depending on from_end
567+
offset: u32,
568+
/// thing being indexed must be at least this long
569+
min_length: u32,
570+
/// counting backwards from end?
571+
from_end: bool,
568572
},
569573

570-
// "Downcast" to a variant of an ADT. Currently, we only introduce
571-
// this for ADTs with more than one variant. It may be better to
572-
// just introduce it always, or always for enums.
574+
/// "Downcast" to a variant of an ADT. Currently, we only introduce
575+
/// this for ADTs with more than one variant. It may be better to
576+
/// just introduce it always, or always for enums.
573577
Downcast(AdtDef<'tcx>, usize),
574578
}
575579

@@ -654,9 +658,9 @@ impl<'tcx> Debug for Lvalue<'tcx> {
654658
///////////////////////////////////////////////////////////////////////////
655659
// Operands
656660
//
657-
// These are values that can appear inside an rvalue (or an index
658-
// lvalue). They are intentionally limited to prevent rvalues from
659-
// being nested in one another.
661+
/// These are values that can appear inside an rvalue (or an index
662+
/// lvalue). They are intentionally limited to prevent rvalues from
663+
/// being nested in one another.
660664
661665
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
662666
pub enum Operand<'tcx> {
@@ -675,20 +679,20 @@ impl<'tcx> Debug for Operand<'tcx> {
675679
}
676680

677681
///////////////////////////////////////////////////////////////////////////
678-
// Rvalues
682+
/// Rvalues
679683
680684
#[derive(Clone, RustcEncodable, RustcDecodable)]
681685
pub enum Rvalue<'tcx> {
682-
// x (either a move or copy, depending on type of x)
686+
/// x (either a move or copy, depending on type of x)
683687
Use(Operand<'tcx>),
684688

685-
// [x; 32]
689+
/// [x; 32]
686690
Repeat(Operand<'tcx>, TypedConstVal<'tcx>),
687691

688-
// &x or &mut x
692+
/// &x or &mut x
689693
Ref(Region, BorrowKind, Lvalue<'tcx>),
690694

691-
// length of a [X] or [X;n] value
695+
/// length of a [X] or [X;n] value
692696
Len(Lvalue<'tcx>),
693697

694698
Cast(CastKind, Operand<'tcx>, Ty<'tcx>),
@@ -697,21 +701,21 @@ pub enum Rvalue<'tcx> {
697701

698702
UnaryOp(UnOp, Operand<'tcx>),
699703

700-
// Creates an *uninitialized* Box
704+
/// Creates an *uninitialized* Box
701705
Box(Ty<'tcx>),
702706

703-
// Create an aggregate value, like a tuple or struct. This is
704-
// only needed because we want to distinguish `dest = Foo { x:
705-
// ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case
706-
// that `Foo` has a destructor. These rvalues can be optimized
707-
// away after type-checking and before lowering.
707+
/// Create an aggregate value, like a tuple or struct. This is
708+
/// only needed because we want to distinguish `dest = Foo { x:
709+
/// ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case
710+
/// that `Foo` has a destructor. These rvalues can be optimized
711+
/// away after type-checking and before lowering.
708712
Aggregate(AggregateKind<'tcx>, Vec<Operand<'tcx>>),
709713

710-
// Generates a slice of the form `&input[from_start..L-from_end]`
711-
// where `L` is the length of the slice. This is only created by
712-
// slice pattern matching, so e.g. a pattern of the form `[x, y,
713-
// .., z]` might create a slice with `from_start=2` and
714-
// `from_end=1`.
714+
/// Generates a slice of the form `&input[from_start..L-from_end]`
715+
/// where `L` is the length of the slice. This is only created by
716+
/// slice pattern matching, so e.g. a pattern of the form `[x, y,
717+
/// .., z]` might create a slice with `from_start=2` and
718+
/// `from_end=1`.
715719
Slice {
716720
input: Lvalue<'tcx>,
717721
from_start: usize,
@@ -878,11 +882,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
878882
}
879883

880884
///////////////////////////////////////////////////////////////////////////
881-
// Constants
882-
//
883-
// Two constants are equal if they are the same constant. Note that
884-
// this does not necessarily mean that they are "==" in Rust -- in
885-
// particular one must be wary of `NaN`!
885+
/// Constants
886+
///
887+
/// Two constants are equal if they are the same constant. Note that
888+
/// this does not necessarily mean that they are "==" in Rust -- in
889+
/// particular one must be wary of `NaN`!
886890
887891
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
888892
pub struct Constant<'tcx> {

src/librustc_mir/build/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ struct CFG<'tcx> {
3434
}
3535

3636
///////////////////////////////////////////////////////////////////////////
37-
// The `BlockAnd` "monad" packages up the new basic block along with a
38-
// produced value (sometimes just unit, of course). The `unpack!`
39-
// macro (and methods below) makes working with `BlockAnd` much more
40-
// convenient.
37+
/// The `BlockAnd` "monad" packages up the new basic block along with a
38+
/// produced value (sometimes just unit, of course). The `unpack!`
39+
/// macro (and methods below) makes working with `BlockAnd` much more
40+
/// convenient.
4141
4242
#[must_use] // if you don't use one of these results, you're leaving a dangling edge
4343
pub struct BlockAnd<T>(BasicBlock, T);
@@ -77,7 +77,7 @@ macro_rules! unpack {
7777
}
7878

7979
///////////////////////////////////////////////////////////////////////////
80-
// construct() -- the main entry point for building MIR for a function
80+
/// the main entry point for building MIR for a function
8181
8282
pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
8383
_span: Span,

src/librustc_mir/hair/mod.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -85,33 +85,33 @@ pub enum StmtKind<'tcx> {
8585
},
8686
}
8787

88-
// The Hair trait implementor translates their expressions (`&'tcx H::Expr`)
89-
// into instances of this `Expr` enum. This translation can be done
90-
// basically as lazilly or as eagerly as desired: every recursive
91-
// reference to an expression in this enum is an `ExprRef<'tcx>`, which
92-
// may in turn be another instance of this enum (boxed), or else an
93-
// untranslated `&'tcx H::Expr`. Note that instances of `Expr` are very
94-
// shortlived. They are created by `Hair::to_expr`, analyzed and
95-
// converted into MIR, and then discarded.
96-
//
97-
// If you compare `Expr` to the full compiler AST, you will see it is
98-
// a good bit simpler. In fact, a number of the more straight-forward
99-
// MIR simplifications are already done in the impl of `Hair`. For
100-
// example, method calls and overloaded operators are absent: they are
101-
// expected to be converted into `Expr::Call` instances.
88+
/// The Hair trait implementor translates their expressions (`&'tcx H::Expr`)
89+
/// into instances of this `Expr` enum. This translation can be done
90+
/// basically as lazilly or as eagerly as desired: every recursive
91+
/// reference to an expression in this enum is an `ExprRef<'tcx>`, which
92+
/// may in turn be another instance of this enum (boxed), or else an
93+
/// untranslated `&'tcx H::Expr`. Note that instances of `Expr` are very
94+
/// shortlived. They are created by `Hair::to_expr`, analyzed and
95+
/// converted into MIR, and then discarded.
96+
///
97+
/// If you compare `Expr` to the full compiler AST, you will see it is
98+
/// a good bit simpler. In fact, a number of the more straight-forward
99+
/// MIR simplifications are already done in the impl of `Hair`. For
100+
/// example, method calls and overloaded operators are absent: they are
101+
/// expected to be converted into `Expr::Call` instances.
102102
#[derive(Clone, Debug)]
103103
pub struct Expr<'tcx> {
104-
// type of this expression
104+
/// type of this expression
105105
pub ty: Ty<'tcx>,
106106

107-
// lifetime of this expression if it should be spilled into a
108-
// temporary; should be None only if in a constant context
107+
/// lifetime of this expression if it should be spilled into a
108+
/// temporary; should be None only if in a constant context
109109
pub temp_lifetime: Option<CodeExtent>,
110110

111-
// span of the expression in the source
111+
/// span of the expression in the source
112112
pub span: Span,
113113

114-
// kind of expression
114+
/// kind of expression
115115
pub kind: ExprKind<'tcx>,
116116
}
117117

@@ -194,7 +194,8 @@ pub enum ExprKind<'tcx> {
194194
VarRef {
195195
id: ast::NodeId,
196196
},
197-
SelfRef, // first argument, used for self in a closure
197+
/// first argument, used for self in a closure
198+
SelfRef,
198199
StaticRef {
199200
id: DefId,
200201
},
@@ -278,7 +279,7 @@ pub enum LogicalOp {
278279
pub enum PatternKind<'tcx> {
279280
Wild,
280281

281-
// x, ref x, x @ P, etc
282+
/// x, ref x, x @ P, etc
282283
Binding {
283284
mutability: Mutability,
284285
name: ast::Name,
@@ -288,21 +289,22 @@ pub enum PatternKind<'tcx> {
288289
subpattern: Option<Pattern<'tcx>>,
289290
},
290291

291-
// Foo(...) or Foo{...} or Foo, where `Foo` is a variant name from an adt with >1 variants
292+
/// Foo(...) or Foo{...} or Foo, where `Foo` is a variant name from an adt with >1 variants
292293
Variant {
293294
adt_def: AdtDef<'tcx>,
294295
variant_index: usize,
295296
subpatterns: Vec<FieldPattern<'tcx>>,
296297
},
297298

298-
// (...), Foo(...), Foo{...}, or Foo, where `Foo` is a variant name from an adt with 1 variant
299+
/// (...), Foo(...), Foo{...}, or Foo, where `Foo` is a variant name from an adt with 1 variant
299300
Leaf {
300301
subpatterns: Vec<FieldPattern<'tcx>>,
301302
},
302303

304+
/// box P, &P, &mut P, etc
303305
Deref {
304306
subpattern: Pattern<'tcx>,
305-
}, // box P, &P, &mut P, etc
307+
},
306308

307309
Constant {
308310
value: ConstVal,
@@ -313,14 +315,14 @@ pub enum PatternKind<'tcx> {
313315
hi: Literal<'tcx>,
314316
},
315317

316-
// matches against a slice, checking the length and extracting elements
318+
/// matches against a slice, checking the length and extracting elements
317319
Slice {
318320
prefix: Vec<Pattern<'tcx>>,
319321
slice: Option<Pattern<'tcx>>,
320322
suffix: Vec<Pattern<'tcx>>,
321323
},
322324

323-
// fixed match against an array, irrefutable
325+
/// fixed match against an array, irrefutable
324326
Array {
325327
prefix: Vec<Pattern<'tcx>>,
326328
slice: Option<Pattern<'tcx>>,

0 commit comments

Comments
 (0)