-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Very confusing error on attempt to pass path::Path
by value
#23286
Comments
I've hit this too and was completely baffled about what the compiler was saying. |
Same here, this was my code: pub fn assure_config_dir_exists(dir: &str) -> Result<Path, ArgumentError> {
Ok(Path::new(dir))
} This works. Something that I didn't expect is that pub fn assure_config_dir_exists(dir: &str) -> Result<&Path, ArgumentError> {
Ok(Path::new(dir))
} |
Can confirm that this behaviour is still present in |
Confirmed in rustc 1.0 and 1.2.0-nightly (613e57b 2015-06-01) (built 2015-06-02). |
I just hit this and was confused as well. |
Nominating. This seems like an important error to try to improve. triage: I-nominated |
The issue here is how we report errors on trait-matching in the presence of nested obligations - we report the predicate that failed to shallowly match and not the original obligation. We essentially have:
and we require that |
All right, I'll give it P-high. I've been thinking of tackling this issue that @arielb1 is describing as part of another change. This is kind of a dup but I'm going to keep it separate. triage: P-high |
Does #26617 fix this issue? |
No it doesn't |
On the other hand, just calling
I am semi-worried about a deep chain of types filling the screen with an error, not sure what to do about that. |
Here's a possible set of rules to follow which would fix the problem:
This avoids breaking encapsulation: outside its own module it becomes impossible to tell from an error message that a Path is represented as a [u8] - for all intents and purposes it's a new unsized type, unrelated to any others. |
new error style: ``` path.rs:4:6: 4:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277] path.rs:4 fn f(p: Path) {} ^ path.rs:4:6: 4:7 help: run `rustc --explain E0277` to see a detailed explanation path.rs:4:6: 4:7 note: `[u8]` does not have a constant size known at compile-time path.rs:4:6: 4:7 note: required because it appears within the type `std::sys::os_str::Slice` path.rs:4:6: 4:7 note: required because it appears within the type `std::ffi::os_str::OsStr` path.rs:4:6: 4:7 note: required because it appears within the type `std::path::Path` path.rs:4:6: 4:7 note: all local variables must have a statically known size path.rs:7:5: 7:36 error: the trait `core::marker::Send` is not implemented for the type `alloc::rc::Rc<()>` [E0277] path.rs:7 foo::<BTreeMap<Rc<()>, Rc<()>>>(); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ path.rs:7:5: 7:36 help: run `rustc --explain E0277` to see a detailed explanation path.rs:7:5: 7:36 note: `alloc::rc::Rc<()>` cannot be sent between threads safely path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::node::Node<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::map::BTreeMap<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required by `foo` error: aborting due to 2 previous errors ``` This improves the rust-lang#21793/rust-lang#23286 situation
…sakis new error style: ``` path.rs:4:6: 4:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277] path.rs:4 fn f(p: Path) {} ^ path.rs:4:6: 4:7 help: run `rustc --explain E0277` to see a detailed explanation path.rs:4:6: 4:7 note: `[u8]` does not have a constant size known at compile-time path.rs:4:6: 4:7 note: required because it appears within the type `std::sys::os_str::Slice` path.rs:4:6: 4:7 note: required because it appears within the type `std::ffi::os_str::OsStr` path.rs:4:6: 4:7 note: required because it appears within the type `std::path::Path` path.rs:4:6: 4:7 note: all local variables must have a statically known size path.rs:7:5: 7:36 error: the trait `core::marker::Send` is not implemented for the type `alloc::rc::Rc<()>` [E0277] path.rs:7 foo::<BTreeMap<Rc<()>, Rc<()>>>(); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ path.rs:7:5: 7:36 help: run `rustc --explain E0277` to see a detailed explanation path.rs:7:5: 7:36 note: `alloc::rc::Rc<()>` cannot be sent between threads safely path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::node::Node<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::map::BTreeMap<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required by `foo` error: aborting due to 2 previous errors ``` This improves the #21793/#23286 situation r? @nikomatsakis
…sakis new error style: ``` path.rs:4:6: 4:7 error: the trait `core::marker::Sized` is not implemented for the type `[u8]` [E0277] path.rs:4 fn f(p: Path) {} ^ path.rs:4:6: 4:7 help: run `rustc --explain E0277` to see a detailed explanation path.rs:4:6: 4:7 note: `[u8]` does not have a constant size known at compile-time path.rs:4:6: 4:7 note: required because it appears within the type `std::sys::os_str::Slice` path.rs:4:6: 4:7 note: required because it appears within the type `std::ffi::os_str::OsStr` path.rs:4:6: 4:7 note: required because it appears within the type `std::path::Path` path.rs:4:6: 4:7 note: all local variables must have a statically known size path.rs:7:5: 7:36 error: the trait `core::marker::Send` is not implemented for the type `alloc::rc::Rc<()>` [E0277] path.rs:7 foo::<BTreeMap<Rc<()>, Rc<()>>>(); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ path.rs:7:5: 7:36 help: run `rustc --explain E0277` to see a detailed explanation path.rs:7:5: 7:36 note: `alloc::rc::Rc<()>` cannot be sent between threads safely path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::node::Node<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required because it appears within the type `collections::btree::map::BTreeMap<alloc::rc::Rc<()>, alloc::rc::Rc<()>>` path.rs:7:5: 7:36 note: required by `foo` error: aborting due to 2 previous errors ``` Fixes #21793 Fixes #23286 r? @nikomatsakis
Has this really been fixed? It looks like the error was cleaned up a bit, but it still states that |
@marcusklaas It should now list all of the steps which result in the Sized bound being violated, including both |
This is definitely an improvement, but the order of information still seems backwards to me: I feel like I want to see first that |
Hmm, I see your point. The current message reflects more how the compiler operators internally than the mental model of the user. We could invert the message, I imagine, though what I'd really prefer to do is to keep more information than we have now (which @jroesch has been working on) in terms of keeping the full "obligation stack". But in any case that if we wanted to invert the stack trace I imagine we could, with a little bit of legwork. I'd be happy to mentor this. I'll re-open for now. |
Point out the known type when field doesn't satisfy bound For file ```rust use std::path::Path; fn f(p: Path) { } ``` provide the following error ```nocode error[E0277]: the trait bound `[u8]: std::marker::Sized` is not satisfied in `std::path::Path` --> file.rs:3:6 | 3 | fn f(p: Path) { } | ^ within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]` | = note: `[u8]` does not have a constant size known at compile-time = note: required because it appears within the type `std::path::Path` = note: all local variables must have a statically known size ``` Fix rust-lang#23286.
With the latest version of Rust.
|
+1
|
Reopening as the output is still confusing. |
Is there any updates on this one ? |
@sourcepirate I do not believe anyone has tried to address this recently. |
Custom E0277 diagnostic for `Path` r? @nikomatsakis we have a way to target `Path` exclusively, we need to identify the correct text to show to consider rust-lang#23286 fixed.
Custom E0277 diagnostic for `Path` r? @nikomatsakis we have a way to target `Path` exclusively, we need to identify the correct text to show to consider #23286 fixed.
Current output
|
The current output looks pretty great. Explains what the error is, where it's coming from and how to fix it. |
Provide structured suggestion on unsized fields and fn params * Suggest borrowing or boxing unsized fields * Suggest borrowing fn parameters * Remove some verbosity of unsized errors * Remove `on_unimplemented` note from `trait Sized` Fix rust-lang#23286, fix rust-lang#28653. r? @davidtwco
The issue is still present. I have a simple struct as below: pub struct Paths {
home_config_path: Path, // "Path" is underlined red
local_config_path: Path,
log_path: Path,
} I use VSCode with rust-analyzer and it complains saying:
If you prefer screenshot:
(Yes, I have a Environment
Unfortunately, I have no way to tell the rust-analyzer version because the extension downloads it itself. It's safe to assume it is the latest version at the time I write this reply. If relevant:
Possible QuestionsWhy do I think this is not related to rust-analyzer?It's because |
Are neither of these suggestions applicable for your case? Should their wording be made clearer or more prominent? |
@estebank Actually using |
produces
We should give an explicit hint that
Path
should be passed by reference. Also the error does not mentionPath
and the typeu8
does not appear in the program.UPDATE: The message now includes a full stack trace of types, but it would be better to start out with the type the user knows about (
Path
, in this case) and only discuss[u8]
last. -- @nikomatsakisThe text was updated successfully, but these errors were encountered: