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 13 pull requests #73498

Merged
merged 47 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit Hold shift click to select a range
730f736
Fix asinh of negative values
Ralith May 23, 2020
f7d745f
tag/niche terminology cleanup
RalfJung May 23, 2020
7a6d03c
miri errors: rename InvalidDiscriminant -> InvalidTag
RalfJung May 30, 2020
20abc70
Don't intern memory in const prop.
oli-obk Jun 3, 2020
1e88f13
Stop allowing `Indirect(..)` values to be propagated
wesleywiser Jun 8, 2020
9ceb9bb
Move copying of self-contained objects to new function
mati865 Jun 2, 2020
638ebbc
Move copying of MinGW CRT to the better location
mati865 Jun 2, 2020
961974f
Use enum to distinguish dependency type
mati865 Jun 2, 2020
5d29883
Move some libs to self-contained directory
mati865 Jun 11, 2020
e9ac01a
Get self-contained directory path via dedicated function
mati865 Jun 8, 2020
43905cd
Move shipped MinGW linker to self-contained dir
mati865 Jun 8, 2020
d5ea0e9
Report error when casting an C-like enum implementing Drop
oddg May 15, 2020
e32db84
Add rust features to print target features
aszenz Jun 14, 2020
a40156e
UI test for deprecation warning of casting enum implementing Drop
oddg Jun 14, 2020
0906066
Test that bounds checks are elided when slice len is checked up-front
erikdesjardins Jun 15, 2020
d3ca6fd
Enable static-pie for the x86_64-unknown-linux-musl target
haraldh Jun 15, 2020
b5809b0
Update src/librustc_typeck/check/cast.rs
nikomatsakis Jun 15, 2020
10c8d2a
add FIXME to EnumTagInfo
RalfJung Jun 15, 2020
e0975b9
elaborate, add check for exact bounds
erikdesjardins Jun 15, 2020
f3dfe80
Adjust error message
oddg Jun 16, 2020
1990f97
Disallow loading crates with non-ascii identifier name.
crlf0710 Jun 13, 2020
4506a35
add header for rust specific feature
aszenz Jun 16, 2020
9f50f84
break long line for formatting
aszenz Jun 16, 2020
457acbd
trim whitespace
aszenz Jun 16, 2020
caffb28
add blank line bw sections
aszenz Jun 17, 2020
6351850
ignore-debug: debug assertions in slice indexing prevent the optimiza…
erikdesjardins Jun 17, 2020
a7c2cf8
Reduce pointer casts in Box::into_boxed_slice
cuviper Jun 17, 2020
d134870
Document format correction
qy3u Jun 18, 2020
abb5800
Ensure std benchmarks get tested.
ehuss Jun 8, 2020
8aecafe
Fix liballoc doc spelling
pickfire Jun 18, 2020
ec8ff1c
Liballoc clean up macro_rules style
pickfire Jun 18, 2020
111c2d2
Rearrange liballoc __impl_slice_eq1
pickfire Jun 18, 2020
5a9ff05
Disable core benches on wasm (benches not supported).
ehuss Jun 18, 2020
35a2915
Remove now-redundant branch
Ralith Jun 19, 2020
27d4737
Rollup merge of #70740 - haraldh:static-pie, r=petrochenkov
RalfJung Jun 19, 2020
9c54c65
Rollup merge of #72331 - oddg:forbid-cast-of-cenum-implementing-drop,…
RalfJung Jun 19, 2020
99be102
Rollup merge of #72486 - Ralith:asinh-fix, r=dtolnay
RalfJung Jun 19, 2020
5e7eec2
Rollup merge of #72497 - RalfJung:tag-term, r=oli-obk
RalfJung Jun 19, 2020
ea3c309
Rollup merge of #72999 - mati865:separate-self-contained-dir, r=Mark-…
RalfJung Jun 19, 2020
098949b
Rollup merge of #73130 - wesleywiser:remove_const_prop_for_indirects,…
RalfJung Jun 19, 2020
78f3e9c
Rollup merge of #73142 - ehuss:std-benches, r=dtolnay
RalfJung Jun 19, 2020
3b4bec2
Rollup merge of #73305 - crlf0710:disallow_loading_monsters, r=petroc…
RalfJung Jun 19, 2020
8d79ebd
Rollup merge of #73346 - aszenz:patch-1, r=cuviper
RalfJung Jun 19, 2020
7d3238f
Rollup merge of #73362 - erikdesjardins:bounds, r=nikomatsakis
RalfJung Jun 19, 2020
fc2ce7c
Rollup merge of #73459 - cuviper:into_boxed_slice-unicast, r=dtolnay
RalfJung Jun 19, 2020
f7d833e
Rollup merge of #73464 - qy3u:fs-document-format-correction, r=jonas-…
RalfJung Jun 19, 2020
028c908
Rollup merge of #73479 - pickfire:liballoc-spell, r=dtolnay
RalfJung Jun 19, 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
11 changes: 11 additions & 0 deletions src/librustc_session/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 534,16 @@ declare_lint! {
@feature_gate = sym::unsafe_block_in_unsafe_fn;
}

