Skip to content

Commit 6f4b04f

Browse files
committed
---
yaml --- r: 60675 b: refs/heads/auto c: c658132 h: refs/heads/master i: 60673: d499cae 60671: 38fa908 v: v3
1 parent 414cd42 commit 6f4b04f

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 5787bf3093e75aa28fb081160f7d7fa66f528f9c
17+
refs/heads/auto: c6581325ac38ce3f96cb7a0ea0aad35feed173c1
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/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,

branches/auto/src/librustc/middle/lint.rs

Lines changed: 71 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,58 @@ 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 mut has_doc = false;
976+
for field.node.attrs.each |attr| {
977+
if attr.node.is_sugared_doc {
978+
has_doc = true;
979+
break;
980+
}
981+
}
982+
if !has_doc {
983+
cx.span_lint(missing_struct_doc, field.span, "missing documentation \
984+
for a field.");
985+
}
986+
},
987+
.. *visit::default_simple_visitor()
988+
})
989+
}
990+
991+
fn lint_missing_trait_doc(cx: @mut Context) -> visit::vt<()> {
992+
visit::mk_simple_visitor(@visit::SimpleVisitor {
993+
visit_trait_method: |method| {
994+
let mut has_doc = false;
995+
let span = match copy *method {
996+
ast::required(m) => {
997+
for m.attrs.each |attr| {
998+
if attr.node.is_sugared_doc {
999+
has_doc = true;
1000+
break;
1001+
}
1002+
}
1003+
m.span
1004+
},
1005+
ast::provided(m) => {
1006+
for m.attrs.each |attr| {
1007+
if attr.node.is_sugared_doc {
1008+
has_doc = true;
1009+
break;
1010+
}
1011+
}
1012+
m.span
1013+
}
1014+
};
1015+
if !has_doc {
1016+
cx.span_lint(missing_trait_doc, span, "missing documentation \
1017+
for a method.");
1018+
}
1019+
},
1020+
.. *visit::default_simple_visitor()
1021+
})
1022+
}
1023+
9551024
pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
9561025
let cx = @mut Context {
9571026
dict: @get_lint_dict(),
@@ -980,6 +1049,8 @@ pub fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
9801049
cx.add_lint(lint_unused_mut(cx));
9811050
cx.add_lint(lint_session(cx));
9821051
cx.add_lint(lint_unnecessary_allocations(cx));
1052+
cx.add_lint(lint_missing_struct_doc(cx));
1053+
cx.add_lint(lint_missing_trait_doc(cx));
9831054

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

0 commit comments

Comments
 (0)