diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 0434c1ba59a10..b5dad5ccdea8e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -229,15 +229,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } => { err.span_label(span, format!("cannot {ACT}", ACT = act)); - if let Some((span, message)) = annotate_struct_field( + if let Some(span) = get_mut_span_in_struct_field( self.infcx.tcx, Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty, field, ) { - err.span_suggestion( + err.span_suggestion_verbose( span, "consider changing this to be mutable", - message, + " mut ".into(), Applicability::MaybeIncorrect, ); } @@ -1059,18 +1059,18 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool { ty.is_closure() || ty.is_generator() } -/// Adds a suggestion to a struct definition given a field access to a local. -/// This function expects the local to be a reference to a struct in order to produce a suggestion. +/// Given a field that needs to be mutable, returns a span where the " mut " could go. +/// This function expects the local to be a reference to a struct in order to produce a span. /// /// ```text -/// LL | s: &'a String -/// | ---------- use `&'a mut String` here to make mutable +/// LL | s: &'a String +/// | ^^^ returns a span taking up the space here /// ``` -fn annotate_struct_field<'tcx>( +fn get_mut_span_in_struct_field<'tcx>( tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, field: &mir::Field, -) -> Option<(Span, String)> { +) -> Option { // Expect our local to be a reference to a struct of some kind. if let ty::Ref(_, ty, _) = ty.kind() { if let ty::Adt(def, _) = ty.kind() { @@ -1081,25 +1081,10 @@ fn annotate_struct_field<'tcx>( // Now we're dealing with the actual struct that we're going to suggest a change to, // we can expect a field that is an immutable reference to a type. if let hir::Node::Field(field) = node { - if let hir::TyKind::Rptr( - lifetime, - hir::MutTy { mutbl: hir::Mutability::Not, ref ty }, - ) = field.ty.kind + if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = + field.ty.kind { - // Get the snippets in two parts - the named lifetime (if there is one) and - // type being referenced, that way we can reconstruct the snippet without loss - // of detail. - let type_snippet = tcx.sess.source_map().span_to_snippet(ty.span).ok()?; - let lifetime_snippet = if !lifetime.is_elided() { - format!("{} ", tcx.sess.source_map().span_to_snippet(lifetime.span).ok()?) - } else { - String::new() - }; - - return Some(( - field.ty.span, - format!("&{}mut {}", lifetime_snippet, &*type_snippet,), - )); + return Some(lifetime.span.between(ty.span)); } } } diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs index 1df5540e3b840..2269fdf481471 100644 --- a/compiler/rustc_codegen_ssa/src/back/metadata.rs +++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs @@ -257,9 +257,9 @@ pub fn create_compressed_metadata_file( return compressed.to_vec(); }; let section = file.add_section( - file.segment_name(StandardSegment::Data).to_vec(), + file.segment_name(StandardSegment::Debug).to_vec(), b".rustc".to_vec(), - SectionKind::Data, + SectionKind::Debug, ); let offset = file.append_section_data(section, &compressed, 1); diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 49e6a7df10301..38ad8283f4df0 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -58,7 +58,7 @@ struct CheckAttrVisitor<'tcx> { tcx: TyCtxt<'tcx>, } -impl CheckAttrVisitor<'tcx> { +impl CheckAttrVisitor<'_> { /// Checks any attribute. fn check_attributes( &self, @@ -382,7 +382,7 @@ impl CheckAttrVisitor<'tcx> { &self, hir_id: HirId, attr_span: &Span, - attrs: &'hir [Attribute], + attrs: &[Attribute], span: &Span, target: Target, ) -> bool { @@ -1481,7 +1481,7 @@ impl CheckAttrVisitor<'tcx> { /// Checks if the `#[repr]` attributes on `item` are valid. fn check_repr( &self, - attrs: &'hir [Attribute], + attrs: &[Attribute], span: &Span, target: Target, item: Option>, @@ -1663,7 +1663,7 @@ impl CheckAttrVisitor<'tcx> { } } - fn check_used(&self, attrs: &'hir [Attribute], target: Target) { + fn check_used(&self, attrs: &[Attribute], target: Target) { for attr in attrs { if attr.has_name(sym::used) && target != Target::Static { self.tcx @@ -1842,7 +1842,7 @@ impl CheckAttrVisitor<'tcx> { } } -impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 9ccf76b5700c2..a5a65740707e6 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -78,7 +78,7 @@ impl<'tcx> CheckConstTraitVisitor<'tcx> { impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<'tcx> { /// check for const trait impls, and errors if the impl uses provided/default functions /// of the trait being implemented; as those provided functions can be non-const. - fn visit_item(&mut self, item: &'hir hir::Item<'hir>) { + fn visit_item<'hir>(&mut self, item: &'hir hir::Item<'hir>) { let _: Option<_> = try { if let hir::ItemKind::Impl(ref imp) = item.kind { if let hir::Constness::Const = imp.constness { @@ -134,11 +134,11 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor< }; } - fn visit_trait_item(&mut self, _: &'hir hir::TraitItem<'hir>) {} + fn visit_trait_item<'hir>(&mut self, _: &'hir hir::TraitItem<'hir>) {} - fn visit_impl_item(&mut self, _: &'hir hir::ImplItem<'hir>) {} + fn visit_impl_item<'hir>(&mut self, _: &'hir hir::ImplItem<'hir>) {} - fn visit_foreign_item(&mut self, _: &'hir hir::ForeignItem<'hir>) {} + fn visit_foreign_item<'hir>(&mut self, _: &'hir hir::ForeignItem<'hir>) {} } #[derive(Copy, Clone)] diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 772791324019a..3b15332c678fd 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -150,7 +150,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands. fn check_for_self_assign(&mut self, assign: &'tcx hir::Expr<'tcx>) { - fn check_for_self_assign_helper( + fn check_for_self_assign_helper<'tcx>( tcx: TyCtxt<'tcx>, typeck_results: &'tcx ty::TypeckResults<'tcx>, lhs: &'tcx hir::Expr<'tcx>, @@ -600,7 +600,7 @@ struct DeadVisitor<'tcx> { live_symbols: FxHashSet, } -impl DeadVisitor<'tcx> { +impl<'tcx> DeadVisitor<'tcx> { fn should_warn_about_item(&mut self, item: &hir::Item<'_>) -> bool { let should_warn = matches!( item.kind, @@ -672,7 +672,7 @@ impl DeadVisitor<'tcx> { } } -impl Visitor<'tcx> for DeadVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> { type Map = Map<'tcx>; /// Walk nested items in place so that we don't report dead-code diff --git a/compiler/rustc_passes/src/intrinsicck.rs b/compiler/rustc_passes/src/intrinsicck.rs index 008b856ebf2fa..064c469662842 100644 --- a/compiler/rustc_passes/src/intrinsicck.rs +++ b/compiler/rustc_passes/src/intrinsicck.rs @@ -62,7 +62,7 @@ fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { ty } -impl ExprVisitor<'tcx> { +impl<'tcx> ExprVisitor<'tcx> { fn def_id_is_transmute(&self, def_id: DefId) -> bool { self.tcx.fn_sig(def_id).abi() == RustIntrinsic && self.tcx.item_name(def_id) == sym::transmute @@ -487,7 +487,7 @@ impl ExprVisitor<'tcx> { } } -impl Visitor<'tcx> for ItemVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for ItemVisitor<'tcx> { type Map = intravisit::ErasedMap<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { @@ -504,7 +504,7 @@ impl Visitor<'tcx> for ItemVisitor<'tcx> { } } -impl Visitor<'tcx> for ExprVisitor<'tcx> { +impl<'tcx> Visitor<'tcx> for ExprVisitor<'tcx> { type Map = intravisit::ErasedMap<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 388c33917c64f..a808d6c8348a7 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -28,7 +28,7 @@ struct LanguageItemCollector<'tcx> { tcx: TyCtxt<'tcx>, } -impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { +impl<'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { fn visit_item(&mut self, item: &hir::Item<'_>) { self.check_for_lang(Target::from_item(item), item.hir_id()); @@ -50,7 +50,7 @@ impl ItemLikeVisitor<'v> for LanguageItemCollector<'tcx> { fn visit_foreign_item(&mut self, _: &hir::ForeignItem<'_>) {} } -impl LanguageItemCollector<'tcx> { +impl<'tcx> LanguageItemCollector<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> LanguageItemCollector<'tcx> { LanguageItemCollector { tcx, items: LanguageItems::new() } } diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index 558d8958b1358..00e8eb5eb2b38 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -20,7 +20,7 @@ struct LayoutTest<'tcx> { tcx: TyCtxt<'tcx>, } -impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> { +impl<'tcx> ItemLikeVisitor<'tcx> for LayoutTest<'tcx> { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { match item.kind { ItemKind::TyAlias(..) @@ -42,7 +42,7 @@ impl ItemLikeVisitor<'tcx> for LayoutTest<'tcx> { fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {} } -impl LayoutTest<'tcx> { +impl<'tcx> LayoutTest<'tcx> { fn dump_layout_of(&self, item_def_id: LocalDefId, item: &hir::Item<'tcx>, attr: &Attribute) { let tcx = self.tcx; let param_env = self.tcx.param_env(item_def_id); @@ -114,7 +114,7 @@ struct UnwrapLayoutCx<'tcx> { param_env: ParamEnv<'tcx>, } -impl LayoutOfHelpers<'tcx> for UnwrapLayoutCx<'tcx> { +impl<'tcx> LayoutOfHelpers<'tcx> for UnwrapLayoutCx<'tcx> { type LayoutOfResult = TyAndLayout<'tcx>; fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! { @@ -127,19 +127,19 @@ impl LayoutOfHelpers<'tcx> for UnwrapLayoutCx<'tcx> { } } -impl HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> { +impl<'tcx> HasTyCtxt<'tcx> for UnwrapLayoutCx<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } } -impl HasParamEnv<'tcx> for UnwrapLayoutCx<'tcx> { +impl<'tcx> HasParamEnv<'tcx> for UnwrapLayoutCx<'tcx> { fn param_env(&self) -> ParamEnv<'tcx> { self.param_env } } -impl HasDataLayout for UnwrapLayoutCx<'tcx> { +impl<'tcx> HasDataLayout for UnwrapLayoutCx<'tcx> { fn data_layout(&self) -> &TargetDataLayout { self.tcx.data_layout() } diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index d6528364e9806..8a411f01d6ee2 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -6,7 +6,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(crate_visibility_modifier)] -#![feature(in_band_lifetimes)] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(nll)] diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 10b8c3104fcad..55ae808dc3089 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -23,7 +23,7 @@ pub struct LibFeatureCollector<'tcx> { lib_features: LibFeatures, } -impl LibFeatureCollector<'tcx> { +impl<'tcx> LibFeatureCollector<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> { LibFeatureCollector { tcx, lib_features: new_lib_features() } } @@ -110,7 +110,7 @@ impl LibFeatureCollector<'tcx> { } } -impl Visitor<'tcx> for LibFeatureCollector<'tcx> { +impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 4ae1e5cee925e..3ee104316795a 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -198,7 +198,7 @@ struct IrMaps<'tcx> { lnks: IndexVec, } -impl IrMaps<'tcx> { +impl<'tcx> IrMaps<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> IrMaps<'tcx> { IrMaps { tcx, diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index d3ecd18a93c5a..07cb165d79670 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -37,7 +37,7 @@ impl<'tcx> Visitor<'tcx> for CheckNakedFunctions<'tcx> { fn visit_fn( &mut self, - fk: FnKind<'v>, + fk: FnKind<'_>, _fd: &'tcx hir::FnDecl<'tcx>, body_id: hir::BodyId, span: Span, diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index fc56a339215be..707e6b123daa2 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -22,7 +22,7 @@ use rustc_target::spec::abi::Abi; // Returns true if the given item must be inlined because it may be // monomorphized or it was marked with `#[inline]`. This will only return // true for functions. -fn item_might_be_inlined(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>, attrs: &CodegenFnAttrs) -> bool { +fn item_might_be_inlined(tcx: TyCtxt<'_>, item: &hir::Item<'_>, attrs: &CodegenFnAttrs) -> bool { if attrs.requests_inline() { return true; } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 92911c3cd2455..5f19991f9c78b 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -655,7 +655,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { // stable (assuming they have not inherited instability from their parent). } -fn stability_index(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> { +fn stability_index<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> Index<'tcx> { let is_staged_api = tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api; let mut staged_api = FxHashMap::default(); @@ -737,7 +737,7 @@ struct Checker<'tcx> { tcx: TyCtxt<'tcx>, } -impl Visitor<'tcx> for Checker<'tcx> { +impl<'tcx> Visitor<'tcx> for Checker<'tcx> { type Map = Map<'tcx>; /// Because stability levels are scoped lexically, we want to walk @@ -866,7 +866,7 @@ struct CheckTraitImplStable<'tcx> { fully_stable: bool, } -impl Visitor<'tcx> for CheckTraitImplStable<'tcx> { +impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'tcx> { type Map = Map<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/compiler/rustc_passes/src/upvars.rs b/compiler/rustc_passes/src/upvars.rs index 91b8ae07637df..2d84c8caada80 100644 --- a/compiler/rustc_passes/src/upvars.rs +++ b/compiler/rustc_passes/src/upvars.rs @@ -42,7 +42,7 @@ struct LocalCollector { locals: FxHashSet, } -impl Visitor<'tcx> for LocalCollector { +impl<'tcx> Visitor<'tcx> for LocalCollector { type Map = intravisit::ErasedMap<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { @@ -71,7 +71,7 @@ impl CaptureCollector<'_, '_> { } } -impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> { +impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> { type Map = intravisit::ErasedMap<'tcx>; fn nested_visit_map(&mut self) -> NestedVisitorMap { diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index 7456f886ea5d8..deed9901cc9e4 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -215,6 +215,7 @@ pub trait PartialEq { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] + #[default_method_body_is_const] fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } @@ -1031,6 +1032,7 @@ pub trait PartialOrd: PartialEq { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] + #[default_method_body_is_const] fn lt(&self, other: &Rhs) -> bool { matches!(self.partial_cmp(other), Some(Less)) } @@ -1050,6 +1052,7 @@ pub trait PartialOrd: PartialEq { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] + #[default_method_body_is_const] fn le(&self, other: &Rhs) -> bool { // Pattern `Some(Less | Eq)` optimizes worse than negating `None | Some(Greater)`. // FIXME: The root cause was fixed upstream in LLVM with: @@ -1072,6 +1075,7 @@ pub trait PartialOrd: PartialEq { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] + #[default_method_body_is_const] fn gt(&self, other: &Rhs) -> bool { matches!(self.partial_cmp(other), Some(Greater)) } @@ -1091,6 +1095,7 @@ pub trait PartialOrd: PartialEq { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] + #[default_method_body_is_const] fn ge(&self, other: &Rhs) -> bool { matches!(self.partial_cmp(other), Some(Greater | Equal)) } diff --git a/library/core/tests/cmp.rs b/library/core/tests/cmp.rs index 11cf7add07ada..58fee19ca7490 100644 --- a/library/core/tests/cmp.rs +++ b/library/core/tests/cmp.rs @@ -203,3 +203,36 @@ fn cmp_default() { assert!(Fool(false) != Fool(false)); assert_eq!(Fool(false), Fool(true)); } + +#[cfg(not(bootstrap))] +mod const_cmp { + use super::*; + + struct S(i32); + + impl const PartialEq for S { + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + } + + impl const PartialOrd for S { + fn partial_cmp(&self, other: &Self) -> Option { + let ret = match (self.0, other.0) { + (a, b) if a > b => Ordering::Greater, + (a, b) if a < b => Ordering::Less, + _ => Ordering::Equal, + }; + + Some(ret) + } + } + + const _: () = assert!(S(1) == S(1)); + const _: () = assert!(S(0) != S(1)); + + const _: () = assert!(S(1) <= S(1)); + const _: () = assert!(S(1) >= S(1)); + const _: () = assert!(S(0) < S(1)); + const _: () = assert!(S(1) > S(0)); +} diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index b7a4512152521..232ccdf39d456 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" description = "The Rust Standard Library" -edition = "2018" +edition = "2021" [lib] crate-type = ["dylib", "rlib"] diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 2293fb6b55812..749d51d4981c3 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -38,10 +38,9 @@ macro_rules! error { ($e:expr, $s:expr) => { match $e { Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s), - Err(ref err) => assert!( - err.raw_os_error() == Some($s), - format!("`{}` did not have a code of `{}`", err, $s) - ), + Err(ref err) => { + assert!(err.raw_os_error() == Some($s), "`{}` did not have a code of `{}`", err, $s) + } } }; } @@ -58,7 +57,7 @@ macro_rules! error_contains { match $e { Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s), Err(ref err) => { - assert!(err.to_string().contains($s), format!("`{}` did not contain `{}`", err, $s)) + assert!(err.to_string().contains($s), "`{}` did not contain `{}`", err, $s) } } }; diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index a29008140f784..6e6f5212b4651 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -16,8 +16,6 @@ mod libc { pub use libc::c_int; pub struct ucred; pub struct cmsghdr; - #[cfg(target_os = "dragonfly")] - pub struct cmsgcred; pub type pid_t = i32; pub type gid_t = u32; pub type uid_t = u32; @@ -185,11 +183,6 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> { #[derive(Clone)] pub struct SocketCred(libc::ucred); -#[cfg(target_os = "dragonfly")] -#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -#[derive(Clone)] -pub struct SocketCred(libc::cmsgcred); - #[cfg(any(doc, target_os = "android", target_os = "linux",))] impl SocketCred { /// Create a Unix credential struct. @@ -241,57 +234,6 @@ impl SocketCred { } } -#[cfg(target_os = "dragonfly")] -impl SocketCred { - /// Create a Unix credential struct. - /// - /// PID, UID and GID is set to 0. - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - #[must_use] - pub fn new() -> SocketCred { - SocketCred(libc::cmsgcred { cmsgcred_pid: 0, cmsgcred_uid: 0, cmsgcred_gid: 0 }) - } - - /// Set the PID. - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn set_pid(&mut self, pid: libc::pid_t) { - self.0.cmsgcred_pid = pid; - } - - /// Get the current PID. - #[must_use] - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn get_pid(&self) -> libc::pid_t { - self.0.cmsgcred_pid - } - - /// Set the UID. - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn set_uid(&mut self, uid: libc::uid_t) { - self.0.cmsgcred_uid = uid; - } - - /// Get the current UID. - #[must_use] - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn get_uid(&self) -> libc::uid_t { - self.0.cmsgcred_uid - } - - /// Set the GID. - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn set_gid(&mut self, gid: libc::gid_t) { - self.0.cmsgcred_gid = gid; - } - - /// Get the current GID. - #[must_use] - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn get_gid(&self) -> libc::gid_t { - self.0.cmsgcred_gid - } -} - /// This control message contains file descriptors. /// /// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_RIGHTS`. @@ -314,11 +256,7 @@ impl<'a> Iterator for ScmRights<'a> { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>); -#[cfg(target_os = "dragonfly")] -#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::cmsgcred>); - -#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))] +#[cfg(any(doc, target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] impl<'a> Iterator for ScmCredentials<'a> { type Item = SocketCred; @@ -362,7 +300,7 @@ impl<'a> AncillaryData<'a> { /// # Safety /// /// `data` must contain a valid control message and the control message must be type of - /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDS`. + /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDENTIALS`. #[cfg(any(doc, target_os = "android", target_os = "linux",))] unsafe fn as_credentials(data: &'a [u8]) -> Self { let ancillary_data_iter = AncillaryDataIter::new(data); @@ -382,9 +320,6 @@ impl<'a> AncillaryData<'a> { libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)), #[cfg(any(target_os = "android", target_os = "linux",))] libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)), - #[cfg(target_os = "dragonfly")] - libc::SCM_CREDS => Ok(AncillaryData::as_credentials(data)), - cmsg_type => { Err(AncillaryError::Unknown { cmsg_level: libc::SOL_SOCKET, cmsg_type }) } @@ -609,19 +544,6 @@ impl<'a> SocketAncillary<'a> { ) } - #[cfg(target_os = "dragonfly")] - #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] - pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool { - self.truncated = false; - add_to_ancillary_data( - &mut self.buffer, - &mut self.length, - creds, - libc::SOL_SOCKET, - libc::SCM_CREDS, - ) - } - /// Clears the ancillary data, removing all values. /// /// # Example diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index f23f8f94a242f..a2caccc784917 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -854,14 +854,8 @@ impl UnixDatagram { /// /// # Examples /// - #[cfg_attr( - any(target_os = "android", target_os = "linux", target_os = "dragonfly"), - doc = "```no_run" - )] - #[cfg_attr( - not(any(target_os = "android", target_os = "linux", target_os = "dragonfly")), - doc = "```ignore" - )] + #[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")] + #[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")] /// #![feature(unix_socket_ancillary_data)] /// use std::os::unix::net::UnixDatagram; /// @@ -871,7 +865,7 @@ impl UnixDatagram { /// Ok(()) /// } /// ``` - #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))] + #[cfg(any(doc, target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { self.0.set_passcred(passcred) @@ -883,7 +877,7 @@ impl UnixDatagram { /// Get the socket option `SO_PASSCRED`. /// /// [`set_passcred`]: UnixDatagram::set_passcred - #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "dragonfly",))] + #[cfg(any(doc, target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn passcred(&self) -> io::Result { self.0.passcred() diff --git a/library/std/src/process.rs b/library/std/src/process.rs index bf35d71bc4f05..e012594dd4648 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1600,7 +1600,6 @@ impl ExitStatusError { /// ``` /// #![feature(exit_status_error)] /// # if cfg!(unix) { - /// use std::convert::TryFrom; /// use std::num::NonZeroI32; /// use std::process::Command; /// diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index 15d0dbe07fe7e..a82a0172126d4 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -408,12 +408,12 @@ impl Socket { Ok(raw != 0) } - #[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))] + #[cfg(any(target_os = "android", target_os = "linux",))] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int) } - #[cfg(any(target_os = "android", target_os = "linux", target_os = "dragonfly",))] + #[cfg(any(target_os = "android", target_os = "linux",))] pub fn passcred(&self) -> io::Result { let passcred: libc::c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED)?; Ok(passcred != 0) diff --git a/library/std/src/thread/tests.rs b/library/std/src/thread/tests.rs index ca0d88135a5d8..4f2c81731a335 100644 --- a/library/std/src/thread/tests.rs +++ b/library/std/src/thread/tests.rs @@ -1,6 +1,7 @@ use super::Builder; use crate::any::Any; use crate::mem; +use crate::panic::panic_any; use crate::result; use crate::sync::{ mpsc::{channel, Sender}, @@ -183,7 +184,7 @@ fn test_simple_newsched_spawn() { } #[test] -fn test_try_panic_message_static_str() { +fn test_try_panic_message_string_literal() { match thread::spawn(move || { panic!("static string"); }) @@ -199,9 +200,9 @@ fn test_try_panic_message_static_str() { } #[test] -fn test_try_panic_message_owned_str() { +fn test_try_panic_any_message_owned_str() { match thread::spawn(move || { - panic!("owned string".to_string()); + panic_any("owned string".to_string()); }) .join() { @@ -215,9 +216,9 @@ fn test_try_panic_message_owned_str() { } #[test] -fn test_try_panic_message_any() { +fn test_try_panic_any_message_any() { match thread::spawn(move || { - panic!(box 413u16 as Box); + panic_any(box 413u16 as Box); }) .join() { @@ -233,10 +234,10 @@ fn test_try_panic_message_any() { } #[test] -fn test_try_panic_message_unit_struct() { +fn test_try_panic_any_message_unit_struct() { struct Juju; - match thread::spawn(move || panic!(Juju)).join() { + match thread::spawn(move || panic_any(Juju)).join() { Err(ref e) if e.is::() => {} Err(_) | Ok(()) => panic!(), } diff --git a/src/test/ui/did_you_mean/issue-38147-2.rs b/src/test/ui/did_you_mean/issue-38147-2.rs index fe2634d88abf4..154b149b72073 100644 --- a/src/test/ui/did_you_mean/issue-38147-2.rs +++ b/src/test/ui/did_you_mean/issue-38147-2.rs @@ -1,11 +1,16 @@ struct Bar<'a> { - s: &'a String + s: &'a String, + // use wonky spaces to ensure we are creating the span correctly + longer_name: & 'a Vec } impl<'a> Bar<'a> { fn f(&mut self) { self.s.push('x'); //~^ ERROR cannot borrow `*self.s` as mutable, as it is behind a `&` reference + + self.longer_name.push(13); + //~^ ERROR cannot borrow `*self.longer_name` as mutable, as it is behind a `&` reference } } diff --git a/src/test/ui/did_you_mean/issue-38147-2.stderr b/src/test/ui/did_you_mean/issue-38147-2.stderr index 8bf5c76977da5..7c287a7dbfa0d 100644 --- a/src/test/ui/did_you_mean/issue-38147-2.stderr +++ b/src/test/ui/did_you_mean/issue-38147-2.stderr @@ -1,12 +1,25 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference - --> $DIR/issue-38147-2.rs:7:9 + --> $DIR/issue-38147-2.rs:9:9 | -LL | s: &'a String - | ---------- help: consider changing this to be mutable: `&'a mut String` -... LL | self.s.push('x'); | ^^^^^^^^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | s: &'a mut String, + | +++ + +error[E0596]: cannot borrow `*self.longer_name` as mutable, as it is behind a `&` reference + --> $DIR/issue-38147-2.rs:12:9 + | +LL | self.longer_name.push(13); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | longer_name: & 'a mut Vec + | +++ -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0596`. diff --git a/src/test/ui/did_you_mean/issue-38147-3.stderr b/src/test/ui/did_you_mean/issue-38147-3.stderr index 0e1e42261c42b..94ffe17f10116 100644 --- a/src/test/ui/did_you_mean/issue-38147-3.stderr +++ b/src/test/ui/did_you_mean/issue-38147-3.stderr @@ -1,11 +1,13 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-3.rs:7:9 | -LL | s: &'a String - | ---------- help: consider changing this to be mutable: `&'a mut String` -... LL | self.s.push('x'); | ^^^^^^^^^^^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | s: &'a mut String + | +++ error: aborting due to previous error diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index 7d6fcbc0be215..db2a7087b994e 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit 7d6fcbc0be2151bfa85ec146545b42d8be2fb28c +Subproject commit db2a7087b994e20f264f26ad6db75184282ad120 diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index 3f59fefd041eb..f610dbd806aea 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -23,8 +23,10 @@ pub fn check(path: &Path, bad: &mut bool) { return; } - // Library crates are not yet ready to migrate to 2021. - if path.components().any(|c| c.as_os_str() == "library") { + // Not all library crates are ready to migrate to 2021. + if file.components().any(|c| c.as_os_str() == "library") + && file.components().all(|c| c.as_os_str() != "std") + { let has = contents.lines().any(is_edition_2018); if !has { tidy_error!(