Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #63043

Merged
merged 27 commits into from
Jul 27, 2019
Merged
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8ba9b10
Fix cycle error with existential types
Aaron1011 Jul 5, 2019
ec62699
Fix bug when opaque type was nested in another type.
Aaron1011 Jul 5, 2019
2f05160
Remove unecessary doc comment
Aaron1011 Jul 5, 2019
2ab8d61
s/consts/`const` items/
Aaron1011 Jul 5, 2019
3600832
Address review comments
Aaron1011 Jul 5, 2019
66b2b97
Fix test stderr
Aaron1011 Jul 6, 2019
2f41962
Add explanation to 'existential_type_const' test
Aaron1011 Jul 6, 2019
44bf6b6
tests: Add minimal reproduction of #61963.
davidtwco Jul 20, 2019
eb4fbda
Simplify save-analysis JSON dumper interface
Mark-Simulacrum Jul 25, 2019
68c0ba2
Rename JsonDumper to Dumper
Mark-Simulacrum Jul 25, 2019
b75dfa8
Don't access a static just for its size and alignment
oli-obk Jul 25, 2019
d9ac0c6
Rewrite `get_size_and_align` so it doesn't duplicate work
oli-obk Jul 25, 2019
34e7a3c
Fix tidy
oli-obk Jul 26, 2019
3bc1d01
Clear up `get_size_and_align`
oli-obk Jul 26, 2019
796e7a8
Address review comments
oli-obk Jul 26, 2019
6e04ca7
Update src/librustc_mir/interpret/memory.rs
oli-obk Jul 26, 2019
0cd7167
Update src/librustc_mir/interpret/memory.rs
oli-obk Jul 26, 2019
d7b2110
add repr(transparent) to IoSliceMut where missing
nivkner Jul 26, 2019
cae8680
lowering: Omit bare trait lint on macro call sites
davidtwco Jul 26, 2019
13b4100
Add lib section to rustc_lexer's Cargo.toml
topecongiro Jul 27, 2019
98f29f5
Add comment
topecongiro Jul 27, 2019
4b8031c
Rollup merge of #62423 - Aaron1011:fix/existential-cycle, r=oli-obk
Centril Jul 27, 2019
a13f1f8
Rollup merge of #62979 - Mark-Simulacrum:json-dumper-pretty, r=Xanewok
Centril Jul 27, 2019
b25d74f
Rollup merge of #62982 - oli-obk:static_cycle, r=RalfJung
Centril Jul 27, 2019
4ad743c
Rollup merge of #63013 - nivkner:ffi-safe-slice, r=sfackler
Centril Jul 27, 2019
513ab54
Rollup merge of #63014 - davidtwco:rustfix-incorrect-dyn-suggestion, …
Centril Jul 27, 2019
51769b3
Rollup merge of #63036 - topecongiro:add-lib-section, r=matklad
Centril Jul 27, 2019
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
75 changes: 41 additions & 34 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
@@ -535,41 +535,48 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
id: AllocId,
liveness: AllocCheck,
) -> InterpResult<'static, (Size, Align)> {
// Regular allocations.
if let Ok(alloc) = self.get(id) {
return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align));
}
// Function pointers.
if let Ok(_) = self.get_fn_alloc(id) {
return if let AllocCheck::Dereferencable = liveness {
// The caller requested no function pointers.
err!(DerefFunctionPointer)
} else {
Ok((Size::ZERO, Align::from_bytes(1).unwrap()))
};
}
// Foreign statics.
// Can't do this in the match argument, we may get cycle errors since the lock would
// be held throughout the match.
let alloc = self.tcx.alloc_map.lock().get(id);
match alloc {
Some(GlobalAlloc::Static(did)) => {
assert!(self.tcx.is_foreign_item(did));
// Use size and align of the type
let ty = self.tcx.type_of(did);
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
return Ok((layout.size, layout.align.abi));
// Don't use `self.get` here as that will
// a) cause cycles in case `id` refers to a static
// b) duplicate a static's allocation in miri
match self.alloc_map.get_or(id, || Err(())) {
Ok((_, alloc)) => Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)),
Err(()) => {
// Not a local allocation, check the global `tcx.alloc_map`.

// Can't do this in the match argument, we may get cycle errors since the lock would
// be held throughout the match.
let alloc = self.tcx.alloc_map.lock().get(id);
match alloc {
Some(GlobalAlloc::Static(did)) => {
// Use size and align of the type.
let ty = self.tcx.type_of(did);
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
Ok((layout.size, layout.align.abi))
},
Some(GlobalAlloc::Memory(alloc)) =>
// Need to duplicate the logic here, because the global allocations have
// different associated types than the interpreter-local ones.
Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)),
Some(GlobalAlloc::Function(_)) => {
if let AllocCheck::Dereferencable = liveness {
// The caller requested no function pointers.
err!(DerefFunctionPointer)
} else {
Ok((Size::ZERO, Align::from_bytes(1).unwrap()))
}
},
// The rest must be dead.
None => if let AllocCheck::MaybeDead = liveness {
// Deallocated pointers are allowed, we should be able to find
// them in the map.
Ok(*self.dead_alloc_map.get(&id)
.expect("deallocated pointers should all be recorded in \
`dead_alloc_map`"))
} else {
err!(DanglingPointerDeref)
},
}
}
_ => {}
}
// The rest must be dead.
if let AllocCheck::MaybeDead = liveness {
// Deallocated pointers are allowed, we should be able to find
// them in the map.
Ok(*self.dead_alloc_map.get(&id)
.expect("deallocated pointers should all be recorded in `dead_alloc_map`"))
} else {
err!(DanglingPointerDeref)
}
}

11 changes: 11 additions & 0 deletions src/test/ui/consts/static-cycle-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass

struct Foo {
foo: Option<&'static Foo>
}

static FOO: Foo = Foo {
foo: Some(&FOO),
};

fn main() {}