10000 Rollup of 10 pull requests by Dylan-DPC-zz · Pull Request #78232 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 10 pull requests #78232

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

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3b37d94
Add some tests
Nadrieril Oct 17, 2020
bb81110
Destructure byte array constants to array patterns instead of keeping…
oli-obk Sep 29, 2020
c3d0445
Destructure byte slices and remove all the workarounds
oli-obk Oct 1, 2020
99852e0
A ConstantValue constructor with a slice pattern is an error
Nadrieril Oct 17, 2020
3708c86
Treat booleans as integers with valid range 0..=1
oli-obk Oct 2, 2020
f504e9a
Fix comment
Nadrieril Oct 17, 2020
aa41720
Handle ranges of float consistently
Nadrieril Oct 17, 2020
d1a784e
Treat string literals separately from other constants
Nadrieril Oct 17, 2020
da0ba2f
The only remaining constant patterns are opaque
Nadrieril Oct 18, 2020
c4ae6c2
Add comment
Nadrieril Oct 18, 2020
13a5067
Unignore test
Oct 13, 2020
0558e6e
bootstrap: fall back to auto-detected CXX
jonas-schievink Oct 14, 2020
77a7ccf
bootstrap: configure native toolchain for run-make
jonas-schievink Oct 14, 2020
e36de6b
Move issue-36710 test to run-make
jonas-schievink Oct 14, 2020
a671604
Ignore test on WASM
jonas-schievink Oct 14, 2020
d7c7649
ignore-thumb
jonas-schievink Oct 16, 2020
60594b1
Ignore on 32-bit targets
Oct 19, 2020
2780e35
Throw core::panic!("message") as &str instead of String.
m-ou-se Oct 19, 2020
9890217
Fix ui test for updated core::panic behaviour.
m-ou-se Oct 19, 2020
d80f127
Avoid panic_bounds_check in fmt::write.
m-ou-se Oct 19, 2020
5bfd3e7
Accidentally fixed #78071
Nadrieril Oct 19, 2020
ea24395
Add debug_asserts for the unsafe indexing in fmt::write.
m-ou-se Oct 20, 2020
5948e62
Sync LLVM submodule if it has been initialized
est31 Oct 20, 2020
356d5b5
Add test to check for fmt::write bloat.
m-ou-se Oct 20, 2020
e852a4a
Update cargo
ehuss Oct 20, 2020
52640f2
[mir-opt] Allow debuginfo to be generated for a constant or a Place
wesleywiser May 30, 2020
2202653
Miri engine validity check: simplify code with 'matches!'
RalfJung Oct 21, 2020
fcaf233
Miri engine interning: improve comments, and entirely skip ZST
RalfJung Oct 21, 2020
3519411
Add a test for #53708
Nadrieril Oct 21, 2020
faf8710
Explain the `Opaque` special case in specialization
Nadrieril Oct 21, 2020
484d9eb
Move fmt-write-bloat test to run-make-fulldeps.
m-ou-se Oct 21, 2020
3a58ad9
Update `compiler_builtins` to 0.1.36
JohnTitor Oct 21, 2020
10d6f2d
Add regression test for #73298
varkor Oct 21, 2020
7fecaca
Rollup merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
Dylan-DPC Oct 22, 2020
80897de
Rollup merge of #77901 - jonas-schievink:unignore-test-36710, r=Mark-…
Dylan-DPC Oct 22, 2020
d08f484
Rollup merge of #78072 - Nadrieril:cleanup-constant-matching, r=varkor
Dylan-DPC Oct 22, 2020
4b223d7
Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r…
Dylan-DPC Oct 22, 2020
4816d30
Rollup merge of #78122 - fusion-engineering-forks:fmt-write-bounds-ch…
Dylan-DPC Oct 22, 2020
8b861e3
Rollup merge of #78153 - est31:downloaded_llvm_maybe_sync, r=Mark-Sim…
Dylan-DPC Oct 22, 2020
faa1d37
Rollup merge of #78169 - ehuss:update-cargo, r=ehuss
Dylan-DPC Oct 22, 2020
03a4fcb
Rollup merge of #78179 - RalfJung:miri-comments, r=oli-obk
Dylan-DPC Oct 22, 2020
db12963
Rollup merge of #78207 - varkor:issue-73298, r=lcnr
Dylan-DPC Oct 22, 2020
62ffb30
Rollup merge of #78209 - JohnTitor:compiler-builtins, r=Amanieu
Dylan-DPC Oct 22, 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
Destructure byte array constants to array patterns instead of keeping…
… them opaque
  • Loading branch information