declare_lint! {
pub CENUM_IMPL_DROP_CAST,
Warn,
"a C-like enum implementing Drop is cast",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
edition: None,
};
}

declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
Expand Down Expand Up @@ -607,6 617,7 @@ declare_lint_pass! {
ASM_SUB_REGISTER,
UNSAFE_OP_IN_UNSAFE_FN,
INCOMPLETE_INCLUDE,
CENUM_IMPL_DROP_CAST,
]
}

Expand Down
30 changes: 27 additions & 3 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 678,10 @@ impl<'a, 'tcx> CastCheck<'tcx> {
(FnPtr, Ptr(mt)) => self.check_fptr_ptr_cast(fcx, mt),

// prim -> prim
(Int(CEnum), Int(_)) => Ok(CastKind::EnumCast),
(Int(CEnum), Int(_)) => {
self.cenum_impl_drop_lint(fcx);
Ok(CastKind::EnumCast)
}
(Int(Char) | Int(Bool), Int(_)) => Ok(CastKind::PrimIntCast),

(Int(_) | Float, Int(_) | Float) => Ok(CastKind::NumericCast),
Expand Down Expand Up @@ -775,11 778,13 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// Coerce to a raw pointer so that we generate AddressOf in MIR.
let array_ptr_type = fcx.tcx.mk_ptr(m_expr);
fcx.try_coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No)
.unwrap_or_else(|_| bug!(
.unwrap_or_else(|_| {
bug!(
"could not cast from reference to array to pointer to array ({:?} to {:?})",
self.expr_ty,
array_ptr_type,
));
)
});

// this will report a type mismatch if needed
fcx.demand_eqtype(self.span, ety, m_cast.ty);
Expand Down Expand Up @@ -809,6 814,25 @@ impl<'a, 'tcx> CastCheck<'tcx> {
Err(err) => Err(err),
}
}

fn cenum_impl_drop_lint(&self, fcx: &FnCtxt<'a, 'tcx>) {
if let ty::Adt(d, _) = self.expr_ty.kind {
if d.has_dtor(fcx.tcx) {
fcx.tcx.struct_span_lint_hir(
lint::builtin::CENUM_IMPL_DROP_CAST,
self.expr.hir_id,
self.span,
|err| {
err.build(&format!(
"cannot cast enum `{}` into integer `{}` because it implements `Drop`",
self.expr_ty, self.cast_ty
))
.emit();
},
);
}
}
}
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/cenum_impl_drop_cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,18 @@
#![deny(cenum_impl_drop_cast)]

enum E {
A = 0,
}

impl Drop for E {
fn drop(&mut self) {
println!("Drop");
}
}

fn main() {
let e = E::A;
let i = e as u32;
//~^ ERROR cannot cast enum `E` into integer `u32` because it implements `Drop`
//~| WARN this was previously accepted
}
16 changes: 16 additions & 0 deletions src/test/ui/cenum_impl_drop_cast.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,16 @@
error: cannot cast enum `E` into integer `u32` because it implements `Drop`
--> $DIR/cenum_impl_drop_cast.rs:15:13
|
LL | let i = e as u32;
| ^^^^^^^^
|
note: the lint level is defined here
--> $DIR/cenum_impl_drop_cast.rs:1:9
|
LL | #![deny(cenum_impl_drop_cast)]
| ^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333>

error: aborting due to previous error