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

Regression in interaction between lifetime parameter and defaulted type parameter #49344

Closed
bsteinb opened this issue Mar 24, 2018 · 5 comments
Closed
Assignees
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bsteinb
Copy link

bsteinb commented Mar 24, 2018

The mpi crate contains (approximately) the following code that used to work before nightly-2018-03-02:

use std::cell::Cell;
use std::marker::PhantomData;

pub struct Request<'a, S: Scope<'a> = StaticScope> {
    scope: S,
    phantom: PhantomData<Cell<&'a ()>>,
}

pub unsafe trait Scope<'a> {
    /// Registers a request with the scope.
    fn register(&self);

    /// Unregisters a request from the scope.
    unsafe fn unregister(&self);
}

pub struct StaticScope;

unsafe impl Scope<'static> for StaticScope {
    fn register(&self) {}

    unsafe fn unregister(&self) {}
}

The newest nightly compiler that successfully compiles this is:

rustc 1.26.0-nightly (0ff9872b2 2018-02-28)
binary: rustc
commit-hash: 0ff9872b2280009f094af0df3dcdc542cc46a5fd
commit-date: 2018-02-28
host: x86_64-apple-darwin
release: 1.26.0-nightly
LLVM version: 6.0

It no longer compiles on:

rustc 1.26.0-nightly (3eeb5a665 2018-03-01)
binary: rustc
commit-hash: 3eeb5a665e313c5b281820099e04d4c6c8188b46
commit-date: 2018-03-01
host: x86_64-apple-darwin
release: 1.26.0-nightly
LLVM version: 6.0

Was this not supposed to ever work or is this a regression?

@pietroalbini pietroalbini added A-lifetimes Area: Lifetimes / regions I-nominated regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 27, 2018
@bsteinb
Copy link
Author

bsteinb commented Mar 28, 2018

Oops, it seems I completely forgot to paste the resulting error message:

error[E0308]: mismatched types
 --> src/lib.rs:4:1
  |
4 | / pub struct Request<'a, S: Scope<'a> = StaticScope> {
5 | |     scope: S,
6 | |     phantom: PhantomData<Cell<&'a ()>>,
7 | | }
  | |_^ lifetime mismatch
  |
  = note: expected type `Scope<'a>`
             found type `Scope<'static>`
note: the lifetime 'a as defined on the struct at 4:1...
 --> src/lib.rs:4:1
  |
4 | pub struct Request<'a, S: Scope<'a> = StaticScope> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...does not necessarily outlive the static lifetime

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `rsmpi-request-lifetime-issue`.

To learn more, run the command again with --verbose.

Sorry about that. As mentioned in the original issue the problem can be worked around by not having the type parameter S default to StaticScope and instead always specify both parameters explicitly, e.g. Request<'static, StaticScope>

@nikomatsakis
Copy link
Contributor

I'm guessing this is caused by #46785 but I'm not sure yet

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Apr 5, 2018

cc @leodasvacas -- I think was something of an unexpected interaction, do you agree? I think we are probably checking that the default value (StaticScope) meets the bounds Scope<'a>, but we shouldn't be, because it talks about 'a.

@nikomatsakis
Copy link
Contributor

triage: P-high

@nikomatsakis nikomatsakis self-assigned this Apr 5, 2018
@leoyvens
Copy link
Contributor

leoyvens commented Apr 5, 2018

Yes it's a bug in that PR, we should not be doing this check in predicates with lifetimes, I'll work on a fix.

leoyvens added a commit to leoyvens/rust that referenced this issue Apr 5, 2018
bors added a commit that referenced this issue Apr 8, 2018
Fix regression in defaults #49344

Fixes #49344 by not checking the well-formedness wrt defaults of predicates that contain lifetimes, which is consistent with not checking generic predicates.

r? @nikomatsakis
leoyvens added a commit to leoyvens/rust that referenced this issue Apr 10, 2018
bors added a commit that referenced this issue Apr 14, 2018
[beta] Backport fix for regression in defaults

This proposes a backport of #49704, which fixes a regression that affects beta.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants