Skip to content

Commit fbbf57e

Browse files
committed
Internal documentation and code style
1 parent 4ce1daf commit fbbf57e

File tree

7 files changed

+67
-41
lines changed

7 files changed

+67
-41
lines changed

src/compiler-rt

Submodule compiler-rt updated 2251 files

src/librustc/front/map/blocks.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ struct ClosureParts<'a> {
130130

131131
impl<'a> ClosureParts<'a> {
132132
fn new(d: &'a FnDecl, b: &'a Block, id: NodeId, s: Span) -> ClosureParts<'a> {
133-
ClosureParts { decl: d, body: b, id: id, span: s }
133+
ClosureParts {
134+
decl: d,
135+
body: b,
136+
id: id,
137+
span: s
138+
}
134139
}
135140
}
136141

src/librustc/front/map/collector.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ use syntax::codemap::Span;
2222
/// A Visitor that walks over an AST and collects Node's into an AST
2323
/// Map.
2424
pub struct NodeCollector<'ast> {
25+
/// The crate
2526
pub krate: &'ast Crate,
27+
/// The node map
2628
pub map: Vec<MapEntry<'ast>>,
29+
/// The definitions, used for name resolution
2730
pub definitions: Definitions,
31+
/// The parrent of this node
2832
pub parent_node: NodeId,
2933
}
3034

src/librustc/front/map/definitions.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use syntax::ast;
1616
use syntax::parse::token::InternedString;
1717
use util::nodemap::NodeMap;
1818

19+
/// A definition, that defines are
1920
#[derive(Clone)]
2021
pub struct Definitions {
2122
data: Vec<DefData>,
@@ -66,36 +67,53 @@ pub type DefPath = Vec<DisambiguatedDefPathData>;
6667
pub enum DefPathData {
6768
// Root: these should only be used for the root nodes, because
6869
// they are treated specially by the `def_path` function.
70+
/// The crate root (marker)
6971
CrateRoot,
72+
/// An inlined root
7073
InlinedRoot(DefPath),
7174

7275
// Catch-all for random DefId things like DUMMY_NODE_ID
7376
Misc,
7477

7578
// Different kinds of items and item-like things:
79+
/// An implementation
7680
Impl(ast::Name),
81+
/// A type (struct, enum, etc.)
7782
Type(ast::Name),
83+
/// A module declaration
7884
Mod(ast::Name),
85+
/// A value
7986
Value(ast::Name),
87+
/// A macro rule
8088
MacroDef(ast::Name),
89+
/// A closure expression
8190
ClosureExpr,
8291

8392
// Subportions of items
93+
/// A type parameter (generic parameter)
8494
TypeParam(ast::Name),
95+
/// A lifetime definition
8596
LifetimeDef(ast::Name),
97+
/// A variant of a enum
8698
EnumVariant(ast::Name),
99+
/// A positional field, for example a tuple field
87100
PositionalField,
101+
/// A struct field
88102
Field(hir::StructFieldKind),
89-
StructCtor, // implicit ctor for a tuple-like struct
90-
Initializer, // initializer for a const
91-
Binding(ast::Name), // pattern binding
92-
93-
// An external crate that does not have an `extern crate` in this
94-
// crate.
103+
/// Implicit ctor for a tuple-like struct
104+
StructCtor,
105+
/// Initializer for a constant
106+
Initializer,
107+
/// A pattern binding
108+
Binding(ast::Name),
109+
110+
/// An external crate that does not have an `extern crate` in this
111+
/// crate.
95112
DetachedCrate(ast::Name),
96113
}
97114

98115
impl Definitions {
116+
/// Create new empty definition map
99117
pub fn new() -> Definitions {
100118
Definitions {
101119
data: vec![],
@@ -104,6 +122,7 @@ impl Definitions {
104122
}
105123
}
106124

125+
/// Get the number of definitions
107126
pub fn len(&self) -> usize {
108127
self.data.len()
109128
}
@@ -138,6 +157,7 @@ impl Definitions {
138157
}
139158
}
140159

160+
/// Add a definition with a parrent definition
141161
pub fn create_def_with_parent(&mut self,
142162
parent: Option<DefIndex>,
143163
node_id: ast::NodeId,

src/librustc_back/sha2.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ fn write_u32_be(dst: &mut[u8], input: u32) {
2525

2626
/// Read the value of a vector of bytes as a u32 value in big-endian format.
2727
fn read_u32_be(input: &[u8]) -> u32 {
28-
return
29-
(input[0] as u32) << 24 |
28+
(input[0] as u32) << 24 |
3029
(input[1] as u32) << 16 |
3130
(input[2] as u32) << 8 |
32-
(input[3] as u32);
31+
(input[3] as u32)
3332
}
3433

3534
/// Read a vector of bytes into a vector of u32s. The values are read in big-endian format.
@@ -50,7 +49,7 @@ trait ToBits {
5049

5150
impl ToBits for u64 {
5251
fn to_bits(self) -> (u64, u64) {
53-
return (self >> 61, self << 3);
52+
(self >> 61, self << 3)
5453
}
5554
}
5655

@@ -64,7 +63,7 @@ fn add_bytes_to_bits(bits: u64, bytes: u64) -> u64 {
6463
}
6564

6665
match bits.checked_add(new_low_bits) {
67-
Some(x) => return x,
66+
Some(x) => x,
6867
None => panic!("numeric overflow occurred.")
6968
}
7069
}
@@ -113,10 +112,10 @@ struct FixedBuffer64 {
113112
impl FixedBuffer64 {
114113
/// Create a new FixedBuffer64
115114
fn new() -> FixedBuffer64 {
116-
return FixedBuffer64 {
115+
FixedBuffer64 {
117116
buffer: [0; 64],
118117
buffer_idx: 0
119-
};
118+
}
120119
}
121120
}
122121

@@ -175,13 +174,13 @@ impl FixedBuffer for FixedBuffer64 {
175174

176175
fn next<'s>(&'s mut self, len: usize) -> &'s mut [u8] {
177176
self.buffer_idx += len;
178-
return &mut self.buffer[self.buffer_idx - len..self.buffer_idx];
177+
&mut self.buffer[self.buffer_idx - len..self.buffer_idx]
179178
}
180179

181180
fn full_buffer<'s>(&'s mut self) -> &'s [u8] {
182181
assert!(self.buffer_idx == 64);
183182
self.buffer_idx = 0;
184-
return &self.buffer[..64];
183+
&self.buffer[..64]
185184
}
186185

187186
fn position(&self) -> usize { self.buffer_idx }
@@ -278,7 +277,7 @@ struct Engine256State {
278277

279278
impl Engine256State {
280279
fn new(h: &[u32; 8]) -> Engine256State {
281-
return Engine256State {
280+
Engine256State {
282281
h0: h[0],
283282
h1: h[1],
284283
h2: h[2],
@@ -287,7 +286,7 @@ impl Engine256State {
287286
h5: h[5],
288287
h6: h[6],
289288
h7: h[7]
290-
};
289+
}
291290
}
292291

293292
fn reset(&mut self, h: &[u32; 8]) {
@@ -433,7 +432,7 @@ struct Engine256 {
433432

434433
impl Engine256 {
435434
fn new(h: &[u32; 8]) -> Engine256 {
436-
return Engine256 {
435+
Engine256 {
437436
length_bits: 0,
438437
buffer: FixedBuffer64::new(),
439438
state: Engine256State::new(h),
@@ -457,17 +456,15 @@ impl Engine256 {
457456
}
458457

459458
fn finish(&mut self) {
460-
if self.finished {
461-
return;
459+
if !self.finished {
460+
let self_state = &mut self.state;
461+
self.buffer.standard_padding(8, |input: &[u8]| { self_state.process_block(input) });
462+
write_u32_be(self.buffer.next(4), (self.length_bits >> 32) as u32 );
463+
write_u32_be(self.buffer.next(4), self.length_bits as u32);
464+
self_state.process_block(self.buffer.full_buffer());
465+
466+
self.finished = true;
462467
}
463-
464-
let self_state = &mut self.state;
465-
self.buffer.standard_padding(8, |input: &[u8]| { self_state.process_block(input) });
466-
write_u32_be(self.buffer.next(4), (self.length_bits >> 32) as u32 );
467-
write_u32_be(self.buffer.next(4), self.length_bits as u32);
468-
self_state.process_block(self.buffer.full_buffer());
469-
470-
self.finished = true;
471468
}
472469
}
473470

src/librustc_back/svh.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ impl Svh {
6767
}
6868

6969
pub fn calculate(metadata: &Vec<String>, krate: &hir::Crate) -> Svh {
70+
fn hex(b: u64) -> char {
71+
let b = (b & 0xf) as u8;
72+
let b = match b {
73+
0 ... 9 => '0' as u8 + b,
74+
_ => 'a' as u8 + b - 10,
75+
};
76+
b as char
77+
}
78+
7079
// FIXME (#14132): This is better than it used to be, but it still not
7180
// ideal. We now attempt to hash only the relevant portions of the
7281
// Crate AST as well as the top-level crate attributes. (However,
@@ -101,17 +110,8 @@ impl Svh {
101110
}
102111

103112
let hash = state.finish();
104-
return Svh {
113+
Svh {
105114
hash: (0..64).step_by(4).map(|i| hex(hash >> i)).collect()
106-
};
107-
108-
fn hex(b: u64) -> char {
109-
let b = (b & 0xf) as u8;
110-
let b = match b {
111-
0 ... 9 => '0' as u8 + b,
112-
_ => 'a' as u8 + b - 10,
113-
};
114-
b as char
115115
}
116116
}
117117
}

src/llvm

0 commit comments

Comments
 (0)