8000 fix fallout from rust-lang/rust#119820 by lcnr · Pull Request #69 · maciejhirsz/ramhorns · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix fallout from rust-lang/rust#119820 #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
29 changes: 27 additions & 2 deletions ramhorns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ pub use template::{Section, Template};
#[cfg(feature = "export_derive")]
pub use ramhorns_derive::Content;

/// `Ramhorms::get` previously had a where-bound
/// `for<'a> Cow<'a, str>: std::borrow::Borrow<S>`.
///
/// This where-bound ended up always constraining `S` to `str`.
///
/// There are two potentially applicable impls here:
/// - `impl<T, U> Borrow<T> for Cow<'_, T, U>` from beef
/// - `impl<T> Borrow<T> for T` from std
/// The impl from std always resulted in a higher-ranked region error,
/// previously causing us to only consider the first impl, constraining `S`.
/// This behavior changed in https://github.com/rust-lang/rust/pull/119820,
/// causing that where-bound to be ambiguous.
mod private {
pub struct BackCompat;
pub trait ConstrainToStr<S: ?Sized> {
fn convert(value: &S) -> &str;
}
impl ConstrainToStr<str> for BackCompat {
fn convert(value: &str) -> &str {
value
}
}
}

/// Aggregator for [`Template`s](./struct.Template.html), that allows them to
/// be loaded from the file system and use partials: `{{>partial}}`
///
Expand Down Expand Up @@ -203,10 +227,11 @@ impl<H: BuildHasher + Default> Ramhorns<H> {
/// Get the template with the given name, if it exists.
pub fn get<S>(&self, name: &S) -> Option<&Template<'static>>
where
for<'a> Cow<'a, str>: std::borrow::Borrow<S>,
private::BackCompat: private::ConstrainToStr<S>,
S: std::hash::Hash + AsRef<Path> + Eq + ?Sized,
{
self.partials.get(name)
self.partials
.get(<private::BackCompat as private::ConstrainToStr<S>>::convert(name))
}

/// Get the template with the given name. If the template doesn't exist,
Expand Down
0