From 5de094e579f8fa6c32df0690fd3e47a33c1cb6ef Mon Sep 17 00:00:00 2001 From: bobtwinkles Date: Thu, 1 Feb 2018 22:26:48 -0500 Subject: mir: Fix 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. --- src/test/ui/nll/trait-associated-constant.rs | 42 +++++++++++++++++++ src/test/ui/nll/trait-associated-constant.stderr | 52 ++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/test/ui/nll/trait-associated-constant.rs create mode 100644 src/test/ui/nll/trait-associated-constant.stderr (limited to 'src/test') 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 or the MIT license +// , 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..100e3362886 --- /dev/null +++ b/src/test/ui/nll/trait-associated-constant.stderr @@ -0,0 +1,52 @@ +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 { +31 | | const AC: Option<&'c str> = None; +32 | | //~^ ERROR: mismatched types +33 | | } + | |_^ +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 { +31 | | const AC: Option<&'c str> = None; +32 | | //~^ ERROR: mismatched types +33 | | } + | |_^ + +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 { +38 | | const AC: Option<&'a str> = None; +39 | | //~^ ERROR: mismatched types +40 | | } + | |_^ +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 { +38 | | const AC: Option<&'a str> = None; +39 | | //~^ ERROR: mismatched types +40 | | } + | |_^ + +error: aborting due to 2 previous errors + -- cgit 1.4.1-3-g733a5