Fix and test upvar name printing for validity
This commit is contained in:
parent
69576fcdee
commit
c96eb706f0
3 changed files with 42 additions and 10 deletions
21
src/test/ui/consts/const-eval/ub-upvars.rs
Normal file
21
src/test/ui/consts/const-eval/ub-upvars.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// 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.
|
||||
|
||||
#![feature(const_transmute,const_let)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior
|
||||
let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
||||
let another_var = 13;
|
||||
move || { let _ = bad_ref; let _ = another_var; }
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/consts/const-eval/ub-upvars.stderr
Normal file
15
src/test/ui/consts/const-eval/ub-upvars.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error[E0080]: this constant likely exhibits undefined behavior
|
||||
--> $DIR/ub-upvars.rs:15:1
|
||||
|
|
||||
LL | / const BAD_UPVAR: &FnOnce() = &{ //~ ERROR this constant likely exhibits undefined behavior
|
||||
LL | | let bad_ref: &'static u16 = unsafe { mem::transmute(0usize) };
|
||||
LL | | let another_var = 13;
|
||||
LL | | move || { let _ = bad_ref; let _ = another_var; }
|
||||
LL | | };
|
||||
| |__^ type validation failed: encountered 0 at .<deref>.<closure-var(bad_ref)>, but expected something greater or equal to 1
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue