From b1e32eaab24d09f17346b716730589f87f2f2a32 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Sat, 2 Sep 2023 19:26:10 -0600 Subject: [PATCH 1/5] rustdoc: update comment in search.js for #107629 --- src/librustdoc/html/static/js/search.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 42088e73554..82ea3e5c0c5 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -2486,18 +2486,25 @@ ${item.displayPath}${name}\ let crateSize = 0; /** - * The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f` - * are arrays with the same length. n[i] contains the name of an item. - * t[i] contains the type of that item (as a string of characters that represent an - * offset in `itemTypes`). d[i] contains the description of that item. + * The raw search data for a given crate. `n`, `t`, `d`, `i`, and `f` + * are arrays with the same length. `q`, `a`, and `c` use a sparse + * representation for compactness. * - * q[i] contains the full path of the item, or an empty string indicating - * "same as q[i-1]". + * `n[i]` contains the name of an item. * - * i[i] contains an item's parent, usually a module. For compactness, + * `t[i]` contains the type of that item + * (as a string of characters that represent an offset in `itemTypes`). + * + * `d[i]` contains the description of that item. + * + * `q` contains the full paths of the items. For compactness, it is a set of + * (index, path) pairs used to create a map. If a given index `i` is + * not present, this indicates "same as the last index present". + * + * `i[i]` contains an item's parent, usually a module. For compactness, * it is a set of indexes into the `p` array. * - * f[i] contains function signatures, or `0` if the item isn't a function. + * `f[i]` contains function signatures, or `0` if the item isn't a function. * Functions are themselves encoded as arrays. The first item is a list of * types representing the function's inputs, and the second list item is a list * of types representing the function's output. Tuples are flattened. @@ -2511,6 +2518,8 @@ ${item.displayPath}${name}\ * * `p` is a list of path/type pairs. It is used for parents and function parameters. * + * `c` is an array of item indices that are deprecated. + * * @type {{ * doc: string, * a: Object, From 10f491756876d378f2e1d7fa84bee1410b480212 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sun, 3 Sep 2023 08:21:18 +0530 Subject: [PATCH 2/5] Emit unused doc comment warnings for pat and expr fields --- compiler/rustc_lint/src/builtin.rs | 14 +++++++++ .../unused/unused-doc-comments-edge-cases.rs | 26 ++++++++++++++++ .../unused-doc-comments-edge-cases.stderr | 30 ++++++++++++++++--- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4b6917fdfdd..de228bdb850 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1001,8 +1001,22 @@ fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) { warn_if_doc(cx, arm_span, "match arms", &arm.attrs); } + fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &ast::Pat) { + if let ast::PatKind::Struct(_, _, fields, _) = &pat.kind { + for field in fields { + warn_if_doc(cx, field.span, "pattern fields", &field.attrs); + } + } + } + fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { warn_if_doc(cx, expr.span, "expressions", &expr.attrs); + + if let ExprKind::Struct(s) = &expr.kind { + for field in &s.fields { + warn_if_doc(cx, field.span, "expression fields", &field.attrs); + } + } } fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) { diff --git a/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs b/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs index 54d86c31fb4..ba32fb566e8 100644 --- a/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs +++ b/tests/ui/lint/unused/unused-doc-comments-edge-cases.rs @@ -26,6 +26,32 @@ fn doc_comment_on_expr(num: u8) -> bool { num == 3 } +fn doc_comment_on_expr_field() -> bool { + struct S { foo: i32 } + + let x = S { + /// useless doc comment + //~^ ERROR: unused doc comment + foo: 3 + }; + + true +} + +fn doc_comment_on_pat_field() -> bool { + struct S { foo: i32 } + + let S { + /// useless doc comment + //~^ ERROR: unused doc comment + foo + } = S { + foo: 3 + }; + + true +} + fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} //~^ ERROR: unused doc comment diff --git a/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr index 078b780d8b9..b5aa6215797 100644 --- a/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr +++ b/tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr @@ -42,7 +42,29 @@ LL | num == 3 = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:29:27 + --> $DIR/unused-doc-comments-edge-cases.rs:33:9 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | foo: 3 + | ------ rustdoc does not generate documentation for expression fields + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:45:9 + | +LL | /// useless doc comment + | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | +LL | foo + | --- rustdoc does not generate documentation for pattern fields + | + = help: use `//` for a plain comment + +error: unused doc comment + --> $DIR/unused-doc-comments-edge-cases.rs:55:27 | LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} | ^^^^^^^^^^^^ - rustdoc does not generate documentation for generic parameters @@ -50,7 +72,7 @@ LL | fn doc_comment_on_generic<#[doc = "x"] T>(val: T) {} = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:33:5 + --> $DIR/unused-doc-comments-edge-cases.rs:59:5 | LL | /// unused doc comment | ^^^^^^^^^^^^^^^^^^^^^^ @@ -63,7 +85,7 @@ LL | | } = help: use `//` for a plain comment error: unused doc comment - --> $DIR/unused-doc-comments-edge-cases.rs:40:1 + --> $DIR/unused-doc-comments-edge-cases.rs:66:1 | LL | /// unused doc comment | ^^^^^^^^^^^^^^^^^^^^^^ @@ -89,7 +111,7 @@ help: you might have meant to return this value LL | return true; | ++++++ + -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0308, E0658. For more information about an error, try `rustc --explain E0308`. From a0a71732f92919f80b96a24612501020e32ca2a7 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Sun, 3 Sep 2023 08:38:17 +0530 Subject: [PATCH 3/5] Fix code that now emits unused doc comment warning for expr field --- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index c08fe54c39c..7736183027f 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -555,8 +555,8 @@ fn lower_path(&mut self, qpath: &hir::QPath<'_>, id: hir::HirId, span: Span) -> subpattern: pattern, ascription: Ascription { annotation, - /// Note that use `Contravariant` here. See the - /// `variance` field documentation for details. + // Note that use `Contravariant` here. See the + // `variance` field documentation for details. variance: ty::Variance::Contravariant, }, }, From 7e648f0d7209b6a985475a4cc4a1a02fce10bd86 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 3 Sep 2023 12:46:56 +0200 Subject: [PATCH 4/5] Use named arguments in `code-color.goml` GUI test --- tests/rustdoc-gui/code-color.goml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/rustdoc-gui/code-color.goml b/tests/rustdoc-gui/code-color.goml index 833fa05db42..cfc997d6517 100644 --- a/tests/rustdoc-gui/code-color.goml +++ b/tests/rustdoc-gui/code-color.goml @@ -19,6 +19,18 @@ define-function: ( }, ) -call-function: ("check-colors", ("ayu", "rgb(230, 225, 207)", "rgb(255, 180, 84)")) -call-function: ("check-colors", ("dark", "rgb(221, 221, 221)", "rgb(221, 221, 221)")) -call-function: ("check-colors", ("light", "rgb(0, 0, 0)", "rgb(0, 0, 0)")) +call-function: ("check-colors", { + "theme": "ayu", + "doc_code_color": "rgb(230, 225, 207)", + "doc_inline_code_color": "rgb(255, 180, 84)", +}) +call-function: ("check-colors", { + "theme": "dark", + "doc_code_color": "rgb(221, 221, 221)", + "doc_inline_code_color": "rgb(221, 221, 221)", +}) +call-function: ("check-colors", { + "theme": "light", + "doc_code_color": "rgb(0, 0, 0)", + "doc_inline_code_color": "rgb(0, 0, 0)", +}) From 8e5dff1d382098cb1d9e547c0c2dc92c7fd4b547 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 3 Sep 2023 12:49:22 +0200 Subject: [PATCH 5/5] Migrate GUI colors test to original CSS color format --- tests/rustdoc-gui/code-color.goml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/rustdoc-gui/code-color.goml b/tests/rustdoc-gui/code-color.goml index cfc997d6517..92bdfb25b00 100644 --- a/tests/rustdoc-gui/code-color.goml +++ b/tests/rustdoc-gui/code-color.goml @@ -21,16 +21,16 @@ define-function: ( call-function: ("check-colors", { "theme": "ayu", - "doc_code_color": "rgb(230, 225, 207)", - "doc_inline_code_color": "rgb(255, 180, 84)", + "doc_code_color": "#e6e1cf", + "doc_inline_code_color": "#ffb454", }) call-function: ("check-colors", { "theme": "dark", - "doc_code_color": "rgb(221, 221, 221)", - "doc_inline_code_color": "rgb(221, 221, 221)", + "doc_code_color": "#ddd", + "doc_inline_code_color": "#ddd", }) call-function: ("check-colors", { "theme": "light", - "doc_code_color": "rgb(0, 0, 0)", - "doc_inline_code_color": "rgb(0, 0, 0)", + "doc_code_color": "black", + "doc_inline_code_color": "black", })