Skip to content

NLL may be mishandling _ within type-ascription expression form  #57731

Closed

Description

@pnkfelix

Adapted from examples given on #55748. Note that observing this bug requires use of feature(type_ascription) and therefore is not high priority.

consider the following code (play):

#![feature(nll, type_ascription)]

#![allow(dead_code, unused_mut)]
type PairCoupledTypes<T> = (T, T);

#[cfg(this_is_just_here_for_comparison_it_behaves_same_with_and_without_nll)]
fn coupled_types_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
    let ((y, _z),) = ((s, &_x),): (PairCoupledTypes<&u32>,);
    y //~ ERROR unsatisfied lifetime constraints
}

fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
    let ((y, _z),) = ((s, &_x),): (PairCoupledTypes<_>,);
    y //~ ERROR unsatisfied lifetime constraints
}

fn main() {}

Right now, as written, this compiles without error. (Note that fn coupled_types_rhs is not included; that function will error with and without NLL.)

If you remove the nll in the feature declaration, the code for fn coupled_wilds_rhs is rejected.

This is an indication that either:

  1. NLL has a bug in how it is handling _ in the type-ascription expression form EXPR: TYPE, or
  2. there exists some argument that fn coupled_wilds_rhs should be accepted (and that NLL is correct in accepting it), but I do not see how such an argument exists that would not also imply that we should be seeing the same behavior in fn coupled_types_rhs.

Activity

  1. matthewjasper commented on Jan 18, 2019

    @matthewjasper
    Contributor

    I had a brief look, the annotation is dropped before we get to NLL. Probably here:

    if ty.has_free_regions() || ty.has_projections() {
    let c_ty = self.infcx.canonicalize_response(&UserTypeAnnotation::Ty(ty));
    debug!("to_ty_saving_user_provided_ty: c_ty={:?}", c_ty);
    self.tables.borrow_mut().user_provided_types_mut().insert(ast_ty.hir_id, c_ty);
    }

  2. added
    NLL-soundWorking towards the "invalid code does not compile" goal
    on Jan 19, 2019
  3. matthewjasper commented on Jan 21, 2019

    @matthewjasper
    Contributor

    This also applies to casts, so it is visble on stable:

    fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
        let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,);
        y //~ ERROR unsatisfied lifetime constraints
    }
  4. pnkfelix commented on Jan 25, 2019

    @pnkfelix
    ContributorAuthor

    so it is visble on stable

    type ascription is feature-gated though, no?

  5. pnkfelix commented on Jan 25, 2019

    @pnkfelix
    ContributorAuthor

    (or did you mean to use as, as in ((s, _x),) as (PairCoupledTypes<_>,), in your example?)

  6. matthewjasper commented on Jan 25, 2019

    @matthewjasper
    Contributor

    Yes, it should be as in the example.

  7. added a commit that references this issue on Jan 25, 2019
    0b1669d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)NLL-soundWorking towards the "invalid code does not compile" goal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions