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

Make trait lifetime parameters early bound in static fn type. #10506

Merged
merged 2 commits into from
Dec 6, 2013

Conversation

nikomatsakis
Copy link
Contributor

Make trait lifetime parameters early bound in static fn type. Reasoning for this change is (hopefully) explained well enough in the comment, so I'll not duplicate it here. Fixes #10391.

r? @pnkfelix

// A',B',C', // Then type params from trait
// D':Trait<'a,'b,'c,A',B',C'>, // Then this sucker
// E',F',G' // Then type params from `foo()`, offset by 1
// >(...) -> D' {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as on #10556 about using a different syntax for the primed type-vars. But I assume you will fix that eventually, it need not hold up this patch...

bors added a commit that referenced this pull request Dec 2, 2013
…es, r=pnkfelix

Make trait lifetime parameters early bound in static fn type. Reasoning for this change is (hopefully) explained well enough in the comment, so I'll not duplicate it here. Fixes #10391.

r? @pnkfelix
@dwrensha
Copy link
Contributor

dwrensha commented Dec 4, 2013

I am eagerly awaiting this patch! Unfortunately, it looks like traits with lifetime parameters do not work across crate boundaries.

After applying this patch, I tried compiling the following two crates:

// other.rs

#[link(name = "other", package_id = "other", vers="0.0")];
#[crate_type = "lib"];

pub enum Value<'v> {
    A(&'v str),
    B,
}

pub trait Decoder<'v> {
    fn read(&mut self) -> Value<'v>;
}

pub trait Decodable<'v, D: Decoder<'v>> {
    fn decode(d: &mut D) -> Self;
}

// main.rs

extern mod other;

struct S;

impl<'v, D: other::Decoder<'v>> other::Decodable<'v, D> for S {
    fn decode(d: &mut D) -> S {
        match d.read() {
            other::A(..) => S,
            other::B => other::Decodable::decode(d),
        }
    }
}

fn main (){}

The result:

$ rustc other.rs
$ rustc main.rs -L.
main.rs:7:12: 7:29 error: wrong number of lifetime parameters: expected 0 but found 1
main.rs:7 impl<'v, D: other::Decoder<'v>> other::Decodable<'v, D> for S {
                      ^~~~~~~~~~~~~~~~~
main.rs:7:32: 7:55 error: wrong number of lifetime parameters: expected 0 but found 1
main.rs:7 impl<'v, D: other::Decoder<'v>> other::Decodable<'v, D> for S {
                                          ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

@dwrensha
Copy link
Contributor

dwrensha commented Dec 5, 2013

Aha! This patch appears to fix that problem:
dwrensha@c746bd8

I'd submit a pull request now, but I'd want to include a test case and try it locally, and "make check" is currently broken for me. :/

@dwrensha
Copy link
Contributor

dwrensha commented Dec 5, 2013

Update: I got make check working and submitted a pull request for the cross-crate trait problem. #10813

@nikomatsakis
Copy link
Contributor Author

@dwrensha great! I've been meaning to look into your example to try and figure out what the problem was :)

bors added a commit that referenced this pull request Dec 6, 2013
…es, r=pnkfelix

Make trait lifetime parameters early bound in static fn type. Reasoning for this change is (hopefully) explained well enough in the comment, so I'll not duplicate it here. Fixes #10391.

r? @pnkfelix
@bors bors closed this Dec 6, 2013
@bors bors merged commit e9d364d into rust-lang:master Dec 6, 2013
bors added a commit that referenced this pull request Dec 9, 2013
Before applying this patch, the included testcase fails with:
```
src/test/run-pass/xcrate-trait-lifetime-param.rs:20:10: 20:28 error: wrong number of lifetime parameters: expected 0 but found 1
src/test/run-pass/xcrate-trait-lifetime-param.rs:20 impl <'a> other::FromBuf<'a> for Reader<'a> {
                                                              ^~~~~~~~~~~~~~~~~~
```

There's another example in my comments to #10506.
@nikomatsakis nikomatsakis deleted the issue-10391-ICE-with-lifetimes branch March 30, 2016 16:13
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 6, 2023
…flip1995

Add `tests_outside_test_module` lint

Adds `tests_outside_test_module` from rust-lang#10506. This PR **doesn't** close the issue, just resolves task 1.

changelog: [`tests_outside_test_module`]: The lint has been added
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 23, 2023
Add `items_after_test_module` lint

Resolves task *3* of rust-lang#10506, alongside *1* resolved at rust-lang#10543 in an effort to help standarize a little bit more testing modules.

---

changelog:[`items_after_test_module`]: Added the lint.
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

Successfully merging this pull request may close these issues.

ICE using trait lifetime in a method definition
4 participants