From 38e4233a3291b0b8e3148e7ea47da66c9d8b307f Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sat, 13 Feb 2021 22:17:15 +1100 Subject: [PATCH 01/26] 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/26] 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/26] 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/26] 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/26] :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/26] 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 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 07/26] 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 08/26] 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 09/26] 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 10/26] 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 11/26] 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 12/26] 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 13/26] 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 ef731b31dbd5f1dccf4a863290c8286b9601e323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 24 Feb 2021 00:00:00 +0000 Subject: [PATCH 14/26] Use small hash set in `mir_inliner_callees` Use small hash set in `mir_inliner_callees` to avoid temporary allocation when possible and quadratic behaviour for large number of callees. --- compiler/rustc_mir/src/transform/inline/cycle.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_mir/src/transform/inline/cycle.rs b/compiler/rustc_mir/src/transform/inline/cycle.rs index 4c24bec0ce3ad..295f3ec70dc78 100644 --- a/compiler/rustc_mir/src/transform/inline/cycle.rs +++ b/compiler/rustc_mir/src/transform/inline/cycle.rs @@ -1,4 +1,5 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::mir::TerminatorKind; @@ -140,7 +141,7 @@ crate fn mir_inliner_callees<'tcx>( // Functions from other crates and MIR shims _ => tcx.instance_mir(instance), }; - let mut calls = Vec::new(); + let mut calls = SsoHashSet::new(); for bb_data in body.basic_blocks() { let terminator = bb_data.terminator(); if let TerminatorKind::Call { func, .. } = &terminator.kind { @@ -149,12 +150,8 @@ crate fn mir_inliner_callees<'tcx>( ty::FnDef(def_id, substs) => (*def_id, *substs), _ => continue, }; - // We've seen this before - if calls.contains(&call) { - continue; - } - calls.push(call); + calls.insert(call); } } - tcx.arena.alloc_slice(&calls) + tcx.arena.alloc_from_iter(calls.iter().copied()) } From 3ac62cafa39c73f5594e9c43add2c89f50cef3f5 Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Wed, 24 Feb 2021 12:24:36 +0100 Subject: [PATCH 15/26] Use libc::accept4 on Android instead of raw syscall. --- library/std/src/sys/unix/net.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 7198a2f08d668..587ffe15981d5 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -195,6 +195,7 @@ impl Socket { // glibc 2.10 and musl 0.9.5. cfg_if::cfg_if! { if #[cfg(any( + target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", @@ -206,13 +207,6 @@ impl Socket { libc::accept4(self.0.raw(), storage, len, libc::SOCK_CLOEXEC) })?; Ok(Socket(FileDesc::new(fd))) - // While the Android kernel supports the syscall, - // it is not included in all versions of Android's libc. - } else if #[cfg(target_os = "android")] { - let fd = cvt_r(|| unsafe { - libc::syscall(libc::SYS_accept4, self.0.raw(), storage, len, libc::SOCK_CLOEXEC) - })?; - Ok(Socket(FileDesc::new(fd as c_int))) } else { let fd = cvt_r(|| unsafe { libc::accept(self.0.raw(), storage, len) })?; let fd = FileDesc::new(fd); From f291131f2e992aff2d491e93445c6278c82b898b Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Wed, 24 Feb 2021 12:47:28 +0100 Subject: [PATCH 16/26] Bump minimum libc version to 0.2.85 for std. --- library/std/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 1c738761e8a00..275fcc4c29299 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -libc = { version = "0.2.79", default-features = false, features = ['rustc-dep-of-std'] } +libc = { version = "0.2.85", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.39" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } From e56364fa995ce0e8e607fabdd4b959d3da848e2c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 24 Feb 2021 22:35:03 +0800 Subject: [PATCH 17/26] 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 ce80f280bad83192ce41153770521e32a673ea64 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 24 Feb 2021 10:29:23 -0800 Subject: [PATCH 18/26] Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index bf5a5d5e5d3ae..572e201536dc2 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit bf5a5d5e5d3ae842a63bfce6d070dfd438cf6070 +Subproject commit 572e201536dc2e4920346e28037b63c0f4d88b3c From 9ce567efc20e3bfc8409ae92af74ebfc53b83aa8 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 24 Feb 2021 10:35:40 -0800 Subject: [PATCH 19/26] 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 20/26] 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 21/26] 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 22/26] 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 23/26] 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 5ad60888275852136adea38aebc7fcce69b52474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 24 Feb 2021 12:21:18 -0800 Subject: [PATCH 24/26] Substitute erased lifetimes on bad placeholder type Fix #82455. --- compiler/rustc_typeck/src/collect.rs | 12 ++++++++++ .../ui/typeck/typeck_type_placeholder_item.rs | 12 ++++++++++ .../typeck_type_placeholder_item.stderr | 22 +++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index fc8e50b4b65ba..d754a24c58be1 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -371,6 +371,11 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { span: Span, ) -> &'tcx Const<'tcx> { bad_placeholder_type(self.tcx(), vec![span]).emit(); + // Typeck doesn't expect erased regions to be returned from `type_of`. + let ty = self.tcx.fold_regions(ty, &mut false, |r, _| match r { + ty::ReErased => self.tcx.lifetimes.re_static, + _ => r, + }); self.tcx().const_error(ty) } @@ -1647,6 +1652,12 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { match get_infer_ret_ty(&sig.decl.output) { Some(ty) => { let fn_sig = tcx.typeck(def_id).liberated_fn_sigs()[hir_id]; + // Typeck doesn't expect erased regions to be returned from `type_of`. + let fn_sig = tcx.fold_regions(fn_sig, &mut false, |r, _| match r { + ty::ReErased => tcx.lifetimes.re_static, + _ => r, + }); + let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_ty(ty); let mut diag = bad_placeholder_type(tcx, visitor.0); @@ -1675,6 +1686,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { } } diag.emit(); + ty::Binder::bind(fn_sig) } None => AstConv::ty_of_fn( diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.rs b/src/test/ui/typeck/typeck_type_placeholder_item.rs index 2c8b1e76b1b82..2523362fdc4b6 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item.rs +++ b/src/test/ui/typeck/typeck_type_placeholder_item.rs @@ -208,3 +208,15 @@ impl Qux for Struct { const D: _ = 42; //~^ ERROR the type placeholder `_` is not allowed within types on item signatures } + +fn map(_: fn() -> Option<&'static T>) -> Option { + None +} + +fn value() -> Option<&'static _> { +//~^ ERROR the type placeholder `_` is not allowed within types on item signatures + Option::<&'static u8>::None +} + +const _: Option<_> = map(value); +//~^ ERROR the type placeholder `_` is not allowed within types on item signatures diff --git a/src/test/ui/typeck/typeck_type_placeholder_item.stderr b/src/test/ui/typeck/typeck_type_placeholder_item.stderr index 684f451b7c3f6..1034402bfb08d 100644 --- a/src/test/ui/typeck/typeck_type_placeholder_item.stderr +++ b/src/test/ui/typeck/typeck_type_placeholder_item.stderr @@ -158,7 +158,7 @@ LL | fn test11(x: &usize) -> &_ { | -^ | || | |not allowed in type signatures - | help: replace with the correct return type: `&&usize` + | help: replace with the correct return type: `&'static &'static usize` error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:52:52 @@ -410,6 +410,24 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa LL | type Y = impl Trait<_>; | ^ not allowed in type signatures +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item.rs:216:31 + | +LL | fn value() -> Option<&'static _> { + | ----------------^- + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `Option<&'static u8>` + +error[E0121]: the type placeholder `_` is not allowed within types on item signatures + --> $DIR/typeck_type_placeholder_item.rs:221:10 + | +LL | const _: Option<_> = map(value); + | ^^^^^^^^^ + | | + | not allowed in type signatures + | help: replace `_` with the correct type: `Option` + error[E0121]: the type placeholder `_` is not allowed within types on item signatures --> $DIR/typeck_type_placeholder_item.rs:140:31 | @@ -614,7 +632,7 @@ LL | const D: _ = 42; | not allowed in type signatures | help: replace `_` with the correct type: `i32` -error: aborting due to 67 previous errors +error: aborting due to 69 previous errors Some errors have detailed explanations: E0121, E0282, E0403. For more information about an error, try `rustc --explain E0121`. From 67f17342ee542220e1c972633bb71d49cfe97e84 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 26 Feb 2021 08:32:38 +0100 Subject: [PATCH 25/26] 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 26/26] 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: