-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Clean up how documentation works
- Loading branch information
Showing
15 changed files
with
427 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,39 @@ | ||
use core::mem::replace; | ||
|
||
use std::ffi::OsStr; | ||
|
||
use crate::alloc::prelude::*; | ||
use crate::alloc::{self, try_format, HashSet, String}; | ||
use crate::alloc::{self, HashMap}; | ||
use crate::cli::EntryPoint; | ||
use crate::workspace; | ||
use crate::item::ComponentRef; | ||
use crate::ItemBuf; | ||
|
||
/// Helper to perform non-conflicting crate naming. | ||
#[derive(Default)] | ||
pub(crate) struct Naming { | ||
names: HashSet<String>, | ||
count: usize, | ||
names: HashMap<ItemBuf, usize>, | ||
} | ||
|
||
impl Naming { | ||
/// Construct a unique crate name for the given entrypoint. | ||
pub(crate) fn name(&mut self, e: &EntryPoint<'_>) -> alloc::Result<String> { | ||
let name = match &e { | ||
pub(crate) fn item(&mut self, e: &EntryPoint<'_>) -> alloc::Result<ItemBuf> { | ||
let mut item = match &e { | ||
EntryPoint::Path(path) => match path.file_stem().and_then(OsStr::to_str) { | ||
Some(name) => String::try_from(name)?, | ||
None => String::try_from("entry")?, | ||
Some(name) => ItemBuf::with_crate(name)?, | ||
None => ItemBuf::with_crate("entry")?, | ||
}, | ||
EntryPoint::Package(p) => { | ||
let name = p.found.name.as_str(); | ||
|
||
let ext = match &p.found.kind { | ||
workspace::FoundKind::Binary => "bin", | ||
workspace::FoundKind::Test => "test", | ||
workspace::FoundKind::Example => "example", | ||
workspace::FoundKind::Bench => "bench", | ||
}; | ||
|
||
try_format!("{}-{name}-{ext}", p.package.name) | ||
ItemBuf::with_crate_item(&p.package.name, [name])? | ||
} | ||
}; | ||
|
||
// TODO: make it so that we can communicate different entrypoints in the | ||
// visitors context instead of this hackery. | ||
Ok(if !self.names.try_insert(name.try_clone()?)? { | ||
let next = self.count.wrapping_add(1); | ||
let index = replace(&mut self.count, next); | ||
try_format!("{name}{index}") | ||
} else { | ||
name | ||
}) | ||
let values = self.names.entry(item.try_clone()?).or_try_default()?; | ||
|
||
if *values > 0 { | ||
let name = try_format!("{}", *values - 1); | ||
item.push(ComponentRef::Str(&name))?; | ||
} | ||
|
||
*values += 1; | ||
Ok(item) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -902,6 +902,7 @@ impl Context { | |
.entry(i.hash) | ||
.or_try_default()? | ||
.try_push(i.trait_hash)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
|
Oops, something went wrong.