From 38e4233a3291b0b8e3148e7ea47da66c9d8b307f Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sat, 13 Feb 2021 22:17:15 +1100 Subject: [PATCH 01/27] Replace const_cstr with cstr crate --- Cargo.lock | 11 +++++++ compiler/rustc_codegen_llvm/Cargo.toml | 1 + compiler/rustc_codegen_llvm/src/abi.rs | 2 +- compiler/rustc_codegen_llvm/src/attributes.rs | 30 +++++++++---------- compiler/rustc_codegen_llvm/src/builder.rs | 8 ++--- compiler/rustc_codegen_llvm/src/consts.rs | 6 ++-- compiler/rustc_codegen_llvm/src/context.rs | 6 ++-- .../src/debuginfo/metadata.rs | 6 ++-- .../rustc_data_structures/src/const_cstr.rs | 30 ------------------- compiler/rustc_data_structures/src/lib.rs | 1 - src/tools/tidy/src/deps.rs | 1 + 11 files changed, 42 insertions(+), 60 deletions(-) delete mode 100644 compiler/rustc_data_structures/src/const_cstr.rs diff --git a/Cargo.lock b/Cargo.lock index a9e65ffc39107..d90649d89638f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -866,6 +866,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cstr" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c11a39d776a3b35896711da8a04dc1835169dcd36f710878187637314e47941b" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "ctor" version = "0.1.15" @@ -3620,6 +3630,7 @@ name = "rustc_codegen_llvm" version = "0.0.0" dependencies = [ "bitflags", + "cstr", "libc", "measureme", "rustc-demangle", diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index f9373640dce5e..33e588c3dae15 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [dependencies] bitflags = "1.0" +cstr = "0.2" libc = "0.2" measureme = "9.0.0" snap = "1" diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index a69241e456f16..d714ff1fe9b4a 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -554,7 +554,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { llvm::AddCallSiteAttrString( callsite, llvm::AttributePlace::Function, - rustc_data_structures::const_cstr!("cmse_nonsecure_call"), + cstr::cstr!("cmse_nonsecure_call"), ); } } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 26111729ba5b2..09ece6164ebd1 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -2,8 +2,8 @@ use std::ffi::CString; +use cstr::cstr; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; @@ -75,8 +75,8 @@ pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("frame-pointer"), - const_cstr!("all"), + cstr!("frame-pointer"), + cstr!("all"), ); } } @@ -95,7 +95,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("instrument-function-entry-inlined"), + cstr!("instrument-function-entry-inlined"), &mcount_name, ); } @@ -129,16 +129,16 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { StackProbeType::None => None, // Request LLVM to generate the probes inline. If the given LLVM version does not support // this, no probe is generated at all (even if the attribute is specified). - StackProbeType::Inline => Some(const_cstr!("inline-asm")), + StackProbeType::Inline => Some(cstr!("inline-asm")), // Flag our internal `__rust_probestack` function as the stack probe symbol. // This is defined in the `compiler-builtins` crate for each architecture. - StackProbeType::Call => Some(const_cstr!("__rust_probestack")), + StackProbeType::Call => Some(cstr!("__rust_probestack")), // Pick from the two above based on the LLVM version. StackProbeType::InlineOrCall { min_llvm_version_for_inline } => { if llvm_util::get_version() < min_llvm_version_for_inline { - Some(const_cstr!("__rust_probestack")) + Some(cstr!("__rust_probestack")) } else { - Some(const_cstr!("inline-asm")) + Some(cstr!("inline-asm")) } } }; @@ -146,7 +146,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("probe-stack"), + cstr!("probe-stack"), attr_value, ); } @@ -169,7 +169,7 @@ pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("target-cpu"), + cstr!("target-cpu"), target_cpu.as_c_str(), ); } @@ -180,7 +180,7 @@ pub fn apply_tune_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("tune-cpu"), + cstr!("tune-cpu"), tune_cpu.as_c_str(), ); } @@ -289,7 +289,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: Attribute::NoAlias.apply_llfn(llvm::AttributePlace::ReturnValue, llfn); } if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY) { - llvm::AddFunctionAttrString(llfn, Function, const_cstr!("cmse_nonsecure_entry")); + llvm::AddFunctionAttrString(llfn, Function, cstr!("cmse_nonsecure_entry")); } sanitize(cx, codegen_fn_attrs.no_sanitize, llfn); @@ -319,7 +319,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("target-features"), + cstr!("target-features"), &val, ); } @@ -332,7 +332,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("wasm-import-module"), + cstr!("wasm-import-module"), &module, ); @@ -342,7 +342,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty:: llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, - const_cstr!("wasm-import-name"), + cstr!("wasm-import-name"), &name, ); } diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index d2f4d3edc2207..f4852c91e53d5 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -5,13 +5,13 @@ use crate::llvm::{AtomicOrdering, AtomicRmwBinOp, SynchronizationScope}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; +use cstr::cstr; use libc::{c_char, c_uint}; use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, TypeKind}; use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::MemFlags; -use rustc_data_structures::const_cstr; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; use rustc_middle::ty::layout::TyAndLayout; @@ -979,7 +979,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> { - let name = const_cstr!("cleanuppad"); + let name = cstr!("cleanuppad"); let ret = unsafe { llvm::LLVMRustBuildCleanupPad( self.llbuilder, @@ -1003,7 +1003,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> { - let name = const_cstr!("catchpad"); + let name = cstr!("catchpad"); let ret = unsafe { llvm::LLVMRustBuildCatchPad( self.llbuilder, @@ -1022,7 +1022,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unwind: Option<&'ll BasicBlock>, num_handlers: usize, ) -> &'ll Value { - let name = const_cstr!("catchswitch"); + let name = cstr!("catchswitch"); let ret = unsafe { llvm::LLVMRustBuildCatchSwitch( self.llbuilder, diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 16e1a8a1242ae..99046839973d5 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -5,9 +5,9 @@ use crate::llvm::{self, True}; use crate::type_::Type; use crate::type_of::LayoutLlvmExt; use crate::value::Value; +use cstr::cstr; use libc::c_uint; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::interpret::{ @@ -419,9 +419,9 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { .all(|&byte| byte == 0); let sect_name = if all_bytes_are_zero { - const_cstr!("__DATA,__thread_bss") + cstr!("__DATA,__thread_bss") } else { - const_cstr!("__DATA,__thread_data") + cstr!("__DATA,__thread_data") }; llvm::LLVMSetSection(g, sect_name.as_ptr()); } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index ee099f93258b7..3ddc742420202 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -7,10 +7,10 @@ use crate::llvm_util; use crate::type_::Type; use crate::value::Value; +use cstr::cstr; use rustc_codegen_ssa::base::wants_msvc_seh; use rustc_codegen_ssa::traits::*; use rustc_data_structures::base_n; -use rustc_data_structures::const_cstr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::bug; @@ -414,8 +414,8 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn create_used_variable(&self) { - let name = const_cstr!("llvm.used"); - let section = const_cstr!("llvm.metadata"); + let name = cstr!("llvm.used"); + let section = cstr!("llvm.metadata"); let array = self.const_array(&self.type_ptr_to(self.type_i8()), &*self.used_statics.borrow()); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6e7c0b3e3478a..4c332a81a1c90 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -18,8 +18,8 @@ use crate::llvm::debuginfo::{ }; use crate::value::Value; +use cstr::cstr; use rustc_codegen_ssa::traits::*; -use rustc_data_structures::const_cstr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -1072,7 +1072,7 @@ pub fn compile_unit_metadata( gcov_cu_info.len() as c_uint, ); - let llvm_gcov_ident = const_cstr!("llvm.gcov"); + let llvm_gcov_ident = cstr!("llvm.gcov"); llvm::LLVMAddNamedMetadataOperand( debug_context.llmod, llvm_gcov_ident.as_ptr(), @@ -1090,7 +1090,7 @@ pub fn compile_unit_metadata( ); llvm::LLVMAddNamedMetadataOperand( debug_context.llmod, - const_cstr!("llvm.ident").as_ptr(), + cstr!("llvm.ident").as_ptr(), llvm::LLVMMDNodeInContext(debug_context.llcontext, &name_metadata, 1), ); } diff --git a/compiler/rustc_data_structures/src/const_cstr.rs b/compiler/rustc_data_structures/src/const_cstr.rs deleted file mode 100644 index 1ebcb87818ecf..0000000000000 --- a/compiler/rustc_data_structures/src/const_cstr.rs +++ /dev/null @@ -1,30 +0,0 @@ -/// This macro creates a zero-overhead &CStr by adding a NUL terminator to -/// the string literal passed into it at compile-time. Use it like: -/// -/// ``` -/// let some_const_cstr = const_cstr!("abc"); -/// ``` -/// -/// The above is roughly equivalent to: -/// -/// ``` -/// let some_const_cstr = CStr::from_bytes_with_nul(b"abc\0").unwrap() -/// ``` -/// -/// Note that macro only checks the string literal for internal NULs if -/// debug-assertions are enabled in order to avoid runtime overhead in release -/// builds. -#[macro_export] -macro_rules! const_cstr { - ($s:expr) => {{ - use std::ffi::CStr; - - let str_plus_nul = concat!($s, "\0"); - - if cfg!(debug_assertions) { - CStr::from_bytes_with_nul(str_plus_nul.as_bytes()).unwrap() - } else { - unsafe { CStr::from_bytes_with_nul_unchecked(str_plus_nul.as_bytes()) } - } - }}; -} diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 5880bbd3de44e..24c91c39c7357 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -70,7 +70,6 @@ pub mod base_n; pub mod binary_search_util; pub mod box_region; pub mod captures; -pub mod const_cstr; pub mod flock; pub mod functor; pub mod fx; diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index f127086724fc6..f8e0bcc357d91 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -85,6 +85,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "crossbeam-epoch", "crossbeam-queue", "crossbeam-utils", + "cstr", "datafrog", "difference", "digest", From fece59b56cbeda4faa7c148ad58569c2bd52a52d Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 18:29:14 +0900 Subject: [PATCH 02/27] Change `find_anon_type` method to function --- .../nice_region_error/different_lifetimes.rs | 5 +- .../nice_region_error/find_anon_type.rs | 114 +++++++++--------- .../error_reporting/nice_region_error/mod.rs | 2 +- .../nice_region_error/named_anon_conflict.rs | 3 +- 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index cdd68d83f22b1..1b35c4032f44c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -1,6 +1,7 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where both the regions are anonymous. +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::infer::error_reporting::nice_region_error::util::AnonymousParamInfo; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use crate::infer::lexical_region_resolve::RegionResolutionError; @@ -66,9 +67,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let scope_def_id_sub = anon_reg_sub.def_id; let bregion_sub = anon_reg_sub.boundregion; - let ty_sup = self.find_anon_type(sup, &bregion_sup)?; + let ty_sup = find_anon_type(self.tcx(), sup, &bregion_sup)?; - let ty_sub = self.find_anon_type(sub, &bregion_sub)?; + let ty_sub = find_anon_type(self.tcx(), sub, &bregion_sub)?; debug!( "try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}", diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs index b014b9832e783..ffdaedf8666c3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -1,4 +1,3 @@ -use crate::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_hir as hir; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::Node; @@ -6,67 +5,64 @@ use rustc_middle::hir::map::Map; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::{self, Region, TyCtxt}; -impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { - /// This function calls the `visit_ty` method for the parameters - /// corresponding to the anonymous regions. The `nested_visitor.found_type` - /// contains the anonymous type. - /// - /// # Arguments - /// region - the anonymous region corresponding to the anon_anon conflict - /// br - the bound region corresponding to the above region which is of type `BrAnon(_)` - /// - /// # Example - /// ``` - /// fn foo(x: &mut Vec<&u8>, y: &u8) - /// { x.push(y); } - /// ``` - /// The function returns the nested type corresponding to the anonymous region - /// for e.g., `&u8` and Vec<`&u8`. - pub(super) fn find_anon_type( - &self, - region: Region<'tcx>, - br: &ty::BoundRegionKind, - ) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> { - if let Some(anon_reg) = self.tcx().is_suitable_region(region) { - let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id); - let fndecl = match self.tcx().hir().get(hir_id) { - Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) - | Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Fn(ref m, ..), - .. - }) - | Node::ImplItem(&hir::ImplItem { - kind: hir::ImplItemKind::Fn(ref m, ..), .. - }) => &m.decl, - _ => return None, - }; +/// This function calls the `visit_ty` method for the parameters +/// corresponding to the anonymous regions. The `nested_visitor.found_type` +/// contains the anonymous type. +/// +/// # Arguments +/// region - the anonymous region corresponding to the anon_anon conflict +/// br - the bound region corresponding to the above region which is of type `BrAnon(_)` +/// +/// # Example +/// ``` +/// fn foo(x: &mut Vec<&u8>, y: &u8) +/// { x.push(y); } +/// ``` +/// The function returns the nested type corresponding to the anonymous region +/// for e.g., `&u8` and Vec<`&u8`. +pub(crate) fn find_anon_type( + tcx: TyCtxt<'tcx>, + region: Region<'tcx>, + br: &ty::BoundRegionKind, +) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnDecl<'tcx>)> { + if let Some(anon_reg) = tcx.is_suitable_region(region) { + let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id); + let fndecl = match tcx.hir().get(hir_id) { + Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) + | Node::TraitItem(&hir::TraitItem { + kind: hir::TraitItemKind::Fn(ref m, ..), .. + }) + | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(ref m, ..), .. }) => { + &m.decl + } + _ => return None, + }; - fndecl - .inputs - .iter() - .find_map(|arg| self.find_component_for_bound_region(arg, br)) - .map(|ty| (ty, &**fndecl)) - } else { - None - } + fndecl + .inputs + .iter() + .find_map(|arg| find_component_for_bound_region(tcx, arg, br)) + .map(|ty| (ty, &**fndecl)) + } else { + None } +} - // This method creates a FindNestedTypeVisitor which returns the type corresponding - // to the anonymous region. - fn find_component_for_bound_region( - &self, - arg: &'tcx hir::Ty<'tcx>, - br: &ty::BoundRegionKind, - ) -> Option<&'tcx hir::Ty<'tcx>> { - let mut nested_visitor = FindNestedTypeVisitor { - tcx: self.tcx(), - bound_region: *br, - found_type: None, - current_index: ty::INNERMOST, - }; - nested_visitor.visit_ty(arg); - nested_visitor.found_type - } +// This method creates a FindNestedTypeVisitor which returns the type corresponding +// to the anonymous region. +fn find_component_for_bound_region( + tcx: TyCtxt<'tcx>, + arg: &'tcx hir::Ty<'tcx>, + br: &ty::BoundRegionKind, +) -> Option<&'tcx hir::Ty<'tcx>> { + let mut nested_visitor = FindNestedTypeVisitor { + tcx, + bound_region: *br, + found_type: None, + current_index: ty::INNERMOST, + }; + nested_visitor.visit_ty(arg); + nested_visitor.found_type } // The FindNestedTypeVisitor captures the corresponding `hir::Ty` of the diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 0599c78ebfd07..8b2d17ac29b69 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -5,8 +5,8 @@ use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::source_map::Span; +pub mod find_anon_type; mod different_lifetimes; -mod find_anon_type; mod named_anon_conflict; mod placeholder_error; mod static_impl_trait; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 2f622231a081e..2f3c0d6957a61 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -1,5 +1,6 @@ //! Error Reporting for Anonymous Region Lifetime Errors //! where one region is named and the other is anonymous. +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::infer::error_reporting::nice_region_error::NiceRegionError; use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::Visitor; @@ -74,7 +75,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { return None; } - if let Some((_, fndecl)) = self.find_anon_type(anon, &br) { + if let Some((_, fndecl)) = find_anon_type(self.tcx(), anon, &br) { if self.is_self_anon(is_first, scope_def_id) { return None; } From 17176ccd78033b0b73f12b0d67e28edb1b002104 Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 18:38:20 +0900 Subject: [PATCH 03/27] Add indication of anonymous lifetime position --- .../src/infer/error_reporting/mod.rs | 10 ++++- ...issing-lifetimes-in-signature-2.nll.stderr | 6 +-- .../missing-lifetimes-in-signature-2.stderr | 6 +-- .../missing-lifetimes-in-signature.nll.stderr | 41 ++++++++----------- .../missing-lifetimes-in-signature.stderr | 30 ++++++-------- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 9e55f7e558999..f4eb861d61dae 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -50,6 +50,7 @@ use super::region_constraints::GenericKind; use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs}; use crate::infer; +use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type; use crate::traits::error_reporting::report_object_safety_error; use crate::traits::{ IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode, @@ -179,7 +180,14 @@ fn msg_span_from_early_bound_and_free_regions( } ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => { - (format!("the anonymous lifetime #{} defined on", idx + 1), tcx.hir().span(node)) + if let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) { + ("the anonymous lifetime defined on".to_string(), ty.span) + } else { + ( + format!("the anonymous lifetime #{} defined on", idx + 1), + tcx.hir().span(node), + ) + } } _ => ( format!("the lifetime `{}` as defined on", region), diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr index b359826cb4ae4..7e07a5775bb12 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.nll.stderr @@ -7,11 +7,11 @@ LL | | t.test(); LL | | }); | |______^ | -note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 19:1... - --> $DIR/missing-lifetimes-in-signature-2.rs:19:1 +note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... + --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr index c7def9b668d9c..4e7d52978400f 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr @@ -6,11 +6,11 @@ LL | fn func(foo: &Foo, t: T) { LL | foo.bar(move |_| { | ^^^ | -note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 19:1... - --> $DIR/missing-lifetimes-in-signature-2.rs:19:1 +note: the parameter type `T` must be valid for the anonymous lifetime defined on the function body at 19:24... + --> $DIR/missing-lifetimes-in-signature-2.rs:19:24 | LL | fn func(foo: &Foo, t: T) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature-2.rs:20:13: 23:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature-2.rs:20:9 | diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr index 1bfcdab5d860d..b509610b89e26 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.nll.stderr @@ -25,14 +25,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 25:1... - --> $DIR/missing-lifetimes-in-signature.rs:25:1 - | -LL | / fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 25:26... + --> $DIR/missing-lifetimes-in-signature.rs:25:26 + | +LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:47:45 @@ -40,14 +37,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 47:1... - --> $DIR/missing-lifetimes-in-signature.rs:47:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 47:34... + --> $DIR/missing-lifetimes-in-signature.rs:47:34 | -LL | / fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:59:58 @@ -55,11 +49,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the method body at 59:5... - --> $DIR/missing-lifetimes-in-signature.rs:59:5 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the method body at 59:47... + --> $DIR/missing-lifetimes-in-signature.rs:59:47 | LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ error[E0311]: the parameter type `G` may not live long enough --> $DIR/missing-lifetimes-in-signature.rs:68:45 @@ -67,14 +61,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a | ^^^^^^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 68:1... - --> $DIR/missing-lifetimes-in-signature.rs:68:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 68:34... + --> $DIR/missing-lifetimes-in-signature.rs:68:34 | -LL | / fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a + | ^^^^^^ error[E0621]: explicit lifetime required in the type of `dest` --> $DIR/missing-lifetimes-in-signature.rs:73:5 diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr index 69e95efa72d50..789fff7acc29b 100644 --- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr @@ -33,14 +33,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 25:1... - --> $DIR/missing-lifetimes-in-signature.rs:25:1 - | -LL | / fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 25:26... + --> $DIR/missing-lifetimes-in-signature.rs:25:26 + | +LL | fn bar(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:30:5: 32:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:25:37 | @@ -57,14 +54,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the function body at 47:1... - --> $DIR/missing-lifetimes-in-signature.rs:47:1 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the function body at 47:34... + --> $DIR/missing-lifetimes-in-signature.rs:47:34 | -LL | / fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ -LL | | -LL | | where -LL | | G: Get - | |_____________^ +LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:52:5: 54:6]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:47:45 | @@ -81,11 +75,11 @@ error[E0311]: the parameter type `G` may not live long enough LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { | ^^^^^^^^^^^^^^^^^^ | -note: the parameter type `G` must be valid for the anonymous lifetime #1 defined on the method body at 59:5... - --> $DIR/missing-lifetimes-in-signature.rs:59:5 +note: the parameter type `G` must be valid for the anonymous lifetime defined on the method body at 59:47... + --> $DIR/missing-lifetimes-in-signature.rs:59:47 | LL | fn qux<'b, G: Get + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:61:9: 63:10]` will meet its required lifetime bounds --> $DIR/missing-lifetimes-in-signature.rs:59:58 | From ce1a521012017a352dc15ef1036b3dc56fa676ca Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Sun, 21 Feb 2021 22:51:49 +0900 Subject: [PATCH 04/27] Apply tidy check --- .../src/infer/error_reporting/nice_region_error/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs index 8b2d17ac29b69..e20436690b3aa 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mod.rs @@ -5,8 +5,8 @@ use rustc_errors::{DiagnosticBuilder, ErrorReported}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::source_map::Span; -pub mod find_anon_type; mod different_lifetimes; +pub mod find_anon_type; mod named_anon_conflict; mod placeholder_error; mod static_impl_trait; From 5f7d6631f94db4bcc0498568d00f24b0bb9a382e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 22 Feb 2021 12:02:37 +0200 Subject: [PATCH 05/27] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 7435b9e98c928..14de9e54a6d9e 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 7435b9e98c9280043605748c11a1f450669e04d6 +Subproject commit 14de9e54a6d9ef070399b34a11634294a8cc3ca5 From 888811b0598aa18c3e41d1c03f4caf6cd794eaa4 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 22 Feb 2021 19:02:02 +0800 Subject: [PATCH 06/27] Add Future trait for doc_spotlight feature doc --- src/doc/unstable-book/src/language-features/doc-spotlight.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/doc-spotlight.md b/src/doc/unstable-book/src/language-features/doc-spotlight.md index 8117755fef1c8..00a05e509b87c 100644 --- a/src/doc/unstable-book/src/language-features/doc-spotlight.md +++ b/src/doc/unstable-book/src/language-features/doc-spotlight.md @@ -5,8 +5,8 @@ The tracking issue for this feature is: [#45040] The `doc_spotlight` feature allows the use of the `spotlight` parameter to the `#[doc]` attribute, to "spotlight" a specific trait on the return values of functions. Adding a `#[doc(spotlight)]` attribute to a trait definition will make rustdoc print extra information for functions which return -a type that implements that trait. This attribute is applied to the `Iterator`, `io::Read`, and -`io::Write` traits in the standard library. +a type that implements that trait. This attribute is applied to the `Iterator`, `io::Read`, +`io::Write` and `Future` traits in the standard library. You can do this on your own traits, like this: From 8f4d435401a33a7d9a096453a33a3a58a5150e00 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 29 Dec 2020 23:16:16 -0500 Subject: [PATCH 07/27] Rename rustdoc lints to be a tool lint instead of built-in. - Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests Otherwise, all `rustdoc::` lints would be ignored. - Register all existing lints as removed This unfortunately doesn't work with `register_renamed` because tool lints have not yet been registered when rustc is running. For similar reasons, `check_backwards_compat` doesn't work either. Call `register_removed` directly instead. - Fix fallout + Rustdoc lints for compiler/ + Rustdoc lints for library/ Note that this does *not* suggest `rustdoc::broken_intra_doc_links` for `rustdoc::intra_doc_link_resolution_failure`, since there was no time when the latter was valid. --- compiler/rustc_ast/src/attr/mod.rs | 2 +- compiler/rustc_error_codes/src/lib.rs | 3 +- compiler/rustc_lint/src/context.rs | 6 +- compiler/rustc_lint/src/lib.rs | 34 +++-- compiler/rustc_lint_defs/src/builtin.rs | 83 ---------- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/lib.rs | 3 +- src/bootstrap/builder.rs | 18 ++- src/librustdoc/core.rs | 144 ++++++++++++++---- src/librustdoc/doctest.rs | 10 +- src/librustdoc/html/markdown.rs | 3 +- src/librustdoc/lib.rs | 1 + .../passes/collect_intra_doc_links.rs | 6 +- src/librustdoc/passes/doc_test_lints.rs | 7 +- src/librustdoc/passes/html_tags.rs | 3 +- src/librustdoc/passes/non_autolinks.rs | 3 +- .../rustdoc-ui/assoc-item-not-in-scope.rs | 2 +- .../rustdoc-ui/assoc-item-not-in-scope.stderr | 4 +- src/test/rustdoc-ui/check-attr-test.rs | 2 +- src/test/rustdoc-ui/check-attr-test.stderr | 4 +- src/test/rustdoc-ui/check-attr.rs | 2 +- src/test/rustdoc-ui/check-attr.stderr | 4 +- src/test/rustdoc-ui/check-fail.stderr | 4 +- src/test/rustdoc-ui/check.stderr | 2 +- .../deny-intra-link-resolution-failure.rs | 2 +- .../deny-intra-link-resolution-failure.stderr | 4 +- src/test/rustdoc-ui/doc-without-codeblock.rs | 2 +- .../rustdoc-ui/doc-without-codeblock.stderr | 6 +- src/test/rustdoc-ui/intra-doc/alias-ice.rs | 2 +- .../rustdoc-ui/intra-doc/alias-ice.stderr | 4 +- src/test/rustdoc-ui/intra-doc/ambiguity.rs | 2 +- .../rustdoc-ui/intra-doc/ambiguity.stderr | 4 +- src/test/rustdoc-ui/intra-doc/anchors.rs | 2 +- src/test/rustdoc-ui/intra-doc/anchors.stderr | 4 +- .../rustdoc-ui/intra-doc/broken-reexport.rs | 2 +- .../intra-doc/disambiguator-mismatch.rs | 2 +- .../intra-doc/disambiguator-mismatch.stderr | 4 +- .../rustdoc-ui/intra-doc/double-anchor.stderr | 2 +- src/test/rustdoc-ui/intra-doc/errors.rs | 2 +- src/test/rustdoc-ui/intra-doc/errors.stderr | 4 +- .../incompatible-primitive-disambiguator.rs | 2 +- ...ncompatible-primitive-disambiguator.stderr | 4 +- .../intra-doc/malformed-generics.rs | 2 +- .../intra-doc/malformed-generics.stderr | 4 +- .../intra-doc/non-path-primitives.rs | 2 +- .../intra-doc/non-path-primitives.stderr | 4 +- .../rustdoc-ui/intra-doc/prim-conflict.rs | 2 +- .../rustdoc-ui/intra-doc/prim-conflict.stderr | 4 +- .../intra-doc/private.private.stderr | 2 +- .../intra-doc/private.public.stderr | 2 +- .../rustdoc-ui/intra-doc/span-ice-55723.rs | 2 +- .../intra-doc/span-ice-55723.stderr | 4 +- .../intra-doc/unused-extern-crate.rs | 2 +- .../intra-doc/unused-extern-crate.stderr | 4 +- .../rustdoc-ui/intra-doc/warning-crlf.stderr | 2 +- src/test/rustdoc-ui/intra-doc/warning.stderr | 2 +- src/test/rustdoc-ui/invalid-html-tags.rs | 2 +- src/test/rustdoc-ui/invalid-html-tags.stderr | 4 +- src/test/rustdoc-ui/issue-58473-2.rs | 2 +- .../rustdoc-ui/issue-74134.private.stderr | 2 +- src/test/rustdoc-ui/issue-74134.public.stderr | 2 +- src/test/rustdoc-ui/lint-group.stderr | 8 +- .../lint-missing-doc-code-example.rs | 4 +- .../lint-missing-doc-code-example.stderr | 4 +- src/test/rustdoc-ui/private-doc-test.rs | 2 +- src/test/rustdoc-ui/private-item-doc-test.rs | 2 +- .../rustdoc-ui/private-item-doc-test.stderr | 4 +- src/test/rustdoc-ui/pub-export-lint.rs | 2 +- src/test/rustdoc-ui/pub-export-lint.stderr | 4 +- .../reference-link-reports-error-once.rs | 2 +- .../reference-link-reports-error-once.stderr | 4 +- src/test/rustdoc-ui/reference-links.rs | 2 +- src/test/rustdoc-ui/reference-links.stderr | 4 +- src/test/rustdoc-ui/unknown-renamed-lints.rs | 13 +- .../rustdoc-ui/unknown-renamed-lints.stderr | 24 ++- src/test/rustdoc-ui/url-improvements.rs | 4 +- src/test/rustdoc-ui/url-improvements.stderr | 4 +- .../rustdoc/intra-doc/non-path-primitives.rs | 2 +- 78 files changed, 301 insertions(+), 243 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 4dcbe4831be27..e4fb87493b8f4 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -36,7 +36,7 @@ impl MarkedAttrs { } pub fn is_known_lint_tool(m_item: Ident) -> bool { - [sym::clippy, sym::rustc].contains(&m_item.name) + [sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name) } impl NestedMetaItem { diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index e4a702531442e..14ddb3e20793a 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -1,4 +1,5 @@ -#![deny(invalid_codeblock_attributes)] +#![cfg_attr(bootstrap, deny(invalid_codeblock_attributes))] +#![cfg_attr(not(bootstrap), deny(rustdoc::invalid_codeblock_attributes))] //! This library is used to gather all error codes into one place, //! the goal being to make their maintenance easier. diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index b8db51f590d84..7d5577cdca663 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -89,6 +89,7 @@ impl SessionLintStore for LintStore { } /// The target of the `by_name` map, which accounts for renaming/deprecation. +#[derive(Debug)] enum TargetLint { /// A direct lint target Id(LintId), @@ -470,7 +471,10 @@ impl LintStore { Some(&Id(ref id)) => { CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name))) } - _ => CheckLintNameResult::NoLint(None), + Some(other) => { + tracing::debug!("got renamed lint {:?}", other); + CheckLintNameResult::NoLint(None) + } } } } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 638b73c27a8d7..67c0e999f5518 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -69,9 +69,7 @@ use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::{ - BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS, - EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS, - MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS, + BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS, }; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; @@ -314,17 +312,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // MACRO_USE_EXTERN_CRATE ); - add_lint_group!( - "rustdoc", - NON_AUTOLINKS, - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - INVALID_CODEBLOCK_ATTRIBUTES, - MISSING_DOC_CODE_EXAMPLES, - PRIVATE_DOC_TESTS, - INVALID_HTML_TAGS - ); - // Register renamed and removed lints. store.register_renamed("single_use_lifetime", "single_use_lifetimes"); store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths"); @@ -334,8 +321,25 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { store.register_renamed("async_idents", "keyword_idents"); store.register_renamed("exceeding_bitshifts", "arithmetic_overflow"); store.register_renamed("redundant_semicolon", "redundant_semicolons"); - store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links"); store.register_renamed("overlapping_patterns", "overlapping_range_endpoints"); + + // These were moved to tool lints, but rustc still sees them when compiling normally, before + // tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use + // `register_renamed` explicitly. + const RUSTDOC_LINTS: &[&str] = &[ + "broken_intra_doc_links", + "private_intra_doc_links", + "missing_doc_code_examples", + "private_doc_tests", + "invalid_codeblock_attributes", + "invalid_html_tags", + "non_autolinks", + ]; + for rustdoc_lint in RUSTDOC_LINTS { + // FIXME: maybe we could get `register_renamed` to work for tool lints? + store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); + } + store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); store.register_removed("negate_unsigned", "cast a signed value instead"); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 686d09dd7fcb4..94efbc14afcdd 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1874,39 +1874,6 @@ declare_lint! { "detects labels that are never used" } -declare_lint! { - /// The `broken_intra_doc_links` lint detects failures in resolving - /// intra-doc link targets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub BROKEN_INTRA_DOC_LINKS, - Warn, - "failures in resolving intra-doc link targets" -} - -declare_lint! { - /// This is a subset of `broken_intra_doc_links` that warns when linking from - /// a public item to a private one. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub PRIVATE_INTRA_DOC_LINKS, - Warn, - "linking from a public item to a private one" -} - -declare_lint! { - /// The `invalid_codeblock_attributes` lint detects code block attributes - /// in documentation examples that have potentially mis-typed values. This - /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub INVALID_CODEBLOCK_ATTRIBUTES, - Warn, - "codeblock attribute looks a lot like a known one" -} - declare_lint! { /// The `missing_crate_level_docs` lint detects if documentation is /// missing at the crate root. This is a `rustdoc` only lint, see the @@ -1918,49 +1885,6 @@ declare_lint! { "detects crates with no crate-level documentation" } -declare_lint! { - /// The `missing_doc_code_examples` lint detects publicly-exported items - /// without code samples in their documentation. This is a `rustdoc` only - /// lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub MISSING_DOC_CODE_EXAMPLES, - Allow, - "detects publicly-exported items without code samples in their documentation" -} - -declare_lint! { - /// The `private_doc_tests` lint detects code samples in docs of private - /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see - /// the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub PRIVATE_DOC_TESTS, - Allow, - "detects code samples in docs of private items not documented by rustdoc" -} - -declare_lint! { - /// The `invalid_html_tags` lint detects invalid HTML tags. This is a - /// `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub INVALID_HTML_TAGS, - Allow, - "detects invalid HTML tags in doc comments" -} - -declare_lint! { - /// The `non_autolinks` lint detects when a URL could be written using - /// only angle brackets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub NON_AUTOLINKS, - Warn, - "detects URLs that could be written using only angle brackets" -} - declare_lint! { /// The `where_clauses_object_safety` lint detects for [object safety] of /// [where clauses]. @@ -3019,14 +2943,7 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - INVALID_CODEBLOCK_ATTRIBUTES, MISSING_CRATE_LEVEL_DOCS, - MISSING_DOC_CODE_EXAMPLES, - INVALID_HTML_TAGS, - PRIVATE_DOC_TESTS, - NON_AUTOLINKS, WHERE_CLAUSES_OBJECT_SAFETY, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, MACRO_USE_EXTERN_CRATE, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 653d70b6cf244..f9f58c7d9e073 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1004,6 +1004,7 @@ symbols! { rustc_then_this_would_need, rustc_unsafe_specialization_marker, rustc_variance, + rustdoc, rustfmt, rvalue_static_promotion, sanitize, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 7c0e5ab8926ef..72816d62bce37 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -295,7 +295,8 @@ pub mod primitive; unused_imports, unsafe_op_in_unsafe_fn )] -#[allow(non_autolinks)] +#[cfg_attr(bootstrap, allow(non_autolinks))] +#[cfg_attr(not(bootstrap), allow(rustdoc::non_autolinks))] // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet. #[allow(clashing_extern_declarations)] diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 08f10fbd794aa..eb6b1b9dfbea3 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -753,8 +753,15 @@ impl<'a> Builder<'a> { .env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler)) .env("CFG_RELEASE_CHANNEL", &self.config.channel) .env("RUSTDOC_REAL", self.rustdoc(compiler)) - .env("RUSTC_BOOTSTRAP", "1") - .arg("-Winvalid_codeblock_attributes"); + .env("RUSTC_BOOTSTRAP", "1"); + + // cfg(bootstrap), can be removed on the next beta bump + if compiler.stage == 0 { + cmd.arg("-Winvalid_codeblock_attributes"); + } else { + cmd.arg("-Wrustdoc::invalid_codeblock_attributes"); + } + if self.config.deny_warnings { cmd.arg("-Dwarnings"); } @@ -1308,7 +1315,12 @@ impl<'a> Builder<'a> { // fixed via better support from Cargo. cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" ")); - rustdocflags.arg("-Winvalid_codeblock_attributes"); + // cfg(bootstrap), can be removed on the next beta bump + if compiler.stage == 0 { + rustdocflags.arg("-Winvalid_codeblock_attributes"); + } else { + rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes"); + } } if mode == Mode::Rustc { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index dbf202a732108..9c224b926c42e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -12,6 +12,8 @@ use rustc_hir::{ Path, }; use rustc_interface::{interface, Queries}; +use rustc_lint::LintStore; +use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; @@ -24,9 +26,11 @@ use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; +use std::cell::RefCell; +use std::collections::hash_map::Entry; +use std::lazy::SyncLazy as Lazy; use std::mem; use std::rc::Rc; -use std::{cell::RefCell, collections::hash_map::Entry}; use crate::clean; use crate::clean::inline::build_external_trait; @@ -281,6 +285,106 @@ where (lint_opts, lint_caps) } +declare_tool_lint! { + /// The `broken_intra_doc_links` lint detects failures in resolving + /// intra-doc link targets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links + pub rustdoc::BROKEN_INTRA_DOC_LINKS, + Warn, + "failures in resolving intra-doc link targets" +} + +declare_tool_lint! { + /// This is a subset of `broken_intra_doc_links` that warns when linking from + /// a public item to a private one. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links + pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + Warn, + "linking from a public item to a private one" +} + +declare_tool_lint! { + /// The `invalid_codeblock_attributes` lint detects code block attributes + /// in documentation examples that have potentially mis-typed values. This + /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes + pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + Warn, + "codeblock attribute looks a lot like a known one" +} + +declare_tool_lint! { + /// The `missing_doc_code_examples` lint detects publicly-exported items + /// without code samples in their documentation. This is a `rustdoc` only + /// lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples + pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + Allow, + "detects publicly-exported items without code samples in their documentation" +} + +declare_tool_lint! { + /// The `private_doc_tests` lint detects code samples in docs of private + /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see + /// the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests + pub rustdoc::PRIVATE_DOC_TESTS, + Allow, + "detects code samples in docs of private items not documented by rustdoc" +} + +declare_tool_lint! { + /// The `invalid_html_tags` lint detects invalid HTML tags. This is a + /// `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags + pub rustdoc::INVALID_HTML_TAGS, + Allow, + "detects invalid HTML tags in doc comments" +} + +declare_tool_lint! { + /// The `non_autolinks` lint detects when a URL could be written using + /// only angle brackets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks + pub rustdoc::NON_AUTOLINKS, + Warn, + "detects URLs that could be written using only angle brackets" +} + +static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { + vec![ + BROKEN_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, + MISSING_DOC_CODE_EXAMPLES, + PRIVATE_DOC_TESTS, + INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_HTML_TAGS, + NON_AUTOLINKS, + ] +}); + +crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { + lint_store.register_lints(&**RUSTDOC_LINTS); + lint_store.register_group( + true, + "rustdoc", + None, + RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), + ); + lint_store + .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); +} + /// Parse, resolve, and typecheck the given crate. crate fn create_config( RustdocOptions { @@ -309,37 +413,23 @@ crate fn create_config( let cpath = Some(input.clone()); let input = Input::File(input); - let broken_intra_doc_links = lint::builtin::BROKEN_INTRA_DOC_LINKS.name; - let private_intra_doc_links = lint::builtin::PRIVATE_INTRA_DOC_LINKS.name; - let missing_docs = rustc_lint::builtin::MISSING_DOCS.name; - let missing_doc_example = rustc_lint::builtin::MISSING_DOC_CODE_EXAMPLES.name; - let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name; - let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name; - let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name; - let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name; - let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name; - let non_autolinks = rustc_lint::builtin::NON_AUTOLINKS.name; - let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name; - // In addition to those specific lints, we also need to allow those given through // command line, otherwise they'll get ignored and we don't want that. - let lints_to_show = vec![ - broken_intra_doc_links.to_owned(), - private_intra_doc_links.to_owned(), - missing_docs.to_owned(), - missing_doc_example.to_owned(), - private_doc_tests.to_owned(), - no_crate_level_docs.to_owned(), - invalid_codeblock_attributes_name.to_owned(), - invalid_html_tags.to_owned(), - renamed_and_removed_lints.to_owned(), - unknown_lints.to_owned(), - non_autolinks.to_owned(), + let mut lints_to_show = vec![ + // it's unclear whether these should be part of rustdoc directly + rustc_lint::builtin::MISSING_DOCS.name.to_string(), + rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name.to_string(), + // these are definitely not part of rustdoc, but we want to warn on them anyway. + rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), + rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), ]; + lints_to_show.extend(RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| { // FIXME: why is this necessary? - if lint.name == broken_intra_doc_links || lint.name == invalid_codeblock_attributes_name { + if lint.name == BROKEN_INTRA_DOC_LINKS.name + || lint.name == INVALID_CODEBLOCK_ATTRIBUTES.name + { None } else { Some((lint.name_lower(), lint::Allow)) @@ -379,7 +469,7 @@ crate fn create_config( diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: None, + register_lints: Some(box register_lints), override_queries: Some(|_sess, providers, _external_providers| { // Most lints will require typechecking, so just don't run them. providers.lint_mod = |_, _| {}; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index c3b9fd5a1dd42..eac0ad688d4a2 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -44,11 +44,15 @@ crate struct TestOptions { crate fn run(options: Options) -> Result<(), ErrorReported> { let input = config::Input::File(options.input.clone()); - let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name; + let invalid_codeblock_attributes_name = crate::core::INVALID_CODEBLOCK_ATTRIBUTES.name; // In addition to those specific lints, we also need to allow those given through // command line, otherwise they'll get ignored and we don't want that. - let allowed_lints = vec![invalid_codeblock_attributes_name.to_owned()]; + let allowed_lints = vec![ + invalid_codeblock_attributes_name.to_owned(), + lint::builtin::UNKNOWN_LINTS.name.to_owned(), + lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_owned(), + ]; let (lint_opts, lint_caps) = init_lints(allowed_lints, options.lint_opts.clone(), |lint| { if lint.name == invalid_codeblock_attributes_name { @@ -92,7 +96,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: None, + register_lints: Some(box crate::core::register_lints), override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index b7854bbf82b17..75e3ae1fc6e54 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -21,7 +21,6 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_hir::HirId; use rustc_middle::ty::TyCtxt; -use rustc_session::lint; use rustc_span::edition::Edition; use rustc_span::Span; use std::borrow::Cow; @@ -720,7 +719,7 @@ impl<'tcx> ExtraInfo<'tcx> { (None, None) => return, }; self.tcx.struct_span_lint_hir( - lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES, + crate::core::INVALID_CODEBLOCK_ATTRIBUTES, hir_id, self.sp, |lint| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d7978c4a0228d..3cda0053a4f3a 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -46,6 +46,7 @@ extern crate rustc_infer; extern crate rustc_interface; extern crate rustc_lexer; extern crate rustc_lint; +extern crate rustc_lint_defs; extern crate rustc_metadata; extern crate rustc_middle; extern crate rustc_mir; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index c99e1ecac739c..b396fd8ef3c36 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -16,10 +16,7 @@ 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::{ - builtin::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}, - Lint, -}; +use rustc_session::lint::Lint; use rustc_span::hygiene::{MacroKind, SyntaxContext}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::DUMMY_SP; @@ -35,6 +32,7 @@ use std::ops::Range; use crate::clean::{self, utils::find_nearest_parent_module, Crate, Item, ItemLink, PrimitiveType}; use crate::core::DocContext; +use crate::core::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::fold::DocFolder; use crate::html::markdown::{markdown_links, MarkdownLink}; use crate::passes::Pass; diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 042a895d2fa2f..68327e19b3e05 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -68,8 +68,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo return false; } let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local()); - let (level, source) = - cx.tcx.lint_level_at_node(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id); + let (level, source) = cx.tcx.lint_level_at_node(crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id); level != lint::Level::Allow || matches!(source, LintLevelSource::Default) } @@ -91,7 +90,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); cx.tcx.struct_span_lint_hir( - lint::builtin::MISSING_DOC_CODE_EXAMPLES, + crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| lint.build("missing code example in this documentation").emit(), @@ -100,7 +99,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { } else if tests.found_tests > 0 && !cx.renderinfo.borrow().access_levels.is_public(item.def_id) { cx.tcx.struct_span_lint_hir( - lint::builtin::PRIVATE_DOC_TESTS, + crate::core::PRIVATE_DOC_TESTS, hir_id, span_of_attrs(&item.attrs).unwrap_or(item.source.span()), |lint| lint.build("documentation test in private item").emit(), diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index a6fe7e228d7e8..b97872c633392 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -5,7 +5,6 @@ use crate::fold::DocFolder; use crate::html::markdown::opts; use core::ops::Range; use pulldown_cmark::{Event, Parser, Tag}; -use rustc_session::lint; use std::iter::Peekable; use std::str::CharIndices; @@ -183,7 +182,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { Some(sp) => sp, None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()), }; - cx.tcx.struct_span_lint_hir(lint::builtin::INVALID_HTML_TAGS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::core::INVALID_HTML_TAGS, hir_id, sp, |lint| { lint.build(msg).emit() }); }; diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index 9d4539a9769ca..fe21887fc050b 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -7,7 +7,6 @@ use core::ops::Range; use pulldown_cmark::{Event, LinkType, Parser, Tag}; use regex::Regex; use rustc_errors::Applicability; -use rustc_session::lint; crate const CHECK_NON_AUTOLINKS: Pass = Pass { name: "check-non-autolinks", @@ -74,7 +73,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> { let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs) .or_else(|| span_of_attrs(&item.attrs)) .unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir(lint::builtin::NON_AUTOLINKS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::core::NON_AUTOLINKS, hir_id, sp, |lint| { lint.build(msg) .span_suggestion( sp, diff --git a/src/test/rustdoc-ui/assoc-item-not-in-scope.rs b/src/test/rustdoc-ui/assoc-item-not-in-scope.rs index c5bb4305db7ec..0976515f4a426 100644 --- a/src/test/rustdoc-ui/assoc-item-not-in-scope.rs +++ b/src/test/rustdoc-ui/assoc-item-not-in-scope.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #[derive(Debug)] /// Link to [`S::fmt`] diff --git a/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr b/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr index 92d27179e8c3f..358871b532313 100644 --- a/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr +++ b/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr @@ -7,8 +7,8 @@ LL | /// Link to [`S::fmt`] note: the lint level is defined here --> $DIR/assoc-item-not-in-scope.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/check-attr-test.rs b/src/test/rustdoc-ui/check-attr-test.rs index 665f330e34ea5..023d620bea222 100644 --- a/src/test/rustdoc-ui/check-attr-test.rs +++ b/src/test/rustdoc-ui/check-attr-test.rs @@ -1,6 +1,6 @@ // compile-flags:--test -#![deny(invalid_codeblock_attributes)] +#![deny(rustdoc::invalid_codeblock_attributes)] /// foo /// diff --git a/src/test/rustdoc-ui/check-attr-test.stderr b/src/test/rustdoc-ui/check-attr-test.stderr index 1e067a5d21c44..affd0372a1f5e 100644 --- a/src/test/rustdoc-ui/check-attr-test.stderr +++ b/src/test/rustdoc-ui/check-attr-test.stderr @@ -11,8 +11,8 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`? note: the lint level is defined here --> $DIR/check-attr-test.rs:3:9 | -3 | #![deny(invalid_codeblock_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 | #![deny(rustdoc::invalid_codeblock_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully error: unknown attribute `compilefail`. Did you mean `compile_fail`? diff --git a/src/test/rustdoc-ui/check-attr.rs b/src/test/rustdoc-ui/check-attr.rs index 9e02eab753e26..763bc4c6cddb9 100644 --- a/src/test/rustdoc-ui/check-attr.rs +++ b/src/test/rustdoc-ui/check-attr.rs @@ -1,4 +1,4 @@ -#![deny(invalid_codeblock_attributes)] +#![deny(rustdoc::invalid_codeblock_attributes)] /// foo //~^ ERROR diff --git a/src/test/rustdoc-ui/check-attr.stderr b/src/test/rustdoc-ui/check-attr.stderr index 919eb047eefb5..9312cfb76f35f 100644 --- a/src/test/rustdoc-ui/check-attr.stderr +++ b/src/test/rustdoc-ui/check-attr.stderr @@ -13,8 +13,8 @@ LL | | /// ``` note: the lint level is defined here --> $DIR/check-attr.rs:1:9 | -LL | #![deny(invalid_codeblock_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::invalid_codeblock_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully error: unknown attribute `compilefail`. Did you mean `compile_fail`? diff --git a/src/test/rustdoc-ui/check-fail.stderr b/src/test/rustdoc-ui/check-fail.stderr index b4f255642da53..9f5ccbc6687c2 100644 --- a/src/test/rustdoc-ui/check-fail.stderr +++ b/src/test/rustdoc-ui/check-fail.stderr @@ -21,7 +21,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` error: unknown attribute `testharness`. Did you mean `test_harness`? --> $DIR/check-fail.rs:6:1 @@ -37,7 +37,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function error: unknown attribute `testharness`. Did you mean `test_harness`? diff --git a/src/test/rustdoc-ui/check.stderr b/src/test/rustdoc-ui/check.stderr index 27e5a736148e1..3c29a45a64a98 100644 --- a/src/test/rustdoc-ui/check.stderr +++ b/src/test/rustdoc-ui/check.stderr @@ -37,7 +37,7 @@ note: the lint level is defined here | LL | #![warn(rustdoc)] | ^^^^^^^ - = note: `#[warn(missing_doc_code_examples)]` implied by `#[warn(rustdoc)]` + = note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc)]` warning: missing code example in this documentation --> $DIR/check.rs:9:1 diff --git a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs index 54e7689f3163f..09da124b16206 100644 --- a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs +++ b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// [v2] //~ ERROR pub fn foo() {} diff --git a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr index 9ec9dd4bc9ab7..67d9c3989f5ae 100644 --- a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr +++ b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr @@ -7,8 +7,8 @@ LL | /// [v2] note: the lint level is defined here --> $DIR/deny-intra-link-resolution-failure.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/doc-without-codeblock.rs b/src/test/rustdoc-ui/doc-without-codeblock.rs index 5ad8e8a826f05..6812a454157b9 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.rs +++ b/src/test/rustdoc-ui/doc-without-codeblock.rs @@ -1,4 +1,4 @@ -#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation +#![deny(rustdoc::missing_doc_code_examples)] //~ ERROR missing code example in this documentation /// Some docs. //~^ ERROR missing code example in this documentation diff --git a/src/test/rustdoc-ui/doc-without-codeblock.stderr b/src/test/rustdoc-ui/doc-without-codeblock.stderr index 3372304f44a3d..aac537e9783cd 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.stderr +++ b/src/test/rustdoc-ui/doc-without-codeblock.stderr @@ -1,7 +1,7 @@ error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:1:1 | -LL | / #![deny(missing_doc_code_examples)] +LL | / #![deny(rustdoc::missing_doc_code_examples)] LL | | LL | | /// Some docs. LL | | @@ -13,8 +13,8 @@ LL | | } note: the lint level is defined here --> $DIR/doc-without-codeblock.rs:1:9 | -LL | #![deny(missing_doc_code_examples)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_doc_code_examples)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:7:1 diff --git a/src/test/rustdoc-ui/intra-doc/alias-ice.rs b/src/test/rustdoc-ui/intra-doc/alias-ice.rs index c053e378e7147..51922caeb2543 100644 --- a/src/test/rustdoc-ui/intra-doc/alias-ice.rs +++ b/src/test/rustdoc-ui/intra-doc/alias-ice.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] pub type TypeAlias = usize; diff --git a/src/test/rustdoc-ui/intra-doc/alias-ice.stderr b/src/test/rustdoc-ui/intra-doc/alias-ice.stderr index 3db5fad4cfbdc..5e7ffeeb8a219 100644 --- a/src/test/rustdoc-ui/intra-doc/alias-ice.stderr +++ b/src/test/rustdoc-ui/intra-doc/alias-ice.stderr @@ -7,8 +7,8 @@ LL | /// [broken cross-reference](TypeAlias::hoge) note: the lint level is defined here --> $DIR/alias-ice.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/ambiguity.rs b/src/test/rustdoc-ui/intra-doc/ambiguity.rs index f63435337cfbc..1f3dc722eff8d 100644 --- a/src/test/rustdoc-ui/intra-doc/ambiguity.rs +++ b/src/test/rustdoc-ui/intra-doc/ambiguity.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] diff --git a/src/test/rustdoc-ui/intra-doc/ambiguity.stderr b/src/test/rustdoc-ui/intra-doc/ambiguity.stderr index 7e967dc88bcdd..0f23b9b8adf67 100644 --- a/src/test/rustdoc-ui/intra-doc/ambiguity.stderr +++ b/src/test/rustdoc-ui/intra-doc/ambiguity.stderr @@ -7,8 +7,8 @@ LL | /// [true] note: the lint level is defined here --> $DIR/ambiguity.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to link to the module, prefix with `mod@` | LL | /// [mod@true] diff --git a/src/test/rustdoc-ui/intra-doc/anchors.rs b/src/test/rustdoc-ui/intra-doc/anchors.rs index ccefd2e6fabb5..009b291be1f08 100644 --- a/src/test/rustdoc-ui/intra-doc/anchors.rs +++ b/src/test/rustdoc-ui/intra-doc/anchors.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // A few tests on anchors. diff --git a/src/test/rustdoc-ui/intra-doc/anchors.stderr b/src/test/rustdoc-ui/intra-doc/anchors.stderr index 5b272d960d50f..97b0cea0c1e4d 100644 --- a/src/test/rustdoc-ui/intra-doc/anchors.stderr +++ b/src/test/rustdoc-ui/intra-doc/anchors.stderr @@ -7,8 +7,8 @@ LL | /// Or maybe [Foo::f#hola]. note: the lint level is defined here --> $DIR/anchors.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `hello#people#!` contains multiple anchors --> $DIR/anchors.rs:31:28 diff --git a/src/test/rustdoc-ui/intra-doc/broken-reexport.rs b/src/test/rustdoc-ui/intra-doc/broken-reexport.rs index ef261359ebd9e..862faa50b4ddd 100644 --- a/src/test/rustdoc-ui/intra-doc/broken-reexport.rs +++ b/src/test/rustdoc-ui/intra-doc/broken-reexport.rs @@ -1,7 +1,7 @@ // aux-build:intra-doc-broken.rs // check-pass -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] extern crate intra_doc_broken; diff --git a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs index b9c8e033b1b21..596623190a33f 100644 --- a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs +++ b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined pub enum S {} diff --git a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr index 2f5f3daa29785..5d4d4a699e4f3 100644 --- a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr +++ b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr @@ -7,8 +7,8 @@ LL | /// Link to [struct@S] note: the lint level is defined here --> $DIR/disambiguator-mismatch.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this link resolved to an enum, which is not a struct error: incompatible link kind for `S` diff --git a/src/test/rustdoc-ui/intra-doc/double-anchor.stderr b/src/test/rustdoc-ui/intra-doc/double-anchor.stderr index 1cd9231eded4d..c0241b98b78c1 100644 --- a/src/test/rustdoc-ui/intra-doc/double-anchor.stderr +++ b/src/test/rustdoc-ui/intra-doc/double-anchor.stderr @@ -4,7 +4,7 @@ warning: `with#anchor#error` contains multiple anchors LL | /// docs [label][with#anchor#error] | ^^^^^^^^^^^^^^^^^ contains invalid anchor | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/intra-doc/errors.rs b/src/test/rustdoc-ui/intra-doc/errors.rs index 81e42643ae8fc..b29f7c29b5d86 100644 --- a/src/test/rustdoc-ui/intra-doc/errors.rs +++ b/src/test/rustdoc-ui/intra-doc/errors.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined // FIXME: this should say that it was skipped (maybe an allowed by default lint?) diff --git a/src/test/rustdoc-ui/intra-doc/errors.stderr b/src/test/rustdoc-ui/intra-doc/errors.stderr index 21c806108e3af..061151720578b 100644 --- a/src/test/rustdoc-ui/intra-doc/errors.stderr +++ b/src/test/rustdoc-ui/intra-doc/errors.stderr @@ -7,8 +7,8 @@ LL | /// [path::to::nonexistent::module] note: the lint level is defined here --> $DIR/errors.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved link to `path::to::nonexistent::macro` --> $DIR/errors.rs:11:6 diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs index 0d1d5d1134b7b..3088bcd46531e 100644 --- a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs @@ -1,3 +1,3 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! [static@u8::MIN] //~^ ERROR incompatible link kind diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr index ed1c10f9e0cb8..d4dcc493c8b6a 100644 --- a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr @@ -7,8 +7,8 @@ LL | //! [static@u8::MIN] note: the lint level is defined here --> $DIR/incompatible-primitive-disambiguator.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this link resolved to an associated constant, which is not a static error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs index 9c54092146fef..15e02925ed90d 100644 --- a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs +++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! [Vec<] //~ ERROR //! [Vec $DIR/malformed-generics.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved link to `Vec $DIR/malformed-generics.rs:4:6 diff --git a/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs b/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs index 6785c4c43f541..75159979e8890 100644 --- a/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs +++ b/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #![feature(intra_doc_pointers)] // These are links that could reasonably expected to work, but don't. diff --git a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr index 174758504ae22..610c830560527 100644 --- a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr +++ b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr @@ -7,8 +7,8 @@ LL | //! [[T]::rotate_left] note: the lint level is defined here --> $DIR/non-path-primitives.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `Z` diff --git a/src/test/rustdoc-ui/intra-doc/prim-conflict.rs b/src/test/rustdoc-ui/intra-doc/prim-conflict.rs index 85738ceae8e61..2c1a8b5357aa1 100644 --- a/src/test/rustdoc-ui/intra-doc/prim-conflict.rs +++ b/src/test/rustdoc-ui/intra-doc/prim-conflict.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined /// [char] diff --git a/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr b/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr index 01275f8d9afb0..e4bd9fd4b8f1a 100644 --- a/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr +++ b/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr @@ -7,8 +7,8 @@ LL | /// [char] note: the lint level is defined here --> $DIR/prim-conflict.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to link to the module, prefix with `mod@` | LL | /// [mod@char] diff --git a/src/test/rustdoc-ui/intra-doc/private.private.stderr b/src/test/rustdoc-ui/intra-doc/private.private.stderr index 94a833fcc1a15..cae5b1f20e6c3 100644 --- a/src/test/rustdoc-ui/intra-doc/private.private.stderr +++ b/src/test/rustdoc-ui/intra-doc/private.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] [DontDocMe::f] | ^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: public documentation for `DocMe` links to private item `DontDocMe::f` diff --git a/src/test/rustdoc-ui/intra-doc/private.public.stderr b/src/test/rustdoc-ui/intra-doc/private.public.stderr index 21a60638d5efc..05b202e37fbcb 100644 --- a/src/test/rustdoc-ui/intra-doc/private.public.stderr +++ b/src/test/rustdoc-ui/intra-doc/private.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] [DontDocMe::f] | ^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: public documentation for `DocMe` links to private item `DontDocMe::f` diff --git a/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs b/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs index 7764a6df6ee77..041ec29325923 100644 --- a/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs +++ b/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // An error in calculating spans while reporting intra-doc link resolution errors caused rustdoc to // attempt to slice in the middle of a multibyte character. See diff --git a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr index 10ca14e850fd7..bf4ab9fdd18b1 100644 --- a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr +++ b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr @@ -7,8 +7,8 @@ LL | /// (arr[i]) note: the lint level is defined here --> $DIR/span-ice-55723.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs index 186503cf69d3f..9565830930f41 100644 --- a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs @@ -1,5 +1,5 @@ // compile-flags: --extern zip=whatever.rlib -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// See [zip] crate. //~^ ERROR unresolved pub struct ArrayZip; diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr index b3b57fd131838..5c0df1d1b9e4f 100644 --- a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr @@ -7,8 +7,8 @@ LL | /// See [zip] crate. note: the lint level is defined here --> $DIR/unused-extern-crate.rs:2:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr index 01e4282003766..d46df92649d17 100644 --- a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr +++ b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `error` LL | /// [error] | ^^^^^ no item named `error` in scope | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `error1` diff --git a/src/test/rustdoc-ui/intra-doc/warning.stderr b/src/test/rustdoc-ui/intra-doc/warning.stderr index 430d18165a005..135c432e05342 100644 --- a/src/test/rustdoc-ui/intra-doc/warning.stderr +++ b/src/test/rustdoc-ui/intra-doc/warning.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `Foo::baz` LL | //! Test with [Foo::baz], [Bar::foo], ... | ^^^^^^^^ the struct `Foo` has no field or associated item named `baz` | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default warning: unresolved link to `Bar::foo` --> $DIR/warning.rs:3:35 diff --git a/src/test/rustdoc-ui/invalid-html-tags.rs b/src/test/rustdoc-ui/invalid-html-tags.rs index 9c2fc4beb5eb1..cec44b6d2ca62 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.rs +++ b/src/test/rustdoc-ui/invalid-html-tags.rs @@ -1,4 +1,4 @@ -#![deny(invalid_html_tags)] +#![deny(rustdoc::invalid_html_tags)] //!

💩

//~^ ERROR unclosed HTML tag `p` diff --git a/src/test/rustdoc-ui/invalid-html-tags.stderr b/src/test/rustdoc-ui/invalid-html-tags.stderr index aa9ace006bd1a..335e100c89d89 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.stderr +++ b/src/test/rustdoc-ui/invalid-html-tags.stderr @@ -7,8 +7,8 @@ LL | //!

💩

note: the lint level is defined here --> $DIR/invalid-html-tags.rs:1:9 | -LL | #![deny(invalid_html_tags)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::invalid_html_tags)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unclosed HTML tag `p` --> $DIR/invalid-html-tags.rs:3:9 diff --git a/src/test/rustdoc-ui/issue-58473-2.rs b/src/test/rustdoc-ui/issue-58473-2.rs index e5f3b4daf5729..000b6a329c1a7 100644 --- a/src/test/rustdoc-ui/issue-58473-2.rs +++ b/src/test/rustdoc-ui/issue-58473-2.rs @@ -1,6 +1,6 @@ // check-pass -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /** diff --git a/src/test/rustdoc-ui/issue-74134.private.stderr b/src/test/rustdoc-ui/issue-74134.private.stderr index b802d7e12523a..457987e207496 100644 --- a/src/test/rustdoc-ui/issue-74134.private.stderr +++ b/src/test/rustdoc-ui/issue-74134.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/issue-74134.public.stderr b/src/test/rustdoc-ui/issue-74134.public.stderr index 40aa2ece1a373..07aebc3541fe3 100644 --- a/src/test/rustdoc-ui/issue-74134.public.stderr +++ b/src/test/rustdoc-ui/issue-74134.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/lint-group.stderr b/src/test/rustdoc-ui/lint-group.stderr index 0c111a33b6564..6f8a20f7d53f0 100644 --- a/src/test/rustdoc-ui/lint-group.stderr +++ b/src/test/rustdoc-ui/lint-group.stderr @@ -9,7 +9,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` error: documentation test in private item --> $DIR/lint-group.rs:19:1 @@ -26,7 +26,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc)]` error: missing code example in this documentation --> $DIR/lint-group.rs:26:1 @@ -45,7 +45,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(broken_intra_doc_links)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc)]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unclosed HTML tag `unknown` @@ -59,7 +59,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(invalid_html_tags)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::invalid_html_tags)]` implied by `#[deny(rustdoc)]` error: aborting due to 5 previous errors diff --git a/src/test/rustdoc-ui/lint-missing-doc-code-example.rs b/src/test/rustdoc-ui/lint-missing-doc-code-example.rs index ebe7a242211bf..8d727b0d0b550 100644 --- a/src/test/rustdoc-ui/lint-missing-doc-code-example.rs +++ b/src/test/rustdoc-ui/lint-missing-doc-code-example.rs @@ -1,5 +1,5 @@ #![deny(missing_docs)] -#![deny(missing_doc_code_examples)] +#![deny(rustdoc::missing_doc_code_examples)] //! crate level doc //! ``` @@ -19,7 +19,7 @@ fn test() { mod module1 { //~ ERROR } -#[allow(missing_doc_code_examples)] +#[allow(rustdoc::missing_doc_code_examples)] /// doc mod module2 { diff --git a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr index e02ed4a056c12..370c577f85d8f 100644 --- a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr +++ b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr @@ -8,8 +8,8 @@ LL | | } note: the lint level is defined here --> $DIR/lint-missing-doc-code-example.rs:2:9 | -LL | #![deny(missing_doc_code_examples)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_doc_code_examples)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> $DIR/lint-missing-doc-code-example.rs:37:3 diff --git a/src/test/rustdoc-ui/private-doc-test.rs b/src/test/rustdoc-ui/private-doc-test.rs index 379fa45f9fa3e..a1f9f8dca083e 100644 --- a/src/test/rustdoc-ui/private-doc-test.rs +++ b/src/test/rustdoc-ui/private-doc-test.rs @@ -1,6 +1,6 @@ // check-pass -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /// private doc test diff --git a/src/test/rustdoc-ui/private-item-doc-test.rs b/src/test/rustdoc-ui/private-item-doc-test.rs index 2f1bddc7c75cc..1a3d6cc636d31 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.rs +++ b/src/test/rustdoc-ui/private-item-doc-test.rs @@ -1,4 +1,4 @@ -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /// private doc test diff --git a/src/test/rustdoc-ui/private-item-doc-test.stderr b/src/test/rustdoc-ui/private-item-doc-test.stderr index 70b6638b23711..5df6132987c9f 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.stderr +++ b/src/test/rustdoc-ui/private-item-doc-test.stderr @@ -11,8 +11,8 @@ LL | | /// ``` note: the lint level is defined here --> $DIR/private-item-doc-test.rs:1:9 | -LL | #![deny(private_doc_tests)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::private_doc_tests)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/pub-export-lint.rs b/src/test/rustdoc-ui/pub-export-lint.rs index 3fd3f77400978..f2e66b77bf3ea 100644 --- a/src/test/rustdoc-ui/pub-export-lint.rs +++ b/src/test/rustdoc-ui/pub-export-lint.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// [aloha] //~^ ERROR unresolved link to `aloha` diff --git a/src/test/rustdoc-ui/pub-export-lint.stderr b/src/test/rustdoc-ui/pub-export-lint.stderr index c345def794c08..c6be9c6a9f504 100644 --- a/src/test/rustdoc-ui/pub-export-lint.stderr +++ b/src/test/rustdoc-ui/pub-export-lint.stderr @@ -7,8 +7,8 @@ LL | /// [aloha] note: the lint level is defined here --> $DIR/pub-export-lint.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/reference-link-reports-error-once.rs b/src/test/rustdoc-ui/reference-link-reports-error-once.rs index 7957ee373c49e..71bd2c522ff86 100644 --- a/src/test/rustdoc-ui/reference-link-reports-error-once.rs +++ b/src/test/rustdoc-ui/reference-link-reports-error-once.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// Links to [a] [link][a] /// And also a [third link][a] diff --git a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr index 218eb334a6fc3..b46a51e93fb8b 100644 --- a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr +++ b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr @@ -7,8 +7,8 @@ LL | /// [a]: ref note: the lint level is defined here --> $DIR/reference-link-reports-error-once.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `ref2` diff --git a/src/test/rustdoc-ui/reference-links.rs b/src/test/rustdoc-ui/reference-links.rs index 6e00b9f0fa1a9..e81e034465d7f 100644 --- a/src/test/rustdoc-ui/reference-links.rs +++ b/src/test/rustdoc-ui/reference-links.rs @@ -1,5 +1,5 @@ // Test that errors point to the reference, not to the title text. -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! Links to [a] [link][a] //! //! [a]: std::process::Comman diff --git a/src/test/rustdoc-ui/reference-links.stderr b/src/test/rustdoc-ui/reference-links.stderr index 3df89df21b4c6..c98a2fd7ce690 100644 --- a/src/test/rustdoc-ui/reference-links.stderr +++ b/src/test/rustdoc-ui/reference-links.stderr @@ -7,8 +7,8 @@ LL | //! [a]: std::process::Comman note: the lint level is defined here --> $DIR/reference-links.rs:2:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.rs b/src/test/rustdoc-ui/unknown-renamed-lints.rs index 7faa82ea429c2..e2238a4004c1b 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.rs +++ b/src/test/rustdoc-ui/unknown-renamed-lints.rs @@ -4,5 +4,16 @@ //~^ NOTE lint level is defined #![deny(x)] //~^ ERROR unknown lint +#![deny(rustdoc::x)] +//~^ ERROR unknown lint: `rustdoc::x` #![deny(intra_doc_link_resolution_failure)] -//~^ ERROR lint `intra_doc_link_resolution_failure` has been renamed +//~^ ERROR has been renamed + +// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough. +#![deny(non_autolinks)] +//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints] + +// This doesn't give you the right code directly, but at least points you on the +// right path. +#![deny(rustdoc::intra_doc_link_resolution_failure)] +//~^ ERROR unknown lint diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.stderr b/src/test/rustdoc-ui/unknown-renamed-lints.stderr index f0917f194bb08..1a45f68ae810f 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.stderr +++ b/src/test/rustdoc-ui/unknown-renamed-lints.stderr @@ -10,11 +10,17 @@ note: the lint level is defined here LL | #![deny(unknown_lints)] | ^^^^^^^^^^^^^ -error: lint `intra_doc_link_resolution_failure` has been renamed to `broken_intra_doc_links` +error: unknown lint: `rustdoc::x` --> $DIR/unknown-renamed-lints.rs:7:9 | +LL | #![deny(rustdoc::x)] + | ^^^^^^^^^^ + +error: lint `intra_doc_link_resolution_failure` has been renamed to `rustdoc::broken_intra_doc_links` + --> $DIR/unknown-renamed-lints.rs:9:9 + | LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `broken_intra_doc_links` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links` | note: the lint level is defined here --> $DIR/unknown-renamed-lints.rs:3:9 @@ -22,7 +28,19 @@ note: the lint level is defined here LL | #![deny(renamed_and_removed_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead + --> $DIR/unknown-renamed-lints.rs:13:9 + | +LL | #![deny(non_autolinks)] + | ^^^^^^^^^^^^^ + +error: unknown lint: `rustdoc::intra_doc_link_resolution_failure` + --> $DIR/unknown-renamed-lints.rs:18:9 + | +LL | #![deny(rustdoc::intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: Compilation failed, aborting rustdoc -error: aborting due to 3 previous errors +error: aborting due to 6 previous errors diff --git a/src/test/rustdoc-ui/url-improvements.rs b/src/test/rustdoc-ui/url-improvements.rs index 8531583d38a65..d0b43de2f0e0e 100644 --- a/src/test/rustdoc-ui/url-improvements.rs +++ b/src/test/rustdoc-ui/url-improvements.rs @@ -1,4 +1,4 @@ -#![deny(non_autolinks)] +#![deny(rustdoc::non_autolinks)] /// [http://aa.com](http://aa.com) //~^ ERROR unneeded long form for URL @@ -59,7 +59,7 @@ pub fn c() {} /// [should_not.lint](should_not.lint) pub fn everything_is_fine_here() {} -#[allow(non_autolinks)] +#[allow(rustdoc::non_autolinks)] pub mod foo { /// https://somewhere.com/a?hello=12&bye=11#xyz pub fn bar() {} diff --git a/src/test/rustdoc-ui/url-improvements.stderr b/src/test/rustdoc-ui/url-improvements.stderr index 70ad4b06a515d..f377973656a83 100644 --- a/src/test/rustdoc-ui/url-improvements.stderr +++ b/src/test/rustdoc-ui/url-improvements.stderr @@ -7,8 +7,8 @@ LL | /// [http://aa.com](http://aa.com) note: the lint level is defined here --> $DIR/url-improvements.rs:1:9 | -LL | #![deny(non_autolinks)] - | ^^^^^^^^^^^^^ +LL | #![deny(rustdoc::non_autolinks)] + | ^^^^^^^^^^^^^^^^^^^^^^ error: unneeded long form for URL --> $DIR/url-improvements.rs:5:5 diff --git a/src/test/rustdoc/intra-doc/non-path-primitives.rs b/src/test/rustdoc/intra-doc/non-path-primitives.rs index 48c667ef2d18e..ffa02b0c635b3 100644 --- a/src/test/rustdoc/intra-doc/non-path-primitives.rs +++ b/src/test/rustdoc/intra-doc/non-path-primitives.rs @@ -1,7 +1,7 @@ // ignore-tidy-linelength #![crate_name = "foo"] #![feature(intra_doc_pointers)] -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // @has foo/index.html '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'slice::rotate_left' //! [slice::rotate_left] From 3b13398c8dd183ed6abbf977357a78b0890683ac Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Dec 2020 14:11:15 -0500 Subject: [PATCH 08/27] Move lint machinery into a separate file --- src/librustdoc/core.rs | 175 +----------------- src/librustdoc/doctest.rs | 9 +- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/lib.rs | 1 + src/librustdoc/lint.rs | 164 ++++++++++++++++ .../passes/collect_intra_doc_links.rs | 2 +- src/librustdoc/passes/doc_test_lints.rs | 6 +- src/librustdoc/passes/html_tags.rs | 2 +- src/librustdoc/passes/non_autolinks.rs | 2 +- 9 files changed, 183 insertions(+), 180 deletions(-) create mode 100644 src/librustdoc/lint.rs diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 9c224b926c42e..a3e20f0e36919 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -12,8 +12,6 @@ use rustc_hir::{ Path, }; use rustc_interface::{interface, Queries}; -use rustc_lint::LintStore; -use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; @@ -28,7 +26,6 @@ use rustc_span::DUMMY_SP; use std::cell::RefCell; use std::collections::hash_map::Entry; -use std::lazy::SyncLazy as Lazy; use std::mem; use std::rc::Rc; @@ -227,164 +224,6 @@ crate fn new_handler( ) } -/// This function is used to setup the lint initialization. By default, in rustdoc, everything -/// is "allowed". Depending if we run in test mode or not, we want some of them to be at their -/// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTES" lint is activated in both -/// modes. -/// -/// A little detail easy to forget is that there is a way to set the lint level for all lints -/// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level -/// inside this function. -/// -/// It returns a tuple containing: -/// * Vector of tuples of lints' name and their associated "max" level -/// * HashMap of lint id with their associated "max" level -pub(crate) fn init_lints( - mut allowed_lints: Vec, - lint_opts: Vec<(String, lint::Level)>, - filter_call: F, -) -> (Vec<(String, lint::Level)>, FxHashMap) -where - F: Fn(&lint::Lint) -> Option<(String, lint::Level)>, -{ - let warnings_lint_name = lint::builtin::WARNINGS.name; - - allowed_lints.push(warnings_lint_name.to_owned()); - allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned()); - - let lints = || { - lint::builtin::HardwiredLints::get_lints() - .into_iter() - .chain(rustc_lint::SoftLints::get_lints().into_iter()) - }; - - let lint_opts = lints() - .filter_map(|lint| { - // Permit feature-gated lints to avoid feature errors when trying to - // allow all lints. - if lint.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) { - None - } else { - filter_call(lint) - } - }) - .chain(lint_opts.into_iter()) - .collect::>(); - - let lint_caps = lints() - .filter_map(|lint| { - // We don't want to allow *all* lints so let's ignore - // those ones. - if allowed_lints.iter().any(|l| lint.name == l) { - None - } else { - Some((lint::LintId::of(lint), lint::Allow)) - } - }) - .collect(); - (lint_opts, lint_caps) -} - -declare_tool_lint! { - /// The `broken_intra_doc_links` lint detects failures in resolving - /// intra-doc link targets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub rustdoc::BROKEN_INTRA_DOC_LINKS, - Warn, - "failures in resolving intra-doc link targets" -} - -declare_tool_lint! { - /// This is a subset of `broken_intra_doc_links` that warns when linking from - /// a public item to a private one. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub rustdoc::PRIVATE_INTRA_DOC_LINKS, - Warn, - "linking from a public item to a private one" -} - -declare_tool_lint! { - /// The `invalid_codeblock_attributes` lint detects code block attributes - /// in documentation examples that have potentially mis-typed values. This - /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, - Warn, - "codeblock attribute looks a lot like a known one" -} - -declare_tool_lint! { - /// The `missing_doc_code_examples` lint detects publicly-exported items - /// without code samples in their documentation. This is a `rustdoc` only - /// lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub rustdoc::MISSING_DOC_CODE_EXAMPLES, - Allow, - "detects publicly-exported items without code samples in their documentation" -} - -declare_tool_lint! { - /// The `private_doc_tests` lint detects code samples in docs of private - /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see - /// the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub rustdoc::PRIVATE_DOC_TESTS, - Allow, - "detects code samples in docs of private items not documented by rustdoc" -} - -declare_tool_lint! { - /// The `invalid_html_tags` lint detects invalid HTML tags. This is a - /// `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub rustdoc::INVALID_HTML_TAGS, - Allow, - "detects invalid HTML tags in doc comments" -} - -declare_tool_lint! { - /// The `non_autolinks` lint detects when a URL could be written using - /// only angle brackets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub rustdoc::NON_AUTOLINKS, - Warn, - "detects URLs that could be written using only angle brackets" -} - -static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { - vec![ - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - MISSING_DOC_CODE_EXAMPLES, - PRIVATE_DOC_TESTS, - INVALID_CODEBLOCK_ATTRIBUTES, - INVALID_HTML_TAGS, - NON_AUTOLINKS, - ] -}); - -crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { - lint_store.register_lints(&**RUSTDOC_LINTS); - lint_store.register_group( - true, - "rustdoc", - None, - RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), - ); - lint_store - .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); -} - /// Parse, resolve, and typecheck the given crate. crate fn create_config( RustdocOptions { @@ -413,8 +252,8 @@ crate fn create_config( let cpath = Some(input.clone()); let input = Input::File(input); - // In addition to those specific lints, we also need to allow those given through - // command line, otherwise they'll get ignored and we don't want that. + // By default, rustdoc ignores all lints. + // Specifically unblock lints relevant to documentation or the lint machinery itself. let mut lints_to_show = vec![ // it's unclear whether these should be part of rustdoc directly rustc_lint::builtin::MISSING_DOCS.name.to_string(), @@ -423,12 +262,12 @@ crate fn create_config( rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), ]; - lints_to_show.extend(RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); + lints_to_show.extend(crate::lint::RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); - let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| { + let (lint_opts, lint_caps) = crate::lint::init_lints(lints_to_show, lint_opts, |lint| { // FIXME: why is this necessary? - if lint.name == BROKEN_INTRA_DOC_LINKS.name - || lint.name == INVALID_CODEBLOCK_ATTRIBUTES.name + if lint.name == crate::lint::BROKEN_INTRA_DOC_LINKS.name + || lint.name == crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name { None } else { @@ -469,7 +308,7 @@ crate fn create_config( diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: Some(box register_lints), + register_lints: Some(box crate::lint::register_lints), override_queries: Some(|_sess, providers, _external_providers| { // Most lints will require typechecking, so just don't run them. providers.lint_mod = |_, _| {}; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index eac0ad688d4a2..27ce064669d2c 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -26,8 +26,8 @@ use std::str; use crate::clean::Attributes; use crate::config::Options; -use crate::core::init_lints; use crate::html::markdown::{self, ErrorCodes, Ignore, LangString}; +use crate::lint::init_lints; use crate::passes::span_of_attrs; #[derive(Clone, Default)] @@ -44,10 +44,9 @@ crate struct TestOptions { crate fn run(options: Options) -> Result<(), ErrorReported> { let input = config::Input::File(options.input.clone()); - let invalid_codeblock_attributes_name = crate::core::INVALID_CODEBLOCK_ATTRIBUTES.name; + let invalid_codeblock_attributes_name = crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name; - // In addition to those specific lints, we also need to allow those given through - // command line, otherwise they'll get ignored and we don't want that. + // See core::create_config for what's going on here. let allowed_lints = vec![ invalid_codeblock_attributes_name.to_owned(), lint::builtin::UNKNOWN_LINTS.name.to_owned(), @@ -96,7 +95,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: Some(box crate::core::register_lints), + register_lints: Some(box crate::lint::register_lints), override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 75e3ae1fc6e54..6f01daf36af9a 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -719,7 +719,7 @@ impl<'tcx> ExtraInfo<'tcx> { (None, None) => return, }; self.tcx.struct_span_lint_hir( - crate::core::INVALID_CODEBLOCK_ATTRIBUTES, + crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, hir_id, self.sp, |lint| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3cda0053a4f3a..f5fc3e40d4e92 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -87,6 +87,7 @@ mod formats; // used by the error-index generator, so it needs to be public pub mod html; mod json; +crate mod lint; mod markdown; mod passes; mod theme; diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs new file mode 100644 index 0000000000000..778983868ea01 --- /dev/null +++ b/src/librustdoc/lint.rs @@ -0,0 +1,164 @@ +use rustc_data_structures::fx::FxHashMap; +use rustc_lint::LintStore; +use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; +use rustc_session::{lint, Session}; + +use std::lazy::SyncLazy as Lazy; + +/// This function is used to setup the lint initialization. By default, in rustdoc, everything +/// is "allowed". Depending if we run in test mode or not, we want some of them to be at their +/// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTES" lint is activated in both +/// modes. +/// +/// A little detail easy to forget is that there is a way to set the lint level for all lints +/// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level +/// inside this function. +/// +/// It returns a tuple containing: +/// * Vector of tuples of lints' name and their associated "max" level +/// * HashMap of lint id with their associated "max" level +pub(crate) fn init_lints( + mut allowed_lints: Vec, + lint_opts: Vec<(String, lint::Level)>, + filter_call: F, +) -> (Vec<(String, lint::Level)>, FxHashMap) +where + F: Fn(&lint::Lint) -> Option<(String, lint::Level)>, +{ + let warnings_lint_name = lint::builtin::WARNINGS.name; + + allowed_lints.push(warnings_lint_name.to_owned()); + allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned()); + + let lints = || { + lint::builtin::HardwiredLints::get_lints() + .into_iter() + .chain(rustc_lint::SoftLints::get_lints().into_iter()) + }; + + let lint_opts = lints() + .filter_map(|lint| { + // Permit feature-gated lints to avoid feature errors when trying to + // allow all lints. + if lint.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) { + None + } else { + filter_call(lint) + } + }) + .chain(lint_opts.into_iter()) + .collect::>(); + + let lint_caps = lints() + .filter_map(|lint| { + // We don't want to allow *all* lints so let's ignore + // those ones. + if allowed_lints.iter().any(|l| lint.name == l) { + None + } else { + Some((lint::LintId::of(lint), lint::Allow)) + } + }) + .collect(); + (lint_opts, lint_caps) +} + +declare_tool_lint! { + /// The `broken_intra_doc_links` lint detects failures in resolving + /// intra-doc link targets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links + pub rustdoc::BROKEN_INTRA_DOC_LINKS, + Warn, + "failures in resolving intra-doc link targets" +} + +declare_tool_lint! { + /// This is a subset of `broken_intra_doc_links` that warns when linking from + /// a public item to a private one. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links + pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + Warn, + "linking from a public item to a private one" +} + +declare_tool_lint! { + /// The `invalid_codeblock_attributes` lint detects code block attributes + /// in documentation examples that have potentially mis-typed values. This + /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes + pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + Warn, + "codeblock attribute looks a lot like a known one" +} + +declare_tool_lint! { + /// The `missing_doc_code_examples` lint detects publicly-exported items + /// without code samples in their documentation. This is a `rustdoc` only + /// lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples + pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + Allow, + "detects publicly-exported items without code samples in their documentation" +} + +declare_tool_lint! { + /// The `private_doc_tests` lint detects code samples in docs of private + /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see + /// the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests + pub rustdoc::PRIVATE_DOC_TESTS, + Allow, + "detects code samples in docs of private items not documented by rustdoc" +} + +declare_tool_lint! { + /// The `invalid_html_tags` lint detects invalid HTML tags. This is a + /// `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags + pub rustdoc::INVALID_HTML_TAGS, + Allow, + "detects invalid HTML tags in doc comments" +} + +declare_tool_lint! { + /// The `non_autolinks` lint detects when a URL could be written using + /// only angle brackets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks + pub rustdoc::NON_AUTOLINKS, + Warn, + "detects URLs that could be written using only angle brackets" +} + +crate static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { + vec![ + BROKEN_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, + MISSING_DOC_CODE_EXAMPLES, + PRIVATE_DOC_TESTS, + INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_HTML_TAGS, + NON_AUTOLINKS, + ] +}); + +crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { + lint_store.register_lints(&**RUSTDOC_LINTS); + lint_store.register_group( + true, + "rustdoc", + None, + RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), + ); + lint_store + .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); +} diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b396fd8ef3c36..8d832b61e3385 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -32,9 +32,9 @@ use std::ops::Range; use crate::clean::{self, utils::find_nearest_parent_module, Crate, Item, ItemLink, PrimitiveType}; use crate::core::DocContext; -use crate::core::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::fold::DocFolder; use crate::html::markdown::{markdown_links, MarkdownLink}; +use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::passes::Pass; use super::span_of_attrs; diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 68327e19b3e05..8a78ad06e62d8 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -68,7 +68,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo return false; } let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local()); - let (level, source) = cx.tcx.lint_level_at_node(crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id); + let (level, source) = cx.tcx.lint_level_at_node(crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id); level != lint::Level::Allow || matches!(source, LintLevelSource::Default) } @@ -90,7 +90,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); cx.tcx.struct_span_lint_hir( - crate::core::MISSING_DOC_CODE_EXAMPLES, + crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| lint.build("missing code example in this documentation").emit(), @@ -99,7 +99,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { } else if tests.found_tests > 0 && !cx.renderinfo.borrow().access_levels.is_public(item.def_id) { cx.tcx.struct_span_lint_hir( - crate::core::PRIVATE_DOC_TESTS, + crate::lint::PRIVATE_DOC_TESTS, hir_id, span_of_attrs(&item.attrs).unwrap_or(item.source.span()), |lint| lint.build("documentation test in private item").emit(), diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index b97872c633392..27e669aa44fc0 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -182,7 +182,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { Some(sp) => sp, None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()), }; - cx.tcx.struct_span_lint_hir(crate::core::INVALID_HTML_TAGS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, |lint| { lint.build(msg).emit() }); }; diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index fe21887fc050b..09a1959fa113c 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> { let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs) .or_else(|| span_of_attrs(&item.attrs)) .unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir(crate::core::NON_AUTOLINKS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::lint::NON_AUTOLINKS, hir_id, sp, |lint| { lint.build(msg) .span_suggestion( sp, From 203bf4ba5386122f8d5fca752c1440b8c5d97958 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Dec 2020 14:17:18 -0500 Subject: [PATCH 09/27] Add `declare_rustdoc_lint!` macro --- src/librustdoc/lint.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 778983868ea01..013b7ead5c7c9 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -63,78 +63,86 @@ where (lint_opts, lint_caps) } -declare_tool_lint! { +macro_rules! declare_rustdoc_lint { + ($(#[$attr:meta])* $name: ident, $level: ident, $descr: literal $(,)?) => { + declare_tool_lint! { + $(#[$attr])* pub rustdoc::$name, $level, $descr + } + } +} + +declare_rustdoc_lint! { /// The `broken_intra_doc_links` lint detects failures in resolving /// intra-doc link targets. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub rustdoc::BROKEN_INTRA_DOC_LINKS, + BROKEN_INTRA_DOC_LINKS, Warn, "failures in resolving intra-doc link targets" } -declare_tool_lint! { +declare_rustdoc_lint! { /// This is a subset of `broken_intra_doc_links` that warns when linking from /// a public item to a private one. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, Warn, "linking from a public item to a private one" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `invalid_codeblock_attributes` lint detects code block attributes /// in documentation examples that have potentially mis-typed values. This /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_CODEBLOCK_ATTRIBUTES, Warn, "codeblock attribute looks a lot like a known one" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `missing_doc_code_examples` lint detects publicly-exported items /// without code samples in their documentation. This is a `rustdoc` only /// lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + MISSING_DOC_CODE_EXAMPLES, Allow, "detects publicly-exported items without code samples in their documentation" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `private_doc_tests` lint detects code samples in docs of private /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see /// the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub rustdoc::PRIVATE_DOC_TESTS, + PRIVATE_DOC_TESTS, Allow, "detects code samples in docs of private items not documented by rustdoc" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `invalid_html_tags` lint detects invalid HTML tags. This is a /// `rustdoc` only lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub rustdoc::INVALID_HTML_TAGS, + INVALID_HTML_TAGS, Allow, "detects invalid HTML tags in doc comments" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `non_autolinks` lint detects when a URL could be written using /// only angle brackets. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub rustdoc::NON_AUTOLINKS, + NON_AUTOLINKS, Warn, "detects URLs that could be written using only angle brackets" } From 152635b66be54de8992746c111689cd27bf49728 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 17 Jan 2021 18:52:19 -0500 Subject: [PATCH 10/27] Improve error messages - Use `register_renamed` when rustdoc is running so the lint will still be active and use a structured suggestion - Test the behavior for rustc, not just for rustdoc (because it differs) --- compiler/rustc_lint/src/lib.rs | 4 ++++ src/librustdoc/lint.rs | 4 ++++ src/test/rustdoc-ui/unknown-renamed-lints.rs | 8 +++----- .../rustdoc-ui/unknown-renamed-lints.stderr | 8 ++++---- src/test/ui/lint/rustdoc-renamed.rs | 14 +++++++++++++ src/test/ui/lint/rustdoc-renamed.stderr | 20 +++++++++++++++++++ 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/lint/rustdoc-renamed.rs create mode 100644 src/test/ui/lint/rustdoc-renamed.stderr diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 67c0e999f5518..86ad73d482f24 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -339,6 +339,10 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // FIXME: maybe we could get `register_renamed` to work for tool lints? store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); } + store.register_removed( + "intra_doc_link_resolution_failure", + "use `rustdoc::broken_intra_doc_links` instead", + ); store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 013b7ead5c7c9..7d95561d039f9 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -167,6 +167,10 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { None, RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), ); + for lint in &*RUSTDOC_LINTS { + let name = lint.name_lower(); + lint_store.register_renamed(&name.replace("rustdoc::", ""), &name); + } lint_store .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); } diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.rs b/src/test/rustdoc-ui/unknown-renamed-lints.rs index e2238a4004c1b..d2c78bc477410 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.rs +++ b/src/test/rustdoc-ui/unknown-renamed-lints.rs @@ -7,13 +7,11 @@ #![deny(rustdoc::x)] //~^ ERROR unknown lint: `rustdoc::x` #![deny(intra_doc_link_resolution_failure)] -//~^ ERROR has been renamed +//~^ ERROR renamed to `rustdoc::broken_intra_doc_links` -// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough. #![deny(non_autolinks)] -//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints] +//~^ ERROR renamed to `rustdoc::non_autolinks` -// This doesn't give you the right code directly, but at least points you on the -// right path. +// Explicitly don't try to handle this case, it was never valid #![deny(rustdoc::intra_doc_link_resolution_failure)] //~^ ERROR unknown lint diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.stderr b/src/test/rustdoc-ui/unknown-renamed-lints.stderr index 1a45f68ae810f..0f31673fb47f2 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.stderr +++ b/src/test/rustdoc-ui/unknown-renamed-lints.stderr @@ -28,14 +28,14 @@ note: the lint level is defined here LL | #![deny(renamed_and_removed_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead - --> $DIR/unknown-renamed-lints.rs:13:9 +error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks` + --> $DIR/unknown-renamed-lints.rs:12:9 | LL | #![deny(non_autolinks)] - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks` error: unknown lint: `rustdoc::intra_doc_link_resolution_failure` - --> $DIR/unknown-renamed-lints.rs:18:9 + --> $DIR/unknown-renamed-lints.rs:16:9 | LL | #![deny(rustdoc::intra_doc_link_resolution_failure)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/rustdoc-renamed.rs b/src/test/ui/lint/rustdoc-renamed.rs new file mode 100644 index 0000000000000..71e88bd7f54a5 --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] + +#![deny(unknown_lints)] +#![deny(renamed_and_removed_lints)] +//~^ NOTE lint level is defined + +// both allowed, since the compiler doesn't yet know what rustdoc lints are valid +#![deny(rustdoc::x)] +#![deny(rustdoc::intra_doc_link_resolution_failure)] + +#![deny(intra_doc_link_resolution_failure)] +//~^ ERROR removed: use `rustdoc::broken_intra_doc_links` +#![deny(non_autolinks)] +//~^ ERROR removed: use `rustdoc::non_autolinks` diff --git a/src/test/ui/lint/rustdoc-renamed.stderr b/src/test/ui/lint/rustdoc-renamed.stderr new file mode 100644 index 0000000000000..a7fe3e29d5be0 --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.stderr @@ -0,0 +1,20 @@ +error: lint `intra_doc_link_resolution_failure` has been removed: use `rustdoc::broken_intra_doc_links` instead + --> $DIR/rustdoc-renamed.rs:11:9 + | +LL | #![deny(intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/rustdoc-renamed.rs:4:9 + | +LL | #![deny(renamed_and_removed_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead + --> $DIR/rustdoc-renamed.rs:13:9 + | +LL | #![deny(non_autolinks)] + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From edd42747e2ff24ab0ccc0e4823cf45961ec0844c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 18 Jan 2021 01:14:01 -0500 Subject: [PATCH 11/27] Address review comments - Move MISSING_CRATE_LEVEL_DOCS to rustdoc directly - Update documentation This also takes the opportunity to make the `no-crate-level-doc-lint` test more specific. --- compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint_defs/src/builtin.rs | 12 ------- src/doc/rustdoc/src/lints.md | 35 +++++++++++-------- src/librustdoc/core.rs | 5 ++- src/librustdoc/lint.rs | 12 +++++++ src/test/rustdoc-ui/check.stderr | 13 ++++++- .../rustdoc-ui/no-crate-level-doc-lint.rs | 4 ++- .../rustdoc-ui/no-crate-level-doc-lint.stderr | 6 ++-- 8 files changed, 54 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 86ad73d482f24..a15a972cce721 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -329,6 +329,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { const RUSTDOC_LINTS: &[&str] = &[ "broken_intra_doc_links", "private_intra_doc_links", + "missing_crate_level_docs", "missing_doc_code_examples", "private_doc_tests", "invalid_codeblock_attributes", diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 94efbc14afcdd..d5f8368f3e54b 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1874,17 +1874,6 @@ declare_lint! { "detects labels that are never used" } -declare_lint! { - /// The `missing_crate_level_docs` lint detects if documentation is - /// missing at the crate root. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs - pub MISSING_CRATE_LEVEL_DOCS, - Allow, - "detects crates with no crate-level documentation" -} - declare_lint! { /// The `where_clauses_object_safety` lint detects for [object safety] of /// [where clauses]. @@ -2943,7 +2932,6 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - MISSING_CRATE_LEVEL_DOCS, WHERE_CLAUSES_OBJECT_SAFETY, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, MACRO_USE_EXTERN_CRATE, diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index cce3623dc8f49..174db711bcee7 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -4,12 +4,13 @@ can use them like any other lints by doing this: ```rust -#![allow(missing_docs)] // allows the lint, no diagnostics will be reported -#![warn(missing_docs)] // warn if there are missing docs -#![deny(missing_docs)] // error if there are missing docs -# //! Crate docs. +#![allow(rustdoc::broken_intra_doc_links)] // allows the lint, no diagnostics will be reported +#![warn(rustdoc::broken_intra_doc_links)] // warn if there are broken intra-doc links +#![deny(rustdoc::broken_intra_doc_links)] // error if there are broken intra-doc links ``` +Note that, except for `missing_docs`, these lints are only available when running `rustdoc`, not `rustc`. + Here is the list of the lints provided by `rustdoc`: ## broken_intra_doc_links @@ -51,7 +52,7 @@ warning: `Foo` is both an enum and a function 1 | /// [`Foo`] | ^^^^^ ambiguous link | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default help: to link to the enum, prefix with the item type | 1 | /// [`enum@Foo`] @@ -83,7 +84,7 @@ warning: public documentation for `public` links to private item `private` 1 | /// [private] | ^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` ``` @@ -97,7 +98,7 @@ warning: public documentation for `public` links to private item `private` 1 | /// [private] | ^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without ``` @@ -125,13 +126,15 @@ warning: missing documentation for a function | ^^^^^^^^^^^^^^^^^^^^^ ``` +Note that unlike other rustdoc lints, this lint is also available from `rustc` directly. + ## missing_crate_level_docs This lint is **allowed by default**. It detects if there is no documentation at the crate root. For example: ```rust -#![warn(missing_crate_level_docs)] +#![warn(rustdoc::missing_crate_level_docs)] ``` This will generate the following warning: @@ -155,7 +158,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects when a d is missing a code example. For example: ```rust -#![warn(missing_doc_code_examples)] +#![warn(rustdoc::missing_doc_code_examples)] /// There is no code example! pub fn no_code_example() {} @@ -191,7 +194,7 @@ This lint is **allowed by default**. It detects documentation tests when they are on a private item. For example: ```rust -#![warn(private_doc_tests)] +#![warn(rustdoc::private_doc_tests)] mod foo { /// private doc test @@ -245,7 +248,7 @@ warning: unknown attribute `should-panic`. Did you mean `should_panic`? 5 | | /// ``` | |_______^ | - = note: `#[warn(invalid_codeblock_attributes)]` on by default + = note: `#[warn(rustdoc::invalid_codeblock_attributes)]` on by default = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running ``` @@ -258,7 +261,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects unclosed or invalid HTML tags. For example: ```rust -#![warn(invalid_html_tags)] +#![warn(rustdoc::invalid_html_tags)] ///

/// @@ -275,7 +278,11 @@ warning: unopened HTML tag `script` 2 | | /// | |_____________^ | - = note: `#[warn(invalid_html_tags)]` on by default + note: the lint level is defined here + --> foo.rs:1:9 + | +1 | #![warn(rustdoc::invalid_html_tags)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unclosed HTML tag `h1` --> foo.rs:1:1 @@ -310,7 +317,7 @@ warning: this URL is not a hyperlink 1 | /// http://example.org | ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `` | - = note: `#[warn(non_autolinks)]` on by default + = note: `#[warn(rustdoc::non_autolinks)]` on by default warning: unneeded long form for URL --> foo.rs:2:5 diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a3e20f0e36919..d7ad9423abdbc 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -255,9 +255,8 @@ crate fn create_config( // By default, rustdoc ignores all lints. // Specifically unblock lints relevant to documentation or the lint machinery itself. let mut lints_to_show = vec![ - // it's unclear whether these should be part of rustdoc directly + // it's unclear whether this should be part of rustdoc directly (#77364) rustc_lint::builtin::MISSING_DOCS.name.to_string(), - rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name.to_string(), // these are definitely not part of rustdoc, but we want to warn on them anyway. rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), @@ -474,7 +473,7 @@ crate fn run_global_ctxt( let help = "The following guide may be of use:\n\ https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html"; tcx.struct_lint_node( - rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS, + crate::lint::MISSING_CRATE_LEVEL_DOCS, ctxt.as_local_hir_id(m.def_id).unwrap(), |lint| { let mut diag = diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 7d95561d039f9..e8806c1b6d787 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -104,6 +104,17 @@ declare_rustdoc_lint! { "codeblock attribute looks a lot like a known one" } +declare_rustdoc_lint! { + /// The `missing_crate_level_docs` lint detects if documentation is + /// missing at the crate root. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs + MISSING_CRATE_LEVEL_DOCS, + Allow, + "detects crates with no crate-level documentation" +} + declare_rustdoc_lint! { /// The `missing_doc_code_examples` lint detects publicly-exported items /// without code samples in their documentation. This is a `rustdoc` only @@ -156,6 +167,7 @@ crate static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS, NON_AUTOLINKS, + MISSING_CRATE_LEVEL_DOCS, ] }); diff --git a/src/test/rustdoc-ui/check.stderr b/src/test/rustdoc-ui/check.stderr index 3c29a45a64a98..e6ba9df9b0555 100644 --- a/src/test/rustdoc-ui/check.stderr +++ b/src/test/rustdoc-ui/check.stderr @@ -21,6 +21,17 @@ warning: missing documentation for a function LL | pub fn foo() {} | ^^^^^^^^^^^^ +warning: no documentation found for this crate's top-level module + | +note: the lint level is defined here + --> $DIR/check.rs:7:9 + | +LL | #![warn(rustdoc)] + | ^^^^^^^ + = note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc)]` + = help: The following guide may be of use: + https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html + warning: missing code example in this documentation --> $DIR/check.rs:4:1 | @@ -45,5 +56,5 @@ warning: missing code example in this documentation LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ -warning: 4 warnings emitted +warning: 5 warnings emitted diff --git a/src/test/rustdoc-ui/no-crate-level-doc-lint.rs b/src/test/rustdoc-ui/no-crate-level-doc-lint.rs index 152a7cd88bcb1..3939ec6827ade 100644 --- a/src/test/rustdoc-ui/no-crate-level-doc-lint.rs +++ b/src/test/rustdoc-ui/no-crate-level-doc-lint.rs @@ -1,3 +1,5 @@ -#![deny(missing_crate_level_docs)] +// error-pattern: no documentation found +#![deny(rustdoc::missing_crate_level_docs)] +//^~ NOTE defined here pub fn foo() {} diff --git a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr index 6e7e2fb3eb73f..55ead1a55cfcd 100644 --- a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr +++ b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr @@ -1,10 +1,10 @@ error: no documentation found for this crate's top-level module | note: the lint level is defined here - --> $DIR/no-crate-level-doc-lint.rs:1:9 + --> $DIR/no-crate-level-doc-lint.rs:2:9 | -LL | #![deny(missing_crate_level_docs)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_crate_level_docs)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: The following guide may be of use: https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html From 588c8e1fa26f83096af1a766c2a885c684ba46c4 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 18 Jan 2021 22:24:16 -0500 Subject: [PATCH 12/27] Update comments Note that the FIXME was removed because this can't be fixed, `register_renamed` calls LintId::of and there's no LintId for rustdoc lints when rustc is running. --- compiler/rustc_lint/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index a15a972cce721..547779dd6856a 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -325,7 +325,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // These were moved to tool lints, but rustc still sees them when compiling normally, before // tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use - // `register_renamed` explicitly. + // `register_removed` explicitly. const RUSTDOC_LINTS: &[&str] = &[ "broken_intra_doc_links", "private_intra_doc_links", @@ -337,7 +337,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { "non_autolinks", ]; for rustdoc_lint in RUSTDOC_LINTS { - // FIXME: maybe we could get `register_renamed` to work for tool lints? store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); } store.register_removed( From 75d1e303af04758c26e1aee63f2f0afd53dfd6f8 Mon Sep 17 00:00:00 2001 From: 0yoyoyo <60439919+0yoyoyo@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:39:06 +0900 Subject: [PATCH 13/27] Update test cases --- src/test/ui/issues/issue-16683.stderr | 6 ++--- src/test/ui/issues/issue-17740.stderr | 12 +++++----- src/test/ui/issues/issue-17758.stderr | 6 ++--- src/test/ui/issues/issue-17905-2.stderr | 12 +++++----- .../ui/issues/issue-20831-debruijn.stderr | 6 ++--- src/test/ui/issues/issue-27942.stderr | 12 +++++----- src/test/ui/nll/issue-52742.stderr | 6 ++--- src/test/ui/nll/issue-55394.stderr | 6 ++--- .../ui/nll/type-alias-free-regions.stderr | 12 +++++----- .../regions-infer-paramd-indirect.stderr | 6 ++--- .../ui/ufcs/ufcs-explicit-self-bad.stderr | 24 +++++++++---------- 11 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/test/ui/issues/issue-16683.stderr b/src/test/ui/issues/issue-16683.stderr index 6efc12df8fa2c..35bcf286c440f 100644 --- a/src/test/ui/issues/issue-16683.stderr +++ b/src/test/ui/issues/issue-16683.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.a(); | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 3:5... - --> $DIR/issue-16683.rs:3:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 3:10... + --> $DIR/issue-16683.rs:3:10 | LL | fn b(&self) { - | ^^^^^^^^^^^ + | ^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-16683.rs:4:9 | diff --git a/src/test/ui/issues/issue-17740.stderr b/src/test/ui/issues/issue-17740.stderr index 9fe80232a1421..995f5f1fc3de3 100644 --- a/src/test/ui/issues/issue-17740.stderr +++ b/src/test/ui/issues/issue-17740.stderr @@ -6,11 +6,11 @@ LL | fn bar(self: &mut Foo) { | = note: expected struct `Foo<'a>` found struct `Foo<'_>` -note: the anonymous lifetime #2 defined on the method body at 6:5... - --> $DIR/issue-17740.rs:6:5 +note: the anonymous lifetime defined on the method body at 6:23... + --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 5:7 --> $DIR/issue-17740.rs:5:7 | @@ -30,11 +30,11 @@ note: the lifetime `'a` as defined on the impl at 5:7... | LL | impl <'a> Foo<'a>{ | ^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 6:5 - --> $DIR/issue-17740.rs:6:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 6:23 + --> $DIR/issue-17740.rs:6:23 | LL | fn bar(self: &mut Foo) { - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-17758.stderr b/src/test/ui/issues/issue-17758.stderr index f82e0f53a23df..846e8939b53b8 100644 --- a/src/test/ui/issues/issue-17758.stderr +++ b/src/test/ui/issues/issue-17758.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for autoref due to conflictin LL | self.foo(); | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5... - --> $DIR/issue-17758.rs:6:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 6:12... + --> $DIR/issue-17758.rs:6:12 | LL | fn bar(&self) { - | ^^^^^^^^^^^^^ + | ^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-17758.rs:7:9 | diff --git a/src/test/ui/issues/issue-17905-2.stderr b/src/test/ui/issues/issue-17905-2.stderr index c762a4ab496c9..3c27f7058591c 100644 --- a/src/test/ui/issues/issue-17905-2.stderr +++ b/src/test/ui/issues/issue-17905-2.stderr @@ -6,11 +6,11 @@ LL | fn say(self: &Pair<&str, isize>) { | = note: expected struct `Pair<&str, _>` found struct `Pair<&str, _>` -note: the anonymous lifetime #2 defined on the method body at 8:5... - --> $DIR/issue-17905-2.rs:8:5 +note: the anonymous lifetime defined on the method body at 8:24... + --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ note: ...does not necessarily outlive the lifetime `'_` as defined on the impl at 5:5 --> $DIR/issue-17905-2.rs:5:5 | @@ -30,11 +30,11 @@ note: the lifetime `'_` as defined on the impl at 5:5... | LL | &str, | ^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 8:5 - --> $DIR/issue-17905-2.rs:8:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 8:24 + --> $DIR/issue-17905-2.rs:8:24 | LL | fn say(self: &Pair<&str, isize>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-20831-debruijn.stderr b/src/test/ui/issues/issue-20831-debruijn.stderr index bcfb6b70b2e5f..e68482d1caf69 100644 --- a/src/test/ui/issues/issue-20831-debruijn.stderr +++ b/src/test/ui/issues/issue-20831-debruijn.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the method body at 28:5... - --> $DIR/issue-20831-debruijn.rs:28:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 28:58... + --> $DIR/issue-20831-debruijn.rs:28:58 | LL | fn subscribe(&mut self, t : Box::Output> + 'a>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the impl at 26:6... --> $DIR/issue-20831-debruijn.rs:26:6 | diff --git a/src/test/ui/issues/issue-27942.stderr b/src/test/ui/issues/issue-27942.stderr index 6ce0fa37a8840..80eecb42d1cef 100644 --- a/src/test/ui/issues/issue-27942.stderr +++ b/src/test/ui/issues/issue-27942.stderr @@ -6,11 +6,11 @@ LL | fn select(&self) -> BufferViewHandle; | = note: expected type `Resources<'_>` found type `Resources<'a>` -note: the anonymous lifetime #1 defined on the method body at 5:5... - --> $DIR/issue-27942.rs:5:5 +note: the anonymous lifetime defined on the method body at 5:15... + --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the trait at 3:18 --> $DIR/issue-27942.rs:3:18 | @@ -30,11 +30,11 @@ note: the lifetime `'a` as defined on the trait at 3:18... | LL | pub trait Buffer<'a, R: Resources<'a>> { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 5:5 - --> $DIR/issue-27942.rs:5:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 5:15 + --> $DIR/issue-27942.rs:5:15 | LL | fn select(&self) -> BufferViewHandle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/issue-52742.stderr b/src/test/ui/nll/issue-52742.stderr index 7631ca61e5e15..23bb12f942075 100644 --- a/src/test/ui/nll/issue-52742.stderr +++ b/src/test/ui/nll/issue-52742.stderr @@ -9,11 +9,11 @@ note: ...the reference is valid for the lifetime `'_` as defined on the impl at | LL | impl Foo<'_, '_> { | ^^ -note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the method body at 13:5 - --> $DIR/issue-52742.rs:13:5 +note: ...but the borrowed content is only valid for the anonymous lifetime defined on the method body at 13:31 + --> $DIR/issue-52742.rs:13:31 | LL | fn take_bar(&mut self, b: Bar<'_>) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-55394.stderr b/src/test/ui/nll/issue-55394.stderr index e24ef176db01e..36721f923f7da 100644 --- a/src/test/ui/nll/issue-55394.stderr +++ b/src/test/ui/nll/issue-55394.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` d LL | Foo { bar } | ^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 8:5... - --> $DIR/issue-55394.rs:8:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 8:17... + --> $DIR/issue-55394.rs:8:17 | LL | fn new(bar: &mut Bar) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^ note: ...so that reference does not outlive borrowed content --> $DIR/issue-55394.rs:9:15 | diff --git a/src/test/ui/nll/type-alias-free-regions.stderr b/src/test/ui/nll/type-alias-free-regions.stderr index 38e3e05d1cbb7..6498ecfbe6f9b 100644 --- a/src/test/ui/nll/type-alias-free-regions.stderr +++ b/src/test/ui/nll/type-alias-free-regions.stderr @@ -4,11 +4,11 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` d LL | C { f: b } | ^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 16:5... - --> $DIR/type-alias-free-regions.rs:16:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 16:24... + --> $DIR/type-alias-free-regions.rs:16:24 | LL | fn from_box(b: Box) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...so that the expression is assignable --> $DIR/type-alias-free-regions.rs:17:16 | @@ -35,11 +35,11 @@ error[E0495]: cannot infer an appropriate lifetime due to conflicting requiremen LL | C { f: Box::new(b.0) } | ^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 26:5... - --> $DIR/type-alias-free-regions.rs:26:5 +note: first, the lifetime cannot outlive the anonymous lifetime defined on the method body at 26:23... + --> $DIR/type-alias-free-regions.rs:26:23 | LL | fn from_tuple(b: (B,)) -> Self { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...so that the expression is assignable --> $DIR/type-alias-free-regions.rs:27:25 | diff --git a/src/test/ui/regions/regions-infer-paramd-indirect.stderr b/src/test/ui/regions/regions-infer-paramd-indirect.stderr index 620b25c9e0555..95eb4d1f75b72 100644 --- a/src/test/ui/regions/regions-infer-paramd-indirect.stderr +++ b/src/test/ui/regions/regions-infer-paramd-indirect.stderr @@ -6,11 +6,11 @@ LL | self.f = b; | = note: expected struct `Box>` found struct `Box>` -note: the anonymous lifetime #2 defined on the method body at 21:5... - --> $DIR/regions-infer-paramd-indirect.rs:21:5 +note: the anonymous lifetime defined on the method body at 21:36... + --> $DIR/regions-infer-paramd-indirect.rs:21:36 | LL | fn set_f_bad(&mut self, b: Box) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 16:6 --> $DIR/regions-infer-paramd-indirect.rs:16:6 | diff --git a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr index d7c4817357190..133ecab2296b7 100644 --- a/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr +++ b/src/test/ui/ufcs/ufcs-explicit-self-bad.stderr @@ -33,11 +33,11 @@ LL | fn dummy2(self: &Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime #1 defined on the method body at 37:5... - --> $DIR/ufcs-explicit-self-bad.rs:37:5 +note: the anonymous lifetime defined on the method body at 37:21... + --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 --> $DIR/ufcs-explicit-self-bad.rs:35:6 | @@ -57,11 +57,11 @@ note: the lifetime `'a` as defined on the impl at 35:6... | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #1 defined on the method body at 37:5 - --> $DIR/ufcs-explicit-self-bad.rs:37:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 37:21 + --> $DIR/ufcs-explicit-self-bad.rs:37:21 | LL | fn dummy2(self: &Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error[E0308]: mismatched `self` parameter type --> $DIR/ufcs-explicit-self-bad.rs:39:21 @@ -71,11 +71,11 @@ LL | fn dummy3(self: &&Bar) {} | = note: expected reference `&'a Bar` found reference `&Bar` -note: the anonymous lifetime #2 defined on the method body at 39:5... - --> $DIR/ufcs-explicit-self-bad.rs:39:5 +note: the anonymous lifetime defined on the method body at 39:22... + --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 35:6 --> $DIR/ufcs-explicit-self-bad.rs:35:6 | @@ -95,11 +95,11 @@ note: the lifetime `'a` as defined on the impl at 35:6... | LL | impl<'a, T> SomeTrait for &'a Bar { | ^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined on the method body at 39:5 - --> $DIR/ufcs-explicit-self-bad.rs:39:5 +note: ...does not necessarily outlive the anonymous lifetime defined on the method body at 39:22 + --> $DIR/ufcs-explicit-self-bad.rs:39:22 | LL | fn dummy3(self: &&Bar) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ error: aborting due to 7 previous errors From 24c23f54045549dd7499bac8d35b74f282cacb3a Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 22 Feb 2021 18:17:58 +0200 Subject: [PATCH 14/27] Test hexagon-enum only when llvm target is present See https://github.com/rust-lang/rust/pull/82379#issuecomment-783439754 --- src/test/ui/layout/hexagon-enum.rs | 1 + src/test/ui/layout/hexagon-enum.stderr | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/ui/layout/hexagon-enum.rs b/src/test/ui/layout/hexagon-enum.rs index 4bcfa58f7cf15..8c6c97206649c 100644 --- a/src/test/ui/layout/hexagon-enum.rs +++ b/src/test/ui/layout/hexagon-enum.rs @@ -1,4 +1,5 @@ // compile-flags: --target hexagon-unknown-linux-musl +// needs-llvm-components: hexagon // // Verify that the hexagon targets implement the repr(C) for enums correctly. // diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr index 390eff6e5b957..d4676a5afb25e 100644 --- a/src/test/ui/layout/hexagon-enum.stderr +++ b/src/test/ui/layout/hexagon-enum.stderr @@ -81,7 +81,7 @@ error: layout_of(A) = Layout { raw: 1, }, } - --> $DIR/hexagon-enum.rs:15:1 + --> $DIR/hexagon-enum.rs:16:1 | LL | enum A { Apple } | ^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ error: layout_of(B) = Layout { raw: 1, }, } - --> $DIR/hexagon-enum.rs:19:1 + --> $DIR/hexagon-enum.rs:20:1 | LL | enum B { Banana = 255, } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -257,7 +257,7 @@ error: layout_of(C) = Layout { raw: 2, }, } - --> $DIR/hexagon-enum.rs:23:1 + --> $DIR/hexagon-enum.rs:24:1 | LL | enum C { Chaenomeles = 256, } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -345,7 +345,7 @@ error: layout_of(P) = Layout { raw: 4, }, } - --> $DIR/hexagon-enum.rs:27:1 + --> $DIR/hexagon-enum.rs:28:1 | LL | enum P { Peach = 0x1000_0000isize, } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -433,7 +433,7 @@ error: layout_of(T) = Layout { raw: 4, }, } - --> $DIR/hexagon-enum.rs:33:1 + --> $DIR/hexagon-enum.rs:34:1 | LL | enum T { Tangerine = TANGERINE as isize } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From c02d21033d3603f1dac3bfd6062c37f69a1681cd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 23 Feb 2021 00:07:36 +0300 Subject: [PATCH 15/27] Add tests --- .../ui/proc-macro/auxiliary/test-macros.rs | 22 +++++++++++---- .../derive-helper-legacy-spurious.rs | 13 +++++++++ .../derive-helper-legacy-spurious.stderr | 28 +++++++++++++++++++ .../ui/proc-macro/inert-attribute-order.rs | 23 +++++++++++++++ .../proc-macro/inert-attribute-order.stdout | 7 +++++ 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/proc-macro/derive-helper-legacy-spurious.rs create mode 100644 src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr create mode 100644 src/test/ui/proc-macro/inert-attribute-order.rs create mode 100644 src/test/ui/proc-macro/inert-attribute-order.stdout diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs index 57a7ffa39ef00..a7ed4bc88250d 100644 --- a/src/test/ui/proc-macro/auxiliary/test-macros.rs +++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs @@ -7,7 +7,7 @@ #![crate_type = "proc-macro"] extern crate proc_macro; -use proc_macro::TokenStream; +use proc_macro::{TokenStream, TokenTree}; // Macro that return empty token stream. @@ -80,6 +80,10 @@ pub fn recollect_derive(input: TokenStream) -> TokenStream { // Macros that print their input in the original and re-collected forms (if they differ). fn print_helper(input: TokenStream, kind: &str) -> TokenStream { + print_helper_ext(input, kind, true) +} + +fn print_helper_ext(input: TokenStream, kind: &str, debug: bool) -> TokenStream { let input_display = format!("{}", input); let input_debug = format!("{:#?}", input); let recollected = input.into_iter().collect(); @@ -89,9 +93,11 @@ fn print_helper(input: TokenStream, kind: &str) -> TokenStream { if recollected_display != input_display { println!("PRINT-{} RE-COLLECTED (DISPLAY): {}", kind, recollected_display); } - println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); - if recollected_debug != input_debug { - println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + if debug { + println!("PRINT-{} INPUT (DEBUG): {}", kind, input_debug); + if recollected_debug != input_debug { + println!("PRINT-{} RE-COLLECTED (DEBUG): {}", kind, recollected_debug); + } } recollected } @@ -108,8 +114,12 @@ pub fn print_bang_consume(input: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { - print_helper(input, "ATTR") +pub fn print_attr(args: TokenStream, input: TokenStream) -> TokenStream { + let debug = match &args.into_iter().collect::>()[..] { + [TokenTree::Ident(ident)] if ident.to_string() == "nodebug" => false, + _ => true, + }; + print_helper_ext(input, "ATTR", debug) } #[proc_macro_attribute] diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs new file mode 100644 index 0000000000000..8180aab0caa13 --- /dev/null +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs @@ -0,0 +1,13 @@ +// aux-build:test-macros.rs + +#![dummy] //~ ERROR cannot find attribute `dummy` in this scope + +#[macro_use] +extern crate test_macros; + +#[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive` +#[empty_helper] //~ WARN derive helper attribute is used before it is introduced + //~| WARN this was previously accepted +struct Foo {} + +fn main() {} diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr new file mode 100644 index 0000000000000..96754fed9933c --- /dev/null +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr @@ -0,0 +1,28 @@ +error: cannot find attribute `dummy` in this scope + --> $DIR/derive-helper-legacy-spurious.rs:3:4 + | +LL | #![dummy] + | ^^^^^ + +error: cannot determine resolution for the attribute macro `derive` + --> $DIR/derive-helper-legacy-spurious.rs:8:3 + | +LL | #[derive(Empty)] + | ^^^^^^ + | + = note: import resolution is stuck, try simplifying macro imports + +warning: derive helper attribute is used before it is introduced + --> $DIR/derive-helper-legacy-spurious.rs:9:3 + | +LL | #[derive(Empty)] + | ----- the attribute is introduced here +LL | #[empty_helper] + | ^^^^^^^^^^^^ + | + = note: `#[warn(legacy_derive_helpers)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #79202 + +error: aborting due to 2 previous errors; 1 warning emitted + diff --git a/src/test/ui/proc-macro/inert-attribute-order.rs b/src/test/ui/proc-macro/inert-attribute-order.rs new file mode 100644 index 0000000000000..f807967564116 --- /dev/null +++ b/src/test/ui/proc-macro/inert-attribute-order.rs @@ -0,0 +1,23 @@ +// Order of inert attributes, both built-in and custom is preserved during expansion. + +// check-pass +// compile-flags: -Z span-debug +// aux-build:test-macros.rs + +#![no_std] // Don't load unnecessary hygiene information from std +extern crate std; + +#[macro_use] +extern crate test_macros; + +/// 1 +#[rustfmt::attr2] +#[doc = "3"] +#[print_attr(nodebug)] +#[doc = "4"] +#[rustfmt::attr5] +/// 6 +#[print_attr(nodebug)] +struct S; + +fn main() {} diff --git a/src/test/ui/proc-macro/inert-attribute-order.stdout b/src/test/ui/proc-macro/inert-attribute-order.stdout new file mode 100644 index 0000000000000..7c0620b50b30f --- /dev/null +++ b/src/test/ui/proc-macro/inert-attribute-order.stdout @@ -0,0 +1,7 @@ +PRINT-ATTR INPUT (DISPLAY): /// 1 +#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 +#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; +PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"] +#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; +PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2] +#[rustfmt :: attr5] struct S ; From fc9d578bc5ada5162f49ed02a547cf87f2456a93 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 23 Feb 2021 00:54:09 +0300 Subject: [PATCH 16/27] expand: Preserve order of inert attributes during expansion --- compiler/rustc_expand/src/expand.rs | 23 ++++--- .../derive-helper-legacy-spurious.rs | 3 +- .../derive-helper-legacy-spurious.stderr | 10 +-- .../proc-macro/inert-attribute-order.stdout | 12 ++-- .../proc-macro/issue-75930-derive-cfg.stdout | 64 +++++++++---------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 5a4737842f0af..10c19ea105e4a 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -301,6 +301,8 @@ pub enum InvocationKind { }, Attr { attr: ast::Attribute, + // Re-insertion position for inert attributes. + pos: usize, item: Annotatable, // Required for resolving derive helper attributes. derives: Vec, @@ -690,7 +692,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } _ => unreachable!(), }, - InvocationKind::Attr { attr, mut item, derives } => match ext { + InvocationKind::Attr { attr, pos, mut item, derives } => match ext { SyntaxExtensionKind::Attr(expander) => { self.gate_proc_macro_input(&item); self.gate_proc_macro_attr_item(span, &item); @@ -721,7 +723,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { ExpandResult::Retry(item) => { // Reassemble the original invocation for retrying. return ExpandResult::Retry(Invocation { - kind: InvocationKind::Attr { attr, item, derives }, + kind: InvocationKind::Attr { attr, pos, item, derives }, ..invoc }); } @@ -739,7 +741,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if *mark_used { self.cx.sess.mark_attr_used(&attr); } - item.visit_attrs(|attrs| attrs.push(attr)); + item.visit_attrs(|attrs| attrs.insert(pos, attr)); fragment_kind.expect_from_annotatables(iter::once(item)) } _ => unreachable!(), @@ -1000,17 +1002,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_attr( &mut self, - (attr, derives): (ast::Attribute, Vec), + (attr, pos, derives): (ast::Attribute, usize, Vec), item: Annotatable, kind: AstFragmentKind, ) -> AstFragment { - self.collect(kind, InvocationKind::Attr { attr, item, derives }) + self.collect(kind, InvocationKind::Attr { attr, pos, item, derives }) } /// If `item` is an attribute invocation, remove the attribute and return it together with - /// derives following it. We have to collect the derives in order to resolve legacy derive - /// helpers (helpers written before derives that introduce them). - fn take_first_attr(&mut self, item: &mut impl HasAttrs) -> Option<(ast::Attribute, Vec)> { + /// its position and derives following it. We have to collect the derives in order to resolve + /// legacy derive helpers (helpers written before derives that introduce them). + fn take_first_attr( + &mut self, + item: &mut impl HasAttrs, + ) -> Option<(ast::Attribute, usize, Vec)> { let mut attr = None; item.visit_attrs(|attrs| { @@ -1033,7 +1038,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { }) .collect(); - (attr, following_derives) + (attr, attr_pos, following_derives) }) }); diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs index 8180aab0caa13..4a7e48eed46c3 100644 --- a/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.rs @@ -6,8 +6,7 @@ extern crate test_macros; #[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive` -#[empty_helper] //~ WARN derive helper attribute is used before it is introduced - //~| WARN this was previously accepted +#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope struct Foo {} fn main() {} diff --git a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr index 96754fed9933c..fd1ed8a3d0ff3 100644 --- a/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr +++ b/src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr @@ -12,17 +12,11 @@ LL | #[derive(Empty)] | = note: import resolution is stuck, try simplifying macro imports -warning: derive helper attribute is used before it is introduced +error: cannot find attribute `empty_helper` in this scope --> $DIR/derive-helper-legacy-spurious.rs:9:3 | -LL | #[derive(Empty)] - | ----- the attribute is introduced here LL | #[empty_helper] | ^^^^^^^^^^^^ - | - = note: `#[warn(legacy_derive_helpers)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #79202 -error: aborting due to 2 previous errors; 1 warning emitted +error: aborting due to 3 previous errors diff --git a/src/test/ui/proc-macro/inert-attribute-order.stdout b/src/test/ui/proc-macro/inert-attribute-order.stdout index 7c0620b50b30f..cc215545952df 100644 --- a/src/test/ui/proc-macro/inert-attribute-order.stdout +++ b/src/test/ui/proc-macro/inert-attribute-order.stdout @@ -1,7 +1,7 @@ PRINT-ATTR INPUT (DISPLAY): /// 1 -#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 -#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; -PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"] -#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ; -PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2] -#[rustfmt :: attr5] struct S ; +#[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6 +#[print_attr(nodebug)] struct S ; +PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] +#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ; +PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] +#[rustfmt :: attr5] #[doc = " 6"] struct S ; diff --git a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout index 19aa4dfb60e36..15e63c20eb9bc 100644 --- a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout +++ b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout @@ -1,4 +1,4 @@ -PRINT-ATTR INPUT (DISPLAY): #[allow(dead_code)] #[derive(Print)] #[print_helper(b)] #[print_helper(a)] +PRINT-ATTR INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[derive(Print)] #[print_helper(b)] struct Foo < #[cfg(FALSE)] A, B > { #[cfg(FALSE)] first : String, #[cfg_attr(FALSE, deny(warnings))] second : @@ -23,6 +23,31 @@ struct Foo < #[cfg(FALSE)] A, B > }], #[print_helper(d)] fourth : B } PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "print_helper", + span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "a", + span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0), + }, + ], + span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0), + }, + ], + span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0), + }, Punct { ch: '#', spacing: Alone, @@ -98,31 +123,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ ], span: $DIR/issue-75930-derive-cfg.rs:21:2: 21:19 (#0), }, - Punct { - ch: '#', - spacing: Alone, - span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0), - }, - Group { - delimiter: Bracket, - stream: TokenStream [ - Ident { - ident: "print_helper", - span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0), - }, - Group { - delimiter: Parenthesis, - stream: TokenStream [ - Ident { - ident: "a", - span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0), - }, - ], - span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0), - }, - ], - span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0), - }, Ident { ident: "struct", span: $DIR/issue-75930-derive-cfg.rs:22:1: 22:7 (#0), @@ -1194,7 +1194,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ span: $DIR/issue-75930-derive-cfg.rs:22:32: 65:2 (#0), }, ] -PRINT-DERIVE INPUT (DISPLAY): #[allow(dead_code)] #[print_helper(b)] #[print_helper(a)] struct Foo < B > +PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_helper(b)] struct Foo < B > { second : bool, third : [u8 ; @@ -1217,14 +1217,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Bracket, stream: TokenStream [ Ident { - ident: "allow", + ident: "print_helper", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "dead_code", + ident: "a", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], @@ -1242,14 +1242,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Bracket, stream: TokenStream [ Ident { - ident: "print_helper", + ident: "allow", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "b", + ident: "dead_code", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], @@ -1274,7 +1274,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ delimiter: Parenthesis, stream: TokenStream [ Ident { - ident: "a", + ident: "b", span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0), }, ], From e8dcc02dc5bb8ee26c22d67efa4ede281927e5cb Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Feb 2021 14:42:59 -0800 Subject: [PATCH 17/27] Add a `size()` function to WASI's `MetadataExt`. WASI's `filestat` type includes a size field, so expose it in `MetadataExt` via a `size()` function, similar to the corresponding Unix function. --- library/std/src/sys/wasi/ext/fs.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index a8da003d550ac..1dc7983f18831 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -397,6 +397,8 @@ pub trait MetadataExt { fn ino(&self) -> u64; /// Returns the `st_nlink` field of the internal `filestat_t` fn nlink(&self) -> u64; + /// Returns the `st_size` field of the internal `filestat_t` + fn size(&self) -> u64; /// Returns the `st_atim` field of the internal `filestat_t` fn atim(&self) -> u64; /// Returns the `st_mtim` field of the internal `filestat_t` @@ -415,6 +417,9 @@ impl MetadataExt for fs::Metadata { fn nlink(&self) -> u64 { self.as_inner().as_wasi().nlink } + fn size(&self) -> u64 { + self.as_inner().as_wasi().size + } fn atim(&self) -> u64 { self.as_inner().as_wasi().atim } From 132ec261b0d215f77b71eeee3d814cd304fc1a29 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Feb 2021 14:21:43 -0800 Subject: [PATCH 18/27] Enable API documentation for `std::os::wasi`. This adds API documentation support for `std::os::wasi` modeled after how `std::os::unix` works, so that WASI can be documented [here] along with the other platforms. [here]: https://doc.rust-lang.org/stable/std/os/index.html Two changes of particular interest: - This changes the `AsRawFd` for `io::Stdin` for WASI to return `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and similar for `Stdout` and `Stderr`), which matches how the `unix` version works. `STDIN_FILENO` etc. may not always be explicitly reserved at the WASI level, but as long as we have Rust's `std` and `libc`, I think it's reasonable to guarantee that we'll always use `libc::STDIN_FILENO` for stdin. - This duplicates the `osstr2str` utility function, rather than trying to share it across all the configurations that need it. --- library/std/src/os/mod.rs | 3 +++ library/std/src/sys/mod.rs | 30 +++++++++++++++++++++++++---- library/std/src/sys/wasi/ext/fs.rs | 25 +++++++++++++++--------- library/std/src/sys/wasi/ext/io.rs | 12 ++++++------ library/std/src/sys/wasi/ext/mod.rs | 28 +++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index f61e402e37027..fad5886def700 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -22,6 +22,9 @@ pub use crate::sys::windows_ext as windows; #[doc(cfg(target_os = "linux"))] pub mod linux; +#[cfg(doc)] +pub use crate::sys::wasi_ext as wasi; + // If we're not documenting libstd then we just expose the main modules as we otherwise would. #[cfg(not(doc))] diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index d48d9cb0efce0..d3f53801d2d0f 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -61,9 +61,9 @@ cfg_if::cfg_if! { #[stable(feature = "rust1", since = "1.0.0")] pub use self::ext as unix_ext; } else if #[cfg(any(target_os = "hermit", - target_arch = "wasm32", + all(target_arch = "wasm32", not(target_os = "wasi")), all(target_vendor = "fortanix", target_env = "sgx")))] { - // On wasm right now the module below doesn't compile + // On non-WASI wasm right now the module below doesn't compile // (missing things in `libc` which is empty) so just omit everything // with an empty module #[unstable(issue = "none", feature = "std_internals")] @@ -85,9 +85,9 @@ cfg_if::cfg_if! { #[stable(feature = "rust1", since = "1.0.0")] pub use self::ext as windows_ext; } else if #[cfg(any(target_os = "hermit", - target_arch = "wasm32", + all(target_arch = "wasm32", not(target_os = "wasi")), all(target_vendor = "fortanix", target_env = "sgx")))] { - // On wasm right now the shim below doesn't compile, so + // On non-WASI wasm right now the shim below doesn't compile, so // just omit it #[unstable(issue = "none", feature = "std_internals")] #[allow(missing_docs)] @@ -106,3 +106,25 @@ cfg_if::cfg_if! { pub mod windows_ext; } } + +#[cfg(doc)] +cfg_if::cfg_if! { + if #[cfg(target_os = "wasi")] { + // On WASI we'll document what's already available + #[stable(feature = "rust1", since = "1.0.0")] + pub use self::ext as wasi_ext; + } else if #[cfg(any(target_os = "hermit", + target_arch = "wasm32", + all(target_vendor = "fortanix", target_env = "sgx")))] { + // On non-WASI wasm right now the module below doesn't compile + // (missing things in `libc` which is empty) so just omit everything + // with an empty module + #[unstable(issue = "none", feature = "std_internals")] + #[allow(missing_docs)] + pub mod wasi_ext {} + } else { + // On other platforms like Windows document the bare bones of WASI + #[path = "wasi/ext/mod.rs"] + pub mod wasi_ext; + } +} diff --git a/library/std/src/sys/wasi/ext/fs.rs b/library/std/src/sys/wasi/ext/fs.rs index a8da003d550ac..66b6caf25127d 100644 --- a/library/std/src/sys/wasi/ext/fs.rs +++ b/library/std/src/sys/wasi/ext/fs.rs @@ -3,11 +3,14 @@ #![deny(unsafe_op_in_unsafe_fn)] #![unstable(feature = "wasi_ext", issue = "none")] +use crate::ffi::OsStr; use crate::fs::{self, File, Metadata, OpenOptions}; use crate::io::{self, IoSlice, IoSliceMut}; use crate::path::{Path, PathBuf}; -use crate::sys::fs::osstr2str; use crate::sys_common::{AsInner, AsInnerMut, FromInner}; +// Used for `File::read` on intra-doc links +#[allow(unused_imports)] +use io::{Read, Write}; /// WASI-specific extensions to [`File`]. pub trait FileExt { @@ -54,11 +57,11 @@ pub trait FileExt { /// # Errors /// /// If this function encounters an error of the kind - /// [`ErrorKind::Interrupted`] then the error is ignored and the operation + /// [`io::ErrorKind::Interrupted`] then the error is ignored and the operation /// will continue. /// /// If this function encounters an "end of file" before completely filling - /// the buffer, it returns an error of the kind [`ErrorKind::UnexpectedEof`]. + /// the buffer, it returns an error of the kind [`io::ErrorKind::UnexpectedEof`]. /// The contents of `buf` are unspecified in this case. /// /// If any other read error is encountered then this function immediately @@ -131,16 +134,16 @@ pub trait FileExt { /// The current file cursor is not affected by this function. /// /// This method will continuously call [`write_at`] until there is no more data - /// to be written or an error of non-[`ErrorKind::Interrupted`] kind is + /// to be written or an error of non-[`io::ErrorKind::Interrupted`] kind is /// returned. This method will not return until the entire buffer has been /// successfully written or such an error occurs. The first error that is - /// not of [`ErrorKind::Interrupted`] kind generated from this method will be + /// not of [`io::ErrorKind::Interrupted`] kind generated from this method will be /// returned. /// /// # Errors /// /// This function will return the first error of - /// non-[`ErrorKind::Interrupted`] kind that [`write_at`] returns. + /// non-[`io::ErrorKind::Interrupted`] kind that [`write_at`] returns. /// /// [`write_at`]: FileExt::write_at #[stable(feature = "rw_exact_all_at", since = "1.33.0")] @@ -426,7 +429,7 @@ impl MetadataExt for fs::Metadata { } } -/// WASI-specific extensions for [`FileType`]. +/// WASI-specific extensions for [`fs::FileType`]. /// /// Adds support for special WASI file types such as block/character devices, /// pipes, and sockets. @@ -517,8 +520,12 @@ pub fn symlink, U: AsRef>( /// Create a symbolic link. /// -/// This is a convenience API similar to [`std::os::unix::fs::symlink`] and -/// [`std::os::windows::fs::symlink_file`] and [`symlink_dir`](std::os::windows::fs::symlink_dir). +/// This is a convenience API similar to `std::os::unix::fs::symlink` and +/// `std::os::windows::fs::symlink_file` and `std::os::windows::fs::symlink_dir`. pub fn symlink_path, U: AsRef>(old_path: P, new_path: U) -> io::Result<()> { crate::sys::fs::symlink(old_path.as_ref(), new_path.as_ref()) } + +fn osstr2str(f: &OsStr) -> io::Result<&str> { + f.to_str().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "input must be utf-8")) +} diff --git a/library/std/src/sys/wasi/ext/io.rs b/library/std/src/sys/wasi/ext/io.rs index 81413f39dc1cd..d0edfa9f35f90 100644 --- a/library/std/src/sys/wasi/ext/io.rs +++ b/library/std/src/sys/wasi/ext/io.rs @@ -145,36 +145,36 @@ impl IntoRawFd for fs::File { impl AsRawFd for io::Stdin { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdin.as_raw_fd() + libc::STDIN_FILENO } } impl AsRawFd for io::Stdout { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdout.as_raw_fd() + libc::STDOUT_FILENO } } impl AsRawFd for io::Stderr { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stderr.as_raw_fd() + libc::STDERR_FILENO } } impl<'a> AsRawFd for io::StdinLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdin.as_raw_fd() + libc::STDIN_FILENO } } impl<'a> AsRawFd for io::StdoutLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stdout.as_raw_fd() + libc::STDOUT_FILENO } } impl<'a> AsRawFd for io::StderrLock<'a> { fn as_raw_fd(&self) -> RawFd { - sys::stdio::Stderr.as_raw_fd() + libc::STDERR_FILENO } } diff --git a/library/std/src/sys/wasi/ext/mod.rs b/library/std/src/sys/wasi/ext/mod.rs index 1cda30edcad0a..8a83b24700391 100644 --- a/library/std/src/sys/wasi/ext/mod.rs +++ b/library/std/src/sys/wasi/ext/mod.rs @@ -1,4 +1,32 @@ +//! Platform-specific extensions to `std` for WASI. +//! +//! Provides access to platform-level information on WASI, and exposes +//! WASI-specific functions that would otherwise be inappropriate as +//! part of the core `std` library. +//! +//! It exposes more ways to deal with platform-specific strings (`OsStr`, +//! `OsString`), allows to set permissions more granularly, extract low-level +//! file descriptors from files and sockets, and has platform-specific helpers +//! for spawning processes. +//! +//! # Examples +//! +//! ```no_run +//! use std::fs::File; +//! use std::os::wasi::prelude::*; +//! +//! fn main() -> std::io::Result<()> { +//! let f = File::create("foo.txt")?; +//! let fd = f.as_raw_fd(); +//! +//! // use fd with native WASI bindings +//! +//! Ok(()) +//! } +//! ``` + #![deny(unsafe_op_in_unsafe_fn)] +#![doc(cfg(target_os = "wasi"))] pub mod ffi; pub mod fs; From 46db4bab0b44294a6e41eb756587904f8bed6049 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 23 Feb 2021 09:44:01 -0500 Subject: [PATCH 19/27] Skip emitting closure diagnostic when closure_kind_origins has no entry Fixes #82438 This map is not guarnateed to have an entry for a closure. --- .../diagnostics/mutability_errors.rs | 51 ++++++++++--------- .../closures/issue-82438-mut-without-upvar.rs | 28 ++++++++++ .../issue-82438-mut-without-upvar.stderr | 12 +++++ 3 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/test/ui/closures/issue-82438-mut-without-upvar.rs create mode 100644 src/test/ui/closures/issue-82438-mut-without-upvar.stderr diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index 0400431a542ee..2f40a90fb5516 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -513,32 +513,33 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let id = id.expect_local(); let tables = tcx.typeck(id); let hir_id = tcx.hir().local_def_id_to_hir_id(id); - let (span, place) = &tables.closure_kind_origins()[hir_id]; - let reason = if let PlaceBase::Upvar(upvar_id) = place.base { - let upvar = ty::place_to_string_for_capture(tcx, place); - match tables.upvar_capture(upvar_id) { - ty::UpvarCapture::ByRef(ty::UpvarBorrow { - kind: ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow, - .. - }) => { - format!("mutable borrow of `{}`", upvar) - } - ty::UpvarCapture::ByValue(_) => { - format!("possible mutation of `{}`", upvar) + if let Some((span, place)) = tables.closure_kind_origins().get(hir_id) { + let reason = if let PlaceBase::Upvar(upvar_id) = place.base { + let upvar = ty::place_to_string_for_capture(tcx, place); + match tables.upvar_capture(upvar_id) { + ty::UpvarCapture::ByRef(ty::UpvarBorrow { + kind: ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow, + .. + }) => { + format!("mutable borrow of `{}`", upvar) + } + ty::UpvarCapture::ByValue(_) => { + format!("possible mutation of `{}`", upvar) + } + val => bug!("upvar `{}` borrowed, but not mutably: {:?}", upvar, val), } - val => bug!("upvar `{}` borrowed, but not mutably: {:?}", upvar, val), - } - } else { - bug!("not an upvar") - }; - err.span_label( - *span, - format!( - "calling `{}` requires mutable binding due to {}", - self.describe_place(the_place_err).unwrap(), - reason - ), - ); + } else { + bug!("not an upvar") + }; + err.span_label( + *span, + format!( + "calling `{}` requires mutable binding due to {}", + self.describe_place(the_place_err).unwrap(), + reason + ), + ); + } } // Attempt to search similar mutable associated items for suggestion. diff --git a/src/test/ui/closures/issue-82438-mut-without-upvar.rs b/src/test/ui/closures/issue-82438-mut-without-upvar.rs new file mode 100644 index 0000000000000..5d88e1e77d450 --- /dev/null +++ b/src/test/ui/closures/issue-82438-mut-without-upvar.rs @@ -0,0 +1,28 @@ +use std::error::Error; +struct A { +} + +impl A { + pub fn new() -> A { + A { + } + } + + pub fn f<'a>( + &'a self, + team_name: &'a str, + c: &'a mut dyn FnMut(String, String, u64, u64) + ) -> Result<(), Box> { + Ok(()) + } +} + + +fn main() { + let A = A::new(); + let participant_name = "A"; + + let c = |a, b, c, d| {}; + + A.f(participant_name, &mut c); //~ ERROR cannot borrow +} diff --git a/src/test/ui/closures/issue-82438-mut-without-upvar.stderr b/src/test/ui/closures/issue-82438-mut-without-upvar.stderr new file mode 100644 index 0000000000000..06e2b5d0c1bce --- /dev/null +++ b/src/test/ui/closures/issue-82438-mut-without-upvar.stderr @@ -0,0 +1,12 @@ +error[E0596]: cannot borrow `c` as mutable, as it is not declared as mutable + --> $DIR/issue-82438-mut-without-upvar.rs:27:27 + | +LL | let c = |a, b, c, d| {}; + | - help: consider changing this to be mutable: `mut c` +LL | +LL | A.f(participant_name, &mut c); + | ^^^^^^ cannot borrow as mutable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0596`. From e56364fa995ce0e8e607fabdd4b959d3da848e2c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 24 Feb 2021 22:35:03 +0800 Subject: [PATCH 20/27] Use Oxform comma Co-authored-by: Nathan Nguyen <43092380+nhwn@users.noreply.github.com> --- src/doc/unstable-book/src/language-features/doc-spotlight.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/language-features/doc-spotlight.md b/src/doc/unstable-book/src/language-features/doc-spotlight.md index 00a05e509b87c..9f2ee9aecf472 100644 --- a/src/doc/unstable-book/src/language-features/doc-spotlight.md +++ b/src/doc/unstable-book/src/language-features/doc-spotlight.md @@ -6,7 +6,7 @@ The `doc_spotlight` feature allows the use of the `spotlight` parameter to the ` to "spotlight" a specific trait on the return values of functions. Adding a `#[doc(spotlight)]` attribute to a trait definition will make rustdoc print extra information for functions which return a type that implements that trait. This attribute is applied to the `Iterator`, `io::Read`, -`io::Write` and `Future` traits in the standard library. +`io::Write`, and `Future` traits in the standard library. You can do this on your own traits, like this: From 9ce567efc20e3bfc8409ae92af74ebfc53b83aa8 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:35:40 -0800 Subject: [PATCH 21/27] Cast `libc::STDIN_FILENO` to `RawFd`. WASI's `RawFd` is a `u32`, while `libc` uses `c_int`. --- library/std/src/sys/wasi/ext/io.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/std/src/sys/wasi/ext/io.rs b/library/std/src/sys/wasi/ext/io.rs index d0edfa9f35f90..3c480aa8e19bf 100644 --- a/library/std/src/sys/wasi/ext/io.rs +++ b/library/std/src/sys/wasi/ext/io.rs @@ -145,36 +145,36 @@ impl IntoRawFd for fs::File { impl AsRawFd for io::Stdin { fn as_raw_fd(&self) -> RawFd { - libc::STDIN_FILENO + libc::STDIN_FILENO as RawFd } } impl AsRawFd for io::Stdout { fn as_raw_fd(&self) -> RawFd { - libc::STDOUT_FILENO + libc::STDOUT_FILENO as RawFd } } impl AsRawFd for io::Stderr { fn as_raw_fd(&self) -> RawFd { - libc::STDERR_FILENO + libc::STDERR_FILENO as RawFd } } impl<'a> AsRawFd for io::StdinLock<'a> { fn as_raw_fd(&self) -> RawFd { - libc::STDIN_FILENO + libc::STDIN_FILENO as RawFd } } impl<'a> AsRawFd for io::StdoutLock<'a> { fn as_raw_fd(&self) -> RawFd { - libc::STDOUT_FILENO + libc::STDOUT_FILENO as RawFd } } impl<'a> AsRawFd for io::StderrLock<'a> { fn as_raw_fd(&self) -> RawFd { - libc::STDERR_FILENO + libc::STDERR_FILENO as RawFd } } From 0208fca342977838be7c718fb0335931fbb56cff Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:37:05 -0800 Subject: [PATCH 22/27] Use `super::` to refer to WASI-specific names. This ensures that these names resolve to the right place even when building the WASI support on other platforms for generating the documentation. --- library/std/src/sys/wasi/ext/mod.rs | 8 ++++---- library/std/src/sys/wasi/fs.rs | 2 +- library/std/src/sys/wasi/net.rs | 2 +- library/std/src/sys/wasi/stdio.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/std/src/sys/wasi/ext/mod.rs b/library/std/src/sys/wasi/ext/mod.rs index 8a83b24700391..b08402f077652 100644 --- a/library/std/src/sys/wasi/ext/mod.rs +++ b/library/std/src/sys/wasi/ext/mod.rs @@ -39,14 +39,14 @@ pub mod io; pub mod prelude { #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use crate::sys::ext::ffi::{OsStrExt, OsStringExt}; + pub use super::ffi::{OsStrExt, OsStringExt}; #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use crate::sys::ext::fs::FileTypeExt; + pub use super::fs::FileTypeExt; #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use crate::sys::ext::fs::{DirEntryExt, FileExt, MetadataExt, OpenOptionsExt}; + pub use super::fs::{DirEntryExt, FileExt, MetadataExt, OpenOptionsExt}; #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use crate::sys::ext::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; + pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; } diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index 83debdfc86043..41203aa218dc5 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -9,7 +9,7 @@ use crate::os::wasi::ffi::{OsStrExt, OsStringExt}; use crate::path::{Path, PathBuf}; use crate::ptr; use crate::sync::Arc; -use crate::sys::fd::WasiFd; +use super::fd::WasiFd; use crate::sys::time::SystemTime; use crate::sys::unsupported; use crate::sys_common::FromInner; diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index 8fd4bb76d854f..7fa4f2923b8a5 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -4,7 +4,7 @@ use crate::convert::TryFrom; use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; -use crate::sys::fd::WasiFd; +use super::fd::WasiFd; use crate::sys::{unsupported, Void}; use crate::sys_common::FromInner; use crate::time::Duration; diff --git a/library/std/src/sys/wasi/stdio.rs b/library/std/src/sys/wasi/stdio.rs index d82f6f411863d..c665ee2399660 100644 --- a/library/std/src/sys/wasi/stdio.rs +++ b/library/std/src/sys/wasi/stdio.rs @@ -2,7 +2,7 @@ use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; -use crate::sys::fd::WasiFd; +use super::fd::WasiFd; pub struct Stdin; pub struct Stdout; From e66e2635442b47808a5e23db83b461c11d2943fc Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:43:50 -0800 Subject: [PATCH 23/27] Make the main `wasi` module `cfg(not(doc))`. --- library/std/src/os/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index fad5886def700..ca8c4c9c420a3 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -41,6 +41,10 @@ pub use crate::sys::ext as windows; #[cfg(any(target_os = "linux", target_os = "l4re"))] pub mod linux; +#[cfg(not(doc))] +#[cfg(target_os = "wasi")] +pub mod wasi; + #[cfg(target_os = "android")] pub mod android; #[cfg(target_os = "dragonfly")] @@ -71,7 +75,5 @@ pub mod redox; pub mod solaris; #[cfg(target_os = "vxworks")] pub mod vxworks; -#[cfg(target_os = "wasi")] -pub mod wasi; pub mod raw; From 94e75acf1fd5933ba5821e9b1935796f0bbf23e0 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:47:26 -0800 Subject: [PATCH 24/27] Mention "wasi" in the comment about "main modules". --- library/std/src/os/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index ca8c4c9c420a3..500e8267cf821 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -3,7 +3,7 @@ #![stable(feature = "os", since = "1.0.0")] #![allow(missing_docs, nonstandard_style, missing_debug_implementations)] -// When documenting libstd we want to show unix/windows/linux modules as these are the "main +// When documenting libstd we want to show unix/windows/linux/wasi modules as these are the "main // modules" that are used across platforms, so all modules are enabled when `cfg(doc)` is set. // This should help show platform-specific functionality in a hopefully cross-platform way in the // documentation. From 7d5242a03a9e30fe880ff1af83a3ad7df5e62159 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:58:21 -0800 Subject: [PATCH 25/27] x.py fmt --- library/std/src/sys/wasi/fs.rs | 2 +- library/std/src/sys/wasi/net.rs | 2 +- library/std/src/sys/wasi/stdio.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/wasi/fs.rs b/library/std/src/sys/wasi/fs.rs index 41203aa218dc5..bcf7da46b4b07 100644 --- a/library/std/src/sys/wasi/fs.rs +++ b/library/std/src/sys/wasi/fs.rs @@ -1,5 +1,6 @@ #![deny(unsafe_op_in_unsafe_fn)] +use super::fd::WasiFd; use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut, SeekFrom}; @@ -9,7 +10,6 @@ use crate::os::wasi::ffi::{OsStrExt, OsStringExt}; use crate::path::{Path, PathBuf}; use crate::ptr; use crate::sync::Arc; -use super::fd::WasiFd; use crate::sys::time::SystemTime; use crate::sys::unsupported; use crate::sys_common::FromInner; diff --git a/library/std/src/sys/wasi/net.rs b/library/std/src/sys/wasi/net.rs index 7fa4f2923b8a5..3f294e7df418e 100644 --- a/library/std/src/sys/wasi/net.rs +++ b/library/std/src/sys/wasi/net.rs @@ -1,10 +1,10 @@ #![deny(unsafe_op_in_unsafe_fn)] +use super::fd::WasiFd; use crate::convert::TryFrom; use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; -use super::fd::WasiFd; use crate::sys::{unsupported, Void}; use crate::sys_common::FromInner; use crate::time::Duration; diff --git a/library/std/src/sys/wasi/stdio.rs b/library/std/src/sys/wasi/stdio.rs index c665ee2399660..209d5b996e5b4 100644 --- a/library/std/src/sys/wasi/stdio.rs +++ b/library/std/src/sys/wasi/stdio.rs @@ -1,8 +1,8 @@ #![deny(unsafe_op_in_unsafe_fn)] +use super::fd::WasiFd; use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem::ManuallyDrop; -use super::fd::WasiFd; pub struct Stdin; pub struct Stdout; From 67f17342ee542220e1c972633bb71d49cfe97e84 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 26 Feb 2021 08:32:38 +0100 Subject: [PATCH 26/27] update tracking issue for `relaxed_struct_unsize` --- compiler/rustc_feature/src/active.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 3f484ab568652..6960b735f3324 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -633,7 +633,7 @@ declare_features! ( (active, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391), None), /// Lessens the requirements for structs to implement `Unsize`. - (active, relaxed_struct_unsize, "1.51.0", Some(1), None), + (active, relaxed_struct_unsize, "1.51.0", Some(81793), None), /// Allows macro attributes to observe output of `#[derive]`. (active, macro_attributes_in_derive_output, "1.51.0", Some(81119), None), From 27f7a2e18d456a161382f51a1db6402b36ca0b24 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 27 Feb 2021 01:29:56 +0800 Subject: [PATCH 27/27] Add for example word to spotlight doc As suggested by GuillaumeGomez --- src/doc/unstable-book/src/language-features/doc-spotlight.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/language-features/doc-spotlight.md b/src/doc/unstable-book/src/language-features/doc-spotlight.md index 9f2ee9aecf472..75eff16331898 100644 --- a/src/doc/unstable-book/src/language-features/doc-spotlight.md +++ b/src/doc/unstable-book/src/language-features/doc-spotlight.md @@ -5,8 +5,8 @@ The tracking issue for this feature is: [#45040] The `doc_spotlight` feature allows the use of the `spotlight` parameter to the `#[doc]` attribute, to "spotlight" a specific trait on the return values of functions. Adding a `#[doc(spotlight)]` attribute to a trait definition will make rustdoc print extra information for functions which return -a type that implements that trait. This attribute is applied to the `Iterator`, `io::Read`, -`io::Write`, and `Future` traits in the standard library. +a type that implements that trait. For example, this attribute is applied to the `Iterator`, +`io::Read`, `io::Write`, and `Future` traits in the standard library. You can do this on your own traits, like this: