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

Can't fulfill 'static bound with &'static pointer. #7268

Closed
bblum opened this issue Jun 21, 2013 · 9 comments · Fixed by #18555
Closed

Can't fulfill 'static bound with &'static pointer. #7268

bblum opened this issue Jun 21, 2013 · 9 comments · Fixed by #18555
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority

Comments

@bblum
Copy link
Contributor

bblum commented Jun 21, 2013

This should be legal but isn't:

fn foo<T: 'static>(_: T) {}

fn bar<T>(x: &'static T) {
    foo(x);
}
fn main() {}

@nikomatsakis ?

nominating feature-complete

@nikomatsakis
Copy link
Contributor

no bug. The type parameter T could contain borrowed pointers, as the error message correctly pointed out. You want:

fn foo<T: 'static>(_: T) {}

fn bar<T: 'static>(x: &'static T) {
    foo(x);
}
fn main() {}

@bblum
Copy link
Contributor Author

bblum commented Jun 22, 2013

Not to mean this should change, but it should also be impossible to (safely) construct a &'static &'r T, right?

@nikomatsakis
Copy link
Contributor

That is true.

@nikomatsakis nikomatsakis reopened this Jun 28, 2013
@nikomatsakis
Copy link
Contributor

I decided you're right, we ought to try &'static T as possessing the static bound for all T, since there are already other parts of the type system that rely on the fact that for all &'foo T, T cannot have region pointers that have shorter lifetime than 'foo

@bluss
Copy link
Member

bluss commented Jul 2, 2013

Here is a testcase for putting &'static fn() closures into trait objects. Of course sendable closures are also interesting (do we have to use extern fn for that?).

/*
error: cannot pack type `~Test`, which does not fulfill `'static`, as a trait bounded by 'static
let trait_obj = (~t) as ~EvalOnce:'static;
                ^~~~~~~~~~~~~~~~~~~~~~~~~
*/

struct Test {
    f: &'static fn:'static(),
}

trait EvalOnce {
    fn eval(~self);
}

impl EvalOnce for Test {
    fn eval(~self) {
        (self.f)();
    }
}

fn test_me() {
    let t: Test  = Test { f: || { } };
    let trait_obj = (~t) as ~EvalOnce:'static;
}

@msullivan
Copy link
Contributor

Seconding the nomination for feature complete, I suppose?

@catamorphism
Copy link
Contributor

accepted for production-ready

@pnkfelix
Copy link
Member

Could be added backwards-compatibly in the future. Assigning P-low, not 1.0 blocker.

@pnkfelix
Copy link
Member

@nikomatsakis the natural generalization here, assuming we finish #5121 by allowing lifetime kind bounds other than 'static, is that fn foo<T:'b>(x: &'a T) { ... } would imply that actually T: 'a + 'b, right?

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 30, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 3, 2021
Move `semicolon_if_nothing_returned` to `pedantic`

This moves the `semicolon_if_nothing_returned` lint to `pedantic` category.
I had done rust-lang#7148, but on the master branch, and Github doesn't seem to let me change that, so here's another PR

changelog: Move [`semicolon_if_nothing_returned`] lint into `pedantic` category.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-type-system Area: Type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants