From bcd7e2b38b3eb26004bf94a63814341329233491 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 15 Feb 2020 12:38:34 +0300 Subject: [PATCH 1/7] rustc_lint: Move `unused_doc_comments` from pre-expansion to early lints --- src/librustc_lint/lib.rs | 3 ++- src/test/ui/useless-comment.rs | 4 ++-- src/test/ui/useless-comment.stderr | 33 +++++++----------------------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 2204e104803..d3670056c1a 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -94,7 +94,7 @@ fn lint_mod(tcx: TyCtxt<'_>, module_def_id: DefId) { macro_rules! pre_expansion_lint_passes { ($macro:path, $args:tt) => { - $macro!($args, [KeywordIdents: KeywordIdents, UnusedDocComment: UnusedDocComment,]); + $macro!($args, [KeywordIdents: KeywordIdents,]); }; } @@ -114,6 +114,7 @@ macro_rules! early_lint_passes { NonAsciiIdents: NonAsciiIdents, IncompleteFeatures: IncompleteFeatures, RedundantSemicolon: RedundantSemicolon, + UnusedDocComment: UnusedDocComment, ] ); }; diff --git a/src/test/ui/useless-comment.rs b/src/test/ui/useless-comment.rs index 7d2e5ab6f2b..f19c97e0102 100644 --- a/src/test/ui/useless-comment.rs +++ b/src/test/ui/useless-comment.rs @@ -6,7 +6,7 @@ macro_rules! mac { () => {} } -/// foo //~ ERROR unused doc comment +/// foo //FIXME ERROR unused doc comment mac!(); fn foo() { @@ -29,7 +29,7 @@ fn foo() { #[doc = "bar"] //~ ERROR unused doc comment 3; - /// bar //~ ERROR unused doc comment + /// bar //FIXME ERROR unused doc comment mac!(); let x = /** comment */ 47; //~ ERROR unused doc comment diff --git a/src/test/ui/useless-comment.stderr b/src/test/ui/useless-comment.stderr index e5e4290d0e1..beb2a09f10e 100644 --- a/src/test/ui/useless-comment.stderr +++ b/src/test/ui/useless-comment.stderr @@ -1,18 +1,3 @@ -error: unused doc comment - --> $DIR/useless-comment.rs:9:1 - | -LL | /// foo - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | mac!(); - | ------- rustdoc does not generate documentation for macro expansions - | -note: the lint level is defined here - --> $DIR/useless-comment.rs:3:9 - | -LL | #![deny(unused_doc_comments)] - | ^^^^^^^^^^^^^^^^^^^ - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - error: unused doc comment --> $DIR/useless-comment.rs:13:5 | @@ -20,6 +5,12 @@ LL | /// a | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | let x = 12; | ----------- rustdoc does not generate documentation for statements + | +note: the lint level is defined here + --> $DIR/useless-comment.rs:3:9 + | +LL | #![deny(unused_doc_comments)] + | ^^^^^^^^^^^^^^^^^^^ error: unused doc comment --> $DIR/useless-comment.rs:16:5 @@ -68,16 +59,6 @@ LL | #[doc = "bar"] LL | 3; | - rustdoc does not generate documentation for expressions -error: unused doc comment - --> $DIR/useless-comment.rs:32:5 - | -LL | /// bar - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | mac!(); - | ------- rustdoc does not generate documentation for macro expansions - | - = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion - error: unused doc comment --> $DIR/useless-comment.rs:35:13 | @@ -94,5 +75,5 @@ LL | | LL | | } | |_____- rustdoc does not generate documentation for expressions -error: aborting due to 10 previous errors +error: aborting due to 8 previous errors From 1bd6b98220a7d161288f04a03111ca77b0a4845d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 15 Feb 2020 15:29:45 +0300 Subject: [PATCH 2/7] Emit some additional `unused_doc_comments` lints outside of the main pass --- src/librustc_expand/expand.rs | 5 +++++ src/librustc_lint/builtin.rs | 17 ++++++++++------- src/librustc_session/lint/builtin.rs | 8 ++++++++ src/test/ui/useless-comment.rs | 4 ++-- src/test/ui/useless-comment.stderr | 26 +++++++++++++++++++------- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 371d1f744dd..3c720271e4b 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -14,6 +14,7 @@ use rustc_parse::configure; use rustc_parse::parser::Parser; use rustc_parse::validate_attr; use rustc_parse::DirectoryOwnership; +use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS; use rustc_session::parse::{feature_err, ParseSess}; use rustc_span::source_map::respan; use rustc_span::symbol::{sym, Symbol}; @@ -1090,6 +1091,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { .note("this may become a hard error in a future release") .emit(); } + + if attr.doc_str().is_some() { + self.cx.parse_sess.buffer_lint(&UNUSED_DOC_COMMENTS, attr.span, ast::CRATE_NODE_ID, "yep, it's unused"); + } } } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 93fca43d67c..c0eee7e05c8 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -738,15 +738,18 @@ impl EarlyLintPass for DeprecatedAttr { } } -declare_lint! { - pub UNUSED_DOC_COMMENTS, - Warn, - "detects doc comments that aren't used by rustdoc" +trait UnusedDocCommentExt { + fn warn_if_doc( + &self, + cx: &EarlyContext<'_>, + node_span: Span, + node_kind: &str, + is_macro_expansion: bool, + attrs: &[ast::Attribute], + ); } -declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]); - -impl UnusedDocComment { +impl UnusedDocCommentExt for UnusedDocComment { fn warn_if_doc( &self, cx: &EarlyContext<'_>, diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index 5a360b40d61..5e3367f8696 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -557,3 +557,11 @@ declare_lint_pass! { INLINE_NO_SANITIZE, ] } + +declare_lint! { + pub UNUSED_DOC_COMMENTS, + Warn, + "detects doc comments that aren't used by rustdoc" +} + +declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]); diff --git a/src/test/ui/useless-comment.rs b/src/test/ui/useless-comment.rs index f19c97e0102..d13db2f8f78 100644 --- a/src/test/ui/useless-comment.rs +++ b/src/test/ui/useless-comment.rs @@ -6,7 +6,7 @@ macro_rules! mac { () => {} } -/// foo //FIXME ERROR unused doc comment +/// foo //~ ERROR yep, it's unused mac!(); fn foo() { @@ -29,7 +29,7 @@ fn foo() { #[doc = "bar"] //~ ERROR unused doc comment 3; - /// bar //FIXME ERROR unused doc comment + /// bar //~ ERROR yep, it's unused mac!(); let x = /** comment */ 47; //~ ERROR unused doc comment diff --git a/src/test/ui/useless-comment.stderr b/src/test/ui/useless-comment.stderr index beb2a09f10e..76b37cfec71 100644 --- a/src/test/ui/useless-comment.stderr +++ b/src/test/ui/useless-comment.stderr @@ -1,3 +1,21 @@ +error: yep, it's unused + --> $DIR/useless-comment.rs:9:1 + | +LL | /// foo + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/useless-comment.rs:3:9 + | +LL | #![deny(unused_doc_comments)] + | ^^^^^^^^^^^^^^^^^^^ + +error: yep, it's unused + --> $DIR/useless-comment.rs:32:5 + | +LL | /// bar + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: unused doc comment --> $DIR/useless-comment.rs:13:5 | @@ -5,12 +23,6 @@ LL | /// a | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | let x = 12; | ----------- rustdoc does not generate documentation for statements - | -note: the lint level is defined here - --> $DIR/useless-comment.rs:3:9 - | -LL | #![deny(unused_doc_comments)] - | ^^^^^^^^^^^^^^^^^^^ error: unused doc comment --> $DIR/useless-comment.rs:16:5 @@ -75,5 +87,5 @@ LL | | LL | | } | |_____- rustdoc does not generate documentation for expressions -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors From fa73b617c23a529b1ad966a9814961f1cbc78f6c Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 21 Feb 2020 16:01:48 -0800 Subject: [PATCH 3/7] clean things up --- src/librustc_expand/expand.rs | 8 +++++++- src/librustc_lint/builtin.rs | 29 +++++++---------------------- src/librustc_lint/context.rs | 5 +++++ src/librustc_session/lint.rs | 1 + src/librustc_session/parse.rs | 19 +++++++++++++++++++ src/test/ui/useless-comment.rs | 4 ++-- src/test/ui/useless-comment.stderr | 11 +++++++---- 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 3c720271e4b..0c87d3fe8fc 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -14,6 +14,7 @@ use rustc_parse::configure; use rustc_parse::parser::Parser; use rustc_parse::validate_attr; use rustc_parse::DirectoryOwnership; +use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS; use rustc_session::parse::{feature_err, ParseSess}; use rustc_span::source_map::respan; @@ -1093,7 +1094,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } if attr.doc_str().is_some() { - self.cx.parse_sess.buffer_lint(&UNUSED_DOC_COMMENTS, attr.span, ast::CRATE_NODE_ID, "yep, it's unused"); + self.cx.parse_sess.buffer_lint_with_diagnostic( + &UNUSED_DOC_COMMENTS, + attr.span, + ast::CRATE_NODE_ID, + "unused doc comment", + BuiltinLintDiagnostics::UnusedDocComment(attr.span)); } } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index c0eee7e05c8..705097d4644 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -744,7 +744,6 @@ trait UnusedDocCommentExt { cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, - is_macro_expansion: bool, attrs: &[ast::Attribute], ); } @@ -755,7 +754,6 @@ impl UnusedDocCommentExt for UnusedDocComment { cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, - is_macro_expansion: bool, attrs: &[ast::Attribute], ) { let mut attrs = attrs.into_iter().peekable(); @@ -783,12 +781,6 @@ impl UnusedDocCommentExt for UnusedDocComment { node_span, format!("rustdoc does not generate documentation for {}", node_kind), ); - if is_macro_expansion { - err.help( - "to document an item produced by a macro, \ - the macro must produce the documentation as part of its expansion", - ); - } err.emit(); }); } @@ -797,31 +789,24 @@ impl UnusedDocCommentExt for UnusedDocComment { } impl EarlyLintPass for UnusedDocComment { - fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { - if let ast::ItemKind::Mac(..) = item.kind { - self.warn_if_doc(cx, item.span, "macro expansions", true, &item.attrs); - } - } - fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) { - let (kind, is_macro_expansion) = match stmt.kind { - ast::StmtKind::Local(..) => ("statements", false), - ast::StmtKind::Item(..) => ("inner items", false), - ast::StmtKind::Mac(..) => ("macro expansions", true), + let kind = match stmt.kind { + ast::StmtKind::Local(..) => "statements", + ast::StmtKind::Item(..) => "inner items", // expressions will be reported by `check_expr`. - ast::StmtKind::Semi(..) | ast::StmtKind::Expr(..) => return, + ast::StmtKind::Semi(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Mac(..) => return, }; - self.warn_if_doc(cx, stmt.span, kind, is_macro_expansion, stmt.kind.attrs()); + self.warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs()); } fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) { let arm_span = arm.pat.span.with_hi(arm.body.span.hi()); - self.warn_if_doc(cx, arm_span, "match arms", false, &arm.attrs); + self.warn_if_doc(cx, arm_span, "match arms", &arm.attrs); } fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - self.warn_if_doc(cx, expr.span, "expressions", false, &expr.attrs); + self.warn_if_doc(cx, expr.span, "expressions", &expr.attrs); } } diff --git a/src/librustc_lint/context.rs b/src/librustc_lint/context.rs index 8e8beefa72f..adad1198b09 100644 --- a/src/librustc_lint/context.rs +++ b/src/librustc_lint/context.rs @@ -565,6 +565,11 @@ pub trait LintContext: Sized { BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => { stability::deprecation_suggestion(&mut db, suggestion, span) } + BuiltinLintDiagnostics::UnusedDocComment(span) => { + db.span_label(span, "rustdoc does not generate documentation for macros"); + db.help("to document an item produced by a macro, \ + the macro must produce the documentation as part of its expansion"); + } } // Rewrap `db`, and pass control to the user. decorate(LintDiagnosticBuilder::new(db)); diff --git a/src/librustc_session/lint.rs b/src/librustc_session/lint.rs index 983dfb19919..6d4f1ff5b48 100644 --- a/src/librustc_session/lint.rs +++ b/src/librustc_session/lint.rs @@ -190,6 +190,7 @@ pub enum BuiltinLintDiagnostics { UnusedImports(String, Vec<(Span, String)>), RedundantImport(Vec<(Span, bool)>, Ident), DeprecatedMacro(Option, Span), + UnusedDocComment(Span), } /// Lints that are buffered up early on in the `Session` before the diff --git a/src/librustc_session/parse.rs b/src/librustc_session/parse.rs index 6a4871b6da0..30888e343ed 100644 --- a/src/librustc_session/parse.rs +++ b/src/librustc_session/parse.rs @@ -176,6 +176,25 @@ impl ParseSess { }); } + pub fn buffer_lint_with_diagnostic( + &self, + lint: &'static Lint, + span: impl Into, + node_id: NodeId, + msg: &str, + diagnostic: BuiltinLintDiagnostics, + ) { + self.buffered_lints.with_lock(|buffered_lints| { + buffered_lints.push(BufferedEarlyLint { + span: span.into(), + node_id, + msg: msg.into(), + lint_id: LintId::of(lint), + diagnostic, + }); + }); + } + /// Extend an error with a suggestion to wrap an expression with parentheses to allow the /// parser to continue parsing the following operation as part of the same expression. pub fn expr_parentheses_needed( diff --git a/src/test/ui/useless-comment.rs b/src/test/ui/useless-comment.rs index d13db2f8f78..7d2e5ab6f2b 100644 --- a/src/test/ui/useless-comment.rs +++ b/src/test/ui/useless-comment.rs @@ -6,7 +6,7 @@ macro_rules! mac { () => {} } -/// foo //~ ERROR yep, it's unused +/// foo //~ ERROR unused doc comment mac!(); fn foo() { @@ -29,7 +29,7 @@ fn foo() { #[doc = "bar"] //~ ERROR unused doc comment 3; - /// bar //~ ERROR yep, it's unused + /// bar //~ ERROR unused doc comment mac!(); let x = /** comment */ 47; //~ ERROR unused doc comment diff --git a/src/test/ui/useless-comment.stderr b/src/test/ui/useless-comment.stderr index 76b37cfec71..92817321a88 100644 --- a/src/test/ui/useless-comment.stderr +++ b/src/test/ui/useless-comment.stderr @@ -1,20 +1,23 @@ -error: yep, it's unused +error: unused doc comment --> $DIR/useless-comment.rs:9:1 | LL | /// foo - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros | note: the lint level is defined here --> $DIR/useless-comment.rs:3:9 | LL | #![deny(unused_doc_comments)] | ^^^^^^^^^^^^^^^^^^^ + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion -error: yep, it's unused +error: unused doc comment --> $DIR/useless-comment.rs:32:5 | LL | /// bar - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macros + | + = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion error: unused doc comment --> $DIR/useless-comment.rs:13:5 From b44b4ca60257d80a431b4c1aceb3c1e09fb8389e Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 21 Feb 2020 16:46:14 -0800 Subject: [PATCH 4/7] rustfmt you cruel mistress --- src/librustc_expand/expand.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 0c87d3fe8fc..ab372a41e69 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -14,8 +14,8 @@ use rustc_parse::configure; use rustc_parse::parser::Parser; use rustc_parse::validate_attr; use rustc_parse::DirectoryOwnership; -use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS; +use rustc_session::lint::BuiltinLintDiagnostics; use rustc_session::parse::{feature_err, ParseSess}; use rustc_span::source_map::respan; use rustc_span::symbol::{sym, Symbol}; @@ -1099,7 +1099,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { attr.span, ast::CRATE_NODE_ID, "unused doc comment", - BuiltinLintDiagnostics::UnusedDocComment(attr.span)); + BuiltinLintDiagnostics::UnusedDocComment(attr.span), + ); } } } From 494dd0b71936813e3a5565d5ea88c6fdf07240e3 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 22 Feb 2020 08:28:56 -0800 Subject: [PATCH 5/7] Remove trait --- src/librustc_lint/builtin.rs | 71 +++++++++++++----------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 705097d4644..54b5b922ac7 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -738,52 +738,33 @@ impl EarlyLintPass for DeprecatedAttr { } } -trait UnusedDocCommentExt { - fn warn_if_doc( - &self, - cx: &EarlyContext<'_>, - node_span: Span, - node_kind: &str, - attrs: &[ast::Attribute], - ); -} +fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &[ast::Attribute]) { + let mut attrs = attrs.into_iter().peekable(); -impl UnusedDocCommentExt for UnusedDocComment { - fn warn_if_doc( - &self, - cx: &EarlyContext<'_>, - node_span: Span, - node_kind: &str, - attrs: &[ast::Attribute], - ) { - let mut attrs = attrs.into_iter().peekable(); + // Accumulate a single span for sugared doc comments. + let mut sugared_span: Option = None; - // Accumulate a single span for sugared doc comments. - let mut sugared_span: Option = None; + while let Some(attr) = attrs.next() { + if attr.is_doc_comment() { + sugared_span = + Some(sugared_span.map_or_else(|| attr.span, |span| span.with_hi(attr.span.hi()))); + } - while let Some(attr) = attrs.next() { - if attr.is_doc_comment() { - sugared_span = Some( - sugared_span.map_or_else(|| attr.span, |span| span.with_hi(attr.span.hi())), + if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() { + continue; + } + + let span = sugared_span.take().unwrap_or_else(|| attr.span); + + if attr.is_doc_comment() || attr.check_name(sym::doc) { + cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, |lint| { + let mut err = lint.build("unused doc comment"); + err.span_label( + node_span, + format!("rustdoc does not generate documentation for {}", node_kind), ); - } - - if attrs.peek().map(|next_attr| next_attr.is_doc_comment()).unwrap_or_default() { - continue; - } - - let span = sugared_span.take().unwrap_or_else(|| attr.span); - - if attr.is_doc_comment() || attr.check_name(sym::doc) { - cx.struct_span_lint(UNUSED_DOC_COMMENTS, span, |lint| { - let mut err = lint.build("unused doc comment"); - err.span_label( - node_span, - format!("rustdoc does not generate documentation for {}", node_kind), - ); - err.emit(); - }); - } + err.emit(); + }); } } } @@ -797,16 +778,16 @@ impl EarlyLintPass for UnusedDocComment { ast::StmtKind::Semi(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Mac(..) => return, }; - self.warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs()); + warn_if_doc(cx, stmt.span, kind, stmt.kind.attrs()); } fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) { let arm_span = arm.pat.span.with_hi(arm.body.span.hi()); - self.warn_if_doc(cx, arm_span, "match arms", &arm.attrs); + warn_if_doc(cx, arm_span, "match arms", &arm.attrs); } fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) { - self.warn_if_doc(cx, expr.span, "expressions", &expr.attrs); + warn_if_doc(cx, expr.span, "expressions", &expr.attrs); } } From 40c67221e272c007cfae407d4398b166754491c9 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 22 Feb 2020 15:13:22 -0800 Subject: [PATCH 6/7] make doc comments regular comments --- src/libstd/sys/wasi/fd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/wasi/fd.rs b/src/libstd/sys/wasi/fd.rs index 00327c1743c..bf7db3a799e 100644 --- a/src/libstd/sys/wasi/fd.rs +++ b/src/libstd/sys/wasi/fd.rs @@ -13,7 +13,7 @@ pub struct WasiFd { fn iovec<'a>(a: &'a mut [IoSliceMut<'_>]) -> &'a [wasi::Iovec] { assert_eq!(mem::size_of::>(), mem::size_of::()); assert_eq!(mem::align_of::>(), mem::align_of::()); - /// SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout + // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout unsafe { mem::transmute(a) } @@ -22,7 +22,7 @@ fn iovec<'a>(a: &'a mut [IoSliceMut<'_>]) -> &'a [wasi::Iovec] { fn ciovec<'a>(a: &'a [IoSlice<'_>]) -> &'a [wasi::Ciovec] { assert_eq!(mem::size_of::>(), mem::size_of::()); assert_eq!(mem::align_of::>(), mem::align_of::()); - /// SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout + // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout unsafe { mem::transmute(a) } From 09bc5e3d969a154ffcbeb6827a901d36a6a854eb Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 22 Feb 2020 15:29:03 -0800 Subject: [PATCH 7/7] rustfmt darnit --- src/libstd/sys/wasi/fd.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libstd/sys/wasi/fd.rs b/src/libstd/sys/wasi/fd.rs index bf7db3a799e..8458ded5db0 100644 --- a/src/libstd/sys/wasi/fd.rs +++ b/src/libstd/sys/wasi/fd.rs @@ -14,18 +14,14 @@ fn iovec<'a>(a: &'a mut [IoSliceMut<'_>]) -> &'a [wasi::Iovec] { assert_eq!(mem::size_of::>(), mem::size_of::()); assert_eq!(mem::align_of::>(), mem::align_of::()); // SAFETY: `IoSliceMut` and `IoVec` have exactly the same memory layout - unsafe { - mem::transmute(a) - } + unsafe { mem::transmute(a) } } fn ciovec<'a>(a: &'a [IoSlice<'_>]) -> &'a [wasi::Ciovec] { assert_eq!(mem::size_of::>(), mem::size_of::()); assert_eq!(mem::align_of::>(), mem::align_of::()); // SAFETY: `IoSlice` and `CIoVec` have exactly the same memory layout - unsafe { - mem::transmute(a) - } + unsafe { mem::transmute(a) } } impl WasiFd {