oli-obk authored and Nadrieril committed Oct 18, 2020
commit bb8111069ed38455d915f7f8f0e050bb3c3720cf
32 changes: 4 additions & 28 deletions compiler/rustc_mir_build/src/thir/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,11 @@ use std::iter::{FromIterator, IntoIterator};
use std::ops::RangeInclusive;

crate fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> Pat<'tcx> {
LiteralExpander { tcx: cx.tcx, param_env: cx.param_env }.fold_pattern(&pat)
LiteralExpander { tcx: cx.tcx }.fold_pattern(&pat)
}

struct LiteralExpander<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
}

impl<'tcx> LiteralExpander<'tcx> {
Expand All @@ -328,40 +327,17 @@ impl<'tcx> LiteralExpander<'tcx> {
) -> ConstValue<'tcx> {
debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
match (val, &crty.kind(), &rty.kind()) {
// the easy case, deref a reference
(ConstValue::Scalar(p), x, y) if x == y => {
match p {
Scalar::Ptr(p) => {
let alloc = self.tcx.global_alloc(p.alloc_id).unwrap_memory();
ConstValue::ByRef { alloc, offset: p.offset }
}
Scalar::Raw { .. } => {
let layout = self.tcx.layout_of(self.param_env.and(rty)).unwrap();
if layout.is_zst() {
// Deref of a reference to a ZST is a nop.
ConstValue::Scalar(Scalar::zst())
} else {
// FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;`
bug!("cannot deref {:#?}, {} -> {}", val, crty, rty);
}
}
}
}
// unsize array to slice if pattern is array but match value or other patterns are slice
(ConstValue::Scalar(Scalar::Ptr(p)), ty::Array(t, n), ty::Slice(u)) => {
assert_eq!(t, u);
assert_eq!(p.offset, Size::ZERO);
ConstValue::Slice {
data: self.tcx.global_alloc(p.alloc_id).unwrap_memory(),
start: p.offset.bytes().try_into().unwrap(),
start: 0,
end: n.eval_usize(self.tcx, ty::ParamEnv::empty()).try_into().unwrap(),
}
}
// fat pointers stay the same
(ConstValue::Slice { .. }, _, _)
| (_, ty::Slice(_), ty::Slice(_))
| (_, ty::Str, ty::Str) => val,
// FIXME(oli-obk): this is reachable for `const FOO: &&&u32 = &&&42;` being used
_ => bug!("cannot deref {:#?}, {} -> {}", val, crty, rty),
_ => val,
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,14 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
ty::Slice(elem_ty) if elem_ty == tcx.types.u8 => PatKind::Constant { value: cv },
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
// matching against references, you can only use byte string literals.
// FIXME: clean this up, likely by permitting array patterns when matching on slices
ty::Array(elem_ty, _) if elem_ty == tcx.types.u8 => PatKind::Constant { value: cv },
// The typechecker has a special case for byte string literals, by treating them
// as slices. This means we turn `&[T; N]` constants into slice patterns, which
// has no negative effects on pattern matching, even if we're actually matching on
// arrays.
ty::Array(..) |
// Cannot merge this with the catch all branch below, because the `const_deref`
// changes the type from slice to array, and slice patterns behave differently from
// array patterns.
// changes the type from slice to array, we need to keep the original type in the
// pattern.
ty::Slice(..) => {
let old = self.behind_reference.replace(true);
let array = tcx.deref_const(self.param_env.and(cv));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ LL | match buf {
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8; 4]`

error[E0004]: non-exhaustive patterns: `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
error[E0004]: non-exhaustive patterns: `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered
--> $DIR/match-byte-array-patterns-2.rs:10:11
|
LL | match buf {
| ^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
| ^^^ patterns `&[0_u8..=64_u8, _, _, _]` and `&[66_u8..=u8::MAX, _, _, _]` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&[u8]`
Expand Down
0