Skip to content

Commit df90691

Browse files
committed
Add from docs for tools
1 parent 3b022d8 commit df90691

File tree

23 files changed

+96
-1
lines changed

23 files changed

+96
-1
lines changed

src/tools/clippy/clippy_lints/src/attrs/mixed_attributes_style.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ enum SimpleAttrKind {
1515
}
1616

1717
impl From<&AttrKind> for SimpleAttrKind {
18+
/// Convert an `AttrKind` to a `SimpleAttrKind`, if it's a `DocComment` then `Doc` is returned with no conversion.
19+
///
20+
/// ## Cost
21+
/// If `AttrKind` is `DocComment` it's free, however if it's `Normal` their is heep allocation
1822
fn from(value: &AttrKind) -> Self {
1923
match value {
2024
AttrKind::Normal(attr) => {

src/tools/miri/src/concurrency/thread.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl Idx for ThreadId {
8080
}
8181

8282
impl From<ThreadId> for u64 {
83+
/// Return inner `u32` converted to `u64`
8384
fn from(t: ThreadId) -> Self {
8485
t.0.into()
8586
}

src/tools/miri/src/concurrency/vector_clock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl Idx for VectorIdx {
3434
}
3535

3636
impl From<u32> for VectorIdx {
37+
/// Create new `VectorIdx` with `u32` as inner
3738
#[inline]
3839
fn from(id: u32) -> Self {
3940
Self(id)

src/tools/miri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern crate rustc_middle;
7474
extern crate rustc_session;
7575
extern crate rustc_span;
7676
extern crate rustc_target;
77-
// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are
77+
// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are
7878
// shipped only as rmeta files.
7979
#[allow(unused_extern_crates)]
8080
extern crate rustc_driver;

src/tools/miri/src/shims/io_error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ pub enum IoError {
1414
pub use self::IoError::*;
1515

1616
impl From<io::Error> for IoError {
17+
/// Wrap `io::Error` in `HostError`
1718
fn from(value: io::Error) -> Self {
1819
IoError::HostError(value)
1920
}
2021
}
2122

2223
impl From<io::ErrorKind> for IoError {
24+
/// Convert a `io::ErrorKind` to a `io::Error` then wrap in `HostError`
2325
fn from(value: io::ErrorKind) -> Self {
2426
IoError::HostError(value.into())
2527
}
2628
}
2729

2830
impl From<Scalar> for IoError {
31+
/// Wrap `Scalar` in `Raw`
2932
fn from(value: Scalar) -> Self {
3033
IoError::Raw(value)
3134
}

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ pub enum LangCrateOrigin {
173173
}
174174

175175
impl From<&str> for LangCrateOrigin {
176+
/// Match a string slice for "alloc", "core", "proc-macro", "proc_macro", "std", "test",
177+
/// mapping them to variants of the same name; if none match then it's `Other`
176178
fn from(s: &str) -> Self {
177179
match s {
178180
"alloc" => LangCrateOrigin::Alloc,
@@ -217,6 +219,10 @@ impl CrateDisplayName {
217219
}
218220

219221
impl From<CrateName> for CrateDisplayName {
222+
/// Creates a `CrateDisplayName` from `crate_name` and `crate_name.0`(inner)
223+
///
224+
/// ## Cost
225+
/// This clones `CrateName`
220226
fn from(crate_name: CrateName) -> CrateDisplayName {
221227
let canonical_name = crate_name.0.clone();
222228
CrateDisplayName { crate_name, canonical_name }
@@ -634,6 +640,10 @@ impl Env {
634640
}
635641

636642
impl From<Env> for Vec<(String, String)> {
643+
/// Iterates the hash map entries collects them in to a `Vec` then sorts it.
644+
///
645+
/// ## Cost
646+
/// This is expensive as it `collect`s and `sort`s env
637647
fn from(env: Env) -> Vec<(String, String)> {
638648
let mut entries: Vec<_> = env.entries.into_iter().collect();
639649
entries.sort();

src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub enum CfgExpr {
3838
}
3939

4040
impl From<CfgAtom> for CfgExpr {
41+
/// Wrap `CfgAtom` in `CfgExpr::Atom`
4142
fn from(atom: CfgAtom) -> Self {
4243
CfgExpr::Atom(atom)
4344
}

src/tools/rust-analyzer/crates/hir-def/src/attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ pub enum DocExpr {
245245
}
246246

247247
impl From<DocAtom> for DocExpr {
248+
/// Creates `Atom` with `DocAtom`
248249
fn from(atom: DocAtom) -> Self {
249250
DocExpr::Atom(atom)
250251
}

src/tools/rust-analyzer/crates/hir-def/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl Literal {
146146
}
147147

148148
impl From<ast::LiteralKind> for Literal {
149+
/// Create a `Literal` by matching `LiteralKind`
149150
fn from(ast_lit_kind: ast::LiteralKind) -> Self {
150151
use ast::LiteralKind;
151152
match ast_lit_kind {

src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ impl LiteralConstRef {
637637
}
638638

639639
impl From<Literal> for LiteralConstRef {
640+
/// Make a `LiteralConstRef` from `Literal`
641+
/// - Note: `Char`, `Bool`, `Int`, `Uint` match, other types are not const and return a `Unknown`
640642
fn from(literal: Literal) -> Self {
641643
match literal {
642644
Literal::Char(c) => Self::Char(c),

0 commit comments

Comments
 (0)