Skip to content

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

Closed
@pnkfelix

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.

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