From 013a04431e446fd07a816bcf6f79791d308a1f4b Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:01:32 -0500 Subject: [PATCH 01/21] Add `from` docs for tools --- .../src/attrs/mixed_attributes_style.rs | 4 ++++ src/tools/miri/src/concurrency/thread.rs | 1 + .../miri/src/concurrency/vector_clock.rs | 1 + src/tools/miri/src/lib.rs | 2 +- src/tools/miri/src/shims/io_error.rs | 3 +++ .../rust-analyzer/crates/base-db/src/input.rs | 10 ++++++++ .../rust-analyzer/crates/cfg/src/cfg_expr.rs | 1 + .../rust-analyzer/crates/hir-def/src/attr.rs | 1 + .../rust-analyzer/crates/hir-def/src/hir.rs | 1 + .../crates/hir-def/src/hir/type_ref.rs | 2 ++ .../crates/hir-def/src/item_scope.rs | 3 +++ .../crates/hir-def/src/item_tree.rs | 23 +++++++++++++++++++ .../rust-analyzer/crates/hir-def/src/lib.rs | 17 ++++++++++++++ .../rust-analyzer/crates/hir-def/src/path.rs | 1 + .../crates/hir-ty/src/consteval.rs | 9 ++++++++ .../crates/hir-ty/src/display.rs | 1 + .../rust-analyzer/crates/hir-ty/src/layout.rs | 1 + .../crates/hir-ty/src/mapping.rs | 8 +++++++ .../crates/hir-ty/src/method_resolution.rs | 2 ++ .../crates/hir-ty/src/mir/eval.rs | 1 + .../crates/ide/src/inlay_hints.rs | 2 ++ .../rust-analyzer/crates/ide/src/markup.rs | 2 ++ .../rust-analyzer/crates/ide/src/moniker.rs | 1 + 23 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs index d71c8e9894bf7..2fbb6d36d5fcc 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -15,6 +15,10 @@ enum SimpleAttrKind { } impl From<&AttrKind> for SimpleAttrKind { + /// Convert an `AttrKind` to a `SimpleAttrKind`, if it's a `DocComment` then `Doc` is returned with no conversion. + /// + /// ## Cost + /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heep allocation fn from(value: &AttrKind) -> Self { match value { AttrKind::Normal(attr) => { diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index a8a2491304dd1..ce739c2d0dcd5 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -80,6 +80,7 @@ impl Idx for ThreadId { } impl From for u64 { + /// Return inner `u32` converted to `u64` fn from(t: ThreadId) -> Self { t.0.into() } diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index 345726634299b..bf6132653e01c 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -34,6 +34,7 @@ impl Idx for VectorIdx { } impl From for VectorIdx { + /// Create new `VectorIdx` with `u32` as inner #[inline] fn from(id: u32) -> Self { Self(id) diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 03f76cfa6524c..471e3f31808a5 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -73,7 +73,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_symbol_mangling; extern crate rustc_target; -// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are +// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are // shipped only as rmeta files. #[allow(unused_extern_crates)] extern crate rustc_driver; diff --git a/src/tools/miri/src/shims/io_error.rs b/src/tools/miri/src/shims/io_error.rs index acf3f74a93d8b..c03c6fa5c95d8 100644 --- a/src/tools/miri/src/shims/io_error.rs +++ b/src/tools/miri/src/shims/io_error.rs @@ -14,18 +14,21 @@ pub enum IoError { pub use self::IoError::*; impl From for IoError { + /// Wrap `io::Error` in `HostError` fn from(value: io::Error) -> Self { IoError::HostError(value) } } impl From for IoError { + /// Convert a `io::ErrorKind` to a `io::Error` then wrap in `HostError` fn from(value: io::ErrorKind) -> Self { IoError::HostError(value.into()) } } impl From for IoError { + /// Wrap `Scalar` in `Raw` fn from(value: Scalar) -> Self { IoError::Raw(value) } diff --git a/src/tools/rust-analyzer/crates/base-db/src/input.rs b/src/tools/rust-analyzer/crates/base-db/src/input.rs index bd08387b58219..ba1428f1748cb 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/input.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/input.rs @@ -173,6 +173,8 @@ pub enum LangCrateOrigin { } impl From<&str> for LangCrateOrigin { + /// Match a string slice for "alloc", "core", "proc-macro", "proc_macro", "std", "test", + /// mapping them to variants of the same name; if none match then it's `Other` fn from(s: &str) -> Self { match s { "alloc" => LangCrateOrigin::Alloc, @@ -217,6 +219,10 @@ impl CrateDisplayName { } impl From for CrateDisplayName { + /// Creates a `CrateDisplayName` from `crate_name` and `crate_name.0`(inner) + /// + /// ## Cost + /// This clones `CrateName` fn from(crate_name: CrateName) -> CrateDisplayName { let canonical_name = crate_name.0.clone(); CrateDisplayName { crate_name, canonical_name } @@ -639,6 +645,10 @@ impl Env { } impl From for Vec<(String, String)> { + /// Iterates the hash map entries collects them in to a `Vec` then sorts it. + /// + /// ## Cost + /// This is expensive as it `collect`s and `sort`s env fn from(env: Env) -> Vec<(String, String)> { let mut entries: Vec<_> = env.entries.into_iter().collect(); entries.sort(); diff --git a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs index 0ec082dfa7fcb..a44f6ab2547ba 100644 --- a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs +++ b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs @@ -57,6 +57,7 @@ pub enum CfgExpr { } impl From for CfgExpr { + /// Wrap `CfgAtom` in `CfgExpr::Atom` fn from(atom: CfgAtom) -> Self { CfgExpr::Atom(atom) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs index 710bffcefe900..5ca03c431939b 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs @@ -245,6 +245,7 @@ pub enum DocExpr { } impl From for DocExpr { + /// Creates `Atom` with `DocAtom` fn from(atom: DocAtom) -> Self { DocExpr::Atom(atom) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/hir.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir.rs index 494644d8eff9d..3373b920eb013 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/hir.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/hir.rs @@ -146,6 +146,7 @@ impl Literal { } impl From for Literal { + /// Create a `Literal` by matching `LiteralKind` fn from(ast_lit_kind: ast::LiteralKind) -> Self { use ast::LiteralKind; match ast_lit_kind { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs index 6de4026dff75b..45da78c3082a8 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs @@ -637,6 +637,8 @@ impl LiteralConstRef { } impl From for LiteralConstRef { + /// Make a `LiteralConstRef` from `Literal` + /// - Note: `Char`, `Bool`, `Int`, `Uint` match, other types are not const and return a `Unknown` fn from(literal: Literal) -> Self { match literal { Literal::Char(c) => Self::Char(c), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs index 0ca1eb9bcfe37..63a6fdc18f2e6 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs @@ -37,6 +37,7 @@ pub enum ImportOrExternCrate { } impl From for ImportOrExternCrate { + /// Matches a `ImportOrGlob` to it's corresponding `ImportOrExternCrate` variant, of the same name fn from(value: ImportOrGlob) -> Self { match value { ImportOrGlob::Glob(it) => ImportOrExternCrate::Glob(it), @@ -101,6 +102,7 @@ pub enum ImportOrDef { } impl From for ImportOrDef { + /// Matches a `ImportOrExternCrate` to it's corresponding `ImportOrDef` variant, of the same name fn from(value: ImportOrExternCrate) -> Self { match value { ImportOrExternCrate::Import(it) => ImportOrDef::Import(it), @@ -111,6 +113,7 @@ impl From for ImportOrDef { } impl From for ImportOrDef { + /// Matches a `ImportOrGlob` to it's corresponding `ImportOrDef` variant, of the same name fn from(value: ImportOrGlob) -> Self { match value { ImportOrGlob::Import(it) => ImportOrDef::Import(it), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs index 382afbcb1dd4f..741a228ff43e1 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs @@ -516,6 +516,11 @@ macro_rules! from_attrs { ( $( $var:ident($t:ty) ),+ $(,)? ) => { $( impl From<$t> for AttrOwner { + #[doc = concat!( + "Create a `", stringify!($var), "` from a `", stringify!($t), "`", + "\n\n## Cost", + "This is free as it puts `", stringify!($t), "` into `", stringify!($var), "`" + )] fn from(t: $t) -> AttrOwner { AttrOwner::$var(t) } @@ -722,6 +727,10 @@ macro_rules! mod_items { } impl From for ModItem { + /// Create a `ModItem` from a `GenericModItem` variant of the same name + /// + /// ## Cost + /// Just a `match` fn from(id: GenericModItem) -> ModItem { match id { $( @@ -735,6 +744,10 @@ macro_rules! mod_items { } impl From for AttrOwner { + /// Create a `AttrOwner::ModItem` with `GenericModItem` as inner + /// + /// ## Cost + /// The cost is that of the `t.into()` call fn from(t: GenericModItem) -> AttrOwner { AttrOwner::ModItem(t.into()) } @@ -742,6 +755,7 @@ macro_rules! mod_items { $( impl From> for ModItem { + #[doc = concat!("Create a `ModItem<", stringify!($typ), ">` from a `FileItemTreeId<", stringify!($typ), ">` variant of the same name")] fn from(id: FileItemTreeId<$typ>) -> ModItem { ModItem::$typ(id) } @@ -749,6 +763,7 @@ macro_rules! mod_items { $( #[cfg_attr(ignore_fragment, $generic_params)] impl From> for GenericModItem { + #[doc = concat!("Create a `GenericModItem` from a `FileItemTreeId<", stringify!($typ), ">` variant of the same name")] fn from(id: FileItemTreeId<$typ>) -> GenericModItem { GenericModItem::$typ(id) } @@ -1248,6 +1263,10 @@ macro_rules! impl_froms { ($e:ident { $($v:ident ($t:ty)),* $(,)? }) => { $( impl From<$t> for $e { + #[doc = concat!( + "Create a `", stringify!($e), "` with `", stringify!($t), "` as the inner", + "\n\n## Cost\n", stringify!($t), " gets move into ", stringify!($v) + )] fn from(it: $t) -> $e { $e::$v(it) } @@ -1296,6 +1315,10 @@ impl_froms!(AssocItem { }); impl From for ModItem { + /// Convert the `AssocItem`s inner to a `ModItem` + /// + /// ## Cost + /// The cost is that of the inner items `into` call fn from(item: AssocItem) -> Self { match item { AssocItem::Function(it) => it.into(), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs index 9c947df35e990..ac3877adf17e7 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs @@ -410,18 +410,21 @@ impl PartialEq for ModuleId { } impl From for ModuleId { + /// Make a `ModuleId` with a krate, no block, and local_id of `ROOT` fn from(CrateRootModuleId { krate }: CrateRootModuleId) -> Self { ModuleId { krate, block: None, local_id: DefMap::ROOT } } } impl From for ModuleDefId { + /// Make a `ModuleId` with `CrateRootModuleId` as inner fn from(value: CrateRootModuleId) -> Self { ModuleDefId::ModuleId(value.into()) } } impl From for CrateRootModuleId { + /// Create a `CrateRootModuleId` with `CrateId` as inner fn from(krate: CrateId) -> Self { CrateRootModuleId { krate } } @@ -564,6 +567,7 @@ impl TypeParamId { } impl From for TypeOrConstParamId { + /// Get the inner `TypeOrConstParamId` of `TypeParamId` fn from(it: TypeParamId) -> Self { it.0 } @@ -590,6 +594,7 @@ impl ConstParamId { } impl From for TypeOrConstParamId { + /// Get the inner `TypeOrConstParamId` of `ConstParamId` fn from(it: ConstParamId) -> Self { it.0 } @@ -729,6 +734,7 @@ impl_from!( // Every `DefWithBodyId` is a type owner, since bodies can contain type (e.g. `{ let it: Type = _; }`) impl From for TypeOwnerId { + /// Convert `DefWithBodyId` inner into `TypeOwnerId` fn from(value: DefWithBodyId) -> Self { match value { DefWithBodyId::FunctionId(it) => it.into(), @@ -741,6 +747,7 @@ impl From for TypeOwnerId { } impl From for TypeOwnerId { + /// Convert `GenericDefId` inner into `TypeOwnerId` fn from(value: GenericDefId) -> Self { match value { GenericDefId::FunctionId(it) => it.into(), @@ -896,6 +903,7 @@ pub enum DefWithBodyId { impl_from!(FunctionId, ConstId, StaticId, InTypeConstId for DefWithBodyId); impl From for DefWithBodyId { + /// Make a `VariantId` with `EnumVariantId`, as inner fn from(id: EnumVariantId) -> Self { DefWithBodyId::VariantId(id) } @@ -1008,6 +1016,7 @@ impl GenericDefId { } impl From for GenericDefId { + /// Convert `AssocItemId` inner to `GenericDefId` fn from(item: AssocItemId) -> Self { match item { AssocItemId::FunctionId(f) => f.into(), @@ -1028,6 +1037,7 @@ impl InternValueTrivial for CallableDefId {} impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId); impl From for ModuleDefId { + /// Match `CallableDefId` to `ModuleDefId` fn from(def: CallableDefId) -> ModuleDefId { match def { CallableDefId::FunctionId(f) => ModuleDefId::FunctionId(f), @@ -1089,6 +1099,10 @@ impl_from!( impl TryFrom for AttrDefId { type Error = (); + /// Convert the inner of `ModuleDefId` into `Ok(AttrDefId)` + /// + /// # Errors + /// `BuiltinType` results in `Err` fn try_from(value: ModuleDefId) -> Result { match value { ModuleDefId::ModuleId(it) => Ok(it.into()), @@ -1107,6 +1121,7 @@ impl TryFrom for AttrDefId { } impl From for AttrDefId { + /// Match `ItemContainerId` to the `AttrDefId` variant of the same name fn from(acid: ItemContainerId) -> Self { match acid { ItemContainerId::ModuleId(mid) => AttrDefId::ModuleId(mid), @@ -1117,6 +1132,7 @@ impl From for AttrDefId { } } impl From for AttrDefId { + /// Match `AssocItemId` to the `AttrDefId` variant of the same name fn from(assoc: AssocItemId) -> Self { match assoc { AssocItemId::FunctionId(it) => AttrDefId::FunctionId(it), @@ -1126,6 +1142,7 @@ impl From for AttrDefId { } } impl From for AttrDefId { + /// Convert the inner of `VariantId` into `AttrDefId` fn from(vid: VariantId) -> Self { match vid { VariantId::EnumVariantId(id) => id.into(), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/path.rs b/src/tools/rust-analyzer/crates/hir-def/src/path.rs index 713e7389736a0..0147026c2a44a 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/path.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/path.rs @@ -332,6 +332,7 @@ impl GenericArgs { } impl From for Path { + /// Make a `BarePath` with a new `Interned` containing a `ModPath` using the `Name` fn from(name: Name) -> Path { Path::BarePath(Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name)))) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs index fb604569f439d..d52cc200cbb91 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs @@ -77,6 +77,11 @@ impl ConstEvalError { } impl From for ConstEvalError { + /// Convert `MirLowerError` to `ConstEvalError` by getting inner of `MirLowerError::ConstEvalError` + /// or wrapping it in the `MirLowerError` variant + /// + /// ## Cost + /// Just a `match` fn from(value: MirLowerError) -> Self { match value { MirLowerError::ConstEvalError(_, e) => *e, @@ -86,6 +91,10 @@ impl From for ConstEvalError { } impl From for ConstEvalError { + /// Convert a `MirEvalError` by wrapping it in the `ConstEvalError::MirEvalError` variant + /// + /// ## Cost + /// Free fn from(value: MirEvalError) -> Self { ConstEvalError::MirEvalError(value) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index 95ce36390d33d..81b8dc5aa095c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -463,6 +463,7 @@ pub enum HirDisplayError { FmtError, } impl From for HirDisplayError { + /// Ignore the `fmt::Error` and return `Self::FmtError` fn from(_: fmt::Error) -> Self { Self::FmtError } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs index bbd419d9659bf..641c2c2a2d716 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs @@ -107,6 +107,7 @@ impl fmt::Display for LayoutError { } impl From> for LayoutError { + /// Make a `BadCalc` error from a `LayoutCalculatorError` without payload fn from(err: LayoutCalculatorError) -> Self { LayoutError::BadCalc(err.without_payload()) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs index 2f38e8fa14c0b..7e5e2cc83b6f6 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs @@ -68,48 +68,56 @@ impl ToChalk for TypeAliasAsValue { } impl From for crate::db::InternedCallableDefId { + /// Makes a `InternedCallableDefId` from the `FnDefId`s inner intern id fn from(fn_def_id: FnDefId) -> Self { InternKey::from_intern_id(fn_def_id.0) } } impl From for FnDefId { + /// Makes a `FnDefId` with the `InternedCallableDefId`s intern id fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self { chalk_ir::FnDefId(callable_def_id.as_intern_id()) } } impl From for crate::db::InternedOpaqueTyId { + /// Makes a `InternedOpaqueTyId` from the `OpaqueTyId`s inner intern id fn from(id: OpaqueTyId) -> Self { InternKey::from_intern_id(id.0) } } impl From for OpaqueTyId { + /// Makes a `OpaqueTyId` with the `InternedOpaqueTyId`s intern id fn from(id: crate::db::InternedOpaqueTyId) -> Self { chalk_ir::OpaqueTyId(id.as_intern_id()) } } impl From> for crate::db::InternedClosureId { + /// Makes a `InternedClosureId` from the `ClosureId`s inner intern id fn from(id: chalk_ir::ClosureId) -> Self { Self::from_intern_id(id.0) } } impl From for chalk_ir::ClosureId { + /// Makes a `ClosureId` with the `InternedClosureId`s intern id fn from(id: crate::db::InternedClosureId) -> Self { chalk_ir::ClosureId(id.as_intern_id()) } } impl From> for crate::db::InternedCoroutineId { + /// Makes a `InternedCoroutineId` from the `CoroutineId`s inner intern id fn from(id: chalk_ir::CoroutineId) -> Self { Self::from_intern_id(id.0) } } impl From for chalk_ir::CoroutineId { + /// Makes a `CoroutineId` with the `InternedCoroutineId`s intern id fn from(id: crate::db::InternedCoroutineId) -> Self { chalk_ir::CoroutineId(id.as_intern_id()) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs index c722800527190..a802d1ad195a0 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs @@ -500,6 +500,7 @@ pub enum VisibleFromModule { } impl From> for VisibleFromModule { + /// If some make a `Filter` with `ModuleId` fn from(module: Option) -> Self { match module { Some(module) => Self::Filter(module), @@ -509,6 +510,7 @@ impl From> for VisibleFromModule { } impl From> for VisibleFromModule { + /// If some make an `IncludeBlock` with `BlockId` fn from(block: Option) -> Self { match block { Some(block) => Self::IncludeBlock(block), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs index 74a34e2981710..644e112b7786a 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs @@ -262,6 +262,7 @@ enum IntervalOrOwned { } impl From for IntervalOrOwned { + /// Makes a `Borrowed` with an `Interval` fn from(it: Interval) -> IntervalOrOwned { IntervalOrOwned::Borrowed(it) } diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs index 6babdff52a2be..53f2e6d5ed8ca 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs @@ -571,6 +571,7 @@ impl InlayHintLabel { } impl From for InlayHintLabel { + /// Create a new smallvec with the string as the text, with no linked_location or tooltip fn from(s: String) -> Self { Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None, tooltip: None }], @@ -579,6 +580,7 @@ impl From for InlayHintLabel { } impl From<&str> for InlayHintLabel { + /// Create a new smallvec with the string slice as the text, with no linked_location or tooltip fn from(s: &str) -> Self { Self { parts: smallvec![InlayHintLabelPart { diff --git a/src/tools/rust-analyzer/crates/ide/src/markup.rs b/src/tools/rust-analyzer/crates/ide/src/markup.rs index 750d12542605c..0405a52927095 100644 --- a/src/tools/rust-analyzer/crates/ide/src/markup.rs +++ b/src/tools/rust-analyzer/crates/ide/src/markup.rs @@ -11,12 +11,14 @@ pub struct Markup { } impl From for String { + /// Returns the inner text fn from(markup: Markup) -> Self { markup.text } } impl From for Markup { + /// Make a `Markup` with inner text of `String` fn from(text: String) -> Self { Markup { text } } diff --git a/src/tools/rust-analyzer/crates/ide/src/moniker.rs b/src/tools/rust-analyzer/crates/ide/src/moniker.rs index 5754b4fa82f43..21e54e9d45a17 100644 --- a/src/tools/rust-analyzer/crates/ide/src/moniker.rs +++ b/src/tools/rust-analyzer/crates/ide/src/moniker.rs @@ -55,6 +55,7 @@ pub enum SymbolInformationKind { } impl From for MonikerDescriptorKind { + /// Matches a `SymbolInformationKind` to it's corresponding `MonikerDescriptorKind` fn from(value: SymbolInformationKind) -> Self { match value { SymbolInformationKind::AssociatedType => Self::Type, From 050ad7a0bcd2b4ccc7bee2c0ce009b23939bb588 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:02:14 -0500 Subject: [PATCH 02/21] Add `from` docs to all impls in lib std and core --- library/alloc/src/bstr.rs | 30 +++++++++++++++++++ library/alloc/src/collections/mod.rs | 1 + library/alloc/src/task.rs | 4 +++ library/core/src/array/mod.rs | 13 ++++++++ library/core/src/ascii/ascii_char.rs | 1 + library/core/src/num/error.rs | 3 ++ library/core/src/num/nonzero.rs | 1 + library/core/src/ptr/alignment.rs | 2 ++ library/core/src/range.rs | 6 ++++ library/core/src/sync/exclusive.rs | 1 + .../crates/core_simd/src/masks.rs | 6 ++++ .../crates/core_simd/src/masks/full_masks.rs | 1 + .../crates/core_simd/src/vector.rs | 2 ++ .../crates/core_simd/src/vendor.rs | 1 + library/proc_macro/src/bridge/buffer.rs | 1 + library/proc_macro/src/bridge/closure.rs | 1 + library/proc_macro/src/bridge/rpc.rs | 5 ++++ library/proc_macro/src/lib.rs | 5 ++++ library/std/src/error.rs | 1 + library/std/src/io/buffered/mod.rs | 1 + library/std/src/os/fd/owned.rs | 3 ++ library/std/src/os/linux/process.rs | 2 ++ library/std/src/os/solid/io.rs | 2 ++ library/std/src/os/unix/net/datagram.rs | 1 + library/std/src/os/unix/net/listener.rs | 1 + library/std/src/os/unix/net/stream.rs | 1 + library/std/src/os/windows/io/handle.rs | 1 + library/std/src/os/windows/io/socket.rs | 3 ++ library/std/src/os/xous/ffi/definitions.rs | 4 +++ library/std/src/process.rs | 1 + library/std/src/sync/mpmc/error.rs | 1 + library/std/src/sync/mpmc/select.rs | 1 + library/std/src/sync/poison.rs | 1 + library/std/src/sync/reentrant_lock.rs | 1 + library/std/src/sys/fs/windows.rs | 2 ++ library/std/src/sys/pal/windows/time.rs | 5 ++++ library/std/src/sys/process/uefi.rs | 2 ++ library/std/src/sys/process/unix/common.rs | 5 ++++ library/std/src/sys/process/unix/fuchsia.rs | 1 + library/std/src/sys/process/unix/unix.rs | 1 + .../process/unix/unsupported/wait_status.rs | 1 + library/std/src/sys/process/unix/vxworks.rs | 1 + library/std/src/sys/process/unsupported.rs | 5 ++++ library/std/src/sys/process/windows.rs | 17 +++++++++++ library/std/src/thread/mod.rs | 1 + 45 files changed, 150 insertions(+) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 338c7ac7f8876..79b0129178862 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -180,6 +180,10 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a, const N: usize> From<&'a [u8; N]> for ByteString { +// /// Make a `ByteString` from a byte array ref. +// /// +// /// ## Cost +// /// Allocates a new `Vec` // #[inline] // fn from(s: &'a [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -188,6 +192,10 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl From<[u8; N]> for ByteString { +// /// Make a `ByteString` from a byte array. +// /// +// /// ## Cost +// /// Allocates a new `Vec` // #[inline] // fn from(s: [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -196,6 +204,10 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a [u8]> for ByteString { +// /// Make a `ByteString` from a byte slice. +// /// +// /// ## Cost +// /// Allocates a new `Vec` // #[inline] // fn from(s: &'a [u8]) -> Self { // ByteString(s.to_vec()) @@ -204,6 +216,7 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl From> for ByteString { +// /// Make a `ByteString` with `Vec` as inner // #[inline] // fn from(s: Vec) -> Self { // ByteString(s) @@ -212,6 +225,7 @@ impl Default for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl From for Vec { + /// Return the inner `Vec` of the byte string #[inline] fn from(s: ByteString) -> Self { s.0 @@ -222,6 +236,10 @@ impl From for Vec { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a str> for ByteString { +// /// Make a `ByteString` from a string slices bytes. +// /// +// /// ## Cost +// /// Allocates a new `Vec` // #[inline] // fn from(s: &'a str) -> Self { // ByteString(s.as_bytes().to_vec()) @@ -230,6 +248,7 @@ impl From for Vec { // // #[unstable(feature = "bstr", issue = "134915")] // impl From for ByteString { +// /// Create a `ByteString` from a `String`s bytes // #[inline] // fn from(s: String) -> Self { // ByteString(s.into_bytes()) @@ -599,6 +618,7 @@ impl Clone for Box { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { + /// Create a `Borrowed` cow from a `ByteStr` #[inline] fn from(s: &'a ByteStr) -> Self { Cow::Borrowed(s) @@ -607,6 +627,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box { + /// Create a `Box<[u8]>` from `Box`s raw #[inline] fn from(s: Box<[u8]>) -> Box { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -616,6 +637,7 @@ impl From> for Box { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box<[u8]> { + /// Create a `Box` from `Box<[u8]>`s raw #[inline] fn from(s: Box) -> Box<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -626,6 +648,7 @@ impl From> for Box<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc { + /// Create a `Rc<[u8]>` from `Rc`s raw #[inline] fn from(s: Rc<[u8]>) -> Rc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -636,6 +659,7 @@ impl From> for Rc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc<[u8]> { + /// Create a `Rc` from `Rc<[u8]>`s raw #[inline] fn from(s: Rc) -> Rc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -646,6 +670,7 @@ impl From> for Rc<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc { + /// Create a `Arc` from `Arc<[u8]>`s raw #[inline] fn from(s: Arc<[u8]>) -> Arc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -656,6 +681,7 @@ impl From> for Arc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc<[u8]> { + /// Create a `Arc` from `Arc<[u8]>`s raw #[inline] fn from(s: Arc) -> Arc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -675,6 +701,10 @@ impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>); impl<'a> TryFrom<&'a ByteStr> for String { type Error = core::str::Utf8Error; + /// Convert `ByteStr`s bytes to a utf-8 `String`. + /// + /// # Errors + /// If `ByteStr` is not valid utf-8 #[inline] fn try_from(s: &'a ByteStr) -> Result { Ok(core::str::from_utf8(&s.0)?.into()) diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index fac4d1a65abcb..ac93b13d3bf5a 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -130,6 +130,7 @@ pub use realalloc::collections::TryReserveErrorKind; )] #[cfg(not(test))] impl From for TryReserveError { + /// Wrap kind in `TryReserveError`. #[inline] fn from(kind: TryReserveErrorKind) -> Self { Self { kind } diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index b4116f4988b64..f34deb88fda7d 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -109,6 +109,7 @@ pub trait Wake { impl From> for Waker { /// Use a [`Wake`]-able type as a `Waker`. /// + /// ## Cost /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Arc) -> Waker { // SAFETY: This is safe because raw_waker safely constructs @@ -121,6 +122,7 @@ impl From> for Waker { impl From> for RawWaker { /// Use a `Wake`-able type as a `RawWaker`. /// + /// ## Cost /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Arc) -> RawWaker { raw_waker(waker) @@ -288,6 +290,7 @@ pub trait LocalWake { impl From> for LocalWaker { /// Use a `Wake`-able type as a `LocalWaker`. /// + /// ## Cost /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Rc) -> LocalWaker { // SAFETY: This is safe because raw_waker safely constructs @@ -300,6 +303,7 @@ impl From> for LocalWaker { impl From> for RawWaker { /// Use a `Wake`-able type as a `RawWaker`. /// + /// ## Cost /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Rc) -> RawWaker { local_raw_waker(waker) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 28329bb090845..a27975b385dcf 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -178,11 +178,24 @@ impl Error for TryFromSliceError { #[stable(feature = "try_from_slice_error", since = "1.36.0")] impl From for TryFromSliceError { + /// Match `Infallible` into `TryFromSliceError`. fn from(x: Infallible) -> TryFromSliceError { match x {} } } +#[unstable(feature = "never_type", issue = "35121")] +impl From for TryFromSliceError { + /// Match `!` into `TryFromSliceError`. + #[inline] + fn from(never: !) -> TryFromSliceError { + // Match rather than coerce to make sure that code like + // `From for TryFromSliceError` above will keep working + // when `Infallible` becomes an alias to `!`. + match never {} + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for [T; N] { #[inline] diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 48de4f17b1b3a..aba6530f6f357 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -546,6 +546,7 @@ macro_rules! into_int_impl { $( #[unstable(feature = "ascii_char", issue = "110998")] impl From for $ty { + #[doc = concat!("Convert `AsciiChar` as `u8` into `", stringify!($ty), "`")] #[inline] fn from(chr: AsciiChar) -> $ty { chr as u8 as $ty diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 6ef2fdd14c149..43f8fc3b4149a 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -27,6 +27,8 @@ impl Error for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl From for TryFromIntError { + /// Match `Infallible` into `TryFromIntError`. + #[inline] fn from(x: Infallible) -> TryFromIntError { match x {} } @@ -34,6 +36,7 @@ impl From for TryFromIntError { #[unstable(feature = "never_type", issue = "35121")] impl From for TryFromIntError { + /// Match `!` into `TryFromIntError`. #[inline] fn from(never: !) -> TryFromIntError { // Match rather than coerce to make sure that code like diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 7585ec140e31e..7843c7221033e 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -290,6 +290,7 @@ impl From> for T where T: ZeroablePrimitive, { + /// Get the inner num of `NonZero`. #[inline] fn from(nonzero: NonZero) -> Self { // Call `get` method to keep range information. diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 19311e39b454e..952e3a65b5ebb 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -189,6 +189,7 @@ impl TryFrom for Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for NonZero { + /// `Alignment` is non zero so the inner enum value is returned #[inline] fn from(align: Alignment) -> NonZero { align.as_nonzero() @@ -197,6 +198,7 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { + /// `Alignment` is unsined so the inner enum value is returned #[inline] fn from(align: Alignment) -> usize { align.as_usize() diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 2276112a27bb3..01cb61c42f6d5 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -187,6 +187,7 @@ impl IntoBounds for Range { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::Range { + /// Make a new `legacy::Range` with the same start and end as `Range` #[inline] fn from(value: Range) -> Self { Self { start: value.start, end: value.end } @@ -194,6 +195,7 @@ impl From> for legacy::Range { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for Range { + /// Make a new `Range` with the same start and end as `legacy::Range` #[inline] fn from(value: legacy::Range) -> Self { Self { start: value.start, end: value.end } @@ -363,6 +365,7 @@ impl IntoBounds for RangeInclusive { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeInclusive { + /// Make a new `legacy::RangeInclusive` with the same start and end as `RangeInclusive` #[inline] fn from(value: RangeInclusive) -> Self { Self::new(value.start, value.end) @@ -370,6 +373,7 @@ impl From> for legacy::RangeInclusive { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for RangeInclusive { + /// Make a new `RangeInclusive` with the same start and end as `legacy::RangeInclusive` #[inline] fn from(value: legacy::RangeInclusive) -> Self { assert!( @@ -507,6 +511,7 @@ impl IntoBounds for RangeFrom { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeFrom { + /// Make a new `legacy::RangeFrom` with the same start as `RangeFrom` #[inline] fn from(value: RangeFrom) -> Self { Self { start: value.start } @@ -514,6 +519,7 @@ impl From> for legacy::RangeFrom { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for RangeFrom { + /// Make a new `RangeFrom` with the same start as `legacy::RangeFrom` #[inline] fn from(value: legacy::RangeFrom) -> Self { Self { start: value.start } diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index 340b0b79e40a3..2ad87e7e3e0d9 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -164,6 +164,7 @@ impl Exclusive { #[unstable(feature = "exclusive_wrapper", issue = "98407")] impl From for Exclusive { + /// Creates a new `Exclusive` containing [`T`], wrapping the value in an `Exclusive` #[inline] fn from(t: T) -> Self { Self::new(t) diff --git a/library/portable-simd/crates/core_simd/src/masks.rs b/library/portable-simd/crates/core_simd/src/masks.rs index 19d45f4d3b31a..910240df50dda 100644 --- a/library/portable-simd/crates/core_simd/src/masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks.rs @@ -378,6 +378,7 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + /// Uses `from_array` to create a new `Mask` #[inline] fn from(array: [bool; N]) -> Self { Self::from_array(array) @@ -389,6 +390,10 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + /// Converts a SIMD mask to an array of bools. + /// + /// ## Cost + /// Copies the bytes of the array #[inline] fn from(vector: Mask) -> Self { vector.to_array() @@ -634,6 +639,7 @@ macro_rules! impl_from { where LaneCount: SupportedLaneCount, { + /// Casts the value into the other `Mask` #[inline] fn from(value: Mask<$from, N>) -> Self { value.cast() diff --git a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs index 4e98db4070a9d..7c185e865f429 100644 --- a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs @@ -238,6 +238,7 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + /// Return the inner of the `Mask` #[inline] fn from(value: Mask) -> Self { value.0 diff --git a/library/portable-simd/crates/core_simd/src/vector.rs b/library/portable-simd/crates/core_simd/src/vector.rs index d76a6cd52bfc5..18c0b43d94e0d 100644 --- a/library/portable-simd/crates/core_simd/src/vector.rs +++ b/library/portable-simd/crates/core_simd/src/vector.rs @@ -1047,6 +1047,7 @@ where LaneCount: SupportedLaneCount, T: SimdElement, { + /// Use `from_array` to load the array into a new `Simd` #[inline] fn from(array: [T; N]) -> Self { Self::from_array(array) @@ -1058,6 +1059,7 @@ where LaneCount: SupportedLaneCount, T: SimdElement, { + /// Use `to_array` to store the `Simd` into a new array #[inline] fn from(vector: Simd) -> Self { vector.to_array() diff --git a/library/portable-simd/crates/core_simd/src/vendor.rs b/library/portable-simd/crates/core_simd/src/vendor.rs index 57536e4fc77dc..e37e378540d5f 100644 --- a/library/portable-simd/crates/core_simd/src/vendor.rs +++ b/library/portable-simd/crates/core_simd/src/vendor.rs @@ -7,6 +7,7 @@ macro_rules! from_transmute { }; { @impl $from:ty => $to:ty } => { impl core::convert::From<$from> for $to { + #[doc = concat!("Transmute a `", stringify!($from), "` into a `", stringify!($to), "`")] #[inline] fn from(value: $from) -> $to { // Safety: transmuting between vectors is safe, but the caller of this macro diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 3760749d83a54..8c28d4071c21c 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -127,6 +127,7 @@ impl Drop for Buffer { } impl From> for Buffer { + /// Move data, len, and capacity from `Vec`, then create custom reserve and drop fns. fn from(v: Vec) -> Self { let mut v = ManuallyDrop::new(v); let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity()); diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/bridge/closure.rs index e0e688434dce5..fb6766d0830ca 100644 --- a/library/proc_macro/src/bridge/closure.rs +++ b/library/proc_macro/src/bridge/closure.rs @@ -17,6 +17,7 @@ pub(super) struct Closure<'a, A, R> { struct Env; impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { + /// Create a `Closure` from a function fn from(f: &'a mut F) -> Self { unsafe extern "C" fn call R>(env: *mut Env, arg: A) -> R { unsafe { (*(env as *mut _ as *mut F))(arg) } diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 85fd7d138585c..bec79c5c309d0 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -253,6 +253,7 @@ pub enum PanicMessage { } impl From> for PanicMessage { + /// downcast the payload and wrap it in `StaticStr` or `String`. fn from(payload: Box) -> Self { if let Some(s) = payload.downcast_ref::<&'static str>() { return PanicMessage::StaticStr(s); @@ -265,6 +266,10 @@ impl From> for PanicMessage { } impl From for Box { + /// Return the inner wrapped in `Box`. + /// + /// ## Cost + /// Allocates a new `Box` on the heep fn from(val: PanicMessage) -> Self { match val { PanicMessage::StaticStr(s) => Box::new(s), diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index d9141eab5919f..c37a38a0a7198 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -238,6 +238,7 @@ fn tree_to_bridge_tree( /// Creates a token stream containing a single token tree. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenStream { + /// Convert the tree to a bridge tree then a `TokenStream` fn from(tree: TokenTree) -> TokenStream { TokenStream(Some(bridge::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) } @@ -721,6 +722,7 @@ impl fmt::Debug for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { + /// Wrap `Group` in `TokenTree::Group` fn from(g: Group) -> TokenTree { TokenTree::Group(g) } @@ -728,6 +730,7 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { + /// Wrap `Ident` in `TokenTree::Ident` fn from(g: Ident) -> TokenTree { TokenTree::Ident(g) } @@ -735,6 +738,7 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { + /// Wrap `Punct` in `TokenTree::Punct` fn from(g: Punct) -> TokenTree { TokenTree::Punct(g) } @@ -742,6 +746,7 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { + /// Wrap `Literal` in `TokenTree::Literal` fn from(g: Literal) -> TokenTree { TokenTree::Literal(g) } diff --git a/library/std/src/error.rs b/library/std/src/error.rs index def5f984c88e4..61059f70d5223 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -511,6 +511,7 @@ impl From for Report where E: Error, { + /// Create a `Report` with error of `E`, with all other parameters `false` fn from(error: E) -> Self { Report { error, show_backtrace: false, pretty: false } } diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 475d877528f7f..e72a1392e08f3 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -173,6 +173,7 @@ impl IntoInnerError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for Error { + /// Get the error of the inner buffer fn from(iie: IntoInnerError) -> Error { iie.1 } diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 2dcbfc966189d..7cb829f7be8f9 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -340,6 +340,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpStream { + /// Create a `TcpStream` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( @@ -370,6 +371,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpListener { + /// Create a `TcpListener` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( @@ -400,6 +402,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::UdpSocket { + /// Create a `UdpSocket` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 9195909479729..7d053783b930f 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -131,12 +131,14 @@ impl AsFd for PidFd { } impl From for PidFd { + /// Make a `PidFd` from inner. fn from(fd: OwnedFd) -> Self { Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) } } impl From for OwnedFd { + /// Get the inner of `PidFd` fn from(pid_fd: PidFd) -> Self { pid_fd.into_inner().into_inner().into_inner() } diff --git a/library/std/src/os/solid/io.rs b/library/std/src/os/solid/io.rs index c23d842b238b8..e95ae309d490e 100644 --- a/library/std/src/os/solid/io.rs +++ b/library/std/src/os/solid/io.rs @@ -243,6 +243,7 @@ macro_rules! impl_owned_fd_traits { } impl From for OwnedFd { + #[doc = concat!("Create a `OwnedFd` from inner `", stringify!($t), "`")] #[inline] fn from(socket: net::$t) -> OwnedFd { socket.into_inner().into_socket().into_inner() @@ -250,6 +251,7 @@ macro_rules! impl_owned_fd_traits { } impl From for net::$t { + #[doc = concat!("Create a `", stringify!($t), "` with inner `OwnedFd`")] #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd))) diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 7735637c84059..ece253153c40a 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -981,6 +981,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixDatagram { + /// Takes ownership of a [`OwnedFd`]'s socket file descriptor. #[inline] fn from(owned: OwnedFd) -> Self { unsafe { Self::from_raw_fd(owned.into_raw_fd()) } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 27428c9eb2855..a2d89dcbddb83 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -342,6 +342,7 @@ impl AsFd for UnixListener { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixListener { + /// Make a `UnixListener` with `OwnedFd` as it's inner file descriptor. #[inline] fn from(fd: OwnedFd) -> UnixListener { UnixListener(Socket::from_inner(FromInner::from_inner(fd))) diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 1cab04a454dc0..48c0641485b98 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -694,6 +694,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixStream { + /// Takes ownership of a [`OwnedFd`]'s socket file descriptor. #[inline] fn from(owned: OwnedFd) -> Self { unsafe { Self::from_raw_fd(owned.into_raw_fd()) } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 7f21929b85f99..b1f4c19f50e4f 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -655,6 +655,7 @@ impl AsHandle for crate::thread::JoinHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl From> for OwnedHandle { + /// Get the inner handle of `JoinHandle`. #[inline] fn from(join_handle: crate::thread::JoinHandle) -> OwnedHandle { join_handle.into_inner().into_handle().into_inner() diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 1c228914de93f..773cafe8e902e 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -320,6 +320,7 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::TcpStream { + /// Make a `TcpStream` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) } @@ -345,6 +346,7 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::TcpListener { + /// Make a `TcpListener` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) } @@ -370,6 +372,7 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::UdpSocket { + /// Make a `UdpSocket` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) } diff --git a/library/std/src/os/xous/ffi/definitions.rs b/library/std/src/os/xous/ffi/definitions.rs index 345005bcc78d7..e11edd6bf00f7 100644 --- a/library/std/src/os/xous/ffi/definitions.rs +++ b/library/std/src/os/xous/ffi/definitions.rs @@ -79,6 +79,7 @@ pub enum Error { #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { + /// Match an error code to `Error`, if `usize > 27` or `usize == 22` then return `UnknownError` fn from(src: usize) -> Self { match src { 0 => Self::NoError, @@ -115,6 +116,7 @@ impl From for Error { #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { + /// Convert `i32` to an `Error`, if the conversion fails it `UnknownError` is returned fn from(src: i32) -> Self { let Ok(src) = core::convert::TryInto::::try_into(src) else { return Self::UnknownError; @@ -193,6 +195,7 @@ pub struct Connection(u32); #[stable(feature = "rust1", since = "1.0.0")] impl From for Connection { + /// Make a `Connection` with `u32` as inner fn from(src: u32) -> Connection { Connection(src) } @@ -263,6 +266,7 @@ impl Into<[u32; 4]> for ServerAddress { pub(crate) struct ThreadId(usize); impl From for ThreadId { + /// Make a `ThreadId` with `usize` as inner fn from(src: usize) -> ThreadId { ThreadId(src) } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index f81ce8e1a1a1e..19818cbd0ac09 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1923,6 +1923,7 @@ impl ExitStatusError { #[unstable(feature = "exit_status_error", issue = "84908")] impl From for ExitStatus { + /// Wrap the converted inner of `ExitStatusError` in `ExitStatus` fn from(error: ExitStatusError) -> Self { Self(error.0.into()) } diff --git a/library/std/src/sync/mpmc/error.rs b/library/std/src/sync/mpmc/error.rs index e34b56d08312b..cf90ff138f352 100644 --- a/library/std/src/sync/mpmc/error.rs +++ b/library/std/src/sync/mpmc/error.rs @@ -41,6 +41,7 @@ impl error::Error for SendTimeoutError {} #[unstable(feature = "mpmc_channel", issue = "126840")] impl From> for SendTimeoutError { + /// Make a `SendTimeoutError::Disconnected` with `SendError`s inner fn from(err: SendError) -> SendTimeoutError { match err { SendError(e) => SendTimeoutError::Disconnected(e), diff --git a/library/std/src/sync/mpmc/select.rs b/library/std/src/sync/mpmc/select.rs index 56a83fee2e119..34340b5b693a2 100644 --- a/library/std/src/sync/mpmc/select.rs +++ b/library/std/src/sync/mpmc/select.rs @@ -47,6 +47,7 @@ pub enum Selected { } impl From for Selected { + /// Make a `Selected` from a `usize`, 0-2 match specific variants, the rest matches `Operation` #[inline] fn from(val: usize) -> Selected { match val { diff --git a/library/std/src/sync/poison.rs b/library/std/src/sync/poison.rs index 1b8809734b8a8..efe00f0c359c9 100644 --- a/library/std/src/sync/poison.rs +++ b/library/std/src/sync/poison.rs @@ -340,6 +340,7 @@ impl PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for TryLockError { + /// Wrap `PoisonError` in `Poisoned` variant. fn from(err: PoisonError) -> TryLockError { TryLockError::Poisoned(err) } diff --git a/library/std/src/sync/reentrant_lock.rs b/library/std/src/sync/reentrant_lock.rs index e009eb410efc0..3ed11e6dc365d 100644 --- a/library/std/src/sync/reentrant_lock.rs +++ b/library/std/src/sync/reentrant_lock.rs @@ -373,6 +373,7 @@ impl Default for ReentrantLock { #[unstable(feature = "reentrant_lock", issue = "121440")] impl From for ReentrantLock { + /// Create a new `ReentrantLock` wrapping `T` fn from(t: T) -> Self { Self::new(t) } diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 06bba019393a5..1e3e4ac8f9c9b 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1057,6 +1057,8 @@ impl FileAttr { } } impl From for FileAttr { + /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`, + /// with some conditionals for `file_size` and `reparse_tag`. fn from(wfd: c::WIN32_FIND_DATAW) -> Self { FileAttr { attributes: wfd.dwFileAttributes, diff --git a/library/std/src/sys/pal/windows/time.rs b/library/std/src/sys/pal/windows/time.rs index d9010e3996109..66ccd8762512a 100644 --- a/library/std/src/sys/pal/windows/time.rs +++ b/library/std/src/sys/pal/windows/time.rs @@ -133,6 +133,7 @@ impl fmt::Debug for SystemTime { } impl From for SystemTime { + /// Wrap `c::FILETIME` in `SystemTime`. fn from(t: c::FILETIME) -> SystemTime { SystemTime { t } } @@ -187,6 +188,10 @@ mod perf_counter { } } impl From for super::Instant { + /// Use `PerformanceCounterInstant` to get instant in nano sec, then make a `Duration` from nanos. + /// + /// ## Cost + /// This calls a function that makes an atomic oparation fn from(other: PerformanceCounterInstant) -> Self { let freq = frequency() as u64; let instant_nsec = mul_div_u64(other.ts as u64, NANOS_PER_SEC, freq); diff --git a/library/std/src/sys/process/uefi.rs b/library/std/src/sys/process/uefi.rs index b46418ae9bb67..8b3185b26e37d 100644 --- a/library/std/src/sys/process/uefi.rs +++ b/library/std/src/sys/process/uefi.rs @@ -181,6 +181,7 @@ impl Command { } impl From for Stdio { + /// Diverge the `Pipe`. fn from(pipe: AnonPipe) -> Stdio { pipe.diverge() } @@ -272,6 +273,7 @@ impl ExitCode { } impl From for ExitCode { + /// Match `u8` to a `ExitCode` variant, 0 is `SUCCESS`, else is `FAILURE`. fn from(code: u8) -> Self { match code { 0 => Self::SUCCESS, diff --git a/library/std/src/sys/process/unix/common.rs b/library/std/src/sys/process/unix/common.rs index 8bc17f314911d..6dcd81d0b173f 100644 --- a/library/std/src/sys/process/unix/common.rs +++ b/library/std/src/sys/process/unix/common.rs @@ -484,6 +484,7 @@ impl Stdio { } impl From for Stdio { + /// Wrap `AnonPipe`s inner in the `Fd` variant. fn from(pipe: AnonPipe) -> Stdio { Stdio::Fd(pipe.into_inner()) } @@ -496,12 +497,14 @@ impl From for Stdio { } impl From for Stdio { + /// Wrap `File`s inner in the `Fd` variant. fn from(file: File) -> Stdio { Stdio::Fd(file.into_inner()) } } impl From for Stdio { + /// Make a `StaticFd` from a raw borrow of `libc::STDOUT_FILENO`. fn from(_: io::Stdout) -> Stdio { // This ought really to be is Stdio::StaticFd(input_argument.as_fd()). // But AsFd::as_fd takes its argument by reference, and yields @@ -518,6 +521,7 @@ impl From for Stdio { } impl From for Stdio { + /// Make a `StaticFd` from a raw borrow of `libc::STDERR_FILENO`. fn from(_: io::Stderr) -> Stdio { Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDERR_FILENO) }) } @@ -639,6 +643,7 @@ impl ExitCode { } impl From for ExitCode { + /// Take code by wrapping it in `ExitCode`. fn from(code: u8) -> Self { Self(code) } diff --git a/library/std/src/sys/process/unix/fuchsia.rs b/library/std/src/sys/process/unix/fuchsia.rs index 0de32ecffd4b0..8616ebb467b77 100644 --- a/library/std/src/sys/process/unix/fuchsia.rs +++ b/library/std/src/sys/process/unix/fuchsia.rs @@ -290,6 +290,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a as i64) } diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 42542f81b6545..7abf54ee96ecd 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1085,6 +1085,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a) } diff --git a/library/std/src/sys/process/unix/unsupported/wait_status.rs b/library/std/src/sys/process/unix/unsupported/wait_status.rs index f348d557e4b7e..10d61748ccb54 100644 --- a/library/std/src/sys/process/unix/unsupported/wait_status.rs +++ b/library/std/src/sys/process/unix/unsupported/wait_status.rs @@ -21,6 +21,7 @@ pub struct ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(wait_status: c_int) -> ExitStatus { ExitStatus { wait_status } } diff --git a/library/std/src/sys/process/unix/vxworks.rs b/library/std/src/sys/process/unix/vxworks.rs index 5f1727789a1bc..b9c1e90f66a2f 100644 --- a/library/std/src/sys/process/unix/vxworks.rs +++ b/library/std/src/sys/process/unix/vxworks.rs @@ -236,6 +236,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a) } diff --git a/library/std/src/sys/process/unsupported.rs b/library/std/src/sys/process/unsupported.rs index fee81744f09ec..158b7a23b754e 100644 --- a/library/std/src/sys/process/unsupported.rs +++ b/library/std/src/sys/process/unsupported.rs @@ -111,24 +111,28 @@ impl Command { } impl From for Stdio { + /// Diverge pipe into `Stdio` fn from(pipe: AnonPipe) -> Stdio { pipe.diverge() } } impl From for Stdio { + /// Return a `Stdio::ParentStdout`. fn from(_: io::Stdout) -> Stdio { Stdio::ParentStdout } } impl From for Stdio { + /// Return a `Stdio::ParentStderr`. fn from(_: io::Stderr) -> Stdio { Stdio::ParentStderr } } impl From for Stdio { + /// Wrap `File` in a `Stdio::InheritFile`. fn from(file: File) -> Stdio { Stdio::InheritFile(file) } @@ -267,6 +271,7 @@ impl ExitCode { } impl From for ExitCode { + /// Take `u8` by wrapping it in `ExitCode`. fn from(code: u8) -> Self { Self(code) } diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index 06c15e08f3fb1..c4079b49366ed 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -109,6 +109,7 @@ impl PartialOrd for EnvKey { } impl PartialEq for EnvKey { fn eq(&self, other: &str) -> bool { + // Save an allocation if lengths are different if self.os_string.len() != other.len() { false } else { @@ -120,18 +121,27 @@ impl PartialEq for EnvKey { // Environment variable keys should preserve their original case even though // they are compared using a caseless string mapping. impl From for EnvKey { + /// Create a new `EnvKey` from `OsString` and it's encode wide iter. + /// + /// ## Cost + /// Has to collect `OsString.encode_wide` which allocates a new `Vec` fn from(k: OsString) -> Self { EnvKey { utf16: k.encode_wide().collect(), os_string: k } } } impl From for OsString { + /// Return the inner `OsString` of the `EnvKey` fn from(k: EnvKey) -> Self { k.os_string } } impl From<&OsStr> for EnvKey { + /// Uses `EnvKey::From` to convert the `&OsStr`. + /// + /// ## Cost + /// Converts `&OsStr` to `OsString` which does a heep allocation fn from(k: &OsStr) -> Self { Self::from(k.to_os_string()) } @@ -609,6 +619,7 @@ impl Stdio { } impl From for Stdio { + /// Wrap `AnonPipe` in the `Pipe` variant fn from(pipe: AnonPipe) -> Stdio { Stdio::Pipe(pipe) } @@ -621,18 +632,21 @@ impl From for Stdio { } impl From for Stdio { + /// Wrap `File`s inner in the `Handle` variant fn from(file: File) -> Stdio { Stdio::Handle(file.into_inner()) } } impl From for Stdio { + /// Create a new `Stdio::InheritSpecific` with `c::STD_OUTPUT_HANDLE` fn from(_: io::Stdout) -> Stdio { Stdio::InheritSpecific { from_stdio_id: c::STD_OUTPUT_HANDLE } } } impl From for Stdio { + /// Create a new `Stdio::InheritSpecific` with `c::STD_ERROR_HANDLE` fn from(_: io::Stderr) -> Stdio { Stdio::InheritSpecific { from_stdio_id: c::STD_ERROR_HANDLE } } @@ -728,6 +742,7 @@ impl ExitStatus { /// Converts a raw `u32` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `u32` in a type-safe `ExitStatus` fn from(u: u32) -> ExitStatus { ExitStatus(u) } @@ -777,12 +792,14 @@ impl ExitCode { } impl From for ExitCode { + /// Convert the `u8` to a `u32` then wrap it in a `ExitCode` fn from(code: u8) -> Self { ExitCode(u32::from(code)) } } impl From for ExitCode { + /// Wrap the `u32` in a `ExitCode` fn from(code: u32) -> Self { ExitCode(u32::from(code)) } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 3f3ba02361cc8..5ab936e089e2a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1265,6 +1265,7 @@ mod thread_name_string { } impl From for ThreadNameString { + /// Convert `String` to a `CString` then use that as the `ThreadNameString` inner fn from(s: String) -> Self { Self { inner: CString::new(s).expect("thread name may not contain interior null bytes"), From 10dfebd3d27fe626dbe67498c30ad5a1a720a83b Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:27:03 -0500 Subject: [PATCH 03/21] Fix formatting and add more docs for bstr --- library/alloc/src/bstr.rs | 24 +++++++++++++++--------- library/std/src/sys/fs/windows.rs | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 79b0129178862..4594df2fe1d22 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -225,7 +225,7 @@ impl Default for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl From for Vec { - /// Return the inner `Vec` of the byte string + /// Return the inner `Vec` of the byte string. #[inline] fn from(s: ByteString) -> Self { s.0 @@ -257,6 +257,10 @@ impl From for Vec { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for ByteString { + /// Convert the `ByteStr` to a `Vec` then wrap it in a `ByteString`. + /// + /// ## Cost + /// Allocates a new `Vec` #[inline] fn from(s: &'a ByteStr) -> Self { ByteString(s.0.to_vec()) @@ -265,6 +269,7 @@ impl<'a> From<&'a ByteStr> for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From for Cow<'a, ByteStr> { + /// Wrap `ByteString` in `Cow::Owned`. #[inline] fn from(s: ByteString) -> Self { Cow::Owned(s) @@ -273,6 +278,7 @@ impl<'a> From for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteString> for Cow<'a, ByteStr> { + /// Wrap `ByteString` as byte str in `Cow::Borrowed`. #[inline] fn from(s: &'a ByteString) -> Self { Cow::Borrowed(s.as_bytestr()) @@ -618,7 +624,7 @@ impl Clone for Box { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { - /// Create a `Borrowed` cow from a `ByteStr` + /// Create a `Borrowed` cow from a `ByteStr`. #[inline] fn from(s: &'a ByteStr) -> Self { Cow::Borrowed(s) @@ -627,7 +633,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box { - /// Create a `Box<[u8]>` from `Box`s raw + /// Create a `Box<[u8]>` from `Box`s raw. #[inline] fn from(s: Box<[u8]>) -> Box { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -637,7 +643,7 @@ impl From> for Box { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box<[u8]> { - /// Create a `Box` from `Box<[u8]>`s raw + /// Create a `Box` from `Box<[u8]>`s raw. #[inline] fn from(s: Box) -> Box<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -648,7 +654,7 @@ impl From> for Box<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc { - /// Create a `Rc<[u8]>` from `Rc`s raw + /// Create a `Rc<[u8]>` from `Rc`s raw. #[inline] fn from(s: Rc<[u8]>) -> Rc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -659,7 +665,7 @@ impl From> for Rc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc<[u8]> { - /// Create a `Rc` from `Rc<[u8]>`s raw + /// Create a `Rc` from `Rc<[u8]>`s raw. #[inline] fn from(s: Rc) -> Rc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -670,7 +676,7 @@ impl From> for Rc<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc { - /// Create a `Arc` from `Arc<[u8]>`s raw + /// Create a `Arc` from `Arc<[u8]>`s raw. #[inline] fn from(s: Arc<[u8]>) -> Arc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -681,7 +687,7 @@ impl From> for Arc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc<[u8]> { - /// Create a `Arc` from `Arc<[u8]>`s raw + /// Create a `Arc` from `Arc<[u8]>`s raw. #[inline] fn from(s: Arc) -> Arc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -702,7 +708,7 @@ impl<'a> TryFrom<&'a ByteStr> for String { type Error = core::str::Utf8Error; /// Convert `ByteStr`s bytes to a utf-8 `String`. - /// + /// /// # Errors /// If `ByteStr` is not valid utf-8 #[inline] diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 1e3e4ac8f9c9b..1403ef527689c 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1057,7 +1057,7 @@ impl FileAttr { } } impl From for FileAttr { - /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`, + /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`, /// with some conditionals for `file_size` and `reparse_tag`. fn from(wfd: c::WIN32_FIND_DATAW) -> Self { FileAttr { From c4a51909fa5f460f956d4f64cac2a6e12a795345 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:55:25 -0500 Subject: [PATCH 04/21] Improve consistence --- library/alloc/src/collections/vec_deque/mod.rs | 1 + library/core/src/ptr/non_null.rs | 1 + library/std/src/sync/mpsc.rs | 3 +++ library/std/src/sync/poison.rs | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index f8844e2d3a5cb..656d52d179116 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -3045,6 +3045,7 @@ impl From> for VecDeque { /// [`Vec`]: crate::vec::Vec /// [`VecDeque`]: crate::collections::VecDeque /// + /// ## Cost /// This conversion is guaranteed to run in *O*(1) time /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index c769ba673c61e..3ebcf64402dcb 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1648,6 +1648,7 @@ impl hash::Hash for NonNull { #[unstable(feature = "ptr_internals", issue = "none")] impl From> for NonNull { + /// Return `Unique` casted to a `NonNull`. #[inline] fn from(unique: Unique) -> Self { unique.as_non_null_ptr() diff --git a/library/std/src/sync/mpsc.rs b/library/std/src/sync/mpsc.rs index f942937c14d11..f99eeb2c6333e 100644 --- a/library/std/src/sync/mpsc.rs +++ b/library/std/src/sync/mpsc.rs @@ -1148,6 +1148,7 @@ impl From> for TrySendError { /// /// This conversion always returns a `TrySendError::Disconnected` containing the data in the `SendError`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: SendError) -> TrySendError { match err { @@ -1198,6 +1199,7 @@ impl From for TryRecvError { /// /// This conversion always returns `TryRecvError::Disconnected`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: RecvError) -> TryRecvError { match err { @@ -1233,6 +1235,7 @@ impl From for RecvTimeoutError { /// /// This conversion always returns `RecvTimeoutError::Disconnected`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: RecvError) -> RecvTimeoutError { match err { diff --git a/library/std/src/sync/poison.rs b/library/std/src/sync/poison.rs index efe00f0c359c9..0e3a62d99a64d 100644 --- a/library/std/src/sync/poison.rs +++ b/library/std/src/sync/poison.rs @@ -340,7 +340,7 @@ impl PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for TryLockError { - /// Wrap `PoisonError` in `Poisoned` variant. + /// Wrap `PoisonError` in the `Poisoned` variant. fn from(err: PoisonError) -> TryLockError { TryLockError::Poisoned(err) } From e133fc72a9c5b5237be2cf0b8ac04508b03b4ad7 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 14:00:48 -0500 Subject: [PATCH 05/21] Revert "Add `from` docs for tools" This reverts commit df90691f7f7ec2ff23b1c44edad97a8e12265377. --- .../src/attrs/mixed_attributes_style.rs | 3 ++- src/tools/miri/src/concurrency/thread.rs | 2 +- .../miri/src/concurrency/vector_clock.rs | 2 +- src/tools/miri/src/lib.rs | 2 +- src/tools/miri/src/shims/io_error.rs | 6 ++--- .../rust-analyzer/crates/base-db/src/input.rs | 10 -------- .../rust-analyzer/crates/cfg/src/cfg_expr.rs | 1 - .../rust-analyzer/crates/hir-def/src/attr.rs | 1 - .../rust-analyzer/crates/hir-def/src/hir.rs | 1 - .../crates/hir-def/src/hir/type_ref.rs | 2 -- .../crates/hir-def/src/item_scope.rs | 3 --- .../crates/hir-def/src/item_tree.rs | 23 ------------------- .../rust-analyzer/crates/hir-def/src/lib.rs | 17 -------------- .../rust-analyzer/crates/hir-def/src/path.rs | 1 - .../crates/hir-ty/src/consteval.rs | 9 -------- .../crates/hir-ty/src/display.rs | 1 - .../rust-analyzer/crates/hir-ty/src/layout.rs | 1 - .../crates/hir-ty/src/mapping.rs | 8 ------- .../crates/hir-ty/src/method_resolution.rs | 2 -- .../crates/hir-ty/src/mir/eval.rs | 1 - .../crates/ide/src/inlay_hints.rs | 2 -- .../rust-analyzer/crates/ide/src/markup.rs | 2 -- .../rust-analyzer/crates/ide/src/moniker.rs | 1 - 23 files changed, 8 insertions(+), 93 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs index 2fbb6d36d5fcc..acef07ee5bf96 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -15,7 +15,8 @@ enum SimpleAttrKind { } impl From<&AttrKind> for SimpleAttrKind { - /// Convert an `AttrKind` to a `SimpleAttrKind`, if it's a `DocComment` then `Doc` is returned with no conversion. + /// Convert an `AttrKind` to a `SimpleAttrKind`, + /// if it's a `DocComment` then `Doc` is returned with no conversion. /// /// ## Cost /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heep allocation diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index ce739c2d0dcd5..193209c5a7c0c 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -80,7 +80,7 @@ impl Idx for ThreadId { } impl From for u64 { - /// Return inner `u32` converted to `u64` + /// Return inner `u32` converted to `u64`. fn from(t: ThreadId) -> Self { t.0.into() } diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index bf6132653e01c..8b1dbe4b51df4 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -34,7 +34,7 @@ impl Idx for VectorIdx { } impl From for VectorIdx { - /// Create new `VectorIdx` with `u32` as inner + /// Create new `VectorIdx` with `u32` as inner. #[inline] fn from(id: u32) -> Self { Self(id) diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index 471e3f31808a5..03f76cfa6524c 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -73,7 +73,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_symbol_mangling; extern crate rustc_target; -// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are +// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are // shipped only as rmeta files. #[allow(unused_extern_crates)] extern crate rustc_driver; diff --git a/src/tools/miri/src/shims/io_error.rs b/src/tools/miri/src/shims/io_error.rs index c03c6fa5c95d8..635669fc68f2c 100644 --- a/src/tools/miri/src/shims/io_error.rs +++ b/src/tools/miri/src/shims/io_error.rs @@ -14,21 +14,21 @@ pub enum IoError { pub use self::IoError::*; impl From for IoError { - /// Wrap `io::Error` in `HostError` + /// Wrap `io::Error` in `HostError`. fn from(value: io::Error) -> Self { IoError::HostError(value) } } impl From for IoError { - /// Convert a `io::ErrorKind` to a `io::Error` then wrap in `HostError` + /// Convert a `io::ErrorKind` to a `io::Error` then wrap in `HostError`. fn from(value: io::ErrorKind) -> Self { IoError::HostError(value.into()) } } impl From for IoError { - /// Wrap `Scalar` in `Raw` + /// Wrap `Scalar` in `Raw`. fn from(value: Scalar) -> Self { IoError::Raw(value) } diff --git a/src/tools/rust-analyzer/crates/base-db/src/input.rs b/src/tools/rust-analyzer/crates/base-db/src/input.rs index ba1428f1748cb..bd08387b58219 100644 --- a/src/tools/rust-analyzer/crates/base-db/src/input.rs +++ b/src/tools/rust-analyzer/crates/base-db/src/input.rs @@ -173,8 +173,6 @@ pub enum LangCrateOrigin { } impl From<&str> for LangCrateOrigin { - /// Match a string slice for "alloc", "core", "proc-macro", "proc_macro", "std", "test", - /// mapping them to variants of the same name; if none match then it's `Other` fn from(s: &str) -> Self { match s { "alloc" => LangCrateOrigin::Alloc, @@ -219,10 +217,6 @@ impl CrateDisplayName { } impl From for CrateDisplayName { - /// Creates a `CrateDisplayName` from `crate_name` and `crate_name.0`(inner) - /// - /// ## Cost - /// This clones `CrateName` fn from(crate_name: CrateName) -> CrateDisplayName { let canonical_name = crate_name.0.clone(); CrateDisplayName { crate_name, canonical_name } @@ -645,10 +639,6 @@ impl Env { } impl From for Vec<(String, String)> { - /// Iterates the hash map entries collects them in to a `Vec` then sorts it. - /// - /// ## Cost - /// This is expensive as it `collect`s and `sort`s env fn from(env: Env) -> Vec<(String, String)> { let mut entries: Vec<_> = env.entries.into_iter().collect(); entries.sort(); diff --git a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs index a44f6ab2547ba..0ec082dfa7fcb 100644 --- a/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs +++ b/src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs @@ -57,7 +57,6 @@ pub enum CfgExpr { } impl From for CfgExpr { - /// Wrap `CfgAtom` in `CfgExpr::Atom` fn from(atom: CfgAtom) -> Self { CfgExpr::Atom(atom) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs index 5ca03c431939b..710bffcefe900 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/attr.rs @@ -245,7 +245,6 @@ pub enum DocExpr { } impl From for DocExpr { - /// Creates `Atom` with `DocAtom` fn from(atom: DocAtom) -> Self { DocExpr::Atom(atom) } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/hir.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir.rs index 3373b920eb013..494644d8eff9d 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/hir.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/hir.rs @@ -146,7 +146,6 @@ impl Literal { } impl From for Literal { - /// Create a `Literal` by matching `LiteralKind` fn from(ast_lit_kind: ast::LiteralKind) -> Self { use ast::LiteralKind; match ast_lit_kind { diff --git a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs index 45da78c3082a8..6de4026dff75b 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs @@ -637,8 +637,6 @@ impl LiteralConstRef { } impl From for LiteralConstRef { - /// Make a `LiteralConstRef` from `Literal` - /// - Note: `Char`, `Bool`, `Int`, `Uint` match, other types are not const and return a `Unknown` fn from(literal: Literal) -> Self { match literal { Literal::Char(c) => Self::Char(c), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs index 63a6fdc18f2e6..0ca1eb9bcfe37 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs @@ -37,7 +37,6 @@ pub enum ImportOrExternCrate { } impl From for ImportOrExternCrate { - /// Matches a `ImportOrGlob` to it's corresponding `ImportOrExternCrate` variant, of the same name fn from(value: ImportOrGlob) -> Self { match value { ImportOrGlob::Glob(it) => ImportOrExternCrate::Glob(it), @@ -102,7 +101,6 @@ pub enum ImportOrDef { } impl From for ImportOrDef { - /// Matches a `ImportOrExternCrate` to it's corresponding `ImportOrDef` variant, of the same name fn from(value: ImportOrExternCrate) -> Self { match value { ImportOrExternCrate::Import(it) => ImportOrDef::Import(it), @@ -113,7 +111,6 @@ impl From for ImportOrDef { } impl From for ImportOrDef { - /// Matches a `ImportOrGlob` to it's corresponding `ImportOrDef` variant, of the same name fn from(value: ImportOrGlob) -> Self { match value { ImportOrGlob::Import(it) => ImportOrDef::Import(it), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs index 741a228ff43e1..382afbcb1dd4f 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs @@ -516,11 +516,6 @@ macro_rules! from_attrs { ( $( $var:ident($t:ty) ),+ $(,)? ) => { $( impl From<$t> for AttrOwner { - #[doc = concat!( - "Create a `", stringify!($var), "` from a `", stringify!($t), "`", - "\n\n## Cost", - "This is free as it puts `", stringify!($t), "` into `", stringify!($var), "`" - )] fn from(t: $t) -> AttrOwner { AttrOwner::$var(t) } @@ -727,10 +722,6 @@ macro_rules! mod_items { } impl From for ModItem { - /// Create a `ModItem` from a `GenericModItem` variant of the same name - /// - /// ## Cost - /// Just a `match` fn from(id: GenericModItem) -> ModItem { match id { $( @@ -744,10 +735,6 @@ macro_rules! mod_items { } impl From for AttrOwner { - /// Create a `AttrOwner::ModItem` with `GenericModItem` as inner - /// - /// ## Cost - /// The cost is that of the `t.into()` call fn from(t: GenericModItem) -> AttrOwner { AttrOwner::ModItem(t.into()) } @@ -755,7 +742,6 @@ macro_rules! mod_items { $( impl From> for ModItem { - #[doc = concat!("Create a `ModItem<", stringify!($typ), ">` from a `FileItemTreeId<", stringify!($typ), ">` variant of the same name")] fn from(id: FileItemTreeId<$typ>) -> ModItem { ModItem::$typ(id) } @@ -763,7 +749,6 @@ macro_rules! mod_items { $( #[cfg_attr(ignore_fragment, $generic_params)] impl From> for GenericModItem { - #[doc = concat!("Create a `GenericModItem` from a `FileItemTreeId<", stringify!($typ), ">` variant of the same name")] fn from(id: FileItemTreeId<$typ>) -> GenericModItem { GenericModItem::$typ(id) } @@ -1263,10 +1248,6 @@ macro_rules! impl_froms { ($e:ident { $($v:ident ($t:ty)),* $(,)? }) => { $( impl From<$t> for $e { - #[doc = concat!( - "Create a `", stringify!($e), "` with `", stringify!($t), "` as the inner", - "\n\n## Cost\n", stringify!($t), " gets move into ", stringify!($v) - )] fn from(it: $t) -> $e { $e::$v(it) } @@ -1315,10 +1296,6 @@ impl_froms!(AssocItem { }); impl From for ModItem { - /// Convert the `AssocItem`s inner to a `ModItem` - /// - /// ## Cost - /// The cost is that of the inner items `into` call fn from(item: AssocItem) -> Self { match item { AssocItem::Function(it) => it.into(), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs index ac3877adf17e7..9c947df35e990 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs @@ -410,21 +410,18 @@ impl PartialEq for ModuleId { } impl From for ModuleId { - /// Make a `ModuleId` with a krate, no block, and local_id of `ROOT` fn from(CrateRootModuleId { krate }: CrateRootModuleId) -> Self { ModuleId { krate, block: None, local_id: DefMap::ROOT } } } impl From for ModuleDefId { - /// Make a `ModuleId` with `CrateRootModuleId` as inner fn from(value: CrateRootModuleId) -> Self { ModuleDefId::ModuleId(value.into()) } } impl From for CrateRootModuleId { - /// Create a `CrateRootModuleId` with `CrateId` as inner fn from(krate: CrateId) -> Self { CrateRootModuleId { krate } } @@ -567,7 +564,6 @@ impl TypeParamId { } impl From for TypeOrConstParamId { - /// Get the inner `TypeOrConstParamId` of `TypeParamId` fn from(it: TypeParamId) -> Self { it.0 } @@ -594,7 +590,6 @@ impl ConstParamId { } impl From for TypeOrConstParamId { - /// Get the inner `TypeOrConstParamId` of `ConstParamId` fn from(it: ConstParamId) -> Self { it.0 } @@ -734,7 +729,6 @@ impl_from!( // Every `DefWithBodyId` is a type owner, since bodies can contain type (e.g. `{ let it: Type = _; }`) impl From for TypeOwnerId { - /// Convert `DefWithBodyId` inner into `TypeOwnerId` fn from(value: DefWithBodyId) -> Self { match value { DefWithBodyId::FunctionId(it) => it.into(), @@ -747,7 +741,6 @@ impl From for TypeOwnerId { } impl From for TypeOwnerId { - /// Convert `GenericDefId` inner into `TypeOwnerId` fn from(value: GenericDefId) -> Self { match value { GenericDefId::FunctionId(it) => it.into(), @@ -903,7 +896,6 @@ pub enum DefWithBodyId { impl_from!(FunctionId, ConstId, StaticId, InTypeConstId for DefWithBodyId); impl From for DefWithBodyId { - /// Make a `VariantId` with `EnumVariantId`, as inner fn from(id: EnumVariantId) -> Self { DefWithBodyId::VariantId(id) } @@ -1016,7 +1008,6 @@ impl GenericDefId { } impl From for GenericDefId { - /// Convert `AssocItemId` inner to `GenericDefId` fn from(item: AssocItemId) -> Self { match item { AssocItemId::FunctionId(f) => f.into(), @@ -1037,7 +1028,6 @@ impl InternValueTrivial for CallableDefId {} impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId); impl From for ModuleDefId { - /// Match `CallableDefId` to `ModuleDefId` fn from(def: CallableDefId) -> ModuleDefId { match def { CallableDefId::FunctionId(f) => ModuleDefId::FunctionId(f), @@ -1099,10 +1089,6 @@ impl_from!( impl TryFrom for AttrDefId { type Error = (); - /// Convert the inner of `ModuleDefId` into `Ok(AttrDefId)` - /// - /// # Errors - /// `BuiltinType` results in `Err` fn try_from(value: ModuleDefId) -> Result { match value { ModuleDefId::ModuleId(it) => Ok(it.into()), @@ -1121,7 +1107,6 @@ impl TryFrom for AttrDefId { } impl From for AttrDefId { - /// Match `ItemContainerId` to the `AttrDefId` variant of the same name fn from(acid: ItemContainerId) -> Self { match acid { ItemContainerId::ModuleId(mid) => AttrDefId::ModuleId(mid), @@ -1132,7 +1117,6 @@ impl From for AttrDefId { } } impl From for AttrDefId { - /// Match `AssocItemId` to the `AttrDefId` variant of the same name fn from(assoc: AssocItemId) -> Self { match assoc { AssocItemId::FunctionId(it) => AttrDefId::FunctionId(it), @@ -1142,7 +1126,6 @@ impl From for AttrDefId { } } impl From for AttrDefId { - /// Convert the inner of `VariantId` into `AttrDefId` fn from(vid: VariantId) -> Self { match vid { VariantId::EnumVariantId(id) => id.into(), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/path.rs b/src/tools/rust-analyzer/crates/hir-def/src/path.rs index 0147026c2a44a..713e7389736a0 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/path.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/path.rs @@ -332,7 +332,6 @@ impl GenericArgs { } impl From for Path { - /// Make a `BarePath` with a new `Interned` containing a `ModPath` using the `Name` fn from(name: Name) -> Path { Path::BarePath(Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name)))) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs index d52cc200cbb91..fb604569f439d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs @@ -77,11 +77,6 @@ impl ConstEvalError { } impl From for ConstEvalError { - /// Convert `MirLowerError` to `ConstEvalError` by getting inner of `MirLowerError::ConstEvalError` - /// or wrapping it in the `MirLowerError` variant - /// - /// ## Cost - /// Just a `match` fn from(value: MirLowerError) -> Self { match value { MirLowerError::ConstEvalError(_, e) => *e, @@ -91,10 +86,6 @@ impl From for ConstEvalError { } impl From for ConstEvalError { - /// Convert a `MirEvalError` by wrapping it in the `ConstEvalError::MirEvalError` variant - /// - /// ## Cost - /// Free fn from(value: MirEvalError) -> Self { ConstEvalError::MirEvalError(value) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index 81b8dc5aa095c..95ce36390d33d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -463,7 +463,6 @@ pub enum HirDisplayError { FmtError, } impl From for HirDisplayError { - /// Ignore the `fmt::Error` and return `Self::FmtError` fn from(_: fmt::Error) -> Self { Self::FmtError } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs index 641c2c2a2d716..bbd419d9659bf 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs @@ -107,7 +107,6 @@ impl fmt::Display for LayoutError { } impl From> for LayoutError { - /// Make a `BadCalc` error from a `LayoutCalculatorError` without payload fn from(err: LayoutCalculatorError) -> Self { LayoutError::BadCalc(err.without_payload()) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs index 7e5e2cc83b6f6..2f38e8fa14c0b 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs @@ -68,56 +68,48 @@ impl ToChalk for TypeAliasAsValue { } impl From for crate::db::InternedCallableDefId { - /// Makes a `InternedCallableDefId` from the `FnDefId`s inner intern id fn from(fn_def_id: FnDefId) -> Self { InternKey::from_intern_id(fn_def_id.0) } } impl From for FnDefId { - /// Makes a `FnDefId` with the `InternedCallableDefId`s intern id fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self { chalk_ir::FnDefId(callable_def_id.as_intern_id()) } } impl From for crate::db::InternedOpaqueTyId { - /// Makes a `InternedOpaqueTyId` from the `OpaqueTyId`s inner intern id fn from(id: OpaqueTyId) -> Self { InternKey::from_intern_id(id.0) } } impl From for OpaqueTyId { - /// Makes a `OpaqueTyId` with the `InternedOpaqueTyId`s intern id fn from(id: crate::db::InternedOpaqueTyId) -> Self { chalk_ir::OpaqueTyId(id.as_intern_id()) } } impl From> for crate::db::InternedClosureId { - /// Makes a `InternedClosureId` from the `ClosureId`s inner intern id fn from(id: chalk_ir::ClosureId) -> Self { Self::from_intern_id(id.0) } } impl From for chalk_ir::ClosureId { - /// Makes a `ClosureId` with the `InternedClosureId`s intern id fn from(id: crate::db::InternedClosureId) -> Self { chalk_ir::ClosureId(id.as_intern_id()) } } impl From> for crate::db::InternedCoroutineId { - /// Makes a `InternedCoroutineId` from the `CoroutineId`s inner intern id fn from(id: chalk_ir::CoroutineId) -> Self { Self::from_intern_id(id.0) } } impl From for chalk_ir::CoroutineId { - /// Makes a `CoroutineId` with the `InternedCoroutineId`s intern id fn from(id: crate::db::InternedCoroutineId) -> Self { chalk_ir::CoroutineId(id.as_intern_id()) } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs index a802d1ad195a0..c722800527190 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs @@ -500,7 +500,6 @@ pub enum VisibleFromModule { } impl From> for VisibleFromModule { - /// If some make a `Filter` with `ModuleId` fn from(module: Option) -> Self { match module { Some(module) => Self::Filter(module), @@ -510,7 +509,6 @@ impl From> for VisibleFromModule { } impl From> for VisibleFromModule { - /// If some make an `IncludeBlock` with `BlockId` fn from(block: Option) -> Self { match block { Some(block) => Self::IncludeBlock(block), diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs index 644e112b7786a..74a34e2981710 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs @@ -262,7 +262,6 @@ enum IntervalOrOwned { } impl From for IntervalOrOwned { - /// Makes a `Borrowed` with an `Interval` fn from(it: Interval) -> IntervalOrOwned { IntervalOrOwned::Borrowed(it) } diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs index 53f2e6d5ed8ca..6babdff52a2be 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs @@ -571,7 +571,6 @@ impl InlayHintLabel { } impl From for InlayHintLabel { - /// Create a new smallvec with the string as the text, with no linked_location or tooltip fn from(s: String) -> Self { Self { parts: smallvec![InlayHintLabelPart { text: s, linked_location: None, tooltip: None }], @@ -580,7 +579,6 @@ impl From for InlayHintLabel { } impl From<&str> for InlayHintLabel { - /// Create a new smallvec with the string slice as the text, with no linked_location or tooltip fn from(s: &str) -> Self { Self { parts: smallvec![InlayHintLabelPart { diff --git a/src/tools/rust-analyzer/crates/ide/src/markup.rs b/src/tools/rust-analyzer/crates/ide/src/markup.rs index 0405a52927095..750d12542605c 100644 --- a/src/tools/rust-analyzer/crates/ide/src/markup.rs +++ b/src/tools/rust-analyzer/crates/ide/src/markup.rs @@ -11,14 +11,12 @@ pub struct Markup { } impl From for String { - /// Returns the inner text fn from(markup: Markup) -> Self { markup.text } } impl From for Markup { - /// Make a `Markup` with inner text of `String` fn from(text: String) -> Self { Markup { text } } diff --git a/src/tools/rust-analyzer/crates/ide/src/moniker.rs b/src/tools/rust-analyzer/crates/ide/src/moniker.rs index 21e54e9d45a17..5754b4fa82f43 100644 --- a/src/tools/rust-analyzer/crates/ide/src/moniker.rs +++ b/src/tools/rust-analyzer/crates/ide/src/moniker.rs @@ -55,7 +55,6 @@ pub enum SymbolInformationKind { } impl From for MonikerDescriptorKind { - /// Matches a `SymbolInformationKind` to it's corresponding `MonikerDescriptorKind` fn from(value: SymbolInformationKind) -> Self { match value { SymbolInformationKind::AssociatedType => Self::Type, From 4d83e90a6fb03a89584301a7e39328427604d584 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 14:48:23 -0500 Subject: [PATCH 06/21] Update try-block-bad-type.stderr --- tests/ui/try-block/try-block-bad-type.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/try-block/try-block-bad-type.stderr b/tests/ui/try-block/try-block-bad-type.stderr index 818ab499306f0..9a7b2434dc778 100644 --- a/tests/ui/try-block/try-block-bad-type.stderr +++ b/tests/ui/try-block/try-block-bad-type.stderr @@ -7,9 +7,9 @@ LL | Err("")?; | this can't be annotated with `?` because it has type `Result<_, &str>` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait - = help: the trait `From<&str>` is not implemented for `TryFromSliceError` - but trait `From` is implemented for it - = help: for that trait implementation, expected `Infallible`, found `&str` + = help: the following other types implement trait `From`: + `TryFromSliceError` implements `From` + `TryFromSliceError` implements `From` error[E0271]: type mismatch resolving ` as Try>::Output == &str` --> $DIR/try-block-bad-type.rs:12:9 From 44e408032aefce8b626c01903a353359f1852c42 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:01:53 -0500 Subject: [PATCH 07/21] Update exclusive.rs --- library/core/src/sync/exclusive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index 2ad87e7e3e0d9..14b57ea89dc2c 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -164,7 +164,7 @@ impl Exclusive { #[unstable(feature = "exclusive_wrapper", issue = "98407")] impl From for Exclusive { - /// Creates a new `Exclusive` containing [`T`], wrapping the value in an `Exclusive` + /// Creates a new `Exclusive` wrapping `T`. #[inline] fn from(t: T) -> Self { Self::new(t) From 42fd42517a8d3b6eb86a2d8297cdb64b893abf4b Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:51:20 -0500 Subject: [PATCH 08/21] Apply suggestions from code review --- library/alloc/src/bstr.rs | 4 ++-- library/core/src/array/mod.rs | 14 +------------- library/core/src/num/error.rs | 4 ++-- library/core/src/num/nonzero.rs | 2 +- library/core/src/ptr/alignment.rs | 4 ++-- library/proc_macro/src/bridge/rpc.rs | 2 +- library/std/src/sys/process/windows.rs | 2 +- .../src/attrs/mixed_attributes_style.rs | 2 +- tests/ui/try-block/try-block-bad-type.stderr | 6 +++--- 9 files changed, 14 insertions(+), 26 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 4594df2fe1d22..952937ae81876 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -624,7 +624,7 @@ impl Clone for Box { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { - /// Create a `Borrowed` cow from a `ByteStr`. + /// Wrap `ByteStr` in `Cow::Borrowed`. #[inline] fn from(s: &'a ByteStr) -> Self { Cow::Borrowed(s) @@ -633,7 +633,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box { - /// Create a `Box<[u8]>` from `Box`s raw. + /// Move the bytes from `Box` to `Box<[u8]>`, this does not allocate new memory. #[inline] fn from(s: Box<[u8]>) -> Box { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index a27975b385dcf..cb8fef1356d98 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -178,24 +178,12 @@ impl Error for TryFromSliceError { #[stable(feature = "try_from_slice_error", since = "1.36.0")] impl From for TryFromSliceError { - /// Match `Infallible` into `TryFromSliceError`. + /// Convert `Infallible` into an error that can happen. fn from(x: Infallible) -> TryFromSliceError { match x {} } } -#[unstable(feature = "never_type", issue = "35121")] -impl From for TryFromSliceError { - /// Match `!` into `TryFromSliceError`. - #[inline] - fn from(never: !) -> TryFromSliceError { - // Match rather than coerce to make sure that code like - // `From for TryFromSliceError` above will keep working - // when `Infallible` becomes an alias to `!`. - match never {} - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for [T; N] { #[inline] diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 43f8fc3b4149a..faa659aa8fc47 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -27,7 +27,7 @@ impl Error for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl From for TryFromIntError { - /// Match `Infallible` into `TryFromIntError`. + /// Convert `Infallible` into an error that can happen. #[inline] fn from(x: Infallible) -> TryFromIntError { match x {} @@ -36,7 +36,7 @@ impl From for TryFromIntError { #[unstable(feature = "never_type", issue = "35121")] impl From for TryFromIntError { - /// Match `!` into `TryFromIntError`. + /// Convert `!` into an error that can happen. #[inline] fn from(never: !) -> TryFromIntError { // Match rather than coerce to make sure that code like diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 7843c7221033e..25b37a468e28e 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -290,7 +290,7 @@ impl From> for T where T: ZeroablePrimitive, { - /// Get the inner num of `NonZero`. + /// Returns the contained value as a primitive type. #[inline] fn from(nonzero: NonZero) -> Self { // Call `get` method to keep range information. diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 952e3a65b5ebb..97904063cebc3 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -189,7 +189,7 @@ impl TryFrom for Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for NonZero { - /// `Alignment` is non zero so the inner enum value is returned + /// `Alignment` is non zero so the inner value is returned #[inline] fn from(align: Alignment) -> NonZero { align.as_nonzero() @@ -198,7 +198,7 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { - /// `Alignment` is unsined so the inner enum value is returned + /// `Alignment` is unsined so the inner value is returned #[inline] fn from(align: Alignment) -> usize { align.as_usize() diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index bec79c5c309d0..cd8c206846bac 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -269,7 +269,7 @@ impl From for Box { /// Return the inner wrapped in `Box`. /// /// ## Cost - /// Allocates a new `Box` on the heep + /// Allocates a new `Box` on the heap fn from(val: PanicMessage) -> Self { match val { PanicMessage::StaticStr(s) => Box::new(s), diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index c4079b49366ed..be0b48d5cc50d 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -141,7 +141,7 @@ impl From<&OsStr> for EnvKey { /// Uses `EnvKey::From` to convert the `&OsStr`. /// /// ## Cost - /// Converts `&OsStr` to `OsString` which does a heep allocation + /// Converts `&OsStr` to `OsString` which does a heap allocation fn from(k: &OsStr) -> Self { Self::from(k.to_os_string()) } diff --git a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs index acef07ee5bf96..f2b23dfaaa42d 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -19,7 +19,7 @@ impl From<&AttrKind> for SimpleAttrKind { /// if it's a `DocComment` then `Doc` is returned with no conversion. /// /// ## Cost - /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heep allocation + /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heap allocation fn from(value: &AttrKind) -> Self { match value { AttrKind::Normal(attr) => { diff --git a/tests/ui/try-block/try-block-bad-type.stderr b/tests/ui/try-block/try-block-bad-type.stderr index 9a7b2434dc778..818ab499306f0 100644 --- a/tests/ui/try-block/try-block-bad-type.stderr +++ b/tests/ui/try-block/try-block-bad-type.stderr @@ -7,9 +7,9 @@ LL | Err("")?; | this can't be annotated with `?` because it has type `Result<_, &str>` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait - = help: the following other types implement trait `From`: - `TryFromSliceError` implements `From` - `TryFromSliceError` implements `From` + = help: the trait `From<&str>` is not implemented for `TryFromSliceError` + but trait `From` is implemented for it + = help: for that trait implementation, expected `Infallible`, found `&str` error[E0271]: type mismatch resolving ` as Try>::Output == &str` --> $DIR/try-block-bad-type.rs:12:9 From 5cddbcb8eb48139288fed7fa0a35d7f8740c1dd2 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:42:29 -0500 Subject: [PATCH 09/21] Update library/core/src/ptr/alignment.rs --- library/core/src/ptr/alignment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 97904063cebc3..4d3aaecefbcf4 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -198,7 +198,7 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { - /// `Alignment` is unsined so the inner value is returned + /// `Alignment` is unsigned so the inner value is returned #[inline] fn from(align: Alignment) -> usize { align.as_usize() From b20bd28d2fff991a7262925e1960ddf70305f9c5 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Mon, 24 Feb 2025 12:56:50 -0500 Subject: [PATCH 10/21] Apply suggestions from code review Co-authored-by: Oli Scherer --- library/proc_macro/src/bridge/closure.rs | 2 +- library/proc_macro/src/bridge/rpc.rs | 4 ++-- library/proc_macro/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/bridge/closure.rs index fb6766d0830ca..4d0a251766aac 100644 --- a/library/proc_macro/src/bridge/closure.rs +++ b/library/proc_macro/src/bridge/closure.rs @@ -17,7 +17,7 @@ pub(super) struct Closure<'a, A, R> { struct Env; impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { - /// Create a `Closure` from a function + /// Create a `Closure` from an `FnMut` eg.(function, `||` closure) fn from(f: &'a mut F) -> Self { unsafe extern "C" fn call R>(env: *mut Env, arg: A) -> R { unsafe { (*(env as *mut _ as *mut F))(arg) } diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index cd8c206846bac..ef08941542b61 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -253,7 +253,7 @@ pub enum PanicMessage { } impl From> for PanicMessage { - /// downcast the payload and wrap it in `StaticStr` or `String`. + /// Extract `String` or `&'static str` payloads if available or default to `Unknown` fn from(payload: Box) -> Self { if let Some(s) = payload.downcast_ref::<&'static str>() { return PanicMessage::StaticStr(s); @@ -266,7 +266,7 @@ impl From> for PanicMessage { } impl From for Box { - /// Return the inner wrapped in `Box`. + /// Return the inner message wrapped in `Box`. /// /// ## Cost /// Allocates a new `Box` on the heap diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index c37a38a0a7198..de27127565962 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -238,7 +238,7 @@ fn tree_to_bridge_tree( /// Creates a token stream containing a single token tree. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenStream { - /// Convert the tree to a bridge tree then a `TokenStream` + /// Convert the tree to a `TokenStream` fn from(tree: TokenTree) -> TokenStream { TokenStream(Some(bridge::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) } From 4cbfc8453a99eb759d7f13d64fdb734963631ff0 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:01:31 -0500 Subject: [PATCH 11/21] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra González --- library/proc_macro/src/bridge/buffer.rs | 3 ++- .../clippy/clippy_lints/src/attrs/mixed_attributes_style.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 8c28d4071c21c..7b217c3e5919e 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -127,7 +127,8 @@ impl Drop for Buffer { } impl From> for Buffer { - /// Move data, len, and capacity from `Vec`, then create custom reserve and drop fns. + /// Create a `Buffer` without allocation.\ + /// By moving data, len, and capacity from `Vec`, then create custom reserve and drop fns. fn from(v: Vec) -> Self { let mut v = ManuallyDrop::new(v); let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity()); diff --git a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs index f2b23dfaaa42d..1347e452dce5d 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -19,7 +19,7 @@ impl From<&AttrKind> for SimpleAttrKind { /// if it's a `DocComment` then `Doc` is returned with no conversion. /// /// ## Cost - /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heap allocation + /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` there is heap allocation fn from(value: &AttrKind) -> Self { match value { AttrKind::Normal(attr) => { From 199448bc91df43feb5f16b10d447af12d9e746b3 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Sat, 8 Mar 2025 19:01:02 -0500 Subject: [PATCH 12/21] Apply suggestions from code review Co-authored-by: Jubilee --- library/alloc/src/bstr.rs | 6 +++--- library/core/src/ptr/alignment.rs | 4 ++-- library/core/src/ptr/non_null.rs | 2 +- .../portable-simd/crates/core_simd/src/masks/full_masks.rs | 2 +- library/portable-simd/crates/core_simd/src/vector.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 952937ae81876..47d786e593fae 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -643,7 +643,7 @@ impl From> for Box { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box<[u8]> { - /// Create a `Box` from `Box<[u8]>`s raw. + /// Convert the inner bytes of `Box<[u8]>` to `ByteStr`. #[inline] fn from(s: Box) -> Box<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -707,10 +707,10 @@ impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>); impl<'a> TryFrom<&'a ByteStr> for String { type Error = core::str::Utf8Error; - /// Convert `ByteStr`s bytes to a utf-8 `String`. + /// Convert `ByteStr`s bytes to a UTF-8 `String`. /// /// # Errors - /// If `ByteStr` is not valid utf-8 + /// If `ByteStr` is not valid UTF-8 #[inline] fn try_from(s: &'a ByteStr) -> Result { Ok(core::str::from_utf8(&s.0)?.into()) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 4d3aaecefbcf4..5bd2b59ddabcf 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -189,7 +189,7 @@ impl TryFrom for Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for NonZero { - /// `Alignment` is non zero so the inner value is returned + /// `Alignment` is non-zero so the inner value is returned #[inline] fn from(align: Alignment) -> NonZero { align.as_nonzero() @@ -198,7 +198,7 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { - /// `Alignment` is unsigned so the inner value is returned + /// Return the inner value of `Alignment` #[inline] fn from(align: Alignment) -> usize { align.as_usize() diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 3ebcf64402dcb..fd093e35049d5 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1648,7 +1648,7 @@ impl hash::Hash for NonNull { #[unstable(feature = "ptr_internals", issue = "none")] impl From> for NonNull { - /// Return `Unique` casted to a `NonNull`. + /// Return `Unique` cast to a `NonNull`. #[inline] fn from(unique: Unique) -> Self { unique.as_non_null_ptr() diff --git a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs index 7c185e865f429..232d002394819 100644 --- a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs @@ -238,7 +238,7 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { - /// Return the inner of the `Mask` + /// Return the `MaskElement` of the `Mask` #[inline] fn from(value: Mask) -> Self { value.0 diff --git a/library/portable-simd/crates/core_simd/src/vector.rs b/library/portable-simd/crates/core_simd/src/vector.rs index 18c0b43d94e0d..49d57c977bcea 100644 --- a/library/portable-simd/crates/core_simd/src/vector.rs +++ b/library/portable-simd/crates/core_simd/src/vector.rs @@ -1047,7 +1047,7 @@ where LaneCount: SupportedLaneCount, T: SimdElement, { - /// Use `from_array` to load the array into a new `Simd` + /// Load the array into a new `Simd` #[inline] fn from(array: [T; N]) -> Self { Self::from_array(array) From 894f27056011c931b79a7e3dc62d9b2d196aa8e0 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Tue, 11 Mar 2025 21:54:35 -0400 Subject: [PATCH 13/21] Update library/portable-simd/crates/core_simd/src/masks.rs --- library/portable-simd/crates/core_simd/src/masks.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/portable-simd/crates/core_simd/src/masks.rs b/library/portable-simd/crates/core_simd/src/masks.rs index 910240df50dda..bae7d77a4e815 100644 --- a/library/portable-simd/crates/core_simd/src/masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks.rs @@ -391,9 +391,6 @@ where LaneCount: SupportedLaneCount, { /// Converts a SIMD mask to an array of bools. - /// - /// ## Cost - /// Copies the bytes of the array #[inline] fn from(vector: Mask) -> Self { vector.to_array() From 124bcb2f46ae887e781ac00fae86beb7cac20529 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Mon, 17 Mar 2025 18:59:34 -0400 Subject: [PATCH 14/21] Apply suggestions from code review Co-authored-by: Jubilee --- library/alloc/src/bstr.rs | 20 ++++--------------- library/alloc/src/collections/mod.rs | 1 - library/core/src/num/error.rs | 2 -- .../crates/core_simd/src/masks/full_masks.rs | 1 - library/proc_macro/src/bridge/rpc.rs | 5 +---- library/proc_macro/src/lib.rs | 4 ---- library/std/src/os/xous/ffi/definitions.rs | 2 +- library/std/src/sys/process/windows.rs | 2 +- 8 files changed, 7 insertions(+), 30 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 47d786e593fae..7646ca945a98b 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -180,10 +180,7 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a, const N: usize> From<&'a [u8; N]> for ByteString { -// /// Make a `ByteString` from a byte array ref. -// /// -// /// ## Cost -// /// Allocates a new `Vec` +// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: &'a [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -192,10 +189,7 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl From<[u8; N]> for ByteString { -// /// Make a `ByteString` from a byte array. -// /// -// /// ## Cost -// /// Allocates a new `Vec` +// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -204,10 +198,7 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a [u8]> for ByteString { -// /// Make a `ByteString` from a byte slice. -// /// -// /// ## Cost -// /// Allocates a new `Vec` +// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: &'a [u8]) -> Self { // ByteString(s.to_vec()) @@ -236,10 +227,7 @@ impl From for Vec { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a str> for ByteString { -// /// Make a `ByteString` from a string slices bytes. -// /// -// /// ## Cost -// /// Allocates a new `Vec` +// /// Allocate a new `ByteString` with a copy of the bytes in the slice. // #[inline] // fn from(s: &'a str) -> Self { // ByteString(s.as_bytes().to_vec()) diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index ac93b13d3bf5a..fac4d1a65abcb 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -130,7 +130,6 @@ pub use realalloc::collections::TryReserveErrorKind; )] #[cfg(not(test))] impl From for TryReserveError { - /// Wrap kind in `TryReserveError`. #[inline] fn from(kind: TryReserveErrorKind) -> Self { Self { kind } diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index faa659aa8fc47..41b9b0d797286 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -27,7 +27,6 @@ impl Error for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl From for TryFromIntError { - /// Convert `Infallible` into an error that can happen. #[inline] fn from(x: Infallible) -> TryFromIntError { match x {} @@ -36,7 +35,6 @@ impl From for TryFromIntError { #[unstable(feature = "never_type", issue = "35121")] impl From for TryFromIntError { - /// Convert `!` into an error that can happen. #[inline] fn from(never: !) -> TryFromIntError { // Match rather than coerce to make sure that code like diff --git a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs index 232d002394819..4e98db4070a9d 100644 --- a/library/portable-simd/crates/core_simd/src/masks/full_masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks/full_masks.rs @@ -238,7 +238,6 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { - /// Return the `MaskElement` of the `Mask` #[inline] fn from(value: Mask) -> Self { value.0 diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index ef08941542b61..f4d310257cce0 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -266,10 +266,7 @@ impl From> for PanicMessage { } impl From for Box { - /// Return the inner message wrapped in `Box`. - /// - /// ## Cost - /// Allocates a new `Box` on the heap + /// Wrap the inner message in a newly allocated `Box`. fn from(val: PanicMessage) -> Self { match val { PanicMessage::StaticStr(s) => Box::new(s), diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index de27127565962..097347c256699 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -722,7 +722,6 @@ impl fmt::Debug for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { - /// Wrap `Group` in `TokenTree::Group` fn from(g: Group) -> TokenTree { TokenTree::Group(g) } @@ -730,7 +729,6 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { - /// Wrap `Ident` in `TokenTree::Ident` fn from(g: Ident) -> TokenTree { TokenTree::Ident(g) } @@ -738,7 +736,6 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { - /// Wrap `Punct` in `TokenTree::Punct` fn from(g: Punct) -> TokenTree { TokenTree::Punct(g) } @@ -746,7 +743,6 @@ impl From for TokenTree { #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenTree { - /// Wrap `Literal` in `TokenTree::Literal` fn from(g: Literal) -> TokenTree { TokenTree::Literal(g) } diff --git a/library/std/src/os/xous/ffi/definitions.rs b/library/std/src/os/xous/ffi/definitions.rs index e11edd6bf00f7..f11088776fa84 100644 --- a/library/std/src/os/xous/ffi/definitions.rs +++ b/library/std/src/os/xous/ffi/definitions.rs @@ -266,7 +266,7 @@ impl Into<[u32; 4]> for ServerAddress { pub(crate) struct ThreadId(usize); impl From for ThreadId { - /// Make a `ThreadId` with `usize` as inner + /// Make a `ThreadId` with `usize` as the id fn from(src: usize) -> ThreadId { ThreadId(src) } diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index be0b48d5cc50d..7d65daa95e0a2 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -121,7 +121,7 @@ impl PartialEq for EnvKey { // Environment variable keys should preserve their original case even though // they are compared using a caseless string mapping. impl From for EnvKey { - /// Create a new `EnvKey` from `OsString` and it's encode wide iter. + /// Create a new `EnvKey` from `OsString` and its encode wide iter. /// /// ## Cost /// Has to collect `OsString.encode_wide` which allocates a new `Vec` From 858b821e8727120e989575ca8ec50c9a55f826a2 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:07:36 -0400 Subject: [PATCH 15/21] Apply suggestions from code review --- library/alloc/src/bstr.rs | 14 ++++++------- library/alloc/src/task.rs | 20 ++++--------------- library/std/src/sys/fs/windows.rs | 3 +-- .../miri/src/concurrency/vector_clock.rs | 2 +- src/tools/miri/src/shims/io_error.rs | 3 +-- 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 7646ca945a98b..c6f590a97410e 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -245,10 +245,7 @@ impl From for Vec { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for ByteString { - /// Convert the `ByteStr` to a `Vec` then wrap it in a `ByteString`. - /// - /// ## Cost - /// Allocates a new `Vec` + /// Allocates a `ByteString` containing the bytes of `ByteStr`. #[inline] fn from(s: &'a ByteStr) -> Self { ByteString(s.0.to_vec()) @@ -642,7 +639,7 @@ impl From> for Box<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc { - /// Create a `Rc<[u8]>` from `Rc`s raw. + /// Create an `Rc<[u8]>` from the inner bytes of `Rc`. #[inline] fn from(s: Rc<[u8]>) -> Rc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -653,7 +650,7 @@ impl From> for Rc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc<[u8]> { - /// Create a `Rc` from `Rc<[u8]>`s raw. + /// Create a `Rc` from the bytes of `Rc<[u8]>`. #[inline] fn from(s: Rc) -> Rc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -664,7 +661,7 @@ impl From> for Rc<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc { - /// Create a `Arc` from `Arc<[u8]>`s raw. + /// Create an `Arc` from the bytes of `Arc<[u8]>`. #[inline] fn from(s: Arc<[u8]>) -> Arc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -675,7 +672,8 @@ impl From> for Arc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc<[u8]> { - /// Create a `Arc` from `Arc<[u8]>`s raw. + /// Create a `Arc<[u8]>` from the inner bytes of `Arc`. + #[inline] fn from(s: Arc) -> Arc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index f34deb88fda7d..80831eca5bc8b 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -107,10 +107,7 @@ pub trait Wake { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for Waker { - /// Use a [`Wake`]-able type as a `Waker`. - /// - /// ## Cost - /// No heap allocations or atomic operations are used for this conversion. + /// Use a [`Wake`]-able type as a `Waker`. Without any heap allocations or atomic operations. fn from(waker: Arc) -> Waker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Arc. @@ -120,10 +117,7 @@ impl From> for Waker { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. - /// - /// ## Cost - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `Wake`-able type as a `RawWaker`. Without any heap allocations or atomic operations. fn from(waker: Arc) -> RawWaker { raw_waker(waker) } @@ -288,10 +282,7 @@ pub trait LocalWake { #[unstable(feature = "local_waker", issue = "118959")] impl From> for LocalWaker { - /// Use a `Wake`-able type as a `LocalWaker`. - /// - /// ## Cost - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `Wake`-able type as a `LocalWaker`. Without any heap allocations or atomic operations. fn from(waker: Rc) -> LocalWaker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Rc. @@ -301,10 +292,7 @@ impl From> for LocalWaker { #[allow(ineffective_unstable_trait_impl)] #[unstable(feature = "local_waker", issue = "118959")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. - /// - /// ## Cost - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `Wake`-able type as a `RawWaker`. Without any heap allocations or atomic operations. fn from(waker: Rc) -> RawWaker { local_raw_waker(waker) } diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 1403ef527689c..d57b4cfa55767 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1057,8 +1057,7 @@ impl FileAttr { } } impl From for FileAttr { - /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`, - /// with some conditionals for `file_size` and `reparse_tag`. + /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`. fn from(wfd: c::WIN32_FIND_DATAW) -> Self { FileAttr { attributes: wfd.dwFileAttributes, diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index 8b1dbe4b51df4..dfb7e7218c8d2 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -34,7 +34,7 @@ impl Idx for VectorIdx { } impl From for VectorIdx { - /// Create new `VectorIdx` with `u32` as inner. + /// Create new `VectorIdx` with the inner id of `u32`. #[inline] fn from(id: u32) -> Self { Self(id) diff --git a/src/tools/miri/src/shims/io_error.rs b/src/tools/miri/src/shims/io_error.rs index 635669fc68f2c..065cd34dcdb24 100644 --- a/src/tools/miri/src/shims/io_error.rs +++ b/src/tools/miri/src/shims/io_error.rs @@ -14,7 +14,6 @@ pub enum IoError { pub use self::IoError::*; impl From for IoError { - /// Wrap `io::Error` in `HostError`. fn from(value: io::Error) -> Self { IoError::HostError(value) } @@ -28,7 +27,7 @@ impl From for IoError { } impl From for IoError { - /// Wrap `Scalar` in `Raw`. + /// Create a `Raw` `IoError` with a `Scalar`. fn from(value: Scalar) -> Self { IoError::Raw(value) } From 59a2ea3482afacbc1d83164dc37c0d019ca287f3 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:13:07 -0400 Subject: [PATCH 16/21] Remove changes from tools --- .../clippy/clippy_lints/src/attrs/mixed_attributes_style.rs | 5 ----- src/tools/miri/src/concurrency/thread.rs | 1 - src/tools/miri/src/concurrency/vector_clock.rs | 1 - src/tools/miri/src/shims/io_error.rs | 2 -- 4 files changed, 9 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs index 1347e452dce5d..d71c8e9894bf7 100644 --- a/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs +++ b/src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs @@ -15,11 +15,6 @@ enum SimpleAttrKind { } impl From<&AttrKind> for SimpleAttrKind { - /// Convert an `AttrKind` to a `SimpleAttrKind`, - /// if it's a `DocComment` then `Doc` is returned with no conversion. - /// - /// ## Cost - /// If `AttrKind` is `DocComment` it's free, however if it's `Normal` there is heap allocation fn from(value: &AttrKind) -> Self { match value { AttrKind::Normal(attr) => { diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs index 193209c5a7c0c..a8a2491304dd1 100644 --- a/src/tools/miri/src/concurrency/thread.rs +++ b/src/tools/miri/src/concurrency/thread.rs @@ -80,7 +80,6 @@ impl Idx for ThreadId { } impl From for u64 { - /// Return inner `u32` converted to `u64`. fn from(t: ThreadId) -> Self { t.0.into() } diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index dfb7e7218c8d2..345726634299b 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -34,7 +34,6 @@ impl Idx for VectorIdx { } impl From for VectorIdx { - /// Create new `VectorIdx` with the inner id of `u32`. #[inline] fn from(id: u32) -> Self { Self(id) diff --git a/src/tools/miri/src/shims/io_error.rs b/src/tools/miri/src/shims/io_error.rs index 065cd34dcdb24..acf3f74a93d8b 100644 --- a/src/tools/miri/src/shims/io_error.rs +++ b/src/tools/miri/src/shims/io_error.rs @@ -20,14 +20,12 @@ impl From for IoError { } impl From for IoError { - /// Convert a `io::ErrorKind` to a `io::Error` then wrap in `HostError`. fn from(value: io::ErrorKind) -> Self { IoError::HostError(value.into()) } } impl From for IoError { - /// Create a `Raw` `IoError` with a `Scalar`. fn from(value: Scalar) -> Self { IoError::Raw(value) } From 6891a034928d5471c6e4d6172f43ddf2b46b7ab9 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:44:19 -0400 Subject: [PATCH 17/21] Update library/core/src/ptr/alignment.rs --- library/core/src/ptr/alignment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 5bd2b59ddabcf..38ae00d43980e 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -198,7 +198,7 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { - /// Return the inner value of `Alignment` + /// Return the inner value of `Alignment` as a `usize`. #[inline] fn from(align: Alignment) -> usize { align.as_usize() From 84128a39ea578b65125537e13ebb66c5677aa193 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Wed, 26 Mar 2025 11:14:41 -0400 Subject: [PATCH 18/21] Fix formating --- library/alloc/src/bstr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index c6f590a97410e..030e4c8f027bc 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -673,7 +673,6 @@ impl From> for Arc { #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc<[u8]> { /// Create a `Arc<[u8]>` from the inner bytes of `Arc`. - #[inline] fn from(s: Arc) -> Arc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. From d03e4b8522237361bf1f19ade0aa560aa0582273 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Thu, 10 Apr 2025 12:35:13 -0400 Subject: [PATCH 19/21] Apply suggestions from code review --- library/alloc/src/bstr.rs | 2 +- library/core/src/num/error.rs | 1 - library/std/src/os/unix/net/listener.rs | 2 +- library/std/src/os/xous/ffi/definitions.rs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 030e4c8f027bc..27b650e82a8d1 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -692,7 +692,7 @@ impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>); impl<'a> TryFrom<&'a ByteStr> for String { type Error = core::str::Utf8Error; - /// Convert `ByteStr`s bytes to a UTF-8 `String`. + /// Try to allocate a `ByteStr`s bytes as a UTF-8 `String`. /// /// # Errors /// If `ByteStr` is not valid UTF-8 diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 41b9b0d797286..6ef2fdd14c149 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -27,7 +27,6 @@ impl Error for TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl From for TryFromIntError { - #[inline] fn from(x: Infallible) -> TryFromIntError { match x {} } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index a2d89dcbddb83..62279d99df86f 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -342,7 +342,7 @@ impl AsFd for UnixListener { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixListener { - /// Make a `UnixListener` with `OwnedFd` as it's inner file descriptor. + /// Make a `UnixListener` with `OwnedFd` as it's file descriptor. #[inline] fn from(fd: OwnedFd) -> UnixListener { UnixListener(Socket::from_inner(FromInner::from_inner(fd))) diff --git a/library/std/src/os/xous/ffi/definitions.rs b/library/std/src/os/xous/ffi/definitions.rs index f11088776fa84..9c68485628f66 100644 --- a/library/std/src/os/xous/ffi/definitions.rs +++ b/library/std/src/os/xous/ffi/definitions.rs @@ -79,7 +79,7 @@ pub enum Error { #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { - /// Match an error code to `Error`, if `usize > 27` or `usize == 22` then return `UnknownError` + /// Convert an error code to an `Error` fn from(src: usize) -> Self { match src { 0 => Self::NoError, From 750828d419f7f8960e1618c7210966d6eb2fa9c4 Mon Sep 17 00:00:00 2001 From: TimTheBig <132001783+TimTheBig@users.noreply.github.com> Date: Tue, 15 Apr 2025 20:22:59 -0400 Subject: [PATCH 20/21] Apply suggestions from code review Co-authored-by: Sky --- library/alloc/src/bstr.rs | 4 ---- library/alloc/src/task.rs | 8 ++++---- library/core/src/array/mod.rs | 1 - library/core/src/ptr/alignment.rs | 1 - library/core/src/ptr/non_null.rs | 2 +- library/portable-simd/crates/core_simd/src/vector.rs | 1 - library/proc_macro/src/lib.rs | 1 - library/std/src/io/buffered/mod.rs | 2 +- library/std/src/process.rs | 2 +- library/std/src/sync/mpmc/error.rs | 2 +- library/std/src/sync/poison.rs | 2 +- library/std/src/sys/process/unix/common.rs | 4 ---- library/std/src/sys/process/windows.rs | 5 ++--- 13 files changed, 11 insertions(+), 24 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 27b650e82a8d1..5e1f159ab37d0 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -180,7 +180,6 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a, const N: usize> From<&'a [u8; N]> for ByteString { -// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: &'a [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -189,7 +188,6 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl From<[u8; N]> for ByteString { -// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: [u8; N]) -> Self { // ByteString(s.as_slice().to_vec()) @@ -198,7 +196,6 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a [u8]> for ByteString { -// /// Allocate a new `ByteString` with a copy of the bytes in the array. // #[inline] // fn from(s: &'a [u8]) -> Self { // ByteString(s.to_vec()) @@ -236,7 +233,6 @@ impl From for Vec { // // #[unstable(feature = "bstr", issue = "134915")] // impl From for ByteString { -// /// Create a `ByteString` from a `String`s bytes // #[inline] // fn from(s: String) -> Self { // ByteString(s.into_bytes()) diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index 80831eca5bc8b..b9043845d9e5b 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -107,7 +107,7 @@ pub trait Wake { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for Waker { - /// Use a [`Wake`]-able type as a `Waker`. Without any heap allocations or atomic operations. + /// Use a [`Wake`]-able type as a `Waker`, without any heap allocations or atomic operations. fn from(waker: Arc) -> Waker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Arc. @@ -117,7 +117,7 @@ impl From> for Waker { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. Without any heap allocations or atomic operations. + /// Use a `Wake`-able type as a `RawWaker`, without any heap allocations or atomic operations. fn from(waker: Arc) -> RawWaker { raw_waker(waker) } @@ -282,7 +282,7 @@ pub trait LocalWake { #[unstable(feature = "local_waker", issue = "118959")] impl From> for LocalWaker { - /// Use a `Wake`-able type as a `LocalWaker`. Without any heap allocations or atomic operations. + /// Use a `LocalWake`-able type as a `LocalWaker`, without any heap allocations or atomic operations. fn from(waker: Rc) -> LocalWaker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Rc. @@ -292,7 +292,7 @@ impl From> for LocalWaker { #[allow(ineffective_unstable_trait_impl)] #[unstable(feature = "local_waker", issue = "118959")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. Without any heap allocations or atomic operations. + /// Use a `LocalWake`-able type as a `RawWaker`, without any heap allocations or atomic operations. fn from(waker: Rc) -> RawWaker { local_raw_waker(waker) } diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index cb8fef1356d98..28329bb090845 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -178,7 +178,6 @@ impl Error for TryFromSliceError { #[stable(feature = "try_from_slice_error", since = "1.36.0")] impl From for TryFromSliceError { - /// Convert `Infallible` into an error that can happen. fn from(x: Infallible) -> TryFromSliceError { match x {} } diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 38ae00d43980e..7044e58f453bd 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -189,7 +189,6 @@ impl TryFrom for Alignment { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for NonZero { - /// `Alignment` is non-zero so the inner value is returned #[inline] fn from(align: Alignment) -> NonZero { align.as_nonzero() diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index fd093e35049d5..ced6bdbd4e089 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1648,7 +1648,7 @@ impl hash::Hash for NonNull { #[unstable(feature = "ptr_internals", issue = "none")] impl From> for NonNull { - /// Return `Unique` cast to a `NonNull`. + /// Cast `Unique` to a `NonNull`. #[inline] fn from(unique: Unique) -> Self { unique.as_non_null_ptr() diff --git a/library/portable-simd/crates/core_simd/src/vector.rs b/library/portable-simd/crates/core_simd/src/vector.rs index 49d57c977bcea..3d9937f818a66 100644 --- a/library/portable-simd/crates/core_simd/src/vector.rs +++ b/library/portable-simd/crates/core_simd/src/vector.rs @@ -1059,7 +1059,6 @@ where LaneCount: SupportedLaneCount, T: SimdElement, { - /// Use `to_array` to store the `Simd` into a new array #[inline] fn from(vector: Simd) -> Self { vector.to_array() diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 097347c256699..d9141eab5919f 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -238,7 +238,6 @@ fn tree_to_bridge_tree( /// Creates a token stream containing a single token tree. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl From for TokenStream { - /// Convert the tree to a `TokenStream` fn from(tree: TokenTree) -> TokenStream { TokenStream(Some(bridge::client::TokenStream::from_token_tree(tree_to_bridge_tree(tree)))) } diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index e72a1392e08f3..73d5b2856931b 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -173,7 +173,7 @@ impl IntoInnerError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for Error { - /// Get the error of the inner buffer + /// Extracts the inner [`Error`]. Equivalent to [`into_error`](IntoInnerError::into_error). fn from(iie: IntoInnerError) -> Error { iie.1 } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 19818cbd0ac09..8ca8f0de1bb09 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1923,7 +1923,7 @@ impl ExitStatusError { #[unstable(feature = "exit_status_error", issue = "84908")] impl From for ExitStatus { - /// Wrap the converted inner of `ExitStatusError` in `ExitStatus` + /// Converts an `ExitStatusError` (back) to an `ExitStatus`. fn from(error: ExitStatusError) -> Self { Self(error.0.into()) } diff --git a/library/std/src/sync/mpmc/error.rs b/library/std/src/sync/mpmc/error.rs index cf90ff138f352..8027dd2e9dca6 100644 --- a/library/std/src/sync/mpmc/error.rs +++ b/library/std/src/sync/mpmc/error.rs @@ -41,7 +41,7 @@ impl error::Error for SendTimeoutError {} #[unstable(feature = "mpmc_channel", issue = "126840")] impl From> for SendTimeoutError { - /// Make a `SendTimeoutError::Disconnected` with `SendError`s inner + /// Wrap a `SendError` in the `Disconnected` variant. fn from(err: SendError) -> SendTimeoutError { match err { SendError(e) => SendTimeoutError::Disconnected(e), diff --git a/library/std/src/sync/poison.rs b/library/std/src/sync/poison.rs index 0e3a62d99a64d..b25ef7840bdb0 100644 --- a/library/std/src/sync/poison.rs +++ b/library/std/src/sync/poison.rs @@ -340,7 +340,7 @@ impl PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for TryLockError { - /// Wrap `PoisonError` in the `Poisoned` variant. + /// Wrap a `PoisonError` in the `Poisoned` variant. fn from(err: PoisonError) -> TryLockError { TryLockError::Poisoned(err) } diff --git a/library/std/src/sys/process/unix/common.rs b/library/std/src/sys/process/unix/common.rs index 6dcd81d0b173f..a52da5f392bf5 100644 --- a/library/std/src/sys/process/unix/common.rs +++ b/library/std/src/sys/process/unix/common.rs @@ -484,7 +484,6 @@ impl Stdio { } impl From for Stdio { - /// Wrap `AnonPipe`s inner in the `Fd` variant. fn from(pipe: AnonPipe) -> Stdio { Stdio::Fd(pipe.into_inner()) } @@ -497,14 +496,12 @@ impl From for Stdio { } impl From for Stdio { - /// Wrap `File`s inner in the `Fd` variant. fn from(file: File) -> Stdio { Stdio::Fd(file.into_inner()) } } impl From for Stdio { - /// Make a `StaticFd` from a raw borrow of `libc::STDOUT_FILENO`. fn from(_: io::Stdout) -> Stdio { // This ought really to be is Stdio::StaticFd(input_argument.as_fd()). // But AsFd::as_fd takes its argument by reference, and yields @@ -521,7 +518,6 @@ impl From for Stdio { } impl From for Stdio { - /// Make a `StaticFd` from a raw borrow of `libc::STDERR_FILENO`. fn from(_: io::Stderr) -> Stdio { Stdio::StaticFd(unsafe { BorrowedFd::borrow_raw(libc::STDERR_FILENO) }) } diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index 7d65daa95e0a2..b4f7530bf1720 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -121,7 +121,7 @@ impl PartialEq for EnvKey { // Environment variable keys should preserve their original case even though // they are compared using a caseless string mapping. impl From for EnvKey { - /// Create a new `EnvKey` from `OsString` and its encode wide iter. + /// Create a new `EnvKey` from `OsString`. /// /// ## Cost /// Has to collect `OsString.encode_wide` which allocates a new `Vec` @@ -646,7 +646,6 @@ impl From for Stdio { } impl From for Stdio { - /// Create a new `Stdio::InheritSpecific` with `c::STD_ERROR_HANDLE` fn from(_: io::Stderr) -> Stdio { Stdio::InheritSpecific { from_stdio_id: c::STD_ERROR_HANDLE } } @@ -792,7 +791,7 @@ impl ExitCode { } impl From for ExitCode { - /// Convert the `u8` to a `u32` then wrap it in a `ExitCode` + /// Convert the `u8` then wrap it in a `ExitCode` fn from(code: u8) -> Self { ExitCode(u32::from(code)) } From 464e54d8f267d6e9f8f2091852d178f330b22b0d Mon Sep 17 00:00:00 2001 From: Ryan <132001783+TimTheBig@users.noreply.github.com> Date: Sat, 19 Apr 2025 22:13:26 -0400 Subject: [PATCH 21/21] Apply suggestions from code review Co-authored-by: Sky --- library/alloc/src/bstr.rs | 1 - library/core/src/ptr/alignment.rs | 1 - library/core/src/range.rs | 6 ------ library/proc_macro/src/bridge/buffer.rs | 3 +-- library/std/src/os/fd/owned.rs | 3 --- library/std/src/os/linux/process.rs | 1 - library/std/src/os/unix/net/listener.rs | 1 - library/std/src/os/windows/io/socket.rs | 3 --- 8 files changed, 1 insertion(+), 18 deletions(-) diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 5e1f159ab37d0..4a9ce05f8b45b 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -213,7 +213,6 @@ impl Default for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl From for Vec { - /// Return the inner `Vec` of the byte string. #[inline] fn from(s: ByteString) -> Self { s.0 diff --git a/library/core/src/ptr/alignment.rs b/library/core/src/ptr/alignment.rs index 7044e58f453bd..19311e39b454e 100644 --- a/library/core/src/ptr/alignment.rs +++ b/library/core/src/ptr/alignment.rs @@ -197,7 +197,6 @@ impl From for NonZero { #[unstable(feature = "ptr_alignment_type", issue = "102070")] impl From for usize { - /// Return the inner value of `Alignment` as a `usize`. #[inline] fn from(align: Alignment) -> usize { align.as_usize() diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 01cb61c42f6d5..2276112a27bb3 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -187,7 +187,6 @@ impl IntoBounds for Range { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::Range { - /// Make a new `legacy::Range` with the same start and end as `Range` #[inline] fn from(value: Range) -> Self { Self { start: value.start, end: value.end } @@ -195,7 +194,6 @@ impl From> for legacy::Range { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for Range { - /// Make a new `Range` with the same start and end as `legacy::Range` #[inline] fn from(value: legacy::Range) -> Self { Self { start: value.start, end: value.end } @@ -365,7 +363,6 @@ impl IntoBounds for RangeInclusive { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeInclusive { - /// Make a new `legacy::RangeInclusive` with the same start and end as `RangeInclusive` #[inline] fn from(value: RangeInclusive) -> Self { Self::new(value.start, value.end) @@ -373,7 +370,6 @@ impl From> for legacy::RangeInclusive { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for RangeInclusive { - /// Make a new `RangeInclusive` with the same start and end as `legacy::RangeInclusive` #[inline] fn from(value: legacy::RangeInclusive) -> Self { assert!( @@ -511,7 +507,6 @@ impl IntoBounds for RangeFrom { #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeFrom { - /// Make a new `legacy::RangeFrom` with the same start as `RangeFrom` #[inline] fn from(value: RangeFrom) -> Self { Self { start: value.start } @@ -519,7 +514,6 @@ impl From> for legacy::RangeFrom { } #[unstable(feature = "new_range_api", issue = "125687")] impl From> for RangeFrom { - /// Make a new `RangeFrom` with the same start as `legacy::RangeFrom` #[inline] fn from(value: legacy::RangeFrom) -> Self { Self { start: value.start } diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 7b217c3e5919e..8949d08a654c9 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -127,8 +127,7 @@ impl Drop for Buffer { } impl From> for Buffer { - /// Create a `Buffer` without allocation.\ - /// By moving data, len, and capacity from `Vec`, then create custom reserve and drop fns. + /// Create a `Buffer` without allocation. fn from(v: Vec) -> Self { let mut v = ManuallyDrop::new(v); let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity()); diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 7cb829f7be8f9..2dcbfc966189d 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -340,7 +340,6 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpStream { - /// Create a `TcpStream` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( @@ -371,7 +370,6 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::TcpListener { - /// Create a `TcpListener` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( @@ -402,7 +400,6 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] #[cfg(not(target_os = "trusty"))] impl From for crate::net::UdpSocket { - /// Create a `UdpSocket` with a [`OwnedFd`] as inner. #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(FromInner::from_inner( diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 7d053783b930f..ea49c9afb60fd 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -131,7 +131,6 @@ impl AsFd for PidFd { } impl From for PidFd { - /// Make a `PidFd` from inner. fn from(fd: OwnedFd) -> Self { Self::from_inner(InnerPidFd::from_inner(FileDesc::from_inner(fd))) } diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 62279d99df86f..27428c9eb2855 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -342,7 +342,6 @@ impl AsFd for UnixListener { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixListener { - /// Make a `UnixListener` with `OwnedFd` as it's file descriptor. #[inline] fn from(fd: OwnedFd) -> UnixListener { UnixListener(Socket::from_inner(FromInner::from_inner(fd))) diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 773cafe8e902e..1c228914de93f 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -320,7 +320,6 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::TcpStream { - /// Make a `TcpStream` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) } @@ -346,7 +345,6 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::TcpListener { - /// Make a `TcpListener` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) } @@ -372,7 +370,6 @@ impl From for OwnedSocket { #[stable(feature = "io_safety", since = "1.63.0")] impl From for crate::net::UdpSocket { - /// Make a `UdpSocket` from [`OwnedSocket`]s underlying socket. #[inline] fn from(owned: OwnedSocket) -> Self { unsafe { Self::from_raw_socket(owned.into_raw_socket()) }