Auto merge of #47957 - bobtwinkles:fix_mir_consts, r=nikomatsakis

[NLL] Improve DefiningTy::Const

Fixes #47590 by fixing the way DefiningTy represents constants. Previously, constants were represented using just the type of the variable. However, this will fail to capture early-bound regions as NLL inference vars, resulting in an ICE when we try to compute region VIDs a little bit later in the universal
region resolution process. (ref #47590)
This commit is contained in:
bors 2018-02-07 14:54:15 +00:00
commit fee39ba8bd
4 changed files with 128 additions and 38 deletions

View file

@ -0,0 +1,42 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test cases where we put various lifetime constraints on trait
// associated constants.
#![feature(rustc_attrs)]
use std::option::Option;
trait Anything<'a: 'b, 'b> {
const AC: Option<&'b str>;
}
struct OKStruct { }
impl<'a: 'b, 'b> Anything<'a, 'b> for OKStruct {
const AC: Option<&'b str> = None;
}
struct FailStruct1 { }
impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
const AC: Option<&'c str> = None;
//~^ ERROR: mismatched types
}
struct FailStruct2 { }
impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
const AC: Option<&'a str> = None;
//~^ ERROR: mismatched types
}
fn main() {}

View file

@ -0,0 +1,40 @@
error[E0308]: mismatched types
--> $DIR/trait-associated-constant.rs:31:5
|
31 | const AC: Option<&'c str> = None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected type `std::option::Option<&'b str>`
found type `std::option::Option<&'c str>`
note: the lifetime 'c as defined on the impl at 30:1...
--> $DIR/trait-associated-constant.rs:30:1
|
30 | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 30:1
--> $DIR/trait-associated-constant.rs:30:1
|
30 | impl<'a: 'b, 'b, 'c> Anything<'a, 'b> for FailStruct1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types
--> $DIR/trait-associated-constant.rs:38:5
|
38 | const AC: Option<&'a str> = None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected type `std::option::Option<&'b str>`
found type `std::option::Option<&'a str>`
note: the lifetime 'a as defined on the impl at 37:1...
--> $DIR/trait-associated-constant.rs:37:1
|
37 | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...does not necessarily outlive the lifetime 'b as defined on the impl at 37:1
--> $DIR/trait-associated-constant.rs:37:1
|
37 | impl<'a: 'b, 'b> Anything<'a, 'b> for FailStruct2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors