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 7 pull requests #67573

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4ee18c9
Clean up E0124 explanation
GuillaumeGomez Dec 22, 2019
1474d2a
Clean up E0128 explanation
GuillaumeGomez Dec 22, 2019
101dd7b
Use `is_none` instead of `if let`
JohnTitor Dec 22, 2019
7c485cc
Add test for issue-61747
JohnTitor Dec 22, 2019
96253c2
Add test for issue-66205
JohnTitor Dec 22, 2019
6ec3a63
Add test for issue-66270
JohnTitor Dec 22, 2019
256eec4
Update E0124.md
Dylan-DPC Dec 23, 2019
1485c16
Add long error code explanation message for E0627
ldm0 Dec 23, 2019
587d03b
Yield is an expression form, not a statement.
ldm0 Dec 23, 2019
24f3dcf
remove `description` from `Error` impls in docs
euclio Dec 23, 2019
1f2fa93
Add test for issue-67424
JohnTitor Dec 22, 2019
d918319
Apply suggestion from Centril
JohnTitor Dec 22, 2019
2536c75
Don't ICE on the use of integer addresses for ZST constants in patter…
oli-obk Dec 13, 2019
cc5cc67
Retire `to_ptr` which should already have no users but still kept get…
oli-obk Dec 13, 2019
8be7c54
Simplify `force_allocation_maybe_sized`
oli-obk Dec 13, 2019
53ca738
Comment on a few odd things that we should look at
oli-obk Dec 13, 2019
6976435
Prevent an ICE on invalid transmutes
oli-obk Dec 13, 2019
68ecc21
Interning even happens when validation of a constant fails
oli-obk Dec 14, 2019
c4f9215
Immediately evaluate and validate constants when we want them as oper…
oli-obk Dec 20, 2019
7ef8cf4
Add regression test for ZST statics being allowed to "read" from them…
oli-obk Dec 20, 2019
58eec17
Explain ParamEnv::reveal_all usage
oli-obk Dec 22, 2019
51937ef
Comments should start capitalized and end in a period
oli-obk Dec 22, 2019
5b278bc
Explain what we are doing with parameter environments for statics
oli-obk Dec 22, 2019
efbbc69
Explain the currently necessary existance of `TransmuteSizeDiff`
oli-obk Dec 22, 2019
405dbc6
Remove unintended noisy log statement
oli-obk Dec 22, 2019
eabe066
Typo
oli-obk Dec 22, 2019
af8ca7a
Explain why `const_eval` is ok here
oli-obk Dec 22, 2019
4c40bb7
Early abort instead of building up zero sized values
oli-obk Dec 22, 2019
09dd13c
Add a `const_eval` helper to `InterpCx`
oli-obk Dec 22, 2019
79960b4
Documentation nit
oli-obk Dec 22, 2019
e9dc860
Reintroduce the recursion comment
oli-obk Dec 22, 2019
aaf7015
Use the targetted const eval functions
oli-obk Dec 23, 2019
65bb805
Fix rebase fallout
oli-obk Dec 23, 2019
cefeb66
Use the chocolatey CDN directly to avoid the flaky API
aidanhs Dec 23, 2019
df4d490
Minimize unsafety in encode_utf8
Mark-Simulacrum Dec 23, 2019
318c52f
Rollup merge of #67192 - oli-obk:const_zst_addr, r=RalfJung,varkor
Mark-Simulacrum Dec 24, 2019
587f694
Rollup merge of #67543 - JohnTitor:regression-tests, r=Centril
Mark-Simulacrum Dec 24, 2019
93116b2
Rollup merge of #67547 - GuillaumeGomez:cleanup-err-codes, r=Dylan-DPC
Mark-Simulacrum Dec 24, 2019
8a1015f
Rollup merge of #67551 - ldm0:E0627, r=Dylan-DPC
Mark-Simulacrum Dec 24, 2019
b8b9a0f
Rollup merge of #67561 - euclio:remove-description, r=jonas-schievink
Mark-Simulacrum Dec 24, 2019
cb5e4ab
Rollup merge of #67569 - Mark-Simulacrum:opt-char-encode, r=oli-obk
Mark-Simulacrum Dec 24, 2019
37f97de
Rollup merge of #67572 - aidanhs:aphs-choco-direct-cdn, r=Mark-Simula…
Mark-Simulacrum Dec 24, 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
16 changes: 10 additions & 6 deletions src/ci/scripts/install-msys2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ IFS=$'\n\t'
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"

if isWindows; then
for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10; do
choco install msys2 \
--params="/InstallDir:$(ciCheckoutPath)/msys2 /NoPath" -y --no-progress \
&& mkdir -p "$(ciCheckoutPath)/msys2/home/${USERNAME}" \
&& ciCommandAddPath "$(ciCheckoutPath)/msys2/usr/bin" && break
done
# Pre-followed the api/v2 URL to the CDN since the API can be a bit flakey
curl -sSL https://packages.chocolatey.org/msys2.20190524.0.0.20191030.nupkg > \
msys2.nupkg
curl -sSL https://packages.chocolatey.org/chocolatey-core.extension.1.3.5.1.nupkg > \
chocolatey-core.extension.nupkg
choco install -s . msys2 \
--params="/InstallDir:$(ciCheckoutPath)/msys2 /NoPath" -y --no-progress
rm msys2.nupkg chocolatey-core.extension.nupkg
mkdir -p "$(ciCheckoutPath)/msys2/home/${USERNAME}"
ciCommandAddPath "$(ciCheckoutPath)/msys2/usr/bin"
fi
59 changes: 29 additions & 30 deletions src/libcore/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,36 +434,35 @@ impl char {
#[inline]
pub fn encode_utf8(self, dst: &mut [u8]) -> &mut str {
let code = self as u32;
// SAFETY: each arm checks the size of the slice and only uses `get_unchecked` unsafe ops
unsafe {
let len = if code < MAX_ONE_B && !dst.is_empty() {
*dst.get_unchecked_mut(0) = code as u8;
1
} else if code < MAX_TWO_B && dst.len() >= 2 {
*dst.get_unchecked_mut(0) = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
*dst.get_unchecked_mut(1) = (code & 0x3F) as u8 | TAG_CONT;
2
} else if code < MAX_THREE_B && dst.len() >= 3 {
*dst.get_unchecked_mut(0) = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
*dst.get_unchecked_mut(1) = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*dst.get_unchecked_mut(2) = (code & 0x3F) as u8 | TAG_CONT;
3
} else if dst.len() >= 4 {
*dst.get_unchecked_mut(0) = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
*dst.get_unchecked_mut(1) = (code >> 12 & 0x3F) as u8 | TAG_CONT;
*dst.get_unchecked_mut(2) = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*dst.get_unchecked_mut(3) = (code & 0x3F) as u8 | TAG_CONT;
4
} else {
panic!(
"encode_utf8: need {} bytes to encode U+{:X}, but the buffer has {}",
from_u32_unchecked(code).len_utf8(),
code,
dst.len(),
)
};
from_utf8_unchecked_mut(dst.get_unchecked_mut(..len))
}
let len = self.len_utf8();
match (len, &mut dst[..]) {
(1, [a, ..]) => {
*a = code as u8;
}
(2, [a, b, ..]) => {
*a = (code >> 6 & 0x1F) as u8 | TAG_TWO_B;
*b = (code & 0x3F) as u8 | TAG_CONT;
}
(3, [a, b, c, ..]) => {
*a = (code >> 12 & 0x0F) as u8 | TAG_THREE_B;
*b = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*c = (code & 0x3F) as u8 | TAG_CONT;
}
(4, [a, b, c, d, ..]) => {
*a = (code >> 18 & 0x07) as u8 | TAG_FOUR_B;
*b = (code >> 12 & 0x3F) as u8 | TAG_CONT;
*c = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*d = (code & 0x3F) as u8 | TAG_CONT;
}
_ => panic!(
"encode_utf8: need {} bytes to encode U+{:X}, but the buffer has {}",
len,
code,
dst.len(),
),
};
// SAFETY: We just wrote UTF-8 content in, so converting to str is fine.
unsafe { from_utf8_unchecked_mut(&mut dst[..len]) }
}

/// Encodes this character as UTF-16 into the provided `u16` buffer,
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![feature(slice_patterns)]

#[prelude_import]
#[allow(unused)]
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ pub enum UnsupportedOpInfo<'tcx> {
HeapAllocNonPowerOfTwoAlignment(u64),
ReadFromReturnPointer,
PathNotFound(Vec<String>),
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
}

impl fmt::Debug for UnsupportedOpInfo<'tcx> {
Expand Down Expand Up @@ -460,6 +461,11 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> {
passing data of type {:?}",
callee_ty, caller_ty
),
TransmuteSizeDiff(from_ty, to_ty) => write!(
f,
"tried to transmute from {:?} to {:?}, but their sizes differed",
from_ty, to_ty
),
FunctionRetMismatch(caller_ty, callee_ty) => write!(
f,
"tried to call a function with return type {:?} \
Expand Down
9 changes: 2 additions & 7 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ impl<'tcx, Tag> Scalar<Tag> {
}

