Hide some lints which are not quite right the way they are reported to the user
This commit is contained in:
parent
1398572403
commit
ef5fba0067
2 changed files with 117 additions and 11 deletions
|
@ -144,18 +144,100 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
|
||||||
};
|
};
|
||||||
let r = match f(self) {
|
let r = match f(self) {
|
||||||
Ok(val) => Some(val),
|
Ok(val) => Some(val),
|
||||||
Err(err) => {
|
Err(error) => {
|
||||||
match err.kind {
|
let (stacktrace, span) = self.ecx.generate_stacktrace(None);
|
||||||
|
let diagnostic = ConstEvalErr { span, error, stacktrace };
|
||||||
|
use rustc::mir::interpret::EvalErrorKind::*;
|
||||||
|
match diagnostic.error.kind {
|
||||||
// don't report these, they make no sense in a const prop context
|
// don't report these, they make no sense in a const prop context
|
||||||
EvalErrorKind::MachineError(_) => {},
|
| MachineError(_)
|
||||||
_ => {
|
// at runtime these transformations might make sense
|
||||||
let (frames, span) = self.ecx.generate_stacktrace(None);
|
// FIXME: figure out the rules and start linting
|
||||||
let err = ConstEvalErr {
|
| FunctionPointerTyMismatch(..)
|
||||||
span,
|
// fine at runtime, might be a register address or sth
|
||||||
error: err,
|
| ReadBytesAsPointer
|
||||||
stacktrace: frames,
|
// fine at runtime
|
||||||
};
|
| ReadForeignStatic
|
||||||
err.report_as_lint(
|
| Unimplemented(_)
|
||||||
|
// don't report const evaluator limits
|
||||||
|
| StackFrameLimitReached
|
||||||
|
| NoMirFor(..)
|
||||||
|
| InlineAsm
|
||||||
|
=> {},
|
||||||
|
|
||||||
|
| InvalidMemoryAccess
|
||||||
|
| DanglingPointerDeref
|
||||||
|
| DoubleFree
|
||||||
|
| InvalidFunctionPointer
|
||||||
|
| InvalidBool
|
||||||
|
| InvalidDiscriminant
|
||||||
|
| PointerOutOfBounds { .. }
|
||||||
|
| InvalidNullPointerUsage
|
||||||
|
| MemoryLockViolation { .. }
|
||||||
|
| MemoryAcquireConflict { .. }
|
||||||
|
| ValidationFailure(..)
|
||||||
|
| InvalidMemoryLockRelease { .. }
|
||||||
|
| DeallocatedLockedMemory { .. }
|
||||||
|
| InvalidPointerMath
|
||||||
|
| ReadUndefBytes
|
||||||
|
| DeadLocal
|
||||||
|
| InvalidBoolOp(_)
|
||||||
|
| DerefFunctionPointer
|
||||||
|
| ExecuteMemory
|
||||||
|
| Intrinsic(..)
|
||||||
|
| InvalidChar(..)
|
||||||
|
| AbiViolation(_)
|
||||||
|
| AlignmentCheckFailed{..}
|
||||||
|
| CalledClosureAsFunction
|
||||||
|
| VtableForArgumentlessMethod
|
||||||
|
| ModifiedConstantMemory
|
||||||
|
| AssumptionNotHeld
|
||||||
|
// FIXME: should probably be removed and turned into a bug! call
|
||||||
|
| TypeNotPrimitive(_)
|
||||||
|
| ReallocatedWrongMemoryKind(_, _)
|
||||||
|
| DeallocatedWrongMemoryKind(_, _)
|
||||||
|
| ReallocateNonBasePtr
|
||||||
|
| DeallocateNonBasePtr
|
||||||
|
| IncorrectAllocationInformation(..)
|
||||||
|
| UnterminatedCString(_)
|
||||||
|
| HeapAllocZeroBytes
|
||||||
|
| HeapAllocNonPowerOfTwoAlignment(_)
|
||||||
|
| Unreachable
|
||||||
|
| ReadFromReturnPointer
|
||||||
|
| GeneratorResumedAfterReturn
|
||||||
|
| GeneratorResumedAfterPanic
|
||||||
|
| ReferencedConstant(_)
|
||||||
|
| InfiniteLoop
|
||||||
|
=> {
|
||||||
|
// FIXME: report UB here
|
||||||
|
},
|
||||||
|
|
||||||
|
| OutOfTls
|
||||||
|
| TlsOutOfBounds
|
||||||
|
| PathNotFound(_)
|
||||||
|
=> bug!("these should not be in rustc, but in miri's machine errors"),
|
||||||
|
|
||||||
|
| Layout(_)
|
||||||
|
| UnimplementedTraitSelection
|
||||||
|
| TypeckError
|
||||||
|
| TooGeneric
|
||||||
|
| CheckMatchError
|
||||||
|
// these are just noise
|
||||||
|
=> {},
|
||||||
|
|
||||||
|
// non deterministic
|
||||||
|
| ReadPointerAsBytes
|
||||||
|
// FIXME: implement
|
||||||
|
=> {},
|
||||||
|
|
||||||
|
| Panic
|
||||||
|
| BoundsCheck{..}
|
||||||
|
| Overflow(_)
|
||||||
|
| OverflowNeg
|
||||||
|
| DivisionByZero
|
||||||
|
| RemainderByZero
|
||||||
|
=> {
|
||||||
|
diagnostic.report_as_lint(
|
||||||
self.ecx.tcx,
|
self.ecx.tcx,
|
||||||
"this expression will panic at runtime",
|
"this expression will panic at runtime",
|
||||||
lint_root,
|
lint_root,
|
||||||
|
|
24
src/test/ui/const-eval/const_prop_errors.rs
Normal file
24
src/test/ui/const-eval/const_prop_errors.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// compile-pass
|
||||||
|
|
||||||
|
pub trait Foo {
|
||||||
|
fn foo(self) -> u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Foo for T {
|
||||||
|
fn foo(self) -> u32 {
|
||||||
|
fn bar<T>() { loop {} }
|
||||||
|
bar::<T> as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue