Skip to content

Commit ef5fba0

Browse files
committed
Hide some lints which are not quite right the way they are reported to the user
1 parent 1398572 commit ef5fba0

File tree

2 files changed

+117
-11
lines changed

2 files changed

+117
-11
lines changed

src/librustc_mir/transform/const_prop.rs

+93-11
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,100 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
144144
};
145145
let r = match f(self) {
146146
Ok(val) => Some(val),
147-
Err(err) => {
148-
match err.kind {
147+
Err(error) => {
148+
let (stacktrace, span) = self.ecx.generate_stacktrace(None);
149+
let diagnostic = ConstEvalErr { span, error, stacktrace };
150+
use rustc::mir::interpret::EvalErrorKind::*;
151+
match diagnostic.error.kind {
149152
// don't report these, they make no sense in a const prop context
150-
EvalErrorKind::MachineError(_) => {},
151-
_ => {
152-
let (frames, span) = self.ecx.generate_stacktrace(None);
153-
let err = ConstEvalErr {
154-
span,
155-
error: err,
156-
stacktrace: frames,
157-
};
158-
err.report_as_lint(
153+
| MachineError(_)
154+
// at runtime these transformations might make sense
155+
// FIXME: figure out the rules and start linting
156+
| FunctionPointerTyMismatch(..)
157+
// fine at runtime, might be a register address or sth
158+
| ReadBytesAsPointer
159+
// fine at runtime
160+
| ReadForeignStatic
161+
| Unimplemented(_)
162+
// don't report const evaluator limits
163+
| StackFrameLimitReached
164+
| NoMirFor(..)
165+
| InlineAsm
166+
=> {},
167+
168+
| InvalidMemoryAccess
169+
| DanglingPointerDeref
170+
| DoubleFree
171+
| InvalidFunctionPointer
172+
| InvalidBool
173+
| InvalidDiscriminant
174+
| PointerOutOfBounds { .. }
175+
| InvalidNullPointerUsage
176+
| MemoryLockViolation { .. }
177+
| MemoryAcquireConflict { .. }
178+
| ValidationFailure(..)
179+
| InvalidMemoryLockRelease { .. }
180+
| DeallocatedLockedMemory { .. }
181+
| InvalidPointerMath
182+
| ReadUndefBytes
183+
| DeadLocal
184+
| InvalidBoolOp(_)
185+
| DerefFunctionPointer
186+
| ExecuteMemory
187+
| Intrinsic(..)
188+
| InvalidChar(..)
189+
| AbiViolation(_)
190+
| AlignmentCheckFailed{..}
191+
| CalledClosureAsFunction
192+
| VtableForArgumentlessMethod
193+
| ModifiedConstantMemory
194+
| AssumptionNotHeld
195+
// FIXME: should probably be removed and turned into a bug! call
196+
| TypeNotPrimitive(_)
197+
| ReallocatedWrongMemoryKind(_, _)
198+
| DeallocatedWrongMemoryKind(_, _)
199+
| ReallocateNonBasePtr
200+
| DeallocateNonBasePtr
201+
| IncorrectAllocationInformation(..)
202+
| UnterminatedCString(_)
203+
| HeapAllocZeroBytes
204+
| HeapAllocNonPowerOfTwoAlignment(_)
205+
| Unreachable
206+
| ReadFromReturnPointer
207+
| GeneratorResumedAfterReturn
208+
| GeneratorResumedAfterPanic
209+
| ReferencedConstant(_)
210+
| InfiniteLoop
211+
=> {
212+
// FIXME: report UB here
213+
},
214+
215+
| OutOfTls
216+
| TlsOutOfBounds
217+
| PathNotFound(_)
218+
=> bug!("these should not be in rustc, but in miri's machine errors"),
219+
220+
| Layout(_)
221+
| UnimplementedTraitSelection
222+
| TypeckError
223+
| TooGeneric
224+
| CheckMatchError
225+
// these are just noise
226+
=> {},
227+
228+
// non deterministic
229+
| ReadPointerAsBytes
230+
// FIXME: implement
231+
=> {},
232+
233+
| Panic
234+
| BoundsCheck{..}
235+
| Overflow(_)
236+
| OverflowNeg
237+
| DivisionByZero
238+
| RemainderByZero
239+
=> {
240+
diagnostic.report_as_lint(
159241
self.ecx.tcx,
160242
"this expression will panic at runtime",
161243
lint_root,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
13+
pub trait Foo {
14+
fn foo(self) -> u32;
15+
}
16+
17+
impl<T> Foo for T {
18+
fn foo(self) -> u32 {
19+
fn bar<T>() { loop {} }
20+
bar::<T> as u32
21+
}
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)