Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a113609
keyword docs for else and inkeyword docs for else and in.
gilescope Dec 30, 2019
57f1bb1
clean up E0308 explanation
GuillaumeGomez Feb 13, 2020
64460a1
Update tests
GuillaumeGomez Mar 8, 2020
f5efb68
miri: categorize errors into "unsupported" and "UB"
RalfJung Mar 8, 2020
d02543a
fmt, tweak messages and bless
RalfJung Mar 8, 2020
9a95b01
generalize InvalidNullPointerUsage to InvalidIntPointerUsage
RalfJung Mar 8, 2020
3ebcd78
fmt, and fix rustfmt-induced rebase hickup
RalfJung Mar 8, 2020
2764d3d
start Miri messages lower-case
RalfJung Mar 9, 2020
3e61442
explain why we catch PointerUseAfterFree
RalfJung Mar 9, 2020
d8f8168
avoid boolean inversion
RalfJung Mar 9, 2020
9681422
we are on 2018 edition, use try block
RalfJung Mar 9, 2020
93436d8
make error message less confusing
RalfJung Mar 9, 2020
e219dd4
fmt
RalfJung Mar 11, 2020
b2779d8
Use smaller discriminants for generators
jonas-schievink Mar 9, 2020
4266807
Add a test for generator discriminants
jonas-schievink Mar 9, 2020
49aabd8
Fix rebase fallout
jonas-schievink Mar 14, 2020
73a625b
remove unnecessary hir::map imports
Centril Mar 11, 2020
4392a8b
use direct imports for `rustc::{lint, session}`.
Centril Mar 11, 2020
5a9ccc9
Remove `free_region_map` from `TypeckTables`
matthewjasper Nov 30, 2019
cefd030
Don't use `TypeckTables` in NiceRegionError
matthewjasper Feb 15, 2020
0a7f16e
Erase regions in writeback
matthewjasper Feb 15, 2020
1ee5829
Update tests for erasing regions in typeck
matthewjasper Feb 15, 2020
aa20d96
Don't prepend with space before paren
GuillaumeGomez Mar 17, 2020
429b16e
Make `newtype_index` methods const
ecstatic-morse Mar 10, 2020
7f5a284
Rename `from_u32_const` -> `from_u32`
ecstatic-morse Mar 10, 2020
cc4a577
Add requisite feature gates for const assert
ecstatic-morse Mar 10, 2020
9ac93ee
Hold index of generator `self` arg in `const`
ecstatic-morse Mar 10, 2020
81172d8
Update pretty tests
GuillaumeGomez Mar 17, 2020
9a017da
Update rustdoc test and remove TODO comment
GuillaumeGomez Mar 17, 2020
bc75cba
submod_path_from_attr: simplify & document
Centril Mar 7, 2020
2899a58
extract error_cannot_declare_mod_here
Centril Mar 7, 2020
185c1d3
extract error_decl_mod_in_block
Centril Mar 7, 2020
2db5d49
simplify submod_path
Centril Mar 7, 2020
803de31
submod_path: use id.span
Centril Mar 7, 2020
7108b7f
extract parse_mod
Centril Mar 7, 2020
dfcefa4
extract error_on_circular_module
Centril Mar 7, 2020
ca098b1
detach submod_path from Parser
Centril Mar 8, 2020
53a633f
decouple push_directory from Parser
Centril Mar 8, 2020
98e71cd
decouple eval_src_mod from Parser
Centril Mar 8, 2020
b9e1b26
expand: use push_directory
Centril Mar 8, 2020
8bab88f
de-fatalize outline module parsing
Centril Mar 8, 2020
463995f
extract parse_external_module
Centril Mar 8, 2020
59bf8a0
extract error_on_circular_module
Centril Mar 8, 2020
83a757a
outline modules: parse -> expand.
Centril Mar 8, 2020
f1ca996
parse: module parsing -> item.rs
Centril Mar 8, 2020
ddcc8ec
move Directory -> parser::module
Centril Mar 8, 2020
3796fae
{rustc_parse::parser -> rustc_expand}::module
Centril Mar 8, 2020
31ee8e0
{rustc_parse -> rustc_expand}::config
Centril Mar 8, 2020
a6cb04f
add test for stripped nested outline module
Centril Mar 8, 2020
7d0e5bb
parser/expand: minor cleanup
Centril Mar 9, 2020
fe71342
tweak outline module parsing spans
Centril Mar 9, 2020
41a0b3e
use pretty-compare-only in a test
Centril Mar 10, 2020
5ee4f6f
fix pre-expansion linting infra
Centril Mar 15, 2020
e301291
fix rebase fallout
Centril Mar 15, 2020
8caf688
--bless windows test
Centril Mar 17, 2020
287c4eb
Tidy: fix running rustfmt twice
ehuss Mar 18, 2020
5610684
Rollup merge of #67749 - gilescope:keyword-in, r=Dylan-DPC
Centril Mar 18, 2020
8188b21
Rollup merge of #69139 - GuillaumeGomez:cleanup-e0308, r=Dylan-DPC
Centril Mar 18, 2020
3f583fc
Rollup merge of #69189 - matthewjasper:erase-the-world, r=nikomatsakis
Centril Mar 18, 2020
4118ff6
Rollup merge of #69837 - jonas-schievink:gen-discr-opt, r=tmandry
Centril Mar 18, 2020
23b79d8
Rollup merge of #69838 - Centril:expand-module, r=petrochenkov
Centril Mar 18, 2020
a958314
Rollup merge of #69839 - RalfJung:miri-error-cleanup, r=oli-obk
Centril Mar 18, 2020
2521849
Rollup merge of #69899 - ecstatic-morse:const-idx-methods, r=oli-obk
Centril Mar 18, 2020
292c538
Rollup merge of #69920 - Centril:hir-cleanup, r=Zoxc
Centril Mar 18, 2020
60a2d06
Rollup merge of #70075 - GuillaumeGomez:fix-repr-display, r=petrochenkov
Centril Mar 18, 2020
b6f61a1
Rollup merge of #70106 - ehuss:fix-tidy-fmt-twice, r=Mark-Simulacrum
Centril Mar 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fmt, tweak messages and bless
  • Loading branch information
RalfJung committed Mar 11, 2020
commit d02543a453f0381c92339301fc86bcc08c70abcd
45 changes: 25 additions & 20 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_hir as hir;
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{Pos, Span, def_id::DefId};
use std::{any::Any, env, fmt};
use std::{any::Any, fmt};

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
pub enum ErrorHandled {
Expand Down Expand Up @@ -326,7 +326,10 @@ pub enum UndefinedBehaviorInfo {
/// An enum discriminant was set to a value which was outside the range of valid values.
InvalidDiscriminant(ScalarMaybeUndef),
/// A slice/array index projection went out-of-bounds.
BoundsCheckFailed { len: u64, index: u64 },
BoundsCheckFailed {
len: u64,
index: u64,
},
/// Something was divided by 0 (x / 0).
DivisionByZero,
/// Something was "remainded" by 0 (x % 0).
Expand Down Expand Up @@ -395,16 +398,14 @@ impl fmt::Debug for UndefinedBehaviorInfo {
"reading a null-terminated string starting at {:?} with no null found before end of allocation",
p,
),
PointerUseAfterFree(a) => write!(
f,
"pointer to allocation {:?} was dereferenced after allocation got freed",
a
),
PointerUseAfterFree(a) => {
write!(f, "pointer to {:?} was dereferenced after this allocation got freed", a)
}
InvalidNullPointerUsage => write!(f, "invalid use of NULL pointer"),
PointerOutOfBounds { ptr, msg, allocation_size } => write!(
f,
"{} failed: pointer must be in-bounds at offset {}, \
but is outside bounds of allocation {} which has size {}",
but is outside bounds of {} which has size {}",
msg,
ptr.offset.bytes(),
ptr.alloc_id,
Expand All @@ -416,16 +417,23 @@ impl fmt::Debug for UndefinedBehaviorInfo {
has.bytes(),
required.bytes()
),
WriteToReadOnly(a) => write!(f, "writing to read-only allocation {:?}", a),
WriteToReadOnly(a) => write!(f, "writing to {:?} which is read-only", a),
InvalidFunctionPointer(p) => {
write!(f, "using {:?} as function pointer but it does not point to a function", p)
}
DerefFunctionPointer(a) => write!(f, "accessing data behind function pointer allocation {:?}", a),
DerefFunctionPointer(a) => write!(f, "accessing {:?} which contains a function", a),
ValidationFailure(ref err) => write!(f, "type validation failed: {}", err),
InvalidBool(b) => write!(f, "interpreting an invalid 8-bit value as a bool: {}", b),
InvalidChar(c) => write!(f, "interpreting an invalid 32-bit value as a char: {}", c),
InvalidUndefBytes(Some(p)) => write!(f, "reading uninitialized memory at {:?}, but this operation requires initialized memory", p),
InvalidUndefBytes(None) => write!(f, "using uninitialized data, but this operation requires initialized memory"),
InvalidUndefBytes(Some(p)) => write!(
f,
"reading uninitialized memory at {:?}, but this operation requires initialized memory",
p
),
InvalidUndefBytes(None) => write!(
f,
"using uninitialized data, but this operation requires initialized memory"
),
DeadLocal => write!(f, "accessing a dead local variable"),
ReadFromReturnPlace => write!(f, "tried to read from the return place"),
}
Expand Down Expand Up @@ -472,21 +480,18 @@ impl fmt::Debug for UnsupportedOpInfo {
ConstPropUnsupported(ref msg) => {
write!(f, "Constant propagation encountered an unsupported situation: {}", msg)
}
ReadForeignStatic(did) => write!(f, "tried to read from foreign (extern) static {:?}", did),
ReadForeignStatic(did) => {
write!(f, "tried to read from foreign (extern) static {:?}", did)
}
NoMirFor(did) => write!(f, "could not load MIR for {:?}", did),
ModifiedStatic => write!(
f,
"tried to modify a static's initial value from another static's \
initializer"
),

ReadPointerAsBytes => write!(
f,
"unable to turn this pointer into raw bytes",
),
ReadBytesAsPointer => {
write!(f, "unable to turn these bytes into a pointer")
}
ReadPointerAsBytes => write!(f, "unable to turn this pointer into raw bytes",),
ReadBytesAsPointer => write!(f, "unable to turn these bytes into a pointer"),
}
}
}
Expand Down
29 changes: 22 additions & 7 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
kind: MemoryKind<M::MemoryKinds>,
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
if ptr.offset.bytes() != 0 {
throw_ub_format!("reallocating {:?} which does not point to the beginning of an object", ptr);
throw_ub_format!(
"reallocating {:?} which does not point to the beginning of an object",
ptr
);
}

// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
Expand Down Expand Up @@ -251,7 +254,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
trace!("deallocating: {}", ptr.alloc_id);

if ptr.offset.bytes() != 0 {
throw_ub_format!("deallocating {:?} which does not point to the beginning of an object", ptr);
throw_ub_format!(
"deallocating {:?} which does not point to the beginning of an object",
ptr
);
}

let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) {
Expand All @@ -260,22 +266,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// Deallocating static memory -- always an error
return Err(match self.tcx.alloc_map.lock().get(ptr.alloc_id) {
Some(GlobalAlloc::Function(..)) => err_ub_format!("deallocating a function"),
Some(GlobalAlloc::Static(..)) | Some(GlobalAlloc::Memory(..)) =>
err_ub_format!("deallocating static memory"),
Some(GlobalAlloc::Static(..)) | Some(GlobalAlloc::Memory(..)) => {
err_ub_format!("deallocating static memory")
}
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
}
.into());
}
};

if alloc_kind != kind {
throw_ub_format!("deallocating `{:?}` memory using `{:?}` deallocation operation", alloc_kind, kind);
throw_ub_format!(
"deallocating `{:?}` memory using `{:?}` deallocation operation",
alloc_kind,
kind
);
}
if let Some((size, align)) = old_size_and_align {
if size != alloc.size || align != alloc.align {
throw_ub_format!(
"incorrect layout on deallocation: allocation has size {} and alignment {}, but gave size {} and alignment {}",
alloc.size.bytes(), alloc.align.bytes(), size.bytes(), align.bytes(),
alloc.size.bytes(),
alloc.align.bytes(),
size.bytes(),
align.bytes(),
)
}
}
Expand Down Expand Up @@ -370,7 +384,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// It is sufficient to check this for the end pointer. The addition
// checks for overflow.
let end_ptr = ptr.offset(size, self)?;
if end_ptr.offset > allocation_size { // equal is okay!
if end_ptr.offset > allocation_size {
// equal is okay!
throw_ub!(PointerOutOfBounds { ptr: end_ptr.erase_tag(), msg, allocation_size })
}
// Test align. Check this last; if both bounds and alignment are violated
Expand Down
20 changes: 9 additions & 11 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,16 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
err_ub!(InvalidNullPointerUsage) => {
throw_validation_failure!(format_args!("a NULL {}", kind), self.path)
}
err_ub!(AlignmentCheckFailed { required, has }) => {
throw_validation_failure!(
format_args!(
"an unaligned {} \
err_ub!(AlignmentCheckFailed { required, has }) => throw_validation_failure!(
format_args!(
"an unaligned {} \
(required {} byte alignment but found {})",
kind,
required.bytes(),
has.bytes()
),
self.path
)
}
kind,
required.bytes(),
has.bytes()
),
self.path
),
err_unsup!(ReadBytesAsPointer) => throw_validation_failure!(
format_args!("a dangling {} (created from integer)", kind),
self.path
Expand Down
Loading