-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
If Foo<'a,'b>
requires 'a <= 'b, need to infer (or provide easy way to express) constraint
#13703
Labels
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Comments
I think this issue (as pointed out by @eddyb in IRC) is currently preventing me from implementing iterators for a trait. Here's my testcase (I've reduced it quite a bit from the original code): use std::iter::Iterator;
pub struct PreOrderNodes<'a, 'b> {
queue: Vec<&'a Node<'b>>
}
impl<'a, 'b> Iterator<&'a Node<'b>> for PreOrderNodes<'a, 'b> {
fn next( &mut self ) -> Option<&'a Node<'b>> {
match self.queue.pop() {
ex @ Some( node ) => {
match node.contents {
Children( ref x ) => {
for child in x.as_slice().iter().rev() {
self.queue.push( child )
}
}
_ => ()
};
ex
}
_ => None
}
}
}
pub enum NodeContents<'a> {
Data( &'a [u8] ),
Children( Vec<Node<'a>> )
}
pub struct Node<'a> {
pub name: &'static str,
pub contents: NodeContents<'a>
}
impl<'a> Node<'a> {
pub fn preOrder<'b>( &'b self ) -> PreOrderNodes<'b, 'a> {
PreOrderNodes { queue: vec!( self ) }
}
}
#[cfg(test)]
mod tests {
use super::{Node, Data};
#[test]
fn preOrder() {
static data: &'static [u8] = &[];
let root = Node { name: "a", contents: Data( data ) };
let mut names : Vec<char> = vec!();
root.preOrder().map( |x| {
names.push( x.name.char_at( 0 ) )
});
assert_eq!( names, vec!( 'a' ) )
}
} That with
|
This was fixed by #16453. Both versions of pub struct Foo<'a, 'b: 'a> { foo: &'a &'b int } |
ghost
mentioned this issue
Oct 2, 2014
flip1995
pushed a commit
to flip1995/rust
that referenced
this issue
Dec 15, 2024
…#13763) Close rust-lang#13703 changelog: none
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Forked off from #10396 comment
Consider this code:
I spoke with @eddyb and pointed him at regions-variance-covariant-use-contravariant.rs to illustrate that we do infer
'a <= 'b
from the existence of&'a &'b T
.The fact that the code above does not compile as-is is interesting. I cannot tell if that is actually related to #10396 or not. (That's why I am filing this separate ticket.)
In particular, the constraints are generated by immediate occurrences of
&'a &'b T
, but not by occurrences ofFoo<'a,'b>
(despiteFoo
having a field of type&'a &'b T
within it).There are a couple different approaches to resolving this. The one with least user impact is probably to make occurrences of
Foo<'a,'b>
(when defined as above) also generate the constraint 'a <= 'b.For completeness (and to save others the trouble of running rustc themselves on the above test case) here is the compile failure you get today if you attempt to compile the code above without
--cfg works
:The text was updated successfully, but these errors were encountered: