Skip to content

Commit 2a1af89

Browse files
committed
Auto merge of rust-lang#115510 - GuillaumeGomez:rollup-wh719bn, r=GuillaumeGomez
Rollup of 3 pull requests Successful merges: - rust-lang#115478 (Emit unused doc comment warnings for pat and expr fields) - rust-lang#115490 (rustdoc: update comment in search.js for rust-lang#107629) - rust-lang#115503 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 49523e3 + 38a2d5f commit 2a1af89

File tree

6 files changed

+100
-17
lines changed

6 files changed

+100
-17
lines changed

compiler/rustc_lint/src/builtin.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,22 @@ impl EarlyLintPass for UnusedDocComment {
10011001
warn_if_doc(cx, arm_span, "match arms", &arm.attrs);
10021002
}
10031003

1004+
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat) {
1005+
if let ast::PatKind::Struct(_, _, fields, _) = &pat.kind {
1006+
for field in fields {
1007+
warn_if_doc(cx, field.span, "pattern fields", &field.attrs);
1008+
}
1009+
}
1010+
}
1011+
10041012
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
10051013
warn_if_doc(cx, expr.span, "expressions", &expr.attrs);
1014+
1015+
if let ExprKind::Struct(s) = &expr.kind {
1016+
for field in &s.fields {
1017+
warn_if_doc(cx, field.span, "expression fields", &field.attrs);
1018+
}
1019+
}
10061020
}
10071021

10081022
fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
555555
subpattern: pattern,
556556
ascription: Ascription {
557557
annotation,
558-
/// Note that use `Contravariant` here. See the
559-
/// `variance` field documentation for details.
558+
// Note that use `Contravariant` here. See the
559+
// `variance` field documentation for details.
560560
variance: ty::Variance::Contravariant,
561561
},
562562
},

src/librustdoc/html/static/js/search.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -2537,18 +2537,25 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25372537
let crateSize = 0;
25382538

25392539
/**
2540-
* The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f`
2541-
* are arrays with the same length. n[i] contains the name of an item.
2542-
* t[i] contains the type of that item (as a string of characters that represent an
2543-
* offset in `itemTypes`). d[i] contains the description of that item.
2540+
* The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f`
2541+
* are arrays with the same length. `q`, `a`, and `c` use a sparse
2542+
* representation for compactness.
25442543
*
2545-
* q[i] contains the full path of the item, or an empty string indicating
2546-
* "same as q[i-1]".
2544+
* `n[i]` contains the name of an item.
25472545
*
2548-
* i[i] contains an item's parent, usually a module. For compactness,
2546+
* `t[i]` contains the type of that item
2547+
* (as a string of characters that represent an offset in `itemTypes`).
2548+
*
2549+
* `d[i]` contains the description of that item.
2550+
*
2551+
* `q` contains the full paths of the items. For compactness, it is a set of
2552+
* (index, path) pairs used to create a map. If a given index `i` is
2553+
* not present, this indicates "same as the last index present".
2554+
*
2555+
* `i[i]` contains an item's parent, usually a module. For compactness,
25492556
* it is a set of indexes into the `p` array.
25502557
*
2551-
* f[i] contains function signatures, or `0` if the item isn't a function.
2558+
* `f[i]` contains function signatures, or `0` if the item isn't a function.
25522559
* Functions are themselves encoded as arrays. The first item is a list of
25532560
* types representing the function's inputs, and the second list item is a list
25542561
* of types representing the function's output. Tuples are flattened.
@@ -2562,6 +2569,8 @@ ${item.displayPath}<span class="${type}">${name}</span>\
25622569
*
25632570
* `p` is a list of path/type pairs. It is used for parents and function parameters.
25642571
*
2572+
* `c` is an array of item indices that are deprecated.
2573+
*
25652574
* @type {{
25662575
* doc: string,
25672576
* a: Object,

tests/rustdoc-gui/code-color.goml

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ define-function: (
1919
},
2020
)
2121

22-
call-function: ("check-colors", ("ayu", "rgb(230, 225, 207)", "rgb(255, 180, 84)"))
23-
call-function: ("check-colors", ("dark", "rgb(221, 221, 221)", "rgb(221, 221, 221)"))
24-
call-function: ("check-colors", ("light", "rgb(0, 0, 0)", "rgb(0, 0, 0)"))
22+
call-function: ("check-colors", {
23+
"theme": "ayu",
24+
"doc_code_color": "#e6e1cf",
25+
"doc_inline_code_color": "#ffb454",
26+
})
27+
call-function: ("check-colors", {
28+
"theme": "dark",
29+
"doc_code_color": "#ddd",
30+
"doc_inline_code_color": "#ddd",
31+
})
32+
call-function: ("check-colors", {
33+
"theme": "light",
34+
"doc_code_color": "black",
35+
"doc_inline_code_color": "black",
36+
})

tests/ui/lint/unused/unused-doc-comments-edge-cases.rs

+26
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ fn doc_comment_on_expr(num: u8) -> bool {
2626
num == 3
2727
}
2828

29+
fn doc_comment_on_expr_field() -> bool {
30+
struct S { foo: i32 }
31+
32+
let x = S {
33+
/// useless doc comment
34+
//~^ ERROR: unused doc comment
35+
foo: 3
36+
};
37+
38+
true
39+
}
40+
41+
fn doc_comment_on_pat_field() -> bool {
42+
struct S { foo: i32 }
43+
44+
let S {
45+
/// useless doc comment
46+
//~^ ERROR: unused doc comment
47+
foo
48+
} = S {
49+
foo: 3
50+
};
51+
52+
true
53+
}
54+
2955
fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
3056
//~^ ERROR: unused doc comment
3157

tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr

+26-4
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,37 @@ LL | num == 3
4242
= help: use `//` for a plain comment
4343

4444
error: unused doc comment
45-
--> $DIR/unused-doc-comments-edge-cases.rs:29:27
45+
--> $DIR/unused-doc-comments-edge-cases.rs:33:9
46+
|
47+
LL | /// useless doc comment
48+
| ^^^^^^^^^^^^^^^^^^^^^^^
49+
LL |
50+
LL | foo: 3
51+
| ------ rustdoc does not generate documentation for expression fields
52+
|
53+
= help: use `//` for a plain comment
54+
55+
error: unused doc comment
56+
--> $DIR/unused-doc-comments-edge-cases.rs:45:9
57+
|
58+
LL | /// useless doc comment
59+
| ^^^^^^^^^^^^^^^^^^^^^^^
60+
LL |
61+
LL | foo
62+
| --- rustdoc does not generate documentation for pattern fields
63+
|
64+
= help: use `//` for a plain comment
65+
66+
error: unused doc comment
67+
--> $DIR/unused-doc-comments-edge-cases.rs:55:27
4668
|
4769
LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {}
4870
| ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters
4971
|
5072
= help: use `//` for a plain comment
5173

5274
error: unused doc comment
53-
--> $DIR/unused-doc-comments-edge-cases.rs:33:5
75+
--> $DIR/unused-doc-comments-edge-cases.rs:59:5
5476
|
5577
LL | /// unused doc comment
5678
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -63,7 +85,7 @@ LL | | }
6385
= help: use `//` for a plain comment
6486

6587
error: unused doc comment
66-
--> $DIR/unused-doc-comments-edge-cases.rs:40:1
88+
--> $DIR/unused-doc-comments-edge-cases.rs:66:1
6789
|
6890
LL | /// unused doc comment
6991
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -89,7 +111,7 @@ help: you might have meant to return this value
89111
LL | return true;
90112
| ++++++ +
91113

92-
error: aborting due to 8 previous errors
114+
error: aborting due to 10 previous errors
93115

94116
Some errors have detailed explanations: E0308, E0658.
95117
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)