2015-04-16 07:48:31 -05:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-01-11 05:31:46 -06:00
|
|
|
// Test that negating unsigned integers doesn't compile
|
2015-04-16 07:48:31 -05:00
|
|
|
|
2015-07-13 17:03:24 -05:00
|
|
|
struct S;
|
|
|
|
impl std::ops::Neg for S {
|
|
|
|
type Output = u32;
|
|
|
|
fn neg(self) -> u32 { 0 }
|
|
|
|
}
|
|
|
|
|
2016-04-25 17:13:25 -05:00
|
|
|
// FIXME(eddyb) move this back to a `-1` literal when
|
|
|
|
// MIR building stops eagerly erroring in that case.
|
|
|
|
const _MAX: usize = -(2 - 1);
|
2016-04-01 02:19:29 -05:00
|
|
|
//~^ WARN unary negation of unsigned integer
|
|
|
|
//~| ERROR unary negation of unsigned integer
|
2016-01-11 05:31:46 -06:00
|
|
|
//~| HELP use a cast or the `!` operator
|
2015-04-16 07:48:31 -05:00
|
|
|
|
2015-07-13 17:03:24 -05:00
|
|
|
fn main() {
|
2015-12-16 11:44:15 -06:00
|
|
|
let x = 5u8;
|
|
|
|
let _y = -x; //~ ERROR unary negation of unsigned integer
|
2016-03-14 22:36:43 -05:00
|
|
|
//~^ HELP use a cast or the `!` operator
|
2015-07-13 17:03:24 -05:00
|
|
|
-S; // should not trigger the gate; issue 26840
|
|
|
|
}
|