diff options
| author | bors <bors@rust-lang.org> | 2021-01-22 16:04:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-01-22 16:04:36 +0000 |
| commit | b814b639836aa76b5c6deaa585367150bb2debf4 (patch) | |
| tree | ff77c2ba8ee58410a01d8606ef83071711e78195 /src | |
| parent | f2de221b0063261140a336c448bf1421170c9a74 (diff) | |
| parent | 9c2a5776b205aebec2685966fc24f59dde7fe76a (diff) | |
| download | rust-b814b639836aa76b5c6deaa585367150bb2debf4.tar.gz rust-b814b639836aa76b5c6deaa585367150bb2debf4.zip | |
Auto merge of #81271 - m-ou-se:rollup-xv7gq3w, r=m-ou-se
Rollup of 10 pull requests Successful merges: - #80573 (Deny rustc::internal lints for rustdoc and clippy) - #81173 (Expand docs on Iterator::intersperse) - #81194 (Stabilize std::panic::panic_any.) - #81202 (Don't prefix 0x for each segments in `dbg!(Ipv6)`) - #81225 (Make 'docs' nullable in rustdoc-json output) - #81227 (Remove doctree::StructType) - #81233 (Document why not use concat! in dbg! macro) - #81236 (Gracefully handle loop labels missing leading `'` in different positions) - #81241 (Turn alloc's force_expr macro into a regular macro_rules.) - #81242 (Enforce statically that `MIN_NON_ZERO_CAP` is calculated at compile time) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src')
34 files changed, 416 insertions, 163 deletions
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index c19bb536ce8..6626fead774 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -320,6 +320,13 @@ macro_rules! tool_check_step { cargo.arg("--all-targets"); } + // Enable internal lints for clippy and rustdoc + // NOTE: this intentionally doesn't enable lints for any other tools, + // see https://github.com/rust-lang/rust/pull/80573#issuecomment-754010776 + if $path == "src/tools/rustdoc" || $path == "src/tools/clippy" { + cargo.rustflag("-Zunstable-options"); + } + builder.info(&format!( "Checking stage{} {} artifacts ({} -> {})", builder.top_stage, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 916684baf85..1f9e7f8ae5c 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -5,7 +5,7 @@ use std::iter::once; use rustc_ast as ast; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; -use rustc_hir::def::{CtorKind, DefKind, Res}; +use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_hir::Mutability; use rustc_metadata::creader::LoadedMacro; @@ -17,7 +17,6 @@ use rustc_span::Span; use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind}; use crate::core::DocContext; -use crate::doctree; use super::Clean; @@ -246,11 +245,7 @@ fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct { let variant = cx.tcx.adt_def(did).non_enum_variant(); clean::Struct { - struct_type: match variant.ctor_kind { - CtorKind::Fictive => doctree::Plain, - CtorKind::Fn => doctree::Tuple, - CtorKind::Const => doctree::Unit, - }, + struct_type: variant.ctor_kind, generics: (cx.tcx.generics_of(did), predicates).clean(cx), fields: variant.fields.clean(cx), fields_stripped: false, @@ -262,7 +257,6 @@ fn build_union(cx: &DocContext<'_>, did: DefId) -> clean::Union { let variant = cx.tcx.adt_def(did).non_enum_variant(); clean::Union { - struct_type: doctree::Plain, generics: (cx.tcx.generics_of(did), predicates).clean(cx), fields: variant.fields.clean(cx), fields_stripped: false, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 3ddb2adbf0a..8fa60fa7178 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1827,7 +1827,7 @@ impl Clean<Visibility> for ty::Visibility { impl Clean<VariantStruct> for rustc_hir::VariantData<'_> { fn clean(&self, cx: &DocContext<'_>) -> VariantStruct { VariantStruct { - struct_type: doctree::struct_type_from_def(self), + struct_type: CtorKind::from_hir(self), fields: self.fields().iter().map(|x| x.clean(cx)).collect(), fields_stripped: false, } @@ -1842,7 +1842,7 @@ impl Clean<Item> for ty::VariantDef { self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(), ), CtorKind::Fictive => Variant::Struct(VariantStruct { - struct_type: doctree::Plain, + struct_type: CtorKind::Fictive, fields_stripped: false, fields: self .fields @@ -1996,13 +1996,12 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) { bounds: bounds.clean(cx), }), ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union { - struct_type: doctree::struct_type_from_def(&variant_data), generics: generics.clean(cx), fields: variant_data.fields().clean(cx), fields_stripped: false, }), ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct { - struct_type: doctree::struct_type_from_def(&variant_data), + struct_type: CtorKind::from_hir(variant_data), generics: generics.clean(cx), fields: variant_data.fields().clean(cx), fields_stripped: false, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 666b11b5f80..c767b9dd85b 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -16,7 +16,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_feature::UnstableFeatures; use rustc_hir as hir; -use rustc_hir::def::Res; +use rustc_hir::def::{CtorKind, Res}; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::Mutability; @@ -37,7 +37,6 @@ use crate::clean::inline; use crate::clean::types::Type::{QPath, ResolvedPath}; use crate::clean::Clean; use crate::core::DocContext; -use crate::doctree; use crate::formats::cache::cache; use crate::formats::item_type::ItemType; use crate::html::render::cache::ExternalLocation; @@ -1685,7 +1684,7 @@ impl Visibility { #[derive(Clone, Debug)] crate struct Struct { - crate struct_type: doctree::StructType, + crate struct_type: CtorKind, crate generics: Generics, crate fields: Vec<Item>, crate fields_stripped: bool, @@ -1693,7 +1692,6 @@ crate struct Struct { #[derive(Clone, Debug)] crate struct Union { - crate struct_type: doctree::StructType, crate generics: Generics, crate fields: Vec<Item>, crate fields_stripped: bool, @@ -1704,7 +1702,7 @@ crate struct Union { /// only as a variant in an enum. #[derive(Clone, Debug)] crate struct VariantStruct { - crate struct_type: doctree::StructType, + crate struct_type: CtorKind, crate fields: Vec<Item>, crate fields_stripped: bool, } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index e43ea965c04..8006c3d2771 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::convert::TryFrom; use std::ffi::OsStr; use std::fmt; @@ -219,7 +219,7 @@ crate struct RenderOptions { crate extern_html_root_urls: BTreeMap<String, String>, /// A map of the default settings (values are as for DOM storage API). Keys should lack the /// `rustdoc-` prefix. - crate default_settings: HashMap<String, String>, + crate default_settings: FxHashMap<String, String>, /// If present, suffix added to CSS/JavaScript files when referencing them in generated pages. crate resource_suffix: String, /// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index c87ab833f7a..bbf4de5cdc9 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1,4 +1,5 @@ use rustc_ast as ast; +use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use rustc_errors::{ColorConfig, ErrorReported}; use rustc_hir as hir; @@ -16,7 +17,6 @@ use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP}; use rustc_target::spec::TargetTriple; use tempfile::Builder as TempFileBuilder; -use std::collections::HashMap; use std::env; use std::io::{self, Write}; use std::panic; @@ -704,7 +704,7 @@ crate struct Collector { position: Span, source_map: Option<Lrc<SourceMap>>, filename: Option<PathBuf>, - visited_tests: HashMap<(String, usize), usize>, + visited_tests: FxHashMap<(String, usize), usize>, } impl Collector { @@ -728,7 +728,7 @@ impl Collector { position: DUMMY_SP, source_map, filename, - visited_tests: HashMap::new(), + visited_tests: FxHashMap::default(), } } @@ -1010,7 +1010,7 @@ impl<'a, 'hir, 'tcx> HirCollector<'a, 'hir, 'tcx> { self.codes, self.collector.enable_per_target_ignores, Some(&crate::html::markdown::ExtraInfo::new( - &self.tcx, + self.tcx, hir_id, span_of_attrs(&attrs).unwrap_or(sp), )), diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index f90623c0311..645b2bb193e 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -1,7 +1,5 @@ //! This module is used to store stuff from Rust's AST in a more convenient //! manner (and with prettier names) before cleaning. -crate use self::StructType::*; - use rustc_span::{self, Span, Symbol}; use rustc_hir as hir; @@ -34,21 +32,3 @@ impl Module<'hir> { } } } - -#[derive(Debug, Clone, Copy)] -crate enum StructType { - /// A braced struct - Plain, - /// A tuple struct - Tuple, - /// A unit struct - Unit, -} - -crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType { - match *vdata { - hir::VariantData::Struct(..) => Plain, - hir::VariantData::Tuple(..) => Tuple, - hir::VariantData::Unit(..) => Unit, - } -} diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index c91d6decc0b..5c0f5e50c9e 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use rustc_middle::ty; +use rustc_middle::ty::TyCtxt; use rustc_span::edition::Edition; use crate::clean; @@ -20,7 +20,7 @@ crate trait FormatRenderer<'tcx>: Clone { render_info: RenderInfo, edition: Edition, cache: &mut Cache, - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error>; /// Renders a single non-module item. This means no recursive sub-item rendering is required. @@ -55,7 +55,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( render_info: RenderInfo, diag: &rustc_errors::Handler, edition: Edition, - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, ) -> Result<(), Error> { let (krate, mut cache) = Cache::from_krate( render_info.clone(), diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 4458eea95f3..c6ff4b57a6e 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -1,6 +1,7 @@ -use std::collections::HashMap; use std::path::PathBuf; +use rustc_data_structures::fx::FxHashMap; + use crate::externalfiles::ExternalHtml; use crate::html::escape::Escape; use crate::html::format::{Buffer, Print}; @@ -11,7 +12,7 @@ crate struct Layout { crate logo: String, crate favicon: String, crate external_html: ExternalHtml, - crate default_settings: HashMap<String, String>, + crate default_settings: FxHashMap<String, String>, crate krate: String, /// The given user css file which allow to customize the generated /// documentation theme. diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index cfa6cd96595..7c8b76be374 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -620,7 +620,7 @@ crate fn find_testable_code<T: doctest::Tester>( tests: &mut T, error_codes: ErrorCodes, enable_per_target_ignores: bool, - extra_info: Option<&ExtraInfo<'_, '_>>, + extra_info: Option<&ExtraInfo<'_>>, ) { let mut parser = Parser::new(doc).into_offset_iter(); let mut prev_offset = 0; @@ -681,19 +681,19 @@ crate fn find_testable_code<T: doctest::Tester>( } } -crate struct ExtraInfo<'a, 'b> { +crate struct ExtraInfo<'tcx> { hir_id: Option<HirId>, item_did: Option<DefId>, sp: Span, - tcx: &'a TyCtxt<'b>, + tcx: TyCtxt<'tcx>, } -impl<'a, 'b> ExtraInfo<'a, 'b> { - crate fn new(tcx: &'a TyCtxt<'b>, hir_id: HirId, sp: Span) -> ExtraInfo<'a, 'b> { +impl<'tcx> ExtraInfo<'tcx> { + crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> { ExtraInfo { hir_id: Some(hir_id), item_did: None, sp, tcx } } - crate fn new_did(tcx: &'a TyCtxt<'b>, did: DefId, sp: Span) -> ExtraInfo<'a, 'b> { + crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> { ExtraInfo { hir_id: None, item_did: Some(did), sp, tcx } } @@ -775,7 +775,7 @@ impl LangString { string: &str, allow_error_code_check: ErrorCodes, enable_per_target_ignores: bool, - extra: Option<&ExtraInfo<'_, '_>>, + extra: Option<&ExtraInfo<'_>>, ) -> LangString { let allow_error_code_check = allow_error_code_check.as_bool(); let mut seen_rust_tags = false; @@ -1208,7 +1208,7 @@ crate struct RustCodeBlock { /// Returns a range of bytes for each code block in the markdown that is tagged as `rust` or /// untagged (and assumed to be rust). -crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec<RustCodeBlock> { +crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeBlock> { let mut code_blocks = vec![]; if md.is_empty() { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 26afd705740..6167b75ee50 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -52,10 +52,10 @@ use rustc_attr::{Deprecation, StabilityLevel}; use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; +use rustc_hir::def::CtorKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Mutability; use rustc_middle::middle::stability; -use rustc_middle::ty; use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; @@ -68,7 +68,6 @@ use serde::{Serialize, Serializer}; use crate::clean::{self, AttributesExt, GetDefId, RenderedLink, SelfTy, TypeKind}; use crate::config::{RenderInfo, RenderOptions}; use crate::docfs::{DocFS, PathError}; -use crate::doctree; use crate::error::Error; use crate::formats::cache::{cache, Cache}; use crate::formats::item_type::ItemType; @@ -390,7 +389,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { _render_info: RenderInfo, edition: Edition, cache: &mut Cache, - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error> { // need to save a copy of the options for rendering the index page let md_opts = options.clone(); @@ -3104,7 +3103,7 @@ fn item_struct( _ => None, }) .peekable(); - if let doctree::Plain = s.struct_type { + if let CtorKind::Fictive = s.struct_type { if fields.peek().is_some() { write!( w, @@ -3354,7 +3353,7 @@ fn render_struct( w: &mut Buffer, it: &clean::Item, g: Option<&clean::Generics>, - ty: doctree::StructType, + ty: CtorKind, fields: &[clean::Item], tab: &str, structhead: bool, @@ -3371,7 +3370,7 @@ fn render_struct( write!(w, "{}", g.print()) } match ty { - doctree::Plain => { + CtorKind::Fictive => { if let Some(g) = g { write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true }) } @@ -3403,7 +3402,7 @@ fn render_struct( } write!(w, "}}"); } - doctree::Tuple => { + CtorKind::Fn => { write!(w, "("); for (i, field) in fields.iter().enumerate() { if i > 0 { @@ -3428,7 +3427,7 @@ fn render_struct( } write!(w, ";"); } - doctree::Unit => { + CtorKind::Const => { // Needed for PhantomData. if let Some(g) = g { write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false }) @@ -4463,7 +4462,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea let fields = get_struct_fields_name(&s.fields); if !fields.is_empty() { - if let doctree::Plain = s.struct_type { + if let CtorKind::Fictive = s.struct_type { sidebar.push_str(&format!( "<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\ <div class=\"sidebar-links\">{}</div>", diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 7d05cb016b6..bfd2141d9a1 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -5,11 +5,11 @@ use std::convert::From; use rustc_ast::ast; +use rustc_hir::def::CtorKind; use rustc_span::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_span::Pos; use crate::clean; -use crate::doctree; use crate::formats::item_type::ItemType; use crate::json::types::*; use crate::json::JsonRenderer; @@ -27,7 +27,7 @@ impl JsonRenderer<'_> { name: name.map(|sym| sym.to_string()), source: self.convert_span(source), visibility: self.convert_visibility(visibility), - docs: attrs.collapsed_doc_value().unwrap_or_default(), + docs: attrs.collapsed_doc_value(), links: attrs .links .into_iter() @@ -210,9 +210,9 @@ impl From<clean::Struct> for Struct { impl From<clean::Union> for Struct { fn from(struct_: clean::Union) -> Self { - let clean::Union { struct_type, generics, fields, fields_stripped } = struct_; + let clean::Union { generics, fields, fields_stripped } = struct_; Struct { - struct_type: struct_type.into(), + struct_type: StructType::Union, generics: generics.into(), fields_stripped, fields: ids(fields), @@ -221,13 +221,12 @@ impl From<clean::Union> for Struct { } } -impl From<doctree::StructType> for StructType { - fn from(struct_type: doctree::StructType) -> Self { - use doctree::StructType::*; +impl From<CtorKind> for StructType { + fn from(struct_type: CtorKind) -> Self { match struct_type { - Plain => StructType::Plain, - Tuple => StructType::Tuple, - Unit => StructType::Unit, + CtorKind::Fictive => StructType::Plain, + CtorKind::Fn => StructType::Tuple, + CtorKind::Const => StructType::Unit, } } } diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 64500c1d911..dc50c8a76b2 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -13,7 +13,7 @@ use std::path::PathBuf; use std::rc::Rc; use rustc_data_structures::fx::FxHashMap; -use rustc_middle::ty; +use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; @@ -26,7 +26,7 @@ use crate::html::render::cache::ExternalLocation; #[derive(Clone)] crate struct JsonRenderer<'tcx> { - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, /// A mapping of IDs that contains all local items for this crate which gets output as a top /// level field of the JSON blob. index: Rc<RefCell<FxHashMap<types::Id, types::Item>>>, @@ -131,7 +131,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { _render_info: RenderInfo, _edition: Edition, _cache: &mut Cache, - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error> { debug!("Initializing json renderer"); Ok(( @@ -241,7 +241,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .collect(), - format_version: 1, + format_version: 2, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); diff --git a/src/librustdoc/json/types.rs b/src/librustdoc/json/types.rs index 9335fe9be1a..66cf12954dd 100644 --- a/src/librustdoc/json/types.rs +++ b/src/librustdoc/json/types.rs @@ -68,8 +68,9 @@ pub struct Item { /// By default all documented items are public, but you can tell rustdoc to output private items /// so this field is needed to differentiate. pub visibility: Visibility, - /// The full markdown docstring of this item. - pub docs: String, + /// The full markdown docstring of this item. Absent if there is no documentation at all, + /// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`). + pub docs: Option<String>, /// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs pub links: FxHashMap<String, Id>, /// Stringified versions of the attributes on this item (e.g. `"#[inline]"`) @@ -269,6 +270,7 @@ pub enum StructType { Plain, Tuple, Unit, + Union, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 719aca612f5..d17189b416d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -18,6 +18,7 @@ #![feature(str_split_once)] #![feature(iter_intersperse)] #![recursion_limit = "256"] +#![deny(rustc::internal)] #[macro_use] extern crate lazy_static; @@ -65,7 +66,7 @@ use std::process; use rustc_driver::abort_on_err; use rustc_errors::ErrorReported; use rustc_interface::interface; -use rustc_middle::ty; +use rustc_middle::ty::TyCtxt; use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup}; use rustc_session::getopts; use rustc_session::{early_error, early_warn}; @@ -471,7 +472,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( render_info: config::RenderInfo, diag: &rustc_errors::Handler, edition: rustc_span::edition::Edition, - tcx: ty::TyCtxt<'tcx>, + tcx: TyCtxt<'tcx>, ) -> MainResult { match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, tcx) { Ok(_) => Ok(()), diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 554392c213e..9516130034b 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -108,7 +108,7 @@ impl<'a, 'tcx> DocFolder for SyntaxChecker<'a, 'tcx> { fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> { if let Some(dox) = &item.attrs.collapsed_doc_value() { let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); - let extra = crate::html::markdown::ExtraInfo::new_did(&self.cx.tcx, item.def_id, sp); + let extra = crate::html::markdown::ExtraInfo::new_did(self.cx.tcx, item.def_id, sp); for code_block in markdown::rust_code_blocks(&dox, &extra) { self.check_rust_syntax(&item, &dox, code_block); } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 2694450a520..002d8938f69 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -13,6 +13,7 @@ use rustc_hir::def::{ PerNS, }; use rustc_hir::def_id::{CrateNum, DefId}; +use rustc_middle::ty::TyCtxt; use rustc_middle::{bug, ty}; use rustc_resolve::ParentScope; use rustc_session::lint::{ @@ -85,7 +86,7 @@ impl Res { } } - fn name(self, tcx: ty::TyCtxt<'_>) -> String { + fn name(self, tcx: TyCtxt<'_>) -> String { match self { Res::Def(_, id) => tcx.item_name(id).to_string(), Res::Primitive(prim) => prim.as_str().to_string(), @@ -865,12 +866,11 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { // FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly let self_name = self_id.and_then(|self_id| { - use ty::TyKind; if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) { // using `ty.to_string()` (or any variant) has issues with raw idents let ty = self.cx.tcx.type_of(self_id); let name = match ty.kind() { - TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()), + ty::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()), other if other.is_primitive() => Some(ty.to_string()), _ => None, }; diff --git a/src/test/ui/issues/issue-1962.fixed b/src/test/ui/issues/issue-1962.fixed index b810a90ef37..897fd172b29 100644 --- a/src/test/ui/issues/issue-1962.fixed +++ b/src/test/ui/issues/issue-1962.fixed @@ -3,8 +3,8 @@ fn main() { let mut i = 0; - loop { //~ ERROR denote infinite loops with `loop + 'a: loop { //~ ERROR denote infinite loops with `loop i += 1; - if i == 5 { break; } + if i == 5 { break 'a; } } } diff --git a/src/test/ui/issues/issue-1962.rs b/src/test/ui/issues/issue-1962.rs index 00d2bbd2850..71e87410087 100644 --- a/src/test/ui/issues/issue-1962.rs +++ b/src/test/ui/issues/issue-1962.rs @@ -3,8 +3,8 @@ fn main() { let mut i = 0; - while true { //~ ERROR denote infinite loops with `loop + 'a: while true { //~ ERROR denote infinite loops with `loop i += 1; - if i == 5 { break; } + if i == 5 { break 'a; } } } diff --git a/src/test/ui/issues/issue-1962.stderr b/src/test/ui/issues/issue-1962.stderr index 17142912696..4c32a4cf3dd 100644 --- a/src/test/ui/issues/issue-1962.stderr +++ b/src/test/ui/issues/issue-1962.stderr @@ -1,8 +1,8 @@ error: denote infinite loops with `loop { ... }` --> $DIR/issue-1962.rs:6:5 | -LL | while true { - | ^^^^^^^^^^ help: use `loop` +LL | 'a: while true { + | ^^^^^^^^^^^^^^ help: use `loop` | = note: requested on the command line with `-D while-true` diff --git a/src/test/ui/issues/issue-27042.stderr b/src/test/ui/issues/issue-27042.stderr index 7dee1a6a5f0..59ef28481d0 100644 --- a/src/test/ui/issues/issue-27042.stderr +++ b/src/test/ui/issues/issue-27042.stderr @@ -4,7 +4,7 @@ warning: denote infinite loops with `loop { ... }` LL | / 'b: LL | | LL | | while true { break }; // but here we cite the whole loop - | |____________________________^ help: use `loop` + | |__________________^ help: use `loop` | = note: `#[warn(while_true)]` on by default diff --git a/src/test/ui/label/label_misspelled.rs b/src/test/ui/label/label_misspelled.rs index ebfd5642c9f..e3180b06ecb 100644 --- a/src/test/ui/label/label_misspelled.rs +++ b/src/test/ui/label/label_misspelled.rs @@ -1,18 +1,62 @@ +#![warn(unused_labels)] + fn main() { + 'while_loop: while true { //~ WARN denote infinite loops with + //~^ WARN unused label + while_loop; + //~^ ERROR cannot find value `while_loop` in this scope + }; + 'while_let: while let Some(_) = Some(()) { + //~^ WARN unused label + while_let; + //~^ ERROR cannot find value `while_let` in this scope + } + 'for_loop: for _ in 0..3 { + //~^ WARN unused label + for_loop; + //~^ ERROR cannot find value `for_loop` in this scope + }; 'LOOP: loop { + //~^ WARN unused label LOOP; //~^ ERROR cannot find value `LOOP` in this scope }; +} + +fn foo() { + 'LOOP: loop { + break LOOP; + //~^ ERROR cannot find value `LOOP` in this scope + }; 'while_loop: while true { //~ WARN denote infinite loops with - while_loop; + break while_loop; //~^ ERROR cannot find value `while_loop` in this scope }; 'while_let: while let Some(_) = Some(()) { - while_let; + break while_let; //~^ ERROR cannot find value `while_let` in this scope } 'for_loop: for _ in 0..3 { - for_loop; + break for_loop; //~^ ERROR cannot find value `for_loop` in this scope }; } + +fn bar() { + let foo = (); + 'while_loop: while true { //~ WARN denote infinite loops with + //~^ WARN unused label + break foo; + //~^ ERROR `break` with value from a `while` loop + }; + 'while_let: while let Some(_) = Some(()) { + //~^ WARN unused label + break foo; + //~^ ERROR `break` with value from a `while` loop + } + 'for_loop: for _ in 0..3 { + //~^ WARN unused label + break foo; + //~^ ERROR `break` with value from a `for` loop + }; +} diff --git a/src/test/ui/label/label_misspelled.stderr b/src/test/ui/label/label_misspelled.stderr index 1368ca4126c..b09695787a4 100644 --- a/src/test/ui/label/label_misspelled.stderr +++ b/src/test/ui/label/label_misspelled.stderr @@ -1,47 +1,206 @@ -error[E0425]: cannot find value `LOOP` in this scope - --> $DIR/label_misspelled.rs:3:9 - | -LL | LOOP; - | ^^^^ - | | - | not found in this scope - | help: a label with a similar name exists: `'LOOP` - error[E0425]: cannot find value `while_loop` in this scope - --> $DIR/label_misspelled.rs:7:9 + --> $DIR/label_misspelled.rs:6:9 | +LL | 'while_loop: while true { + | ----------- a label with a similar name exists +LL | LL | while_loop; - | ^^^^^^^^^^ - | | - | not found in this scope - | help: a label with a similar name exists: `'while_loop` + | ^^^^^^^^^^ not found in this scope error[E0425]: cannot find value `while_let` in this scope --> $DIR/label_misspelled.rs:11:9 | +LL | 'while_let: while let Some(_) = Some(()) { + | ---------- a label with a similar name exists +LL | LL | while_let; - | ^^^^^^^^^ - | | - | not found in this scope - | help: a label with a similar name exists: `'while_let` + | ^^^^^^^^^ not found in this scope error[E0425]: cannot find value `for_loop` in this scope - --> $DIR/label_misspelled.rs:15:9 + --> $DIR/label_misspelled.rs:16:9 | +LL | 'for_loop: for _ in 0..3 { + | --------- a label with a similar name exists +LL | LL | for_loop; - | ^^^^^^^^ - | | - | not found in this scope - | help: a label with a similar name exists: `'for_loop` + | ^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `LOOP` in this scope + --> $DIR/label_misspelled.rs:21:9 + | +LL | 'LOOP: loop { + | ----- a label with a similar name exists +LL | +LL | LOOP; + | ^^^^ not found in this scope + +error[E0425]: cannot find value `LOOP` in this scope + --> $DIR/label_misspelled.rs:28:15 + | +LL | 'LOOP: loop { + | ----- a label with a similar name exists +LL | break LOOP; + | ^^^^ + | | + | not found in this scope + | help: use the similarly named label: `'LOOP` + +error[E0425]: cannot find value `while_loop` in this scope + --> $DIR/label_misspelled.rs:32:15 + | +LL | 'while_loop: while true { + | ----------- a label with a similar name exists +LL | break while_loop; + | ^^^^^^^^^^ + | | + | not found in this scope + | help: use the similarly named label: `'while_loop` + +error[E0425]: cannot find value `while_let` in this scope + --> $DIR/label_misspelled.rs:36:15 + | +LL | 'while_let: while let Some(_) = Some(()) { + | ---------- a label with a similar name exists +LL | break while_let; + | ^^^^^^^^^ + | | + | not found in this scope + | help: use the similarly named label: `'while_let` + +error[E0425]: cannot find value `for_loop` in this scope + --> $DIR/label_misspelled.rs:40:15 + | +LL | 'for_loop: for _ in 0..3 { + | --------- a label with a similar name exists +LL | break for_loop; + | ^^^^^^^^ + | | + | not found in this scope + | help: use the similarly named label: `'for_loop` + +warning: unused label + --> $DIR/label_misspelled.rs:4:5 + | +LL | 'while_loop: while true { + | ^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/label_misspelled.rs:1:9 + | +LL | #![warn(unused_labels)] + | ^^^^^^^^^^^^^ warning: denote infinite loops with `loop { ... }` - --> $DIR/label_misspelled.rs:6:5 + --> $DIR/label_misspelled.rs:4:5 | LL | 'while_loop: while true { | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default -error: aborting due to 4 previous errors; 1 warning emitted +warning: unused label + --> $DIR/label_misspelled.rs:9:5 + | +LL | 'while_let: while let Some(_) = Some(()) { + | ^^^^^^^^^^ + +warning: unused label + --> $DIR/label_misspelled.rs:14:5 + | +LL | 'for_loop: for _ in 0..3 { + | ^^^^^^^^^ + +warning: unused label + --> $DIR/label_misspelled.rs:19:5 + | +LL | 'LOOP: loop { + | ^^^^^ + +warning: denote infinite loops with `loop { ... }` + --> $DIR/label_misspelled.rs:31:5 + | +LL | 'while_loop: while true { + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` + +warning: unused label + --> $DIR/label_misspelled.rs:47:5 + | +LL | 'while_loop: while true { + | ^^^^^^^^^^^ + +warning: denote infinite loops with `loop { ... }` + --> $DIR/label_misspelled.rs:47:5 + | +LL | 'while_loop: while true { + | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` + +warning: unused label + --> $DIR/label_misspelled.rs:52:5 + | +LL | 'while_let: while let Some(_) = Some(()) { + | ^^^^^^^^^^ + +warning: unused label + --> $DIR/label_misspelled.rs:57:5 + | +LL | 'for_loop: for _ in 0..3 { + | ^^^^^^^^^ + +error[E0571]: `break` with value from a `while` loop + --> $DIR/label_misspelled.rs:49:9 + | +LL | 'while_loop: while true { + | ----------------------- you can't `break` with a value in a `while` loop +LL | +LL | break foo; + | ^^^^^^^^^ can only break with a value inside `loop` or breakable block + | +help: use `break` on its own without a value inside this `while` loop + | +LL | break; + | ^^^^^ +help: alternatively, you might have meant to use the available loop label + | +LL | break 'while_loop; + | ^^^^^^^^^^^ + +error[E0571]: `break` with value from a `while` loop + --> $DIR/label_misspelled.rs:54:9 + | +LL | 'while_let: while let Some(_) = Some(()) { + | ---------------------------------------- you can't `break` with a value in a `while` loop +LL | +LL | break foo; + | ^^^^^^^^^ can only break with a value inside `loop` or breakable block + | +help: use `break` on its own without a value inside this `while` loop + | +LL | break; + | ^^^^^ +help: alternatively, you might have meant to use the available loop label + | +LL | break 'while_let; + | ^^^^^^^^^^ + +error[E0571]: `break` with value from a `for` loop + --> $DIR/label_misspelled.rs:59:9 + | +LL | 'for_loop: for _ in 0..3 { + | ------------------------ you can't `break` with a value in a `for` loop +LL | +LL | break foo; + | ^^^^^^^^^ can only break with a value inside `loop` or breakable block + | +help: use `break` on its own without a value inside this `for` loop + | +LL | break; + | ^^^^^ +help: alternatively, you might have meant to use the available loop label + | +LL | break 'for_loop; + | ^^^^^^^^^ + +error: aborting due to 11 previous errors; 10 warnings emitted -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0425, E0571. +For more information about an error, try `rustc --explain E0425`. diff --git a/src/test/ui/label/label_misspelled_2.rs b/src/test/ui/label/label_misspelled_2.rs new file mode 100644 index 00000000000..55bbe6b30a5 --- /dev/null +++ b/src/test/ui/label/label_misspelled_2.rs @@ -0,0 +1,16 @@ +#![warn(unused_labels)] + +fn main() { + 'a: for _ in 0..1 { + break 'a; + } + 'b: for _ in 0..1 { + break b; //~ ERROR cannot find value `b` in this scope + } + c: for _ in 0..1 { //~ ERROR malformed loop label + break 'c; + } + d: for _ in 0..1 { //~ ERROR malformed loop label + break d; //~ ERROR cannot find value `d` in this scope + } +} diff --git a/src/test/ui/label/label_misspelled_2.stderr b/src/test/ui/label/label_misspelled_2.stderr new file mode 100644 index 00000000000..960646d9894 --- /dev/null +++ b/src/test/ui/label/label_misspelled_2.stderr @@ -0,0 +1,37 @@ +error: malformed loop label + --> $DIR/label_misspelled_2.rs:10:5 + | +LL | c: for _ in 0..1 { + | ^ help: use the correct loop label format: `'c` + +error: malformed loop label + --> $DIR/label_misspelled_2.rs:13:5 + | +LL | d: for _ in 0..1 { + | ^ help: use the correct loop label format: `'d` + +error[E0425]: cannot find value `b` in this scope + --> $DIR/label_misspelled_2.rs:8:15 + | +LL | 'b: for _ in 0..1 { + | -- a label with a similar name exists +LL | break b; + | ^ + | | + | not found in this scope + | help: use the similarly named label: `'b` + +error[E0425]: cannot find value `d` in this scope + --> $DIR/label_misspelled_2.rs:14:15 + | +LL | d: for _ in 0..1 { + | - a label with a similar name exists +LL | break d; + | ^ + | | + | not found in this scope + | help: use the similarly named label: `'d` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/loops/loop-break-value-no-repeat.stderr b/src/test/ui/loops/loop-break-value-no-repeat.stderr index ff93e9220e9..1c0d39a6e5a 100644 --- a/src/test/ui/loops/loop-break-value-no-repeat.stderr +++ b/src/test/ui/loops/loop-break-value-no-repeat.stderr @@ -1,10 +1,12 @@ error[E0571]: `break` with value from a `for` loop --> $DIR/loop-break-value-no-repeat.rs:12:9 | +LL | for _ in &[1,2,3] { + | ----------------- you can't `break` with a value in a `for` loop LL | break 22 | ^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `for` loop +help: use `break` on its own without a value inside this `for` loop | LL | break | ^^^^^ diff --git a/src/test/ui/loops/loop-break-value.rs b/src/test/ui/loops/loop-break-value.rs index 8a080cfdf49..51c9a36a039 100644 --- a/src/test/ui/loops/loop-break-value.rs +++ b/src/test/ui/loops/loop-break-value.rs @@ -94,6 +94,5 @@ fn main() { 'LOOP: for _ in 0 .. 9 { break LOOP; //~^ ERROR cannot find value `LOOP` in this scope - //~| ERROR `break` with value from a `for` loop } } diff --git a/src/test/ui/loops/loop-break-value.stderr b/src/test/ui/loops/loop-break-value.stderr index 0237435c8b4..adb099f9b17 100644 --- a/src/test/ui/loops/loop-break-value.stderr +++ b/src/test/ui/loops/loop-break-value.stderr @@ -1,11 +1,13 @@ error[E0425]: cannot find value `LOOP` in this scope --> $DIR/loop-break-value.rs:95:15 | +LL | 'LOOP: for _ in 0 .. 9 { + | ----- a label with a similar name exists LL | break LOOP; | ^^^^ | | | not found in this scope - | help: a label with a similar name exists: `'LOOP` + | help: use the similarly named label: `'LOOP` warning: denote infinite loops with `loop { ... }` --> $DIR/loop-break-value.rs:26:5 @@ -18,32 +20,44 @@ LL | 'while_loop: while true { error[E0571]: `break` with value from a `while` loop --> $DIR/loop-break-value.rs:28:9 | +LL | 'while_loop: while true { + | ----------------------- you can't `break` with a value in a `while` loop +LL | break; LL | break (); | ^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `while` loop +help: use `break` on its own without a value inside this `while` loop | LL | break; | ^^^^^ +help: alternatively, you might have meant to use the available loop label + | +LL | break 'while_loop; + | ^^^^^^^^^^^ error[E0571]: `break` with value from a `while` loop --> $DIR/loop-break-value.rs:30:13 | +LL | 'while_loop: while true { + | ----------------------- you can't `break` with a value in a `while` loop +... LL | break 'while_loop 123; | ^^^^^^^^^^^^^^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `while` loop +help: use `break` on its own without a value inside this `while` loop | -LL | break; - | ^^^^^ +LL | break 'while_loop; + | ^^^^^^^^^^^^^^^^^ error[E0571]: `break` with value from a `while` loop --> $DIR/loop-break-value.rs:38:12 | +LL | while let Some(_) = Some(()) { + | ---------------------------- you can't `break` with a value in a `while` loop LL | if break () { | ^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `while` loop +help: use `break` on its own without a value inside this `while` loop | LL | if break { | ^^^^^ @@ -51,10 +65,12 @@ LL | if break { error[E0571]: `break` with value from a `while` loop --> $DIR/loop-break-value.rs:43:9 | +LL | while let Some(_) = Some(()) { + | ---------------------------- you can't `break` with a value in a `while` loop LL | break None; | ^^^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `while` loop +help: use `break` on its own without a value inside this `while` loop | LL | break; | ^^^^^ @@ -62,21 +78,26 @@ LL | break; error[E0571]: `break` with value from a `while` loop --> $DIR/loop-break-value.rs:49:13 | +LL | 'while_let_loop: while let Some(_) = Some(()) { + | --------------------------------------------- you can't `break` with a value in a `while` loop +LL | loop { LL | break 'while_let_loop "nope"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `while` loop +help: use `break` on its own without a value inside this `while` loop | -LL | break; - | ^^^^^ +LL | break 'while_let_loop; + | ^^^^^^^^^^^^^^^^^^^^^ error[E0571]: `break` with value from a `for` loop --> $DIR/loop-break-value.rs:56:9 | +LL | for _ in &[1,2,3] { + | ----------------- you can't `break` with a value in a `for` loop LL | break (); | ^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `for` loop +help: use `break` on its own without a value inside this `for` loop | LL | break; | ^^^^^ @@ -84,10 +105,13 @@ LL | break; error[E0571]: `break` with value from a `for` loop --> $DIR/loop-break-value.rs:57:9 | +LL | for _ in &[1,2,3] { + | ----------------- you can't `break` with a value in a `for` loop +LL | break (); LL | break [()]; | ^^^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `for` loop +help: use `break` on its own without a value inside this `for` loop | LL | break; | ^^^^^ @@ -95,24 +119,16 @@ LL | break; error[E0571]: `break` with value from a `for` loop --> $DIR/loop-break-value.rs:64:13 | +LL | 'for_loop: for _ in &[1,2,3] { + | ---------------------------- you can't `break` with a value in a `for` loop +... LL | break 'for_loop Some(17); | ^^^^^^^^^^^^^^^^^^^^^^^^ can only break with a value inside `loop` or breakable block | -help: instead, use `break` on its own without a value inside this `for` loop - | -LL | break; - | ^^^^^ - -error[E0571]: `break` with value from a `for` loop - --> $DIR/loop-break-value.rs:95:9 - | -LL | break LOOP; - | ^^^^^^^^^^ can only break with a value inside `loop` or breakable block +help: use `break` on its own without a value inside this `for` loop | -help: instead, use `break` on its own without a value inside this `for` loop - | -LL | break; - | ^^^^^ +LL | break 'for_loop; + | ^^^^^^^^^^^^^^^ error[E0308]: mismatched types --> $DIR/loop-break-value.rs:4:31 @@ -171,7 +187,7 @@ LL | break; | expected integer, found `()` | help: give it a value of the expected type: `break value` -error: aborting due to 18 previous errors; 1 warning emitted +error: aborting due to 17 previous errors; 1 warning emitted Some errors have detailed explanations: E0308, E0425, E0571. For more information about an error, try `rustc --explain E0308`. diff --git a/src/tools/clippy/clippy_lints/src/loops.rs b/src/tools/clippy/clippy_lints/src/loops.rs index 1c5ab2874b0..bbcea387de2 100644 --- a/src/tools/clippy/clippy_lints/src/loops.rs +++ b/src/tools/clippy/clippy_lints/src/loops.rs @@ -533,7 +533,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { } // check for never_loop - if let ExprKind::Loop(ref block, _, _) = expr.kind { + if let ExprKind::Loop(ref block, _, _, _) = expr.kind { match never_loop_block(block, expr.hir_id) { NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"), NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (), @@ -543,7 +543,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops { // check for `loop { if let {} else break }` that could be `while let` // (also matches an explicit "match" instead of "if let") // (even if the "match" or "if let" is used for declaration) - if let ExprKind::Loop(ref block, _, LoopSource::Loop) = expr.kind { + if let ExprKind::Loop(ref block, _, LoopSource::Loop, _) = expr.kind { // also check for empty `loop {}` statements, skipping those in #[panic_handler] if block.stmts.is_empty() && block.expr.is_none() && !is_in_panic_handler(cx, expr) { let msg = "empty `loop {}` wastes CPU cycles"; @@ -738,7 +738,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult { | ExprKind::Assign(ref e1, ref e2, _) | ExprKind::AssignOp(_, ref e1, ref e2) | ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id), - ExprKind::Loop(ref b, _, _) => { + ExprKind::Loop(ref b, _, _, _) => { // Break can come from the inner loop so remove them. absorb_break(&never_loop_block(b, main_loop_id)) }, @@ -1314,7 +1314,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { match &expr.kind { // Non-determinism may occur ... don't give a lint - ExprKind::Loop(_, _, _) | ExprKind::Match(_, _, _) => self.should_lint = false, + ExprKind::Loop(..) | ExprKind::Match(..) => self.should_lint = false, ExprKind::Block(block, _) => self.visit_block(block), _ => {}, } diff --git a/src/tools/clippy/clippy_lints/src/needless_continue.rs b/src/tools/clippy/clippy_lints/src/needless_continue.rs index a971d041ca6..603071a5f4a 100644 --- a/src/tools/clippy/clippy_lints/src/needless_continue.rs +++ b/src/tools/clippy/clippy_lints/src/needless_continue.rs @@ -221,7 +221,7 @@ where { if let ast::ExprKind::While(_, loop_block, label) | ast::ExprKind::ForLoop(_, _, loop_block, label) - | ast::ExprKind::Loop(loop_block, label) = &expr.kind + | ast::ExprKind::Loop(loop_block, label, ..) = &expr.kind { func(loop_block, label.as_ref()); } diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index 24da056770c..d5b1767e945 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -325,7 +325,7 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut | ExprKind::Field(ref e, _) | ExprKind::AddrOf(_, _, ref e) | ExprKind::Box(ref e) => check_expr(cx, e, bindings), - ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings), + ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, ..) => check_block(cx, block, bindings), // ExprKind::Call // ExprKind::MethodCall ExprKind::Array(v) | ExprKind::Tup(v) => { diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 43afa65de3e..ca60d335262 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -317,7 +317,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { self.current = cast_pat; self.visit_expr(expr); }, - ExprKind::Loop(ref body, _, desugaring) => { + ExprKind::Loop(ref body, _, desugaring, _) => { let body_pat = self.next("body"); let des = loop_desugaring_name(desugaring); let label_pat = self.next("label"); diff --git a/src/tools/clippy/clippy_lints/src/utils/higher.rs b/src/tools/clippy/clippy_lints/src/utils/higher.rs index 9b3585865da..42ab9a1e7d2 100644 --- a/src/tools/clippy/clippy_lints/src/utils/higher.rs +++ b/src/tools/clippy/clippy_lints/src/utils/higher.rs @@ -142,7 +142,7 @@ pub fn for_loop<'tcx>( if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind; if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind; if iterargs.len() == 1 && arms.len() == 1 && arms[0].guard.is_none(); - if let hir::ExprKind::Loop(ref block, _, _) = arms[0].body.kind; + if let hir::ExprKind::Loop(ref block, ..) = arms[0].body.kind; if block.expr.is_none(); if let [ _, _, ref let_stmt, ref body ] = *block.stmts; if let hir::StmtKind::Local(ref local) = let_stmt.kind; @@ -158,7 +158,7 @@ pub fn for_loop<'tcx>( /// `while cond { body }` becomes `(cond, body)`. pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> { if_chain! { - if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.kind; + if let hir::ExprKind::Loop(block, _, hir::LoopSource::While, _) = &expr.kind; if let hir::Block { expr: Some(expr), .. } = &**block; if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.kind; if let hir::ExprKind::DropTemps(cond) = &cond.kind; diff --git a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs index 10120a8805d..6066383f2ef 100644 --- a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs +++ b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r)) }, (&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node, - (&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => { + (&ExprKind::Loop(ref lb, ref ll, ref lls, _), &ExprKind::Loop(ref rb, ref rl, ref rls, _)) => { lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name) }, (&ExprKind::Match(ref le, ref la, ref ls), &ExprKind::Match(ref re, ref ra, ref rs)) => { @@ -560,7 +560,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { ExprKind::Lit(ref l) => { l.node.hash(&mut self.s); }, - ExprKind::Loop(ref b, ref i, _) => { + ExprKind::Loop(ref b, ref i, ..) => { self.hash_block(b); if let Some(i) = *i { self.hash_name(i.ident.name); |
