diff options
| author | bors <bors@rust-lang.org> | 2018-02-07 14:54:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-02-07 14:54:15 +0000 |
| commit | fee39ba8bd98f5b93c60de51336830fa7f0b9d97 (patch) | |
| tree | 00127a3bc17f717ab08c2951c7ccc81d02b3a884 /src/test | |
| parent | 4f93357d3b8938dfe439329c43c1e4f919a70869 (diff) | |
| parent | e99f8fcbc5ea4cf839575bc7ca56151147346a54 (diff) | |
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)
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/nll/trait-associated-constant.rs | 42 | ||||
| -rw-r--r-- | src/test/ui/nll/trait-associated-constant.stderr | 40 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/test/ui/nll/trait-associated-constant.rs b/src/test/ui/nll/trait-associated-constant.rs new file mode 100644 index 00000000000..b0f5fbf7160 --- /dev/null +++ b/src/test/ui/nll/trait-associated-constant.rs @@ -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() {} diff --git a/src/test/ui/nll/trait-associated-constant.stderr b/src/test/ui/nll/trait-associated-constant.stderr new file mode 100644 index 00000000000..21c1a6ded93 --- /dev/null +++ b/src/test/ui/nll/trait-associated-constant.stderr @@ -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 + |
