diff options
| author | bors <bors@rust-lang.org> | 2021-09-11 03:30:55 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-11 03:30:55 +0000 |
| commit | 22719efcc570b043f2e519d6025e5f36eab38fe2 (patch) | |
| tree | f7fb4178f9e9964f7a1965b9c13e9c1654cb1cd4 /src | |
| parent | b69fe57261086e70aea9d5b58819a1794bf7c121 (diff) | |
| parent | f77311bc2b01a2708e5676a9a3bcb3d07d5040e2 (diff) | |
Auto merge of #88824 - Manishearth:rollup-7bzk9h6, r=Manishearth
Rollup of 15 pull requests
Successful merges:
- #85200 (Ignore derived Clone and Debug implementations during dead code analysis)
- #86165 (Add proc_macro::Span::{before, after}.)
- #87088 (Fix stray notes when the source code is not available)
- #87441 (Emit suggestion when passing byte literal to format macro)
- #88546 (Emit proper errors when on missing closure braces)
- #88578 (fix(rustc): suggest `items` be borrowed in `for i in items[x..]`)
- #88632 (Fix issues with Markdown summary options)
- #88639 (rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields)
- #88667 (Tweak `write_fmt` doc.)
- #88720 (Rustdoc coverage fields count)
- #88732 (RustWrapper: avoid deleted unclear attribute methods)
- #88742 (Fix table in docblocks)
- #88776 (Workaround blink/chromium grid layout limitation of 1000 rows)
- #88807 (Fix typo in docs for iterators)
- #88812 (Fix typo `option` -> `options`.)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
62 files changed, 657 insertions, 125 deletions
diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index a10928a7471..444b1cbf3cc 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -375,7 +375,7 @@ Any reuse of a named label, local or otherwise, can result in a assembler or lin As a consequence, you should only use GNU assembler **numeric** [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions. -Moreover, on x86 when using the default intel syntax, due to [an llvm bug], you shouldn't use labels exclusively made of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values. Using `option(att_syntax)` will avoid any ambiguity, but that affects the syntax of the _entire_ `asm!` block. +Moreover, on x86 when using the default intel syntax, due to [an llvm bug], you shouldn't use labels exclusively made of `0` and `1` digits, e.g. `0`, `11` or `101010`, as they may end up being interpreted as binary values. Using `options(att_syntax)` will avoid any ambiguity, but that affects the syntax of the _entire_ `asm!` block. ```rust,allow_fail #![feature(asm)] diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 0c81a558430..78e4e4ec116 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -557,7 +557,6 @@ fn build_macro( name: Symbol, import_def_id: Option<DefId>, ) -> clean::ItemKind { - let imported_from = cx.tcx.crate_name(def_id.krate); match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.sess()) { LoadedMacro::MacroDef(item_def, _) => { if let ast::ItemKind::MacroDef(ref def) = item_def.kind { @@ -569,7 +568,6 @@ fn build_macro( def_id, cx.tcx.visibility(import_def_id.unwrap_or(def_id)), ), - imported_from: Some(imported_from), }) } else { unreachable!() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e2ad21bba21..7ece2acac7a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1859,7 +1859,6 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) { } ItemKind::Macro(ref macro_def) => MacroItem(Macro { source: display_macro_source(cx, name, ¯o_def, def_id, &item.vis), - imported_from: None, }), ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => { let items = item_ids diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 5eff56a2200..5f09e6ced96 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2202,7 +2202,6 @@ crate struct ImportSource { #[derive(Clone, Debug)] crate struct Macro { crate source: String, - crate imported_from: Option<Symbol>, } #[derive(Clone, Debug)] diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5cd5254f328..c971e231463 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -48,7 +48,7 @@ use pulldown_cmark::{ mod tests; /// Options for rendering Markdown in the main body of documentation. -pub(crate) fn opts() -> Options { +pub(crate) fn main_body_opts() -> Options { Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH @@ -56,9 +56,13 @@ pub(crate) fn opts() -> Options { | Options::ENABLE_SMART_PUNCTUATION } -/// A subset of [`opts()`] used for rendering summaries. +/// Options for rendering Markdown in summaries (e.g., in search results). pub(crate) fn summary_opts() -> Options { - Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION | Options::ENABLE_TABLES + Options::ENABLE_TABLES + | Options::ENABLE_FOOTNOTES + | Options::ENABLE_STRIKETHROUGH + | Options::ENABLE_TASKLISTS + | Options::ENABLE_SMART_PUNCTUATION } /// When `to_string` is called, this struct will emit the HTML corresponding to @@ -441,6 +445,42 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> { } } +/// Wrap HTML tables into `<div>` to prevent having the doc blocks width being too big. +struct TableWrapper<'a, I: Iterator<Item = Event<'a>>> { + inner: I, + stored_events: VecDeque<Event<'a>>, +} + +impl<'a, I: Iterator<Item = Event<'a>>> TableWrapper<'a, I> { + fn new(iter: I) -> Self { + Self { inner: iter, stored_events: VecDeque::new() } + } +} + +impl<'a, I: Iterator<Item = Event<'a>>> Iterator for TableWrapper<'a, I> { + type Item = Event<'a>; + + fn next(&mut self) -> Option<Self::Item> { + if let Some(first) = self.stored_events.pop_front() { + return Some(first); + } + + let event = self.inner.next()?; + + Some(match event { + Event::Start(Tag::Table(t)) => { + self.stored_events.push_back(Event::Start(Tag::Table(t))); + Event::Html(CowStr::Borrowed("<div>")) + } + Event::End(Tag::Table(t)) => { + self.stored_events.push_back(Event::Html(CowStr::Borrowed("</div>"))); + Event::End(Tag::Table(t)) + } + e => e, + }) + } +} + type SpannedEvent<'a> = (Event<'a>, Range<usize>); /// Make headings links with anchor IDs and build up TOC. @@ -981,7 +1021,7 @@ impl Markdown<'_> { } }; - let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); + let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut replacer)); let p = p.into_offset_iter(); let mut s = String::with_capacity(md.len() * 3 / 2); @@ -989,6 +1029,7 @@ impl Markdown<'_> { let p = HeadingLinks::new(p, None, &mut ids); let p = Footnotes::new(p); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); + let p = TableWrapper::new(p); let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); @@ -1000,7 +1041,7 @@ impl MarkdownWithToc<'_> { crate fn into_string(self) -> String { let MarkdownWithToc(md, mut ids, codes, edition, playground) = self; - let p = Parser::new_ext(md, opts()).into_offset_iter(); + let p = Parser::new_ext(md, main_body_opts()).into_offset_iter(); let mut s = String::with_capacity(md.len() * 3 / 2); @@ -1009,7 +1050,8 @@ impl MarkdownWithToc<'_> { { let p = HeadingLinks::new(p, Some(&mut toc), &mut ids); let p = Footnotes::new(p); - let p = CodeBlocks::new(p.map(|(ev, _)| ev), codes, edition, playground); + let p = TableWrapper::new(p.map(|(ev, _)| ev)); + let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); } @@ -1025,7 +1067,7 @@ impl MarkdownHtml<'_> { if md.is_empty() { return String::new(); } - let p = Parser::new_ext(md, opts()).into_offset_iter(); + let p = Parser::new_ext(md, main_body_opts()).into_offset_iter(); // Treat inline HTML as plain text. let p = p.map(|event| match event.0 { @@ -1037,7 +1079,8 @@ impl MarkdownHtml<'_> { let p = HeadingLinks::new(p, None, &mut ids); let p = Footnotes::new(p); - let p = CodeBlocks::new(p.map(|(ev, _)| ev), codes, edition, playground); + let p = TableWrapper::new(p.map(|(ev, _)| ev)); + let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); s @@ -1099,7 +1142,7 @@ fn markdown_summary_with_limit( } }; - let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); + let p = Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut replacer)); let mut p = LinkReplacer::new(p, link_names); let mut buf = HtmlWithLimit::new(length_limit); @@ -1246,7 +1289,8 @@ crate fn markdown_links(md: &str) -> Vec<MarkdownLink> { }); None }; - let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut push)).into_offset_iter(); + let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut push)) + .into_offset_iter(); // There's no need to thread an IdMap through to here because // the IDs generated aren't going to be emitted anywhere. @@ -1285,7 +1329,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeB return code_blocks; } - let mut p = Parser::new_ext(md, opts()).into_offset_iter(); + let mut p = Parser::new_ext(md, main_body_opts()).into_offset_iter(); while let Some((event, offset)) = p.next() { if let Event::Start(Tag::CodeBlock(syntax)) = event { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 172fe5d164b..f71660c4b2a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -224,7 +224,6 @@ struct AllTypes { opaque_tys: FxHashSet<ItemEntry>, statics: FxHashSet<ItemEntry>, constants: FxHashSet<ItemEntry>, - keywords: FxHashSet<ItemEntry>, attributes: FxHashSet<ItemEntry>, derives: FxHashSet<ItemEntry>, trait_aliases: FxHashSet<ItemEntry>, @@ -245,7 +244,6 @@ impl AllTypes { opaque_tys: new_set(100), statics: new_set(100), constants: new_set(100), - keywords: new_set(100), attributes: new_set(100), derives: new_set(100), trait_aliases: new_set(100), diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 470749ef7b3..52505f2d634 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -256,6 +256,10 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl debug!("{:?}", indices); let mut curty = None; + // See: https://github.com/rust-lang/rust/issues/88545 + let item_table_block_size = 900usize; + let mut item_table_nth_element = 0usize; + for &idx in &indices { let myitem = &items[idx]; if myitem.is_stripped() { @@ -275,11 +279,13 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl write!( w, "<h2 id=\"{id}\" class=\"section-header\">\ - <a href=\"#{id}\">{name}</a></h2>\n{}", + <a href=\"#{id}\">{name}</a>\ + </h2>\n{}", ITEM_TABLE_OPEN, id = cx.derive_id(short.to_owned()), name = name ); + item_table_nth_element = 0; } match *myitem.kind { @@ -386,6 +392,13 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl ); } } + + item_table_nth_element += 1; + if item_table_nth_element > item_table_block_size { + w.write_str(ITEM_TABLE_CLOSE); + w.write_str(ITEM_TABLE_OPEN); + item_table_nth_element = 0; + } } if curty.is_some() { @@ -944,15 +957,15 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni } fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]) { - for (i, ty) in s - .iter() - .map(|f| if let clean::StructFieldItem(ref ty) = *f.kind { ty } else { unreachable!() }) - .enumerate() - { + for (i, ty) in s.iter().enumerate() { if i > 0 { w.write_str(", "); } - write!(w, "{}", ty.print(cx)); + match *ty.kind { + clean::StrippedItem(box clean::StructFieldItem(_)) => w.write_str("_"), + clean::StructFieldItem(ref ty) => write!(w, "{}", ty.print(cx)), + _ => unreachable!(), + } } } @@ -1068,24 +1081,27 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum name = variant.name.as_ref().unwrap(), ); for field in fields { - use crate::clean::StructFieldItem; - if let StructFieldItem(ref ty) = *field.kind { - let id = cx.derive_id(format!( - "variant.{}.field.{}", - variant.name.as_ref().unwrap(), - field.name.as_ref().unwrap() - )); - write!( - w, - "<span id=\"{id}\" class=\"variant small-section-header\">\ - <a href=\"#{id}\" class=\"anchor field\"></a>\ - <code>{f}: {t}</code>\ - </span>", - id = id, - f = field.name.as_ref().unwrap(), - t = ty.print(cx) - ); - document(w, cx, field, Some(variant)); + match *field.kind { + clean::StrippedItem(box clean::StructFieldItem(_)) => {} + clean::StructFieldItem(ref ty) => { + let id = cx.derive_id(format!( + "variant.{}.field.{}", + variant.name.as_ref().unwrap(), + field.name.as_ref().unwrap() + )); + write!( + w, + "<span id=\"{id}\" class=\"variant small-section-header\">\ + <a href=\"#{id}\" class=\"anchor field\"></a>\ + <code>{f}: {t}</code>\ + </span>", + id = id, + f = field.name.as_ref().unwrap(), + t = ty.print(cx) + ); + document(w, cx, field, Some(variant)); + } + _ => unreachable!(), } } w.write_str("</div></div>"); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 23ca6eeaf3b..2d4bfc62af6 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -522,6 +522,11 @@ nav.sub { position: relative; } +.docblock > * { + max-width: 100%; + overflow-x: auto; +} + .content .out-of-band { flex-grow: 0; text-align: right; diff --git a/src/librustdoc/passes/bare_urls.rs b/src/librustdoc/passes/bare_urls.rs index 56ef15eb884..37faa674292 100644 --- a/src/librustdoc/passes/bare_urls.rs +++ b/src/librustdoc/passes/bare_urls.rs @@ -2,7 +2,7 @@ use super::Pass; use crate::clean::*; use crate::core::DocContext; use crate::fold::DocFolder; -use crate::html::markdown::opts; +use crate::html::markdown::main_body_opts; use core::ops::Range; use pulldown_cmark::{Event, Parser, Tag}; use regex::Regex; @@ -83,7 +83,7 @@ impl<'a, 'tcx> DocFolder for BareUrlsLinter<'a, 'tcx> { }); }; - let mut p = Parser::new_ext(&dox, opts()).into_offset_iter(); + let mut p = Parser::new_ext(&dox, main_body_opts()).into_offset_iter(); while let Some((event, range)) = p.next() { match event { diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index 92e678e4c02..721af3313d2 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -4,8 +4,10 @@ use crate::fold::{self, DocFolder}; use crate::html::markdown::{find_testable_code, ErrorCodes}; use crate::passes::doc_test_lints::{should_have_doc_example, Tests}; use crate::passes::Pass; +use rustc_hir as hir; use rustc_lint::builtin::MISSING_DOCS; use rustc_middle::lint::LintLevelSource; +use rustc_middle::ty::DefIdTree; use rustc_session::lint; use rustc_span::FileName; use serde::Serialize; @@ -221,10 +223,42 @@ impl<'a, 'b> fold::DocFolder for CoverageCalculator<'a, 'b> { .hir() .local_def_id_to_hir_id(i.def_id.expect_def_id().expect_local()); let (level, source) = self.ctx.tcx.lint_level_at_node(MISSING_DOCS, hir_id); + + // In case we have: + // + // ``` + // enum Foo { Bar(u32) } + // // or: + // struct Bar(u32); + // ``` + // + // there is no need to require documentation on the fields of tuple variants and + // tuple structs. + let should_be_ignored = i + .def_id + .as_def_id() + .and_then(|def_id| self.ctx.tcx.parent(def_id)) + .and_then(|def_id| self.ctx.tcx.hir().get_if_local(def_id)) + .map(|node| { + matches!( + node, + hir::Node::Variant(hir::Variant { + data: hir::VariantData::Tuple(_, _), + .. + }) | hir::Node::Item(hir::Item { + kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _), _), + .. + }) + ) + }) + .unwrap_or(false); + // `missing_docs` is allow-by-default, so don't treat this as ignoring the item - // unless the user had an explicit `allow` - let should_have_docs = - level != lint::Level::Allow || matches!(source, LintLevelSource::Default); + // unless the user had an explicit `allow`. + // + let should_have_docs = !should_be_ignored + && (level != lint::Level::Allow || matches!(source, LintLevelSource::Default)); + debug!("counting {:?} {:?} in {:?}", i.type_(), i.name, filename); self.items.entry(filename).or_default().count_item( has_docs, diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index f29d38e3e07..a0144a5298e 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -2,7 +2,7 @@ use super::Pass; use crate::clean::*; use crate::core::DocContext; use crate::fold::DocFolder; -use crate::html::markdown::opts; +use crate::html::markdown::main_body_opts; use core::ops::Range; use pulldown_cmark::{Event, Parser, Tag}; use std::iter::Peekable; @@ -192,7 +192,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { let mut is_in_comment = None; let mut in_code_block = false; - let p = Parser::new_ext(&dox, opts()).into_offset_iter(); + let p = Parser::new_ext(&dox, main_body_opts()).into_offset_iter(); for (event, range) in p { match event { diff --git a/src/test/rustdoc-gui/docblock-table-overflow.goml b/src/test/rustdoc-gui/docblock-table-overflow.goml index 9ab7cd0fa07..10f516d2dae 100644 --- a/src/test/rustdoc-gui/docblock-table-overflow.goml +++ b/src/test/rustdoc-gui/docblock-table-overflow.goml @@ -7,3 +7,11 @@ compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["sc assert-property: (".top-doc .docblock", {"scrollWidth": "816"}) // However, since there is overflow in the <table>, its scroll width is bigger. assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"}) + +// Checking it works on other doc blocks as well... + +// Logically, the ".docblock" and the "<p>" should have the same scroll width. +compare-elements-property: ("#implementations + details .docblock", "#implementations + details .docblock > p", ["scrollWidth"]) +assert-property: ("#implementations + details .docblock", {"scrollWidth": "816"}) +// However, since there is overflow in the <table>, its scroll width is bigger. +assert-property: ("#implementations + details .docblock table", {"scrollWidth": "1573"}) diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index cb63a9f6002..d5835b78d2f 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -67,6 +67,15 @@ pub mod long_table { /// /// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq pub struct Foo; + + /// | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | + /// | ----------- | ----------- | ----------- | ----------- | + /// | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | + /// + /// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq + impl Foo { + pub fn foo(&self) {} + } } pub mod summary_table { diff --git a/src/test/rustdoc-ui/coverage/enum-tuple-documented.rs b/src/test/rustdoc-ui/coverage/enum-tuple-documented.rs new file mode 100644 index 00000000000..e9c165b1916 --- /dev/null +++ b/src/test/rustdoc-ui/coverage/enum-tuple-documented.rs @@ -0,0 +1,37 @@ +// compile-flags:-Z unstable-options --show-coverage +// check-pass + +// The point of this test is to ensure that the number of "documented" items +// is higher than in `enum-tuple.rs`. + +//! (remember the crate root is still a module) + +/// so check out this enum here +pub enum ThisEnum { + /// VarOne. + VarOne( + /// hello! + String, + ), + /// Var Two. + VarTwo( + /// Hello + String, + /// Bis repetita. + String, + ), +} + +/// Struct. +pub struct ThisStruct( + /// hello + u32, +); + +/// Struct. +pub struct ThisStruct2( + /// hello + u32, + /// Bis repetita. + u8, +); diff --git a/src/test/rustdoc-ui/coverage/enum-tuple-documented.stdout b/src/test/rustdoc-ui/coverage/enum-tuple-documented.stdout new file mode 100644 index 00000000000..82c98f43f3d --- /dev/null +++ b/src/test/rustdoc-ui/coverage/enum-tuple-documented.stdout @@ -0,0 +1,7 @@ ++-------------------------------------+------------+------------+------------+------------+ +| File | Documented | Percentage | Examples | Percentage | ++-------------------------------------+------------+------------+------------+------------+ +| ...overage/enum-tuple-documented.rs | 9 | 100.0% | 0 | 0.0% | ++-------------------------------------+------------+------------+------------+------------+ +| Total | 9 | 100.0% | 0 | 0.0% | ++-------------------------------------+------------+------------+------------+------------+ diff --git a/src/test/rustdoc-ui/coverage/enum-tuple.rs b/src/test/rustdoc-ui/coverage/enum-tuple.rs new file mode 100644 index 00000000000..5fb20545075 --- /dev/null +++ b/src/test/rustdoc-ui/coverage/enum-tuple.rs @@ -0,0 +1,18 @@ +// compile-flags:-Z unstable-options --show-coverage +// check-pass + +//! (remember the crate root is still a module) + +/// so check out this enum here +pub enum ThisEnum { + /// No need to document the field if there is only one in a tuple variant! + VarOne(String), + /// But if there is more than one... still fine! + VarTwo(String, String), +} + +/// Struct. +pub struct ThisStruct(u32); + +/// Struct. +pub struct ThisStruct2(u32, u8); diff --git a/src/test/rustdoc-ui/coverage/enum-tuple.stdout b/src/test/rustdoc-ui/coverage/enum-tuple.stdout new file mode 100644 index 00000000000..a3377d59c07 --- /dev/null +++ b/src/test/rustdoc-ui/coverage/enum-tuple.stdout @@ -0,0 +1,7 @@ ++-------------------------------------+------------+------------+------------+------------+ +| File | Documented | Percentage | Examples | Percentage | ++-------------------------------------+------------+------------+------------+------------+ +| ...ustdoc-ui/coverage/enum-tuple.rs | 6 | 100.0% | 0 | 0.0% | ++-------------------------------------+------------+------------+------------+------------+ +| Total | 6 | 100.0% | 0 | 0.0% | ++-------------------------------------+------------+------------+------------+------------+ diff --git a/src/test/rustdoc-ui/coverage/enums.stdout b/src/test/rustdoc-ui/coverage/enums.stdout index 414d60c86d3..64c012c1f66 100644 --- a/src/test/rustdoc-ui/coverage/enums.stdout +++ b/src/test/rustdoc-ui/coverage/enums.stdout @@ -1,7 +1,7 @@ +-------------------------------------+------------+------------+------------+------------+ | File | Documented | Percentage | Examples | Percentage | +-------------------------------------+------------+------------+------------+------------+ -| ...est/rustdoc-ui/coverage/enums.rs | 6 | 66.7% | 0 | 0.0% | +| ...est/rustdoc-ui/coverage/enums.rs | 6 | 75.0% | 0 | 0.0% | +-------------------------------------+------------+------------+------------+------------+ -| Total | 6 | 66.7% | 0 | 0.0% | +| Total | 6 | 75.0% | 0 | 0.0% | +-------------------------------------+------------+------------+------------+------------+ diff --git a/src/test/rustdoc/issue-88600.rs b/src/test/rustdoc/issue-88600.rs new file mode 100644 index 00000000000..3761805b48b --- /dev/null +++ b/src/test/rustdoc/issue-88600.rs @@ -0,0 +1,34 @@ +// This test ensure that #[doc(hidden)] is applied correctly in enum variant fields. + +// Denotes a field which should be hidden. +pub struct H; + +// Denotes a field which should not be hidden (shown). +pub struct S; + +// @has issue_88600/enum.FooEnum.html +pub enum FooEnum { + // @has - '//*[@id="variant.HiddenTupleItem"]//code' 'HiddenTupleItem(_)' + // @count - '//*[@id="variant.HiddenTupleItem.field.0"]' 0 + HiddenTupleItem(#[doc(hidden)] H), + // @has - '//*[@id="variant.MultipleHidden"]//code' 'MultipleHidden(_, _)' + // @count - '//*[@id="variant.MultipleHidden.field.0"]' 0 + // @count - '//*[@id="variant.MultipleHidden.field.1"]' 0 + MultipleHidden(#[doc(hidden)] H, #[doc(hidden)] H), + // @has - '//*[@id="variant.MixedHiddenFirst"]//code' 'MixedHiddenFirst(_, S)' + // @count - '//*[@id="variant.MixedHiddenFirst.field.0"]' 0 + // @has - '//*[@id="variant.MixedHiddenFirst.field.1"]' '1: S' + MixedHiddenFirst(#[doc(hidden)] H, S), + // @has - '//*[@id="variant.MixedHiddenLast"]//code' 'MixedHiddenLast(S, _)' + // @has - '//*[@id="variant.MixedHiddenLast.field.0"]' '0: S' + // @count - '//*[@id="variant.MixedHiddenLast.field.1"]' 0 + MixedHiddenLast(S, #[doc(hidden)] H), + // @has - '//*[@id="variant.HiddenStruct"]//code' 'HiddenStruct' + // @count - '//*[@id="variant.HiddenStruct.field.h"]' 0 + // @has - '//*[@id="variant.HiddenStruct.field.s"]' 's: S' + HiddenStruct { + #[doc(hidden)] + h: H, + s: S, + }, +} diff --git a/src/test/rustdoc/table-in-docblock.rs b/src/test/rustdoc/table-in-docblock.rs new file mode 100644 index 00000000000..858b589196e --- /dev/null +++ b/src/test/rustdoc/table-in-docblock.rs @@ -0,0 +1,16 @@ +#![crate_name = "foo"] + +// @has foo/struct.Foo.html +// @count - '//*[@class="docblock"]/div/table' 2 +// @!has - '//*[@class="docblock"]/table' +/// | hello | hello2 | +/// | ----- | ------ | +/// | data | data2 | +pub struct Foo; + +impl Foo { + /// | hello | hello2 | + /// | ----- | ------ | + /// | data | data2 | + pub fn foo(&self) {} +} diff --git a/src/test/ui/array-slice-vec/slice_binary_search.rs b/src/test/ui/array-slice-vec/slice_binary_search.rs index 12236960179..4d8022ecba7 100644 --- a/src/test/ui/array-slice-vec/slice_binary_search.rs +++ b/src/test/ui/array-slice-vec/slice_binary_search.rs @@ -2,6 +2,7 @@ // Test binary_search_by_key lifetime. Issue #34683 +#[allow(dead_code)] #[derive(Debug)] struct Assignment { topic: String, diff --git a/src/test/ui/borrowck/borrowck-unused-mut-locals.rs b/src/test/ui/borrowck/borrowck-unused-mut-locals.rs index fd0e346e2b4..23ef975cbbc 100644 --- a/src/test/ui/borrowck/borrowck-unused-mut-locals.rs +++ b/src/test/ui/borrowck/borrowck-unused-mut-locals.rs @@ -1,4 +1,5 @@ // run-pass +#![allow(dead_code)] #![deny(unused_mut)] #[derive(Debug)] diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs index 1cc22fac352..3399bc0018e 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.rs @@ -3,6 +3,7 @@ // check-pass #![allow(unreachable_code)] #![warn(unused)] +#![allow(dead_code)] #[derive(Debug)] struct Point { diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr index 4eac5a2d282..74109772724 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr @@ -1,5 +1,5 @@ warning: value captured by `a` is never read - --> $DIR/liveness.rs:23:9 + --> $DIR/liveness.rs:24:9 | LL | a = 1; | ^ @@ -13,7 +13,7 @@ LL | #![warn(unused)] = help: did you mean to capture by reference instead? warning: unused variable: `a` - --> $DIR/liveness.rs:32:9 + --> $DIR/liveness.rs:33:9 | LL | a += 1; | ^ @@ -27,7 +27,7 @@ LL | #![warn(unused)] = help: did you mean to capture by reference instead? warning: value assigned to `a` is never read - --> $DIR/liveness.rs:52:9 + --> $DIR/liveness.rs:53:9 | LL | a += 1; | ^ @@ -35,7 +35,7 @@ LL | a += 1; = help: maybe it is overwritten before being read? warning: value assigned to `a` is never read - --> $DIR/liveness.rs:76:13 + --> $DIR/liveness.rs:77:13 | LL | a = Some("d1"); | ^ @@ -43,7 +43,7 @@ LL | a = Some("d1"); = help: maybe it is overwritten before being read? warning: value assigned to `b` is never read - --> $DIR/liveness.rs:84:13 + --> $DIR/liveness.rs:85:13 | LL | b = Some("e1"); | ^ @@ -51,7 +51,7 @@ LL | b = Some("e1"); = help: maybe it is overwritten before being read? warning: value assigned to `b` is never read - --> $DIR/liveness.rs:86:13 + --> $DIR/liveness.rs:87:13 | LL | b = Some("e2"); | ^ @@ -59,7 +59,7 @@ LL | b = Some("e2"); = help: maybe it is overwritten before being read? warning: unused variable: `b` - --> $DIR/liveness.rs:84:13 + --> $DIR/liveness.rs:85:13 | LL | b = Some("e1"); | ^ diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs index 10a7d07a1df..465c9476ba6 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.rs @@ -2,6 +2,7 @@ // check-pass #![warn(unused)] +#![allow(dead_code)] #[derive(Debug)] struct MyStruct { diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr index f74303e3dd6..11a440554f7 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr @@ -1,5 +1,5 @@ warning: value assigned to `a` is never read - --> $DIR/liveness_unintentional_copy.rs:19:9 + --> $DIR/liveness_unintentional_copy.rs:20:9 | LL | a = s; | ^ @@ -13,7 +13,7 @@ LL | #![warn(unused)] = help: maybe it is overwritten before being read? warning: unused variable: `a` - --> $DIR/liveness_unintentional_copy.rs:19:9 + --> $DIR/liveness_unintentional_copy.rs:20:9 | LL | a = s; | ^ @@ -27,7 +27,7 @@ LL | #![warn(unused)] = help: did you mean to capture by reference instead? warning: unused variable: `a` - --> $DIR/liveness_unintentional_copy.rs:35:9 + --> $DIR/liveness_unintentional_copy.rs:36:9 | LL | a += x; | ^ diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs index 045fe78040a..ed222b3148f 100644 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/struct-pattern-matching-with-methods.rs @@ -1,6 +1,7 @@ // edition:2021 //check-pass #![warn(unused)] +#![allow(dead_code)] #![feature(rustc_attrs)] #[derive(Debug, Clone, Copy)] diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs index 8e4f91c27e2..3f7ddf93f06 100644 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/unsafe_ptr.rs @@ -3,6 +3,8 @@ // Test that we can use raw ptrs when using `capture_disjoint_fields`. +#![allow(dead_code)] + #[derive(Debug)] struct S { s: String, diff --git a/src/test/ui/const-generics/broken-mir-2.rs b/src/test/ui/const-generics/broken-mir-2.rs index f9e03151374..9d62281178c 100644 --- a/src/test/ui/const-generics/broken-mir-2.rs +++ b/src/test/ui/const-generics/broken-mir-2.rs @@ -1,4 +1,7 @@ // run-pass + +#![allow(dead_code)] + use std::fmt::Debug; #[derive(Debug)] diff --git a/src/test/ui/derives/clone-debug-dead-code.rs b/src/test/ui/derives/clone-debug-dead-code.rs new file mode 100644 index 00000000000..80e91320939 --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code.rs @@ -0,0 +1,45 @@ +// Checks that derived implementations of Clone and Debug do not +// contribute to dead code analysis (issue #84647). + +#![forbid(dead_code)] + +struct A { f: () } +//~^ ERROR: field is never read: `f` + +#[derive(Clone)] +struct B { f: () } +//~^ ERROR: field is never read: `f` + +#[derive(Debug)] +struct C { f: () } +//~^ ERROR: field is never read: `f` + +#[derive(Debug,Clone)] +struct D { f: () } +//~^ ERROR: field is never read: `f` + +struct E { f: () } +//~^ ERROR: field is never read: `f` +// Custom impl, still doesn't read f +impl Clone for E { + fn clone(&self) -> Self { + Self { f: () } + } +} + +struct F { f: () } +// Custom impl that actually reads f +impl Clone for F { + fn clone(&self) -> Self { + Self { f: self.f } + } +} + +fn main() { + let _ = A { f: () }; + let _ = B { f: () }; + let _ = C { f: () }; + let _ = D { f: () }; + let _ = E { f: () }; + let _ = F { f: () }; +} diff --git a/src/test/ui/derives/clone-debug-dead-code.stderr b/src/test/ui/derives/clone-debug-dead-code.stderr new file mode 100644 index 00000000000..226007f3647 --- /dev/null +++ b/src/test/ui/derives/clone-debug-dead-code.stderr @@ -0,0 +1,38 @@ +error: field is never read: `f` + --> $DIR/clone-debug-dead-code.rs:6:12 + | +LL | struct A { f: () } + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/clone-debug-dead-code.rs:4:11 + | +LL | #![forbid(dead_code)] + | ^^^^^^^^^ + +error: field is never read: `f` + --> $DIR/clone-debug-dead-code.rs:10:12 + | +LL | struct B { f: () } + | ^^^^^ + +error: field is never read: `f` + --> $DIR/clone-debug-dead-code.rs:14:12 + | +LL | struct C { f: () } + | ^^^^^ + +error: field is never read: `f` + --> $DIR/clone-debug-dead-code.rs:18:12 + | +LL | struct D { f: () } + | ^^^^^ + +error: field is never read: `f` + --> $DIR/clone-debug-dead-code.rs:21:12 + | +LL | struct E { f: () } + | ^^^^^ + +error: aborting due to 5 previous errors + diff --git a/src/test/ui/deriving/deriving-clone-generic-struct.rs b/src/test/ui/deriving/deriving-clone-generic-struct.rs index f6e105555fd..4374d1594e4 100644 --- a/src/test/ui/deriving/deriving-clone-generic-struct.rs +++ b/src/test/ui/deriving/deriving-clone-generic-struct.rs @@ -1,6 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 +#![allow(dead_code)] + #[derive(Clone)] struct S<T> { foo: (), diff --git a/src/test/ui/deriving/deriving-clone-struct.rs b/src/test/ui/deriving/deriving-clone-struct.rs index 7b0a1d20260..b93cbe5f8b6 100644 --- a/src/test/ui/deriving/deriving-clone-struct.rs +++ b/src/test/ui/deriving/deriving-clone-struct.rs @@ -1,6 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 +#![allow(dead_code)] + #[derive(Clone)] struct S { _int: isize, diff --git a/src/test/ui/deriving/deriving-clone-tuple-struct.rs b/src/test/ui/deriving/deriving-clone-tuple-struct.rs index 166f1be55e0..7ad3f034713 100644 --- a/src/test/ui/deriving/deriving-clone-tuple-struct.rs +++ b/src/test/ui/deriving/deriving-clone-tuple-struct.rs @@ -1,6 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 +#![allow(dead_code)] + #[derive(Clone)] struct S((), ()); diff --git a/src/test/ui/deriving/deriving-in-fn.rs b/src/test/ui/deriving/deriving-in-fn.rs index 8931e94a4f8..07f91d05973 100644 --- a/src/test/ui/deriving/deriving-in-fn.rs +++ b/src/test/ui/deriving/deriving-in-fn.rs @@ -1,4 +1,7 @@ // run-pass + +#![allow(dead_code)] + pub fn main() { #[derive(Debug)] struct Foo { diff --git a/src/test/ui/expr/malformed_closure/missing_braces_around_block.fixed b/src/test/ui/expr/malformed_closure/missing_braces_around_block.fixed new file mode 100644 index 00000000000..c50b9a12b6d --- /dev/null +++ b/src/test/ui/expr/malformed_closure/missing_braces_around_block.fixed @@ -0,0 +1,19 @@ +// This snippet ensures that no attempt to recover on a semicolon instead of +// comma is made next to a closure body. +// +// If this recovery happens, then plenty of errors are emitted. Here, we expect +// only one error. +// +// This is part of issue #88065: +// https://github.com/rust-lang/rust/issues/88065 + +// run-rustfix + +fn main() { + let num = 5; + (1..num).reduce(|a, b| { + //~^ ERROR: closure bodies that contain statements must be surrounded by braces + println!("{}", a); + a * b + }).unwrap(); +} diff --git a/src/test/ui/expr/malformed_closure/missing_braces_around_block.rs b/src/test/ui/expr/malformed_closure/missing_braces_around_block.rs new file mode 100644 index 00000000000..58c81f3a6e2 --- /dev/null +++ b/src/test/ui/expr/malformed_closure/missing_braces_around_block.rs @@ -0,0 +1,19 @@ +// This snippet ensures that no attempt to recover on a semicolon instead of +// comma is made next to a closure body. +// +// If this recovery happens, then plenty of errors are emitted. Here, we expect +// only one error. +// +// This is part of issue #88065: +// https://github.com/rust-lang/rust/issues/88065 + +// run-rustfix + +fn main() { + let num = 5; + (1..num).reduce(|a, b| + //~^ ERROR: closure bodies that contain statements must be surrounded by braces + println!("{}", a); + a * b + ).unwrap(); +} diff --git a/src/test/ui/expr/malformed_closure/missing_braces_around_block.stderr b/src/test/ui/expr/malformed_closure/missing_braces_around_block.stderr new file mode 100644 index 00000000000..dac9a8cfc69 --- /dev/null +++ b/src/test/ui/expr/malformed_closure/missing_braces_around_block.stderr @@ -0,0 +1,38 @@ +error: closure bodies that contain statements must be surrounded by braces + --> $DIR/missing_braces_around_block.rs:14:26 + | +LL | (1..num).reduce(|a, b| + | ^ +... +LL | ).unwrap(); + | ^ + | +note: statement found outside of a block + --> $DIR/missing_braces_around_block.rs:16:26 + | +LL | println!("{}", a); + | -----------------^ this `;` turns the preceding closure into a statement + | | + | this expression is a statement because of the trailing semicolon +note: the closure body may be incorrectly delimited + --> $DIR/missing_braces_around_block.rs:14:21 + | +LL | (1..num).reduce(|a, b| + | _____________________^ +LL | | +LL | | println!("{}", a); + | |_________________________^ this is the parsed closure... +LL | a * b +LL | ).unwrap(); + | - ...but likely you meant the closure to end here +help: try adding braces + | +LL ~ (1..num).reduce(|a, b| { +LL | +LL | println!("{}", a); +LL | a * b +LL ~ }).unwrap(); + | + +error: aborting due to previous error + diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.rs b/src/test/ui/expr/malformed_closure/ruby_style_closure.rs new file mode 100644 index 00000000000..e4341e19687 --- /dev/null +++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.rs @@ -0,0 +1,16 @@ +// Part of issue #27300. +// The problem here is that ruby-style closures are parsed as blocks whose +// first statement is a closure. See the issue for more details: +// https://github.com/rust-lang/rust/issues/27300 + +// Note: this test represents what the compiler currently emits. The error +// message will be improved later. + +fn main() { + let p = Some(45).and_then({ + //~^ expected a `FnOnce<({integer},)>` closure, found `Option<_>` + |x| println!("doubling {}", x); + Some(x * 2) + //~^ ERROR: cannot find value `x` in this scope + }); +} diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr new file mode 100644 index 00000000000..99df0632b4c --- /dev/null +++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr @@ -0,0 +1,18 @@ +error[E0425]: cannot find value `x` in this scope + --> $DIR/ruby_style_closure.rs:13:14 + | +LL | Some(x * 2) + | ^ not found in this scope + +error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` + --> $DIR/ruby_style_closure.rs:10:22 + | +LL | let p = Some(45).and_then({ + | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` + | + = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0277, E0425. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/issues/issue-19358.rs b/src/test/ui/issues/issue-19358.rs index f66e0a1c078..3970a4155e9 100644 --- a/src/test/ui/issues/issue-19358.rs +++ b/src/test/ui/issues/issue-19358.rs @@ -1,4 +1,7 @@ // run-pass + +#![allow(dead_code)] + trait Trait { fn dummy(&self) { } } #[derive(Debug)] diff --git a/src/test/ui/issues/issue-20605.stderr b/src/test/ui/issues/issue-20605.stderr index 25a90df4561..ce3ab6b5998 100644 --- a/src/test/ui/issues/issue-20605.stderr +++ b/src/test/ui/issues/issue-20605.stderr @@ -2,9 +2,12 @@ error[E0277]: the size for values of type `dyn Iterator<Item = &'a mut u8>` cann --> $DIR/issue-20605.rs:2:17 | LL | for item in *things { *item = 0 } - | ^^^^^^^ doesn't have a size known at compile-time + | ^^^^^^^ + | | + | expected an implementor of trait `IntoIterator` + | help: consider mutably borrowing here: `&mut *things` | - = help: the trait `Sized` is not implemented for `dyn Iterator<Item = &'a mut u8>` + = note: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied = note: required because of the requirements on the impl of `IntoIterator` for `dyn Iterator<Item = &'a mut u8>` note: required by `into_iter` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL diff --git a/src/test/ui/issues/issue-3794.rs b/src/test/ui/issues/issue-3794.rs index 408d8d866d8..1809e822c54 100644 --- a/src/test/ui/issues/issue-3794.rs +++ b/src/test/ui/issues/issue-3794.rs @@ -1,5 +1,6 @@ // run-pass #![feature(box_syntax)] +#![allow(dead_code)] trait T { fn print(&self); diff --git a/src/test/ui/issues/issue-86865.rs b/src/test/ui/issues/issue-86865.rs new file mode 100644 index 00000000000..01e0a20a511 --- /dev/null +++ b/src/test/ui/issues/issue-86865.rs @@ -0,0 +1,11 @@ +use std::fmt::Write; + +fn main() { + println!(b"foo"); + //~^ ERROR format argument must be a string literal + //~| HELP consider removing the leading `b` + let mut s = String::new(); + write!(s, b"foo{}", "bar"); + //~^ ERROR format argument must be a string literal + //~| HELP consider removing the leading `b` +} diff --git a/src/test/ui/issues/issue-86865.stderr b/src/test/ui/issues/issue-86865.stderr new file mode 100644 index 00000000000..eed75536631 --- /dev/null +++ b/src/test/ui/issues/issue-86865.stderr @@ -0,0 +1,18 @@ +error: format argument must be a string literal + --> $DIR/issue-86865.rs:4:14 + | +LL | println!(b"foo"); + | -^^^^^ + | | + | help: consider removing the leading `b` + +error: format argument must be a string literal + --> $DIR/issue-86865.rs:8:15 + | +LL | write!(s, b"foo{}", "bar"); + | -^^^^^^^ + | | + | help: consider removing the leading `b` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/monomorphize-abi-alignment.rs b/src/test/ui/monomorphize-abi-alignment.rs index 637b09fc04e..a8d8bd1d5fd 100644 --- a/src/test/ui/monomorphize-abi-alignment.rs +++ b/src/test/ui/monomorphize-abi-alignment.rs @@ -1,6 +1,7 @@ // run-pass #![allow(non_upper_case_globals)] +#![allow(dead_code)] /*! * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment, * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment diff --git a/src/test/ui/moves/move-1-unique.rs b/src/test/ui/moves/move-1-unique.rs index 48baead074a..7d3987f6560 100644 --- a/src/test/ui/moves/move-1-unique.rs +++ b/src/test/ui/moves/move-1-unique.rs @@ -1,5 +1,6 @@ // run-pass #![allow(unused_mut)] +#![allow(dead_code)] #![feature(box_syntax)] #[derive(Clone)] diff --git a/src/test/ui/moves/move-3-unique.rs b/src/test/ui/moves/move-3-unique.rs index 55b10e057d8..d23a852433f 100644 --- a/src/test/ui/moves/move-3-unique.rs +++ b/src/test/ui/moves/move-3-unique.rs @@ -1,5 +1,6 @@ // run-pass #![allow(unused_mut)] +#![allow(dead_code)] #![feature(box_syntax)] #[derive(Clone)] diff --git a/src/test/ui/overloaded/overloaded-autoderef-order.rs b/src/test/ui/overloaded/overloaded-autoderef-order.rs index 1ae16d2a7fc..f48bae55f5f 100644 --- a/src/test/ui/overloaded/overloaded-autoderef-order.rs +++ b/src/test/ui/overloaded/overloaded-autoderef-order.rs @@ -1,5 +1,7 @@ // run-pass +#![allow(dead_code)] + use std::rc::Rc; use std::ops::Deref; diff --git a/src/test/ui/self/ufcs-explicit-self.rs b/src/test/ui/self/ufcs-explicit-self.rs index 4e2405504f0..0aaaa7d47c3 100644 --- a/src/test/ui/self/ufcs-explicit-self.rs +++ b/src/test/ui/self/ufcs-explicit-self.rs @@ -1,5 +1,6 @@ // run-pass #![feature(box_syntax)] +#![allow(dead_code)] #[derive(Copy, Clone)] struct Foo { diff --git a/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs b/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs index 55975cbdb53..ca35a615d21 100644 --- a/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs +++ b/src/test/ui/structs-enums/class-cast-to-trait-multiple-types.rs @@ -1,5 +1,6 @@ // run-pass #![allow(non_camel_case_types)] +#![allow(dead_code)] trait noisy { fn speak(&mut self) -> isize; diff --git a/src/test/ui/structs-enums/class-implement-traits.rs b/src/test/ui/structs-enums/class-implement-traits.rs index c9e98e21b9e..732aa146ce4 100644 --- a/src/test/ui/structs-enums/class-implement-traits.rs +++ b/src/test/ui/structs-enums/class-implement-traits.rs @@ -1,5 +1,6 @@ // run-pass #![allow(non_camel_case_types)] +#![allow(dead_code)] trait noisy { fn speak(&mut self); diff --git a/src/test/ui/structs-enums/functional-struct-upd.rs b/src/test/ui/structs-enums/functional-struct-upd.rs index 51c6b6d7e4f..68ff73a0805 100644 --- a/src/test/ui/structs-enums/functional-struct-upd.rs +++ b/src/test/ui/structs-enums/functional-struct-upd.rs @@ -1,4 +1,7 @@ // run-pass + +#![allow(dead_code)] + #[derive(Debug)] struct Foo { x: isize, diff --git a/src/test/ui/structs-enums/tag-align-shape.rs b/src/test/ui/structs-enums/tag-align-shape.rs index 87282ddbcca..ce599582378 100644 --- a/src/test/ui/structs-enums/tag-align-shape.rs +++ b/src/test/ui/structs-enums/tag-align-shape.rs @@ -1,5 +1,6 @@ // run-pass #![allow(non_camel_case_types)] +#![allow(dead_code)] #[derive(Debug)] enum a_tag { diff --git a/src/test/ui/suggestions/slice-issue-87994.rs b/src/test/ui/suggestions/slice-issue-87994.rs new file mode 100644 index 00000000000..ecb7f54ea25 --- /dev/null +++ b/src/test/ui/suggestions/slice-issue-87994.rs @@ -0,0 +1,16 @@ +fn main() { + let v = vec![1i32, 2, 3]; + for _ in v[1..] { + //~^ ERROR [i32]` is not an iterator [E0277] + //~^^ ERROR known at compilation time + } + struct K { + n: i32, + } + let mut v2 = vec![K { n: 1 }, K { n: 1 }, K { n: 1 }]; + for i2 in v2[1..] { + //~^ ERROR [K]` is not an iterator [E0277] + //~^^ ERROR known at compilation time + i2.n = 2; + } +} diff --git a/src/test/ui/suggestions/slice-issue-87994.stderr b/src/test/ui/suggestions/slice-issue-87994.stderr new file mode 100644 index 00000000000..018f62e783d --- /dev/null +++ b/src/test/ui/suggestions/slice-issue-87994.stderr @@ -0,0 +1,71 @@ +error[E0277]: the size for values of type `[i32]` cannot be known at compilation time + --> $DIR/slice-issue-87994.rs:3:12 + | +LL | for _ in v[1..] { + | ^^^^^^ + | | + | expected an implementor of trait `IntoIterator` + | help: consider borrowing here: `&v[1..]` + | + = note: the trait bound `[i32]: IntoIterator` is not satisfied + = note: required because of the requirements on the impl of `IntoIterator` for `[i32]` +note: required by `into_iter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + | +LL | fn into_iter(self) -> Self::IntoIter; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: `[i32]` is not an iterator + --> $DIR/slice-issue-87994.rs:3:12 + | +LL | for _ in v[1..] { + | ^^^^^^ + | | + | expected an implementor of trait `IntoIterator` + | help: consider borrowing here: `&v[1..]` + | + = note: the trait bound `[i32]: IntoIterator` is not satisfied + = note: required because of the requirements on the impl of `IntoIterator` for `[i32]` +note: required by `into_iter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + | +LL | fn into_iter(self) -> Self::IntoIter; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the size for values of type `[K]` cannot be known at compilation time + --> $DIR/slice-issue-87994.rs:11:13 + | +LL | for i2 in v2[1..] { + | ^^^^^^^ + | | + | expected an implementor of trait `IntoIterator` + | help: consider borrowing here: `&v2[1..]` + | + = note: the trait bound `[K]: IntoIterator` is not satisfied + = note: required because of the requirements on the impl of `IntoIterator` for `[K]` +note: required by `into_iter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + | +LL | fn into_iter(self) -> Self::IntoIter; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: `[K]` is not an iterator + --> $DIR/slice-issue-87994.rs:11:13 + | +LL | for i2 in v2[1..] { + | ^^^^^^^ + | | + | expected an implementor of trait `IntoIterator` + | help: consider borrowing here: `&v2[1..]` + | + = note: the trait bound `[K]: IntoIterator` is not satisfied + = note: required because of the requirements on the impl of `IntoIterator` for `[K]` +note: required by `into_iter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + | +LL | fn into_iter(self) -> Self::IntoIter; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/clippy/clippy_lints/src/macro_use.rs b/src/tools/clippy/clippy_lints/src/macro_use.rs index 7627e0fb289..41e6ad12d05 100644 --- a/src/tools/clippy/clippy_lints/src/macro_use.rs +++ b/src/tools/clippy/clippy_lints/src/macro_use.rs @@ -29,36 +29,21 @@ declare_clippy_lint! { "#[macro_use] is no longer needed" } -const BRACKETS: &[char] = &['<', '>']; - #[derive(Clone, Debug, PartialEq, Eq)] struct PathAndSpan { path: String, span: Span, } -/// `MacroRefData` includes the name of the macro -/// and the path from `SourceMap::span_to_filename`. +/// `MacroRefData` includes the name of the macro. #[derive(Debug, Clone)] pub struct MacroRefData { name: String, - path: String, } impl MacroRefData { - pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self { - let sm = cx.sess().source_map(); - let mut path = sm.filename_for_diagnostics(&sm.span_to_filename(callee)).to_string(); - - // std lib paths are <::std::module::file type> - // so remove brackets, space and type. - if path.contains('<') { - path = path.replace(BRACKETS, ""); - } - if path.contains(' ') { - path = path.split(' ').next().unwrap().to_string(); - } - Self { name, path } + pub fn new(name: String) -> Self { + Self { name } } } @@ -78,7 +63,7 @@ impl MacroUseImports { fn push_unique_macro(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { + if let Some(_callee) = span.source_callee() { if !self.collected.contains(&call_site) { let name = if name.contains("::") { name.split("::").last().unwrap().to_string() @@ -86,7 +71,7 @@ impl MacroUseImports { name.to_string() }; - self.mac_refs.push(MacroRefData::new(name, callee.def_site, cx)); + self.mac_refs.push(MacroRefData::new(name)); self.collected.insert(call_site); } } @@ -95,10 +80,10 @@ impl MacroUseImports { fn push_unique_macro_pat_ty(&mut self, cx: &LateContext<'_>, span: Span) { let call_site = span.source_callsite(); let name = snippet(cx, cx.sess().source_map().span_until_char(call_site, '!'), "_"); - if let Some(callee) = span.source_callee() { + if let Some(_callee) = span.source_callee() { if !self.collected.contains(&call_site) { self.mac_refs - .push(MacroRefData::new(name.to_string(), callee.def_site, cx)); + .push(MacroRefData::new(name.to_string())); self.collected.insert(call_site); } } diff --git a/src/tools/clippy/clippy_lints/src/regex.rs b/src/tools/clippy/clippy_lints/src/regex.rs index eab09733730..89be7bf844f 100644 --- a/src/tools/clippy/clippy_lints/src/regex.rs +++ b/src/tools/clippy/clippy_lints/src/regex.rs @@ -3,8 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; use clippy_utils::{match_def_path, paths}; use if_chain::if_chain; use rustc_ast::ast::{LitKind, StrStyle}; -use rustc_data_structures::fx::FxHashSet; -use rustc_hir::{BorrowKind, Expr, ExprKind, HirId}; +use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{BytePos, Span}; @@ -53,10 +52,7 @@ declare_clippy_lint! { } #[derive(Clone, Default)] -pub struct Regex { - spans: FxHashSet<Span>, - last: Option<HirId>, -} +pub struct Regex {} impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]); diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed index 4c80cabc723..f1f9c123dc8 100644 --- a/src/tools/clippy/tests/ui/default_trait_access.fixed +++ b/src/tools/clippy/tests/ui/default_trait_access.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused_imports)] +#![allow(unused_imports,dead_code)] #![deny(clippy::default_trait_access)] use std::default; diff --git a/src/tools/clippy/tests/ui/default_trait_access.rs b/src/tools/clippy/tests/ui/default_trait_access.rs index a68b6455c04..7f3dfc7f013 100644 --- a/src/tools/clippy/tests/ui/default_trait_access.rs +++ b/src/tools/clippy/tests/ui/default_trait_access.rs @@ -1,6 +1,6 @@ // run-rustfix -#![allow(unused_imports)] +#![allow(unused_imports,dead_code)] #![deny(clippy::default_trait_access)] use std::default; diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs index a9bc89544d8..779a1149f41 100644 --- a/src/tools/rustfmt/src/macros.rs +++ b/src/tools/rustfmt/src/macros.rs @@ -762,7 +762,6 @@ impl MacroArgKind { #[derive(Debug, Clone)] struct ParsedMacroArg { kind: MacroArgKind, - span: Span, } impl ParsedMacroArg { @@ -780,14 +779,10 @@ impl ParsedMacroArg { struct MacroArgParser { /// Either a name of the next metavariable, a separator, or junk. buf: String, - /// The start position on the current buffer. - lo: BytePos, /// The first token of the current buffer. start_tok: Token, /// `true` if we are parsing a metavariable or a repeat. is_meta_var: bool, - /// The position of the last token. - hi: BytePos, /// The last token parsed. last_tok: Token, /// Holds the parsed arguments. @@ -807,8 +802,6 @@ fn last_tok(tt: &TokenTree) -> Token { impl MacroArgParser { fn new() -> MacroArgParser { MacroArgParser { - lo: BytePos(0), - hi: BytePos(0), buf: String::new(), is_meta_var: false, last_tok: Token { @@ -824,7 +817,6 @@ impl MacroArgParser { } fn set_last_tok(&mut self, tok: &TokenTree) { - self.hi = tok.span().hi(); self.last_tok = last_tok(tok); } @@ -836,7 +828,6 @@ impl MacroArgParser { }; self.result.push(ParsedMacroArg { kind: MacroArgKind::Separator(self.buf.clone(), prefix), - span: mk_sp(self.lo, self.hi), }); self.buf.clear(); } @@ -849,7 +840,6 @@ impl MacroArgParser { }; self.result.push(ParsedMacroArg { kind: MacroArgKind::Other(self.buf.clone(), prefix), - span: mk_sp(self.lo, self.hi), }); self.buf.clear(); } @@ -858,11 +848,10 @@ impl MacroArgParser { match iter.next() { Some(TokenTree::Token(Token { kind: TokenKind::Ident(name, _), - span, + .. })) => { self.result.push(ParsedMacroArg { kind: MacroArgKind::MetaVariable(name, self.buf.clone()), - span: mk_sp(self.lo, span.hi()), }); self.buf.clear(); @@ -873,10 +862,9 @@ impl MacroArgParser { } } - fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken, span: Span) { + fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken) { self.result.push(ParsedMacroArg { kind: MacroArgKind::Delimited(delim, inner), - span, }); } @@ -886,19 +874,15 @@ impl MacroArgParser { inner: Vec<ParsedMacroArg>, delim: DelimToken, iter: &mut Cursor, - span: Span, ) -> Option<()> { let mut buffer = String::new(); let mut first = true; - let mut lo = span.lo(); - let mut hi = span.hi(); // Parse '*', '+' or '?. for tok in iter { self.set_last_tok(&tok); if first { first = false; - lo = tok.span().lo(); } match tok { @@ -918,7 +902,6 @@ impl MacroArgParser { } TokenTree::Token(ref t) => { buffer.push_str(&pprust::token_to_string(&t)); - hi = t.span.hi(); } _ => return None, } @@ -930,20 +913,17 @@ impl MacroArgParser { } else { Some(Box::new(ParsedMacroArg { kind: MacroArgKind::Other(buffer, "".to_owned()), - span: mk_sp(lo, hi), })) }; self.result.push(ParsedMacroArg { kind: MacroArgKind::Repeat(delim, inner, another, self.last_tok.clone()), - span: mk_sp(self.lo, self.hi), }); Some(()) } fn update_buffer(&mut self, t: &Token) { if self.buf.is_empty() { - self.lo = t.span.lo(); self.start_tok = t.clone(); } else { let needs_space = match next_space(&self.last_tok.kind) { @@ -999,7 +979,6 @@ impl MacroArgParser { // Start keeping the name of this metavariable in the buffer. self.is_meta_var = true; - self.lo = span.lo(); self.start_tok = Token { kind: TokenKind::Dollar, span, @@ -1012,7 +991,7 @@ impl MacroArgParser { self.add_meta_variable(&mut iter)?; } TokenTree::Token(ref t) => self.update_buffer(t), - TokenTree::Delimited(delimited_span, delimited, ref tts) => { + TokenTree::Delimited(_delimited_span, delimited, ref tts) => { if !self.buf.is_empty() { if next_space(&self.last_tok.kind) == SpaceState::Always { self.add_separator(); @@ -1022,16 +1001,14 @@ impl MacroArgParser { } // Parse the stuff inside delimiters. - let mut parser = MacroArgParser::new(); - parser.lo = delimited_span.open.lo(); + let parser = MacroArgParser::new(); let delimited_arg = parser.parse(tts.clone())?; - let span = delimited_span.entire(); if self.is_meta_var { - self.add_repeat(delimited_arg, delimited, &mut iter, span)?; + self.add_repeat(delimited_arg, delimited, &mut iter)?; self.is_meta_var = false; } else { - self.add_delimited(delimited_arg, delimited, span); + self.add_delimited(delimited_arg, delimited); } } } diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs index 5de0575b5cd..ded34d9032f 100644 --- a/src/tools/rustfmt/src/modules.rs +++ b/src/tools/rustfmt/src/modules.rs @@ -27,7 +27,6 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>; pub(crate) struct Module<'a> { ast_mod_kind: Option<Cow<'a, ast::ModKind>>, pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>, - attrs: Cow<'a, Vec<ast::Attribute>>, inner_attr: Vec<ast::Attribute>, pub(crate) span: Span, } @@ -46,7 +45,6 @@ impl<'a> Module<'a> { .collect(); Module { items: mod_items, - attrs: mod_attrs, inner_attr, span: mod_span, ast_mod_kind, |