/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
/// This method is intentionally private, do not make it public.
#[inline]
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
match self {
Scalar::Raw { data: 0, .. } => throw_unsup!(InvalidNullPointerUsage),
Scalar::Raw { .. } => throw_unsup!(ReadBytesAsPointer),
Expand Down Expand Up @@ -544,12 +545,6 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
}
}

/// Do not call this method! Use either `assert_ptr` or `force_ptr`.
#[inline(always)]
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
self.not_undef()?.to_ptr()
}

/// Do not call this method! Use either `assert_bits` or `force_bits`.
#[inline(always)]
pub fn to_bits(self, target_size: Size) -> InterpResult<'tcx, u128> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let span = self.tcx.def_span(generator_did);

// Do not ICE on closure typeck (#66868).
if let None = self.tcx.hir().as_local_hir_id(generator_did) {
if self.tcx.hir().as_local_hir_id(generator_did).is_none() {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
Ok(ConstValue::Scalar(a_val))
} else if let ty::FnPtr(_) = a.ty.kind {
let alloc_map = tcx.alloc_map.lock();
let a_instance = alloc_map.unwrap_fn(a_val.to_ptr().unwrap().alloc_id);
let b_instance = alloc_map.unwrap_fn(b_val.to_ptr().unwrap().alloc_id);
let a_instance = alloc_map.unwrap_fn(a_val.assert_ptr().alloc_id);
let b_instance = alloc_map.unwrap_fn(b_val.assert_ptr().alloc_id);
if a_instance == b_instance {
Ok(ConstValue::Scalar(a_val))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ E0622: include_str!("./error_codes/E0622.md"),
E0623: include_str!("./error_codes/E0623.md"),
E0624: include_str!("./error_codes/E0624.md"),
E0626: include_str!("./error_codes/E0626.md"),
E0627: include_str!("./error_codes/E0627.md"),
E0631: include_str!("./error_codes/E0631.md"),
E0633: include_str!("./error_codes/E0633.md"),
E0635: include_str!("./error_codes/E0635.md"),
Expand Down Expand Up @@ -574,7 +575,6 @@ E0745: include_str!("./error_codes/E0745.md"),
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
E0625, // thread-local statics cannot be accessed at compile-time
E0627, // yield statement outside of generator literal
E0628, // generators cannot have explicit parameters
E0629, // missing 'feature' (rustc_const_unstable)
// rustc_const_unstable attribute must be paired with stable/unstable
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_error_codes/error_codes/E0124.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
You declared two fields of a struct with the same name. Erroneous code
example:
A struct was declared with two fields having the same name.

Erroneous code example:

```compile_fail,E0124
struct Foo {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_error_codes/error_codes/E0128.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Type parameter defaults can only use parameters that occur before them.
A type parameter with default value is using forward declared identifier.

Erroneous code example:

```compile_fail,E0128
Expand All @@ -7,11 +8,11 @@ struct Foo<T = U, U = ()> {
field2: U,
}
// error: type parameters with a default cannot use forward declared
// identifiers
// identifiers
```

Since type parameters are evaluated in-order, you may be able to fix this issue
by doing:
Type parameter defaults can only use parameters that occur before them. Since
type parameters are evaluated in-order, this issue could be fixed by doing:

```
struct Foo<U = (), T = U> {
Expand Down
30 changes: 30 additions & 0 deletions src/librustc_error_codes/error_codes/E0627.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
A yield expression was used outside of the generator literal.

Erroneous code example:

```compile_fail,E0627
#![feature(generators, generator_trait)]

fn fake_generator() -> &'static str {
yield 1;
return "foo"
}

fn main() {
let mut generator = fake_generator;
}
```

The error occurs because keyword `yield` can only be used inside the generator
literal. This can be fixed by constructing the generator correctly.

```
#![feature(generators, generator_trait)]

fn main() {
let mut generator = || {
yield 1;
return "foo"
};
}
```
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}

/// Reports an error if this is a borrow of local data.
/// This is called for all Yield statements on movable generators
/// This is called for all Yield expressions on movable generators
fn check_for_local_borrow(&mut self, borrow: &BorrowData<'tcx>, yield_span: Span) {
debug!("check_for_local_borrow({:?})", borrow);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub(super) fn is_active<'tcx>(
}

/// Determines if a given borrow is borrowing local data
/// This is called for all Yield statements on movable generators
/// This is called for all Yield expressions on movable generators
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
match place.base {
PlaceBase::Static(_) => false,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn op_to_const<'tcx>(
};
let val = match immediate {
Ok(mplace) => {
let ptr = mplace.ptr.to_ptr().unwrap();
let ptr = mplace.ptr.assert_ptr();
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
ConstValue::ByRef { alloc, offset: ptr.offset }
},
Expand All @@ -99,7 +99,7 @@ fn op_to_const<'tcx>(
// comes from a constant so it can happen have `Undef`, because the indirect
// memory that was read had undefined bytes.
let mplace = op.assert_mem_place();
let ptr = mplace.ptr.to_ptr().unwrap();
let ptr = mplace.ptr.assert_ptr();
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
ConstValue::ByRef { alloc, offset: ptr.offset }
},
Expand Down Expand Up @@ -626,7 +626,7 @@ fn validate_and_turn_into_const<'tcx>(
// whether they become immediates.
let def_id = cid.instance.def.def_id();
if tcx.is_static(def_id) || cid.promoted.is_some() {
let ptr = mplace.ptr.to_ptr()?;
let ptr = mplace.ptr.assert_ptr();
Ok(tcx.mk_const(ty::Const {
val: ty::ConstKind::Value(ConstValue::ByRef {
alloc: ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),
Expand Down
50 changes: 40 additions & 10 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ use syntax_pos::{Span, DUMMY_SP};
use arena::TypedArena;

use smallvec::{smallvec, SmallVec};
use std::borrow::Cow;
use std::cmp::{self, max, min, Ordering};
use std::convert::TryInto;
use std::fmt;
Expand All @@ -260,11 +261,12 @@ use std::ops::RangeInclusive;
use std::u128;

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

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

impl LiteralExpander<'tcx> {
Expand All @@ -284,9 +286,23 @@ impl LiteralExpander<'tcx> {
debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
match (val, &crty.kind, &rty.kind) {
// the easy case, deref a reference
(ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => {
let alloc = self.tcx.alloc_map.lock().unwrap_memory(p.alloc_id);
ConstValue::ByRef { alloc, offset: p.offset }
(ConstValue::Scalar(p), x, y) if x == y => {
match p {
Scalar::Ptr(p) => {
let alloc = self.tcx.alloc_map.lock().unwrap_memory(p.alloc_id);
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)) => {
Expand Down Expand Up @@ -2348,16 +2364,30 @@ fn specialize_one_pattern<'p, 'tcx>(
// just integers. The only time they should be pointing to memory
// is when they are subslices of nonzero slices.
let (alloc, offset, n, ty) = match value.ty.kind {
ty::Array(t, n) => match value.val {
ty::ConstKind::Value(ConstValue::ByRef { offset, alloc, .. }) => {
(alloc, offset, n.eval_usize(cx.tcx, cx.param_env), t)
ty::Array(t, n) => {
let n = n.eval_usize(cx.tcx, cx.param_env);
// Shortcut for `n == 0` where no matter what `alloc` and `offset` we produce,
// the result would be exactly what we early return here.
if n == 0 {
if ctor_wild_subpatterns.len() as u64 == 0 {
return Some(PatStack::from_slice(&[]));
} else {
return None;
}
}
_ => span_bug!(pat.span, "array pattern is {:?}", value,),
},
match value.val {
ty::ConstKind::Value(ConstValue::ByRef { offset, alloc, .. }) => {
(Cow::Borrowed(alloc), offset, n, t)
}
_ => span_bug!(pat.span, "array pattern is {:?}", value,),
}
}
ty::Slice(t) => {
match value.val {
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => {
(data, Size::from_bytes(start as u64), (end - start) as u64, t)
let offset = Size::from_bytes(start as u64);
let n = (end - start) as u64;
(Cow::Borrowed(data), offset, n, t)
}
ty::ConstKind::Value(ConstValue::ByRef { .. }) => {
// FIXME(oli-obk): implement `deref` for `ConstValue`
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,12 @@ pub fn compare_const_vals<'tcx>(
return fallback();
}

// Early return for equal constants (so e.g. references to ZSTs can be compared, even if they
// are just integer addresses).
if a.val == b.val {
return from_bool(true);
}

let a_bits = a.try_eval_bits(tcx, param_env, ty);
let b_bits = b.try_eval_bits(tcx, param_env, ty);

Expand Down
Loading