-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
Allow inner source type of a NamedSource to be borrowed directly #254
Conversation
a612439
to
7c81558
Compare
Looks like you can make this backwards compatibile, but there are still a few issues to address with the You can change pub struct NamedSource<S: SourceCode + ?Sized + 'static = dyn SourceCode + 'static> {
source: Box<S>,
name: String,
} This allows However, in impl<S: SourceCode + ?Sized + 'static> NamedSource<S> {
/// Create a new `NamedSource` using a regular [`SourceCode`] and giving
/// its returned [`SpanContents`] a name.
pub fn new(name: impl AsRef<str>, source: impl Into<Box<S>>) -> Self
where
S: Send + Sync,
{
Self {
source: source.into(),
name: name.as_ref().to_string(),
}
}
} This works fine for
Is there a constraint that we could use instead of |
I don't really see how we can work around that constraint, yeah, so this would necessarily need to be a breaking change :\ My recommendation continues to be that people write their own NamedSource implementation if they want something like this, considering that NamedSource is just so trivial |
Yeah, I don't have a particular opinion either way. I was just looking for simple issues to pick up and this one seemed like a quick fix. I think it actually improves the docs a bit because it makes it a bit more clear in the examples what's going on when you see but I don't like that this is a breaking change for anything currently using |
nvm, it wouldn't. But doing something like this with pub struct LabeledSpan<S: Into<SourceSpan>> {
label: Option<String>,
span: S,
} |
To avoid the breaking changes, what if new generic types are added instead? The existing types can then just be specific variants of the new types. |
Sorry, I have mom brain right now. What do you mean by this? Use a newtype or an alias? (I think using either of these might be breaking too??) |
No worries 😉 I was thinking of adding a new generic |
Fixes: #236
This is a simple direct implementation that just makes NamedSource generic over a SourceCode type parameter. It would be nice if we could give the type parameter a sensible default so that existing diagnostics don't break. I'll test various approaches to make this more backwards compatible over the next few days.
Maybe keeping the source in a
Box
, allowingS
to be?Sized
, and then defaultingS
todyn SourceCode + 'static
but I'm not sure how to change the type ofNamedSource::new
to allow for that, since function arguments must beSized
.