Skip to content
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

Add ?Sized bound to SourceCode to allow casting &str` into it. #414

Open
Diegovsky opened this issue Dec 7, 2024 · 2 comments
Open

Add ?Sized bound to SourceCode to allow casting &str` into it. #414

Diegovsky opened this issue Dec 7, 2024 · 2 comments

Comments

@Diegovsky
Copy link

Diegovsky commented Dec 7, 2024

I'm trying to cast a borrowed &str to a dyn SourceCode but I'm receiving the error:
error[E0277]: the size for values of type str cannot be known at compilation time
and
help: the trait `Sized` is not implemented for `str`
note: required for the cast from `&str` to `&dyn SourceCode`

Which leads me to Source Code's definition, where it is said to be implemented by str and &str (as expected), but it is not marked as ?Sized which I suspect is the reason why this cast can't be made.

@zkat
Copy link
Owner

zkat commented Dec 7, 2024

I think this is happening because you’re trying to turn &str into &dyn SourceCode… that is, str (which is unsized, and does NOT implement SourceCode), into dyn SourceCode

try casting &&str to &dyn SourceCode

@Diegovsky
Copy link
Author

Diegovsky commented Dec 18, 2024

Well, it is implemented for str.

I couldn't do it with &&str because I store an owned String and I'm trying to provide a SourceCode for Diagnostic::source_code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants