Skip to content

Poor error message when a subtype is not Sync as required #20965

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
jdm opened this issue Jan 11, 2015 · 10 comments
Closed

Poor error message when a subtype is not Sync as required #20965

jdm opened this issue Jan 11, 2015 · 10 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@jdm
Copy link
Contributor

jdm commented Jan 11, 2015

If you change https://github.com/servo/servo/blob/81f47344d6e121d86de368a25107415406de3c0f/components/layout/fragment.rs#L227 to read Option<Sender<CanvasMsg>>, trying to build Servo produces a ton of confusing error messages:

   Compiling layout v0.0.1 (file:///Users/jdm/src/servo/components/servo)
block.rs:1485:1: 1903:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
block.rs:1485 impl Flow for BlockFlow {
block.rs:1486     fn class(&self) -> FlowClass {
block.rs:1487         FlowClass::Block
block.rs:1488     }
block.rs:1489
block.rs:1490     fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
              ...
block.rs:1485:1: 1903:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
block.rs:1485 impl Flow for BlockFlow {
block.rs:1486     fn class(&self) -> FlowClass {
block.rs:1487         FlowClass::Block
block.rs:1488     }
block.rs:1489
block.rs:1490     fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
              ...
inline.rs:944:1: 1253:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
inline.rs:944 impl Flow for InlineFlow {
inline.rs:945     fn class(&self) -> FlowClass {
inline.rs:946         FlowClass::Inline
inline.rs:947     }
inline.rs:948
inline.rs:949     fn as_immutable_inline<'a>(&'a self) -> &'a InlineFlow {
              ...
inline.rs:944:1: 1253:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
inline.rs:944 impl Flow for InlineFlow {
inline.rs:945     fn class(&self) -> FlowClass {
inline.rs:946         FlowClass::Inline
inline.rs:947     }
inline.rs:948
inline.rs:949     fn as_immutable_inline<'a>(&'a self) -> &'a InlineFlow {
              ...
list_item.rs:48:1: 124:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
list_item.rs:48 impl Flow for ListItemFlow {
list_item.rs:49     fn class(&self) -> FlowClass {
list_item.rs:50         FlowClass::ListItem
list_item.rs:51     }
list_item.rs:52
list_item.rs:53     fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
                ...
list_item.rs:48:1: 124:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
list_item.rs:48 impl Flow for ListItemFlow {
list_item.rs:49     fn class(&self) -> FlowClass {
list_item.rs:50         FlowClass::ListItem
list_item.rs:51     }
list_item.rs:52
list_item.rs:53     fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
                ...
table_wrapper.rs:215:1: 371:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_wrapper.rs:215 impl Flow for TableWrapperFlow {
table_wrapper.rs:216     fn class(&self) -> FlowClass {
table_wrapper.rs:217         FlowClass::TableWrapper
table_wrapper.rs:218     }
table_wrapper.rs:219
table_wrapper.rs:220     fn as_table_wrapper<'a>(&'a mut self) -> &'a mut TableWrapperFlow {
                     ...
table_wrapper.rs:215:1: 371:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_wrapper.rs:215 impl Flow for TableWrapperFlow {
table_wrapper.rs:216     fn class(&self) -> FlowClass {
table_wrapper.rs:217         FlowClass::TableWrapper
table_wrapper.rs:218     }
table_wrapper.rs:219
table_wrapper.rs:220     fn as_table_wrapper<'a>(&'a mut self) -> &'a mut TableWrapperFlow {
                     ...
table.rs:205:1: 397:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table.rs:205 impl Flow for TableFlow {
table.rs:206     fn class(&self) -> FlowClass {
table.rs:207         FlowClass::Table
table.rs:208     }
table.rs:209
table.rs:210     fn as_table<'a>(&'a mut self) -> &'a mut TableFlow {
             ...
table.rs:205:1: 397:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table.rs:205 impl Flow for TableFlow {
table.rs:206     fn class(&self) -> FlowClass {
table.rs:207         FlowClass::Table
table.rs:208     }
table.rs:209
table.rs:210     fn as_table<'a>(&'a mut self) -> &'a mut TableFlow {
             ...
table_caption.rs:37:1: 94:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_caption.rs:37 impl Flow for TableCaptionFlow {
table_caption.rs:38     fn class(&self) -> FlowClass {
table_caption.rs:39         FlowClass::TableCaption
table_caption.rs:40     }
table_caption.rs:41
table_caption.rs:42     fn as_table_caption<'a>(&'a mut self) -> &'a mut TableCaptionFlow {
                    ...
table_caption.rs:37:1: 94:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_caption.rs:37 impl Flow for TableCaptionFlow {
table_caption.rs:38     fn class(&self) -> FlowClass {
table_caption.rs:39         FlowClass::TableCaption
table_caption.rs:40     }
table_caption.rs:41
table_caption.rs:42     fn as_table_caption<'a>(&'a mut self) -> &'a mut TableCaptionFlow {
                    ...
table_colgroup.rs:56:1: 107:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_colgroup.rs:56 impl Flow for TableColGroupFlow {
table_colgroup.rs:57     fn class(&self) -> FlowClass {
table_colgroup.rs:58         FlowClass::TableColGroup
table_colgroup.rs:59     }
table_colgroup.rs:60
table_colgroup.rs:61     fn as_table_colgroup<'a>(&'a mut self) -> &'a mut TableColGroupFlow {
                     ...
table_colgroup.rs:56:1: 107:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_colgroup.rs:56 impl Flow for TableColGroupFlow {
table_colgroup.rs:57     fn class(&self) -> FlowClass {
table_colgroup.rs:58         FlowClass::TableColGroup
table_colgroup.rs:59     }
table_colgroup.rs:60
table_colgroup.rs:61     fn as_table_colgroup<'a>(&'a mut self) -> &'a mut TableColGroupFlow {
                     ...
table_rowgroup.rs:70:1: 163:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_rowgroup.rs:70 impl Flow for TableRowGroupFlow {
table_rowgroup.rs:71     fn class(&self) -> FlowClass {
table_rowgroup.rs:72         FlowClass::TableRowGroup
table_rowgroup.rs:73     }
table_rowgroup.rs:74
table_rowgroup.rs:75     fn as_table_rowgroup<'a>(&'a mut self) -> &'a mut TableRowGroupFlow {
                     ...
table_rowgroup.rs:70:1: 163:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_rowgroup.rs:70 impl Flow for TableRowGroupFlow {
table_rowgroup.rs:71     fn class(&self) -> FlowClass {
table_rowgroup.rs:72         FlowClass::TableRowGroup
table_rowgroup.rs:73     }
table_rowgroup.rs:74
table_rowgroup.rs:75     fn as_table_rowgroup<'a>(&'a mut self) -> &'a mut TableRowGroupFlow {
                     ...
table_row.rs:151:1: 328:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_row.rs:151 impl Flow for TableRowFlow {
table_row.rs:152     fn class(&self) -> FlowClass {
table_row.rs:153         FlowClass::TableRow
table_row.rs:154     }
table_row.rs:155
table_row.rs:156     fn as_table_row<'a>(&'a mut self) -> &'a mut TableRowFlow {
                 ...
table_row.rs:151:1: 328:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_row.rs:151 impl Flow for TableRowFlow {
table_row.rs:152     fn class(&self) -> FlowClass {
table_row.rs:153         FlowClass::TableRow
table_row.rs:154     }
table_row.rs:155
table_row.rs:156     fn as_table_row<'a>(&'a mut self) -> &'a mut TableRowFlow {
                 ...
table_cell.rs:69:1: 175:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::kinds::marker::NoSync`
table_cell.rs:69 impl Flow for TableCellFlow {
table_cell.rs:70     fn class(&self) -> FlowClass {
table_cell.rs:71         FlowClass::TableCell
table_cell.rs:72     }
table_cell.rs:73
table_cell.rs:74     fn as_table_cell<'a>(&'a mut self) -> &'a mut TableCellFlow {
                 ...
table_cell.rs:69:1: 175:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `flow::Flow`
table_cell.rs:69 impl Flow for TableCellFlow {
table_cell.rs:70     fn class(&self) -> FlowClass {
table_cell.rs:71         FlowClass::TableCell
table_cell.rs:72     }
table_cell.rs:73
table_cell.rs:74     fn as_table_cell<'a>(&'a mut self) -> &'a mut TableCellFlow {
                 ...
error: aborting due to 10 previous errors
Could not compile `layout`.
@jdm
Copy link
Contributor Author

jdm commented Jan 11, 2015

Changing the recursion limit here does not appear to help, nor does the workaround @nikomatsakis suggested for #19318 (I attempted to use it on the CanvasMsg type, but there was no change in the output).

@Aatch
Copy link
Contributor

Aatch commented Jan 12, 2015

So, whats the error here? There is no mention of Send in the output. It's complaining about Sync. The docs for Sender actually say "This half can only be owned by one task, but it can be cloned to send to other tasks". Unless I'm missing some larger context here, the compiler is right.

@jdm
Copy link
Contributor Author

jdm commented Jan 12, 2015

How is the compiler right? Senders should always be able to be sent bare without needing to be wrapped in Arc<Mutex<T>>.

@jdm
Copy link
Contributor Author

jdm commented Jan 12, 2015

It's not clear to me how removing the Arc<Mutex<T>> wrapper in this case ends up causing the errors seen in the log above - none of those types in the messages refer to the modified type.

@kmcallister kmcallister added the A-type-system Area: Type system label Jan 12, 2015
@Aatch
Copy link
Contributor

Aatch commented Jan 12, 2015

@jdm senders can be sent yes, but the compiler isn't complaining about Send it's complaining about Sync. The field you changed is part of all the types the error messages are for, albeit behind a few other types. Wrapping it in Arc<Mutex<T>> caused it to be Sync, removing it prevented that.

I'm not sure where you got the idea this had anything to do with Send given that Send is not mentioned in any of the errors. Flow has Sync as a supertrait, and Sender does not implement Sync, I'm not sure how much more clear I can be.

@jdm
Copy link
Contributor Author

jdm commented Jan 12, 2015

Ah, I see. I appreciate the explanation; I got caught up in the superficial similarity to #19318.

@jdm jdm changed the title Incorrect Send implementation classification Poor error message when a subtype is not Sync as required Jan 12, 2015
@jdm jdm added I-papercut A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 12, 2015
@jdm
Copy link
Contributor Author

jdm commented Jan 12, 2015

Let's morph this to cover the terrible error message, in that case.

@jdm
Copy link
Contributor Author

jdm commented Jan 12, 2015

Then again, a smaller testcase using a more recent version of rustc gives me:

godot2:~ jdm$ rustc /tmp/sync.rs
/tmp/sync.rs:8:1: 9:2 error: the trait `core::kinds::Sync` is not implemented for the type `core::cell::UnsafeCell<std::comm::Flavor<()>>`
/tmp/sync.rs:8 impl Flow for BaseFlow {
/tmp/sync.rs:9 }
/tmp/sync.rs:8:1: 9:2 note: the type `core::cell::UnsafeCell<std::comm::Flavor<()>>` must implement `core::kinds::Sync` because it appears within the type `std::comm::Sender<()>`
/tmp/sync.rs:8 impl Flow for BaseFlow {
/tmp/sync.rs:9 }
/tmp/sync.rs:8:1: 9:2 note: the type `std::comm::Sender<()>` must implement `core::kinds::Sync` because it appears within the type `BaseFlow`
/tmp/sync.rs:8 impl Flow for BaseFlow {
/tmp/sync.rs:9 }
/tmp/sync.rs:8:1: 9:2 note: the trait `core::kinds::Sync` must be implemented because it is required by `Flow`
/tmp/sync.rs:8 impl Flow for BaseFlow {
/tmp/sync.rs:9 }

@Aatch Aatch removed the A-type-system Area: Type system label Jan 12, 2015
@jdm jdm closed this as completed Jan 12, 2015
@nikomatsakis
Copy link
Contributor

(@jdm so I infer you are satisfied with that error message? We did put some effort into making these problems more diagnosable)

@jdm
Copy link
Contributor Author

jdm commented Jan 13, 2015

Yes, the newer error messages give a much more sensible chain of cause and effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants