Skip to content

Commit c94ebea

Browse files
committed
---
yaml --- r: 65263 b: refs/heads/master c: 3d61931 h: refs/heads/master i: 65261: 9fdf555 65259: 7dbe121 65255: f208ca2 65247: 594ced7 v: v3
1 parent 677fe03 commit c94ebea

File tree

5 files changed

+111
-8
lines changed

5 files changed

+111
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2f69bb9ba9d622ccab77840c08f4562a10b44c29
2+
refs/heads/master: 3d61931fcac13aadc88ece7e48567f7ff503fba5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/rust.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,11 +2435,10 @@ match x {
24352435
}
24362436
~~~~
24372437

2438-
Patterns that bind variables default to binding to a copy or move of the matched value
2439-
(depending on the matched value's type).
2440-
This can be made explicit using the ```copy``` keyword,
2441-
changed to bind to a borrowed pointer by using the ```ref``` keyword,
2442-
or to a mutable borrowed pointer using ```ref mut```.
2438+
Patterns that bind variables default to binding to a copy of the matched value. This can be made
2439+
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
2440+
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
2441+
the new binding using ```move```.
24432442

24442443
A pattern that's just an identifier,
24452444
like `Nil` in the previous answer,

trunk/src/librustc/middle/lint.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ pub enum lint {
8282
dead_assignment,
8383
unused_mut,
8484
unnecessary_allocation,
85+
86+
missing_struct_doc,
87+
missing_trait_doc,
8588
}
8689

8790
pub fn level_to_str(lv: level) -> &'static str {
@@ -252,6 +255,20 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
252255
desc: "detects unnecessary allocations that can be eliminated",
253256
default: warn
254257
}),
258+
259+
("missing_struct_doc",
260+
LintSpec {
261+
lint: missing_struct_doc,
262+
desc: "detects missing documentation for structs",
263+
default: allow
264+
}),
265+
266+
("missing_trait_doc",
267+
LintSpec {
268+
lint: missing_trait_doc,
269+
desc: "detects missing documentation for traits",
270+
default: allow
271+
}),
255272
];
256273

257274
/*
@@ -952,6 +969,69 @@ fn lint_unnecessary_allocations(cx: @mut Context) -> visit::vt<()> {
952969
})
953970
}
954971

972+
fn lint_missing_struct_doc(cx: @mut Context) -> visit::vt<()> {
973+
visit::mk_simple_visitor(@visit::SimpleVisitor {
974+
visit_struct_field: |field| {
975+
let relevant = match field.node.kind {
976+
ast::named_field(_, vis) => vis != ast::private,
977+
ast::unnamed_field => false,
978+
};
979+
980+
if relevant {
981+
let mut has_doc = false;
982+
for field.node.attrs.each |attr| {
983+
if attr.node.is_sugared_doc {
984+
has_doc = true;
985+
break;
986+
}
987+
}
988+
if !has_doc {
989+
cx.span_lint(missing_struct_doc, field.span, "missing documentation \
990+
for a field.");
991+
}
992+
}
993+
},
994+
.. *visit::default_simple_visitor()
995+
})
996+
}
997+
998+
fn lint_missing_trait_doc(cx: @mut Context) -> visit::vt<()> {
999+
visit::mk_simple_visitor(@visit::SimpleVisitor {
1000+
visit_trait_method: |method| {
1001+
let mut has_doc = false;
1002+
let span = match copy *method {
1003+
ast::required(m) => {
1004+
for m.attrs.each |attr| {
1005+
if attr.node.is_sugared_doc {
1006+
has_doc = true;
1007+
break;
1008+
}
1009+
}
1010+
m.span
1011+
},
1012+
ast::provided(m) => {
1013+
if m.vis == ast::private {
1014+
has_doc = true;
1015+
} else {
1016+
for m.attrs.each |attr| {
1017+
if attr.node.is_sugared_doc {
1018+
has_doc = true;
1019+
break;
1020+
}
1021+
}
1022+
}
1023+
m.span
1024+
}
1025+
};
1026+
if !has_doc {
1027+
cx.span_lint(missing_trait_doc, span, "missing documentation \
1028+
for a method.");
1029+
}
1030+
},
1031+
.. *visit::default_simple_visitor()
1032+
})
1033+
}
1034+
9551035
pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
9561036
let cx = @mut Context {
9571037
dict: @get_lint_dict(),
@@ -980,6 +1060,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
9801060
cx.add_lint(lint_unused_mut(cx));
9811061
cx.add_lint(lint_session(cx));
9821062
cx.add_lint(lint_unnecessary_allocations(cx));
1063+
cx.add_lint(lint_missing_struct_doc(cx));
1064+
cx.add_lint(lint_missing_trait_doc(cx));
9831065

9841066
// type inference doesn't like this being declared below, we need to tell it
9851067
// what the type of this first function is...

trunk/src/libstd/cell.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ Similar to a mutable option type, but friendlier.
2121
*/
2222

2323
#[mutable]
24-
#[deriving(Clone, DeepClone, Eq)]
24+
#[deriving(Clone)]
2525
pub struct Cell<T> {
2626
priv value: Option<T>
2727
}
2828

29+
impl<T: DeepClone> DeepClone for Cell<T> {
30+
fn deep_clone(&self) -> Cell<T> {
31+
Cell{value: self.value.deep_clone()}
32+
}
33+
}
34+
35+
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
36+
fn eq(&self, other: &Cell<T>) -> bool {
37+
(self.value) == (other.value)
38+
}
39+
fn ne(&self, other: &Cell<T>) -> bool { !self.eq(other) }
40+
}
41+
2942
/// Creates a new full cell with the given value.
3043
pub fn Cell<T>(value: T) -> Cell<T> {
3144
Cell { value: Some(value) }

trunk/src/libstd/option.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,21 @@ use clone::DeepClone;
5454
#[cfg(test)] use str;
5555

5656
/// The option type
57-
#[deriving(Clone, DeepClone, Eq)]
57+
#[deriving(Clone, Eq)]
5858
pub enum Option<T> {
5959
None,
6060
Some(T),
6161
}
6262

63+
impl<T: DeepClone> DeepClone for Option<T> {
64+
fn deep_clone(&self) -> Option<T> {
65+
match *self {
66+
Some(ref x) => Some(x.deep_clone()),
67+
None => None
68+
}
69+
}
70+
}
71+
6372
impl<T:Ord> Ord for Option<T> {
6473
fn lt(&self, other: &Option<T>) -> bool {
6574
match (self, other) {

0 commit comments

Comments
 (0)