Auto merge of #64616 - Centril:rollup-du6728f, r=Centril
Rollup of 6 pull requests Successful merges: - #63448 (fix Miri discriminant handling) - #64592 (Point at original span when emitting unreachable lint) - #64601 (Fix backticks in documentation) - #64606 (Remove unnecessary `mut` in doc example) - #64611 (rustbuild: Don't package libstd twice) - #64613 (rustbuild: Copy crate doc files fewer times) Failed merges: r? @ghost
This commit is contained in:
commit
53b352edb6
@ -762,7 +762,7 @@ impl Step for Analysis {
|
||||
return distdir(builder).join(format!("{}-{}.tar.gz", name, target));
|
||||
}
|
||||
|
||||
builder.ensure(Std { compiler, target });
|
||||
builder.ensure(compile::Std { compiler, target });
|
||||
|
||||
let image = tmpdir(builder).join(format!("{}-{}-image", name, target));
|
||||
|
||||
|
@ -476,11 +476,11 @@ impl Step for Std {
|
||||
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
|
||||
|
||||
builder.run(&mut cargo);
|
||||
builder.cp_r(&my_out, &out);
|
||||
};
|
||||
for krate in &["alloc", "core", "std", "proc_macro", "test"] {
|
||||
run_cargo_rustdoc_for(krate);
|
||||
}
|
||||
builder.cp_r(&my_out, &out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1136,7 +1136,7 @@ fn resolve_local<'tcx>(
|
||||
// Rule A. `let (ref x, ref y) = (foo().x, 44)`. The rvalue `(22, 44)`
|
||||
// would have an extended lifetime, but not `foo()`.
|
||||
//
|
||||
// Rule B. `let x = &foo().x`. The rvalue ``foo()` would have extended
|
||||
// Rule B. `let x = &foo().x`. The rvalue `foo()` would have extended
|
||||
// lifetime.
|
||||
//
|
||||
// In some cases, multiple rules may apply (though not to the same
|
||||
|
@ -127,6 +127,7 @@ impl IntegerExt for Integer {
|
||||
|
||||
pub trait PrimitiveExt {
|
||||
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>;
|
||||
fn to_int_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>;
|
||||
}
|
||||
|
||||
impl PrimitiveExt for Primitive {
|
||||
@ -138,6 +139,16 @@ impl PrimitiveExt for Primitive {
|
||||
Pointer => tcx.mk_mut_ptr(tcx.mk_unit()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return an *integer* type matching this primitive.
|
||||
/// Useful in particular when dealing with enum discriminants.
|
||||
fn to_int_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match *self {
|
||||
Int(i, signed) => i.to_ty(tcx, signed),
|
||||
Pointer => tcx.types.usize,
|
||||
Float(..) => bug!("floats do not have an int type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The first half of a fat pointer.
|
||||
|
@ -643,7 +643,7 @@ impl<'a, 'tcx> SpecializedDecoder<DefIndex> for CacheDecoder<'a, 'tcx> {
|
||||
|
||||
// Both the `CrateNum` and the `DefIndex` of a `DefId` can change in between two
|
||||
// compilation sessions. We use the `DefPathHash`, which is stable across
|
||||
// sessions, to map the old DefId`` to the new one.
|
||||
// sessions, to map the old `DefId` to the new one.
|
||||
impl<'a, 'tcx> SpecializedDecoder<DefId> for CacheDecoder<'a, 'tcx> {
|
||||
#[inline]
|
||||
fn specialized_decode(&mut self) -> Result<DefId, Self::Error> {
|
||||
|
@ -1,11 +1,11 @@
|
||||
//! Functions concerning immediate values and operands, and reading from operands.
|
||||
//! All high-level functions to read from memory work on operands as sources.
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::convert::{TryInto, TryFrom};
|
||||
|
||||
use rustc::{mir, ty};
|
||||
use rustc::ty::layout::{
|
||||
self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, VariantIdx,
|
||||
self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt, PrimitiveExt, VariantIdx,
|
||||
};
|
||||
|
||||
use rustc::mir::interpret::{
|
||||
@ -609,15 +609,20 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
) -> InterpResult<'tcx, (u128, VariantIdx)> {
|
||||
trace!("read_discriminant_value {:#?}", rval.layout);
|
||||
|
||||
let (discr_kind, discr_index) = match rval.layout.variants {
|
||||
let (discr_layout, discr_kind, discr_index) = match rval.layout.variants {
|
||||
layout::Variants::Single { index } => {
|
||||
let discr_val = rval.layout.ty.discriminant_for_variant(*self.tcx, index).map_or(
|
||||
index.as_u32() as u128,
|
||||
|discr| discr.val);
|
||||
return Ok((discr_val, index));
|
||||
}
|
||||
layout::Variants::Multiple { ref discr_kind, discr_index, .. } =>
|
||||
(discr_kind, discr_index),
|
||||
layout::Variants::Multiple {
|
||||
discr: ref discr_layout,
|
||||
ref discr_kind,
|
||||
discr_index,
|
||||
..
|
||||
} =>
|
||||
(discr_layout, discr_kind, discr_index),
|
||||
};
|
||||
|
||||
// read raw discriminant value
|
||||
@ -634,7 +639,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
.map_err(|_| err_unsup!(InvalidDiscriminant(raw_discr.erase_tag())))?;
|
||||
let real_discr = if discr_val.layout.ty.is_signed() {
|
||||
// going from layout tag type to typeck discriminant type
|
||||
// requires first sign extending with the layout discriminant
|
||||
// requires first sign extending with the discriminant layout
|
||||
let sexted = sign_extend(bits_discr, discr_val.layout.size) as i128;
|
||||
// and then zeroing with the typeck discriminant type
|
||||
let discr_ty = rval.layout.ty
|
||||
@ -666,8 +671,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
ref niche_variants,
|
||||
niche_start,
|
||||
} => {
|
||||
let variants_start = niche_variants.start().as_u32() as u128;
|
||||
let variants_end = niche_variants.end().as_u32() as u128;
|
||||
let variants_start = niche_variants.start().as_u32();
|
||||
let variants_end = niche_variants.end().as_u32();
|
||||
let raw_discr = raw_discr.not_undef().map_err(|_| {
|
||||
err_unsup!(InvalidDiscriminant(ScalarMaybeUndef::Undef))
|
||||
})?;
|
||||
@ -682,18 +687,34 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
(dataful_variant.as_u32() as u128, dataful_variant)
|
||||
},
|
||||
Ok(raw_discr) => {
|
||||
let adjusted_discr = raw_discr.wrapping_sub(niche_start)
|
||||
.wrapping_add(variants_start);
|
||||
if variants_start <= adjusted_discr && adjusted_discr <= variants_end {
|
||||
let index = adjusted_discr as usize;
|
||||
assert_eq!(index as u128, adjusted_discr);
|
||||
assert!(index < rval.layout.ty
|
||||
// We need to use machine arithmetic to get the relative variant idx:
|
||||
// variant_index_relative = discr_val - niche_start_val
|
||||
let discr_layout = self.layout_of(discr_layout.value.to_int_ty(*self.tcx))?;
|
||||
let discr_val = ImmTy::from_uint(raw_discr, discr_layout);
|
||||
let niche_start_val = ImmTy::from_uint(niche_start, discr_layout);
|
||||
let variant_index_relative_val = self.binary_op(
|
||||
mir::BinOp::Sub,
|
||||
discr_val,
|
||||
niche_start_val,
|
||||
)?;
|
||||
let variant_index_relative = variant_index_relative_val
|
||||
.to_scalar()?
|
||||
.assert_bits(discr_val.layout.size);
|
||||
// Check if this is in the range that indicates an actual discriminant.
|
||||
if variant_index_relative <= u128::from(variants_end - variants_start) {
|
||||
let variant_index_relative = u32::try_from(variant_index_relative)
|
||||
.expect("we checked that this fits into a u32");
|
||||
// Then computing the absolute variant idx should not overflow any more.
|
||||
let variant_index = variants_start
|
||||
.checked_add(variant_index_relative)
|
||||
.expect("oveflow computing absolute variant idx");
|
||||
assert!((variant_index as usize) < rval.layout.ty
|
||||
.ty_adt_def()
|
||||
.expect("tagged layout for non adt")
|
||||
.variants.len());
|
||||
(adjusted_discr, VariantIdx::from_usize(index))
|
||||
(u128::from(variant_index), VariantIdx::from_u32(variant_index))
|
||||
} else {
|
||||
(dataful_variant.as_u32() as u128, dataful_variant)
|
||||
(u128::from(dataful_variant.as_u32()), dataful_variant)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -8,7 +8,9 @@ use std::hash::Hash;
|
||||
use rustc::mir;
|
||||
use rustc::mir::interpret::truncate;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx};
|
||||
use rustc::ty::layout::{
|
||||
self, Size, Align, LayoutOf, TyLayout, HasDataLayout, VariantIdx, PrimitiveExt
|
||||
};
|
||||
use rustc::ty::TypeFoldable;
|
||||
|
||||
use super::{
|
||||
@ -1027,7 +1029,7 @@ where
|
||||
}
|
||||
layout::Variants::Multiple {
|
||||
discr_kind: layout::DiscriminantKind::Tag,
|
||||
ref discr,
|
||||
discr: ref discr_layout,
|
||||
discr_index,
|
||||
..
|
||||
} => {
|
||||
@ -1038,7 +1040,7 @@ where
|
||||
// raw discriminants for enums are isize or bigger during
|
||||
// their computation, but the in-memory tag is the smallest possible
|
||||
// representation
|
||||
let size = discr.value.size(self);
|
||||
let size = discr_layout.value.size(self);
|
||||
let discr_val = truncate(discr_val, size);
|
||||
|
||||
let discr_dest = self.place_field(dest, discr_index as u64)?;
|
||||
@ -1050,6 +1052,7 @@ where
|
||||
ref niche_variants,
|
||||
niche_start,
|
||||
},
|
||||
discr: ref discr_layout,
|
||||
discr_index,
|
||||
..
|
||||
} => {
|
||||
@ -1057,15 +1060,24 @@ where
|
||||
variant_index.as_usize() < dest.layout.ty.ty_adt_def().unwrap().variants.len(),
|
||||
);
|
||||
if variant_index != dataful_variant {
|
||||
let niche_dest =
|
||||
self.place_field(dest, discr_index as u64)?;
|
||||
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
|
||||
let niche_value = (niche_value as u128)
|
||||
.wrapping_add(niche_start);
|
||||
self.write_scalar(
|
||||
Scalar::from_uint(niche_value, niche_dest.layout.size),
|
||||
niche_dest
|
||||
let variants_start = niche_variants.start().as_u32();
|
||||
let variant_index_relative = variant_index.as_u32()
|
||||
.checked_sub(variants_start)
|
||||
.expect("overflow computing relative variant idx");
|
||||
// We need to use machine arithmetic when taking into account `niche_start`:
|
||||
// discr_val = variant_index_relative + niche_start_val
|
||||
let discr_layout = self.layout_of(discr_layout.value.to_int_ty(*self.tcx))?;
|
||||
let niche_start_val = ImmTy::from_uint(niche_start, discr_layout);
|
||||
let variant_index_relative_val =
|
||||
ImmTy::from_uint(variant_index_relative, discr_layout);
|
||||
let discr_val = self.binary_op(
|
||||
mir::BinOp::Add,
|
||||
variant_index_relative_val,
|
||||
niche_start_val,
|
||||
)?;
|
||||
// Write result.
|
||||
let niche_dest = self.place_field(dest, discr_index as u64)?;
|
||||
self.write_immediate(*discr_val, niche_dest)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
// If there are no arms, that is a diverging match; a special case.
|
||||
if arms.is_empty() {
|
||||
self.diverges.set(self.diverges.get() | Diverges::Always);
|
||||
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
|
||||
return tcx.types.never;
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// warnings).
|
||||
match all_pats_diverge {
|
||||
Diverges::Maybe => Diverges::Maybe,
|
||||
Diverges::Always | Diverges::WarnedAlways => Diverges::WarnedAlways,
|
||||
Diverges::Always { .. } | Diverges::WarnedAlways => Diverges::WarnedAlways,
|
||||
}
|
||||
}).collect();
|
||||
|
||||
@ -167,6 +167,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
prior_arm_ty = Some(arm_ty);
|
||||
}
|
||||
|
||||
// If all of the arms in the `match` diverge,
|
||||
// and we're dealing with an actual `match` block
|
||||
// (as opposed to a `match` desugared from something else'),
|
||||
// we can emit a better note. Rather than pointing
|
||||
// at a diverging expression in an arbitrary arm,
|
||||
// we can point at the entire `match` expression
|
||||
if let (Diverges::Always { .. }, hir::MatchSource::Normal) = (all_arms_diverge, match_src) {
|
||||
all_arms_diverge = Diverges::Always {
|
||||
span: expr.span,
|
||||
custom_note: Some(
|
||||
"any code following this `match` expression is unreachable, as all arms diverge"
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// We won't diverge unless the discriminant or all arms diverge.
|
||||
self.diverges.set(discrim_diverges | all_arms_diverge);
|
||||
|
||||
@ -176,7 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// When the previously checked expression (the scrutinee) diverges,
|
||||
/// warn the user about the match arms being unreachable.
|
||||
fn warn_arms_when_scrutinee_diverges(&self, arms: &'tcx [hir::Arm], source: hir::MatchSource) {
|
||||
if self.diverges.get().always() {
|
||||
if self.diverges.get().is_always() {
|
||||
use hir::MatchSource::*;
|
||||
let msg = match source {
|
||||
IfDesugar { .. } | IfLetDesugar { .. } => "block in `if` expression",
|
||||
|
@ -170,7 +170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
// Any expression that produces a value of type `!` must have diverged
|
||||
if ty.is_never() {
|
||||
self.diverges.set(self.diverges.get() | Diverges::Always);
|
||||
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
|
||||
}
|
||||
|
||||
// Record the type, which applies it effects.
|
||||
|
@ -450,7 +450,20 @@ pub enum Diverges {
|
||||
|
||||
/// Definitely known to diverge and therefore
|
||||
/// not reach the next sibling or its parent.
|
||||
Always,
|
||||
Always {
|
||||
/// The `Span` points to the expression
|
||||
/// that caused us to diverge
|
||||
/// (e.g. `return`, `break`, etc).
|
||||
span: Span,
|
||||
/// In some cases (e.g. a `match` expression
|
||||
/// where all arms diverge), we may be
|
||||
/// able to provide a more informative
|
||||
/// message to the user.
|
||||
/// If this is `None`, a default messsage
|
||||
/// will be generated, which is suitable
|
||||
/// for most cases.
|
||||
custom_note: Option<&'static str>
|
||||
},
|
||||
|
||||
/// Same as `Always` but with a reachability
|
||||
/// warning already emitted.
|
||||
@ -486,8 +499,22 @@ impl ops::BitOrAssign for Diverges {
|
||||
}
|
||||
|
||||
impl Diverges {
|
||||
fn always(self) -> bool {
|
||||
self >= Diverges::Always
|
||||
/// Creates a `Diverges::Always` with the provided `span` and the default note message.
|
||||
fn always(span: Span) -> Diverges {
|
||||
Diverges::Always {
|
||||
span,
|
||||
custom_note: None
|
||||
}
|
||||
}
|
||||
|
||||
fn is_always(self) -> bool {
|
||||
// Enum comparison ignores the
|
||||
// contents of fields, so we just
|
||||
// fill them in with garbage here.
|
||||
self >= Diverges::Always {
|
||||
span: DUMMY_SP,
|
||||
custom_note: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2307,17 +2334,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// Produces warning on the given node, if the current point in the
|
||||
/// function is unreachable, and there hasn't been another warning.
|
||||
fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) {
|
||||
if self.diverges.get() == Diverges::Always &&
|
||||
// FIXME: Combine these two 'if' expressions into one once
|
||||
// let chains are implemented
|
||||
if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() {
|
||||
// If span arose from a desugaring of `if` or `while`, then it is the condition itself,
|
||||
// which diverges, that we are about to lint on. This gives suboptimal diagnostics.
|
||||
// Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
|
||||
!span.is_desugaring(DesugaringKind::CondTemporary) {
|
||||
self.diverges.set(Diverges::WarnedAlways);
|
||||
if !span.is_desugaring(DesugaringKind::CondTemporary) {
|
||||
self.diverges.set(Diverges::WarnedAlways);
|
||||
|
||||
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
|
||||
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
|
||||
|
||||
let msg = format!("unreachable {}", kind);
|
||||
self.tcx().lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, &msg);
|
||||
let msg = format!("unreachable {}", kind);
|
||||
self.tcx().struct_span_lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, &msg)
|
||||
.span_note(
|
||||
orig_span,
|
||||
custom_note.unwrap_or("any code following this expression is unreachable")
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3825,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
//
|
||||
// #41425 -- label the implicit `()` as being the
|
||||
// "found type" here, rather than the "expected type".
|
||||
if !self.diverges.get().always() {
|
||||
if !self.diverges.get().is_always() {
|
||||
// #50009 -- Do not point at the entire fn block span, point at the return type
|
||||
// span, as it is the cause of the requirement, and
|
||||
// `consider_hint_about_removing_semicolon` will point at the last expression
|
||||
|
@ -935,7 +935,7 @@ impl Stdio {
|
||||
/// .expect("Failed to spawn child process");
|
||||
///
|
||||
/// {
|
||||
/// let mut stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
||||
/// let stdin = child.stdin.as_mut().expect("Failed to open stdin");
|
||||
/// stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin");
|
||||
/// }
|
||||
///
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! of source parsed during crate parsing (typically files, in-memory strings,
|
||||
//! or various bits of macro expansion) cover a continuous range of bytes in the
|
||||
//! `SourceMap` and are represented by `SourceFile`s. Byte positions are stored in
|
||||
//! `Span`` and used pervasively in the compiler. They are absolute positions
|
||||
//! `Span` and used pervasively in the compiler. They are absolute positions
|
||||
//! within the `SourceMap`, which upon request can be converted to line and column
|
||||
//! information, source code snippets, etc.
|
||||
|
||||
@ -645,7 +645,7 @@ impl SourceMap {
|
||||
}
|
||||
|
||||
/// Given a `Span`, tries to get a shorter span ending before the first occurrence of `char`
|
||||
/// ``c`.
|
||||
/// `c`.
|
||||
pub fn span_until_char(&self, sp: Span, c: char) -> Span {
|
||||
match self.span_to_snippet(sp) {
|
||||
Ok(snippet) => {
|
||||
|
@ -31,7 +31,7 @@ impl <'a> SpanlessHash<'a> {
|
||||
//
|
||||
// Not okay without two-phase borrows: the implicit
|
||||
// `&mut self` of the receiver is evaluated first, and
|
||||
// that conflicts with the `self.cx`` access during
|
||||
// that conflicts with the `self.cx` access during
|
||||
// argument evaluation, as demonstrated in `fn demo`
|
||||
// above.
|
||||
//
|
||||
|
110
src/test/ui/consts/miri_unleashed/enum_discriminants.rs
Normal file
110
src/test/ui/consts/miri_unleashed/enum_discriminants.rs
Normal file
@ -0,0 +1,110 @@
|
||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||
// run-pass
|
||||
|
||||
//! Make sure that we read and write enum discriminants correctly for corner cases caused
|
||||
//! by layout optimizations.
|
||||
|
||||
const OVERFLOW: usize = {
|
||||
// Tests for https://github.com/rust-lang/rust/issues/62138.
|
||||
#[repr(u8)]
|
||||
#[allow(dead_code)]
|
||||
enum WithWraparoundInvalidValues {
|
||||
X = 1,
|
||||
Y = 254,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum Foo {
|
||||
A,
|
||||
B,
|
||||
C(WithWraparoundInvalidValues),
|
||||
}
|
||||
|
||||
let x = Foo::B;
|
||||
match x {
|
||||
Foo::B => 0,
|
||||
_ => panic!(),
|
||||
}
|
||||
};
|
||||
|
||||
const MORE_OVERFLOW: usize = {
|
||||
pub enum Infallible {}
|
||||
|
||||
// The check that the `bool` field of `V1` is encoding a "niche variant"
|
||||
// (i.e. not `V1`, so `V3` or `V4`) used to be mathematically incorrect,
|
||||
// causing valid `V1` values to be interpreted as other variants.
|
||||
#[allow(dead_code)]
|
||||
pub enum E1 {
|
||||
V1 { f: bool },
|
||||
V2 { f: Infallible },
|
||||
V3,
|
||||
V4,
|
||||
}
|
||||
|
||||
// Computing the discriminant used to be done using the niche type (here `u8`,
|
||||
// from the `bool` field of `V1`), overflowing for variants with large enough
|
||||
// indices (`V3` and `V4`), causing them to be interpreted as other variants.
|
||||
#[allow(dead_code)]
|
||||
pub enum E2<X> {
|
||||
V1 { f: bool },
|
||||
|
||||
/*_00*/ _01(X), _02(X), _03(X), _04(X), _05(X), _06(X), _07(X),
|
||||
_08(X), _09(X), _0A(X), _0B(X), _0C(X), _0D(X), _0E(X), _0F(X),
|
||||
_10(X), _11(X), _12(X), _13(X), _14(X), _15(X), _16(X), _17(X),
|
||||
_18(X), _19(X), _1A(X), _1B(X), _1C(X), _1D(X), _1E(X), _1F(X),
|
||||
_20(X), _21(X), _22(X), _23(X), _24(X), _25(X), _26(X), _27(X),
|
||||
_28(X), _29(X), _2A(X), _2B(X), _2C(X), _2D(X), _2E(X), _2F(X),
|
||||
_30(X), _31(X), _32(X), _33(X), _34(X), _35(X), _36(X), _37(X),
|
||||
_38(X), _39(X), _3A(X), _3B(X), _3C(X), _3D(X), _3E(X), _3F(X),
|
||||
_40(X), _41(X), _42(X), _43(X), _44(X), _45(X), _46(X), _47(X),
|
||||
_48(X), _49(X), _4A(X), _4B(X), _4C(X), _4D(X), _4E(X), _4F(X),
|
||||
_50(X), _51(X), _52(X), _53(X), _54(X), _55(X), _56(X), _57(X),
|
||||
_58(X), _59(X), _5A(X), _5B(X), _5C(X), _5D(X), _5E(X), _5F(X),
|
||||
_60(X), _61(X), _62(X), _63(X), _64(X), _65(X), _66(X), _67(X),
|
||||
_68(X), _69(X), _6A(X), _6B(X), _6C(X), _6D(X), _6E(X), _6F(X),
|
||||
_70(X), _71(X), _72(X), _73(X), _74(X), _75(X), _76(X), _77(X),
|
||||
_78(X), _79(X), _7A(X), _7B(X), _7C(X), _7D(X), _7E(X), _7F(X),
|
||||
_80(X), _81(X), _82(X), _83(X), _84(X), _85(X), _86(X), _87(X),
|
||||
_88(X), _89(X), _8A(X), _8B(X), _8C(X), _8D(X), _8E(X), _8F(X),
|
||||
_90(X), _91(X), _92(X), _93(X), _94(X), _95(X), _96(X), _97(X),
|
||||
_98(X), _99(X), _9A(X), _9B(X), _9C(X), _9D(X), _9E(X), _9F(X),
|
||||
_A0(X), _A1(X), _A2(X), _A3(X), _A4(X), _A5(X), _A6(X), _A7(X),
|
||||
_A8(X), _A9(X), _AA(X), _AB(X), _AC(X), _AD(X), _AE(X), _AF(X),
|
||||
_B0(X), _B1(X), _B2(X), _B3(X), _B4(X), _B5(X), _B6(X), _B7(X),
|
||||
_B8(X), _B9(X), _BA(X), _BB(X), _BC(X), _BD(X), _BE(X), _BF(X),
|
||||
_C0(X), _C1(X), _C2(X), _C3(X), _C4(X), _C5(X), _C6(X), _C7(X),
|
||||
_C8(X), _C9(X), _CA(X), _CB(X), _CC(X), _CD(X), _CE(X), _CF(X),
|
||||
_D0(X), _D1(X), _D2(X), _D3(X), _D4(X), _D5(X), _D6(X), _D7(X),
|
||||
_D8(X), _D9(X), _DA(X), _DB(X), _DC(X), _DD(X), _DE(X), _DF(X),
|
||||
_E0(X), _E1(X), _E2(X), _E3(X), _E4(X), _E5(X), _E6(X), _E7(X),
|
||||
_E8(X), _E9(X), _EA(X), _EB(X), _EC(X), _ED(X), _EE(X), _EF(X),
|
||||
_F0(X), _F1(X), _F2(X), _F3(X), _F4(X), _F5(X), _F6(X), _F7(X),
|
||||
_F8(X), _F9(X), _FA(X), _FB(X), _FC(X), _FD(X), _FE(X), _FF(X),
|
||||
|
||||
V3,
|
||||
V4,
|
||||
}
|
||||
|
||||
if let E1::V2 { .. } = (E1::V1 { f: true }) {
|
||||
unreachable!()
|
||||
}
|
||||
if let E1::V1 { .. } = (E1::V1 { f: true }) {
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
if let E2::V1 { .. } = E2::V3::<Infallible> {
|
||||
unreachable!()
|
||||
}
|
||||
if let E2::V3 { .. } = E2::V3::<Infallible> {
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
0
|
||||
};
|
||||
|
||||
fn main() {
|
||||
assert_eq!(OVERFLOW, 0);
|
||||
assert_eq!(MORE_OVERFLOW, 0);
|
||||
}
|
72
src/test/ui/consts/miri_unleashed/enum_discriminants.stderr
Normal file
72
src/test/ui/consts/miri_unleashed/enum_discriminants.stderr
Normal file
@ -0,0 +1,72 @@
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:23:13
|
||||
|
|
||||
LL | let x = Foo::B;
|
||||
| ^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:25:9
|
||||
|
|
||||
LL | Foo::B => 0,
|
||||
| ^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:88:28
|
||||
|
|
||||
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:88:12
|
||||
|
|
||||
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:108:5
|
||||
|
|
||||
LL | assert_eq!(OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:108:5
|
||||
|
|
||||
LL | assert_eq!(OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:108:5
|
||||
|
|
||||
LL | assert_eq!(OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:109:5
|
||||
|
|
||||
LL | assert_eq!(MORE_OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:109:5
|
||||
|
|
||||
LL | assert_eq!(MORE_OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: skipping const checks
|
||||
--> $DIR/enum_discriminants.rs:109:5
|
||||
|
|
||||
LL | assert_eq!(MORE_OVERFLOW, 0);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/dead-code-ret.rs:6:5
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -5,4 +5,9 @@ LL | fn foo() { if (return) { } }
|
||||
| ^^^
|
||||
|
|
||||
= note: `#[warn(unreachable_code)]` on by default
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/if-ret.rs:6:15
|
||||
|
|
||||
LL | fn foo() { if (return) { } }
|
||||
| ^^^^^^^^
|
||||
|
||||
|
@ -9,6 +9,12 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/issue-2150.rs:7:5
|
||||
|
|
||||
LL | panic!();
|
||||
| ^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/issue-7246.rs:6:5
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #[deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/lint-attr-non-item-node.rs:6:9
|
||||
|
|
||||
LL | break;
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -10,6 +10,11 @@ note: lint level defined here
|
||||
LL | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/liveness-unused.rs:91:9
|
||||
|
|
||||
LL | continue;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: unused variable: `x`
|
||||
--> $DIR/liveness-unused.rs:8:7
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/match-no-arms-unreachable-after.rs:7:5
|
||||
|
|
||||
LL | match v { }
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -10,12 +10,24 @@ note: lint level defined here
|
||||
LL | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/never-assign-dead-code.rs:9:16
|
||||
|
|
||||
LL | let x: ! = panic!("aah");
|
||||
| ^^^^^^^^^^^^^
|
||||
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
warning: unreachable call
|
||||
--> $DIR/never-assign-dead-code.rs:10:5
|
||||
|
|
||||
LL | drop(x);
|
||||
| ^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/never-assign-dead-code.rs:10:10
|
||||
|
|
||||
LL | drop(x);
|
||||
| ^
|
||||
|
||||
warning: unused variable: `x`
|
||||
--> $DIR/never-assign-dead-code.rs:9:9
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_add.rs:17:19
|
||||
|
|
||||
LL | let x = Foo + return;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_again.rs:7:9
|
||||
|
|
||||
LL | continue;
|
||||
| ^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_array.rs:9:26
|
||||
|
|
||||
LL | let x: [usize; 2] = [return, 22];
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_array.rs:14:25
|
||||
|
|
||||
LL | let x: [usize; 2] = [22, return];
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_array.rs:14:30
|
||||
|
|
||||
LL | let x: [usize; 2] = [22, return];
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,18 +9,35 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_assign.rs:10:9
|
||||
|
|
||||
LL | x = return;
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_assign.rs:20:14
|
||||
|
|
||||
LL | *p = return;
|
||||
| ^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_assign.rs:20:9
|
||||
|
|
||||
LL | *p = return;
|
||||
| ^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_assign.rs:26:15
|
||||
|
|
||||
LL | *{return; &mut i} = 22;
|
||||
| ^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_assign.rs:26:7
|
||||
|
|
||||
LL | *{return; &mut i} = 22;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_block.rs:9:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_block.rs:25:9
|
||||
@ -16,6 +21,11 @@ error: unreachable statement
|
||||
LL | println!("foo");
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_block.rs:24:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_box.rs:6:17
|
||||
|
|
||||
LL | let x = box return;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_call.rs:13:9
|
||||
|
|
||||
LL | foo(return, 22);
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable call
|
||||
--> $DIR/expr_call.rs:18:5
|
||||
|
|
||||
LL | bar(return);
|
||||
| ^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_call.rs:18:9
|
||||
|
|
||||
LL | bar(return);
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_cast.rs:9:14
|
||||
|
|
||||
LL | let x = {return} as !;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -12,6 +12,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_if.rs:7:9
|
||||
|
|
||||
LL | if {return} {
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable statement
|
||||
--> $DIR/expr_if.rs:27:5
|
||||
@ -19,6 +24,11 @@ error: unreachable statement
|
||||
LL | println!("But I am.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_if.rs:21:9
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_loop.rs:7:12
|
||||
|
|
||||
LL | loop { return; }
|
||||
| ^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: unreachable statement
|
||||
@ -17,6 +22,11 @@ error: unreachable statement
|
||||
LL | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_loop.rs:20:12
|
||||
|
|
||||
LL | loop { return; }
|
||||
| ^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: unreachable statement
|
||||
@ -25,6 +35,11 @@ error: unreachable statement
|
||||
LL | println!("I am dead.");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_loop.rs:31:5
|
||||
|
|
||||
LL | loop { 'middle: loop { loop { break 'middle; } } }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this `match` expression is unreachable, as all arms diverge
|
||||
--> $DIR/expr_match.rs:7:5
|
||||
|
|
||||
LL | match () { () => return }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: unreachable statement
|
||||
@ -17,6 +22,11 @@ error: unreachable statement
|
||||
LL | println!("I am dead");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this `match` expression is unreachable, as all arms diverge
|
||||
--> $DIR/expr_match.rs:18:5
|
||||
|
|
||||
LL | match () { () if false => return, () => return }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_method.rs:16:13
|
||||
|
|
||||
LL | Foo.foo(return, 22);
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable call
|
||||
--> $DIR/expr_method.rs:21:9
|
||||
|
|
||||
LL | Foo.bar(return);
|
||||
| ^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_method.rs:21:13
|
||||
|
|
||||
LL | Foo.bar(return);
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_repeat.rs:9:26
|
||||
|
|
||||
LL | let x: [usize; 2] = [return; 2];
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_return.rs:10:30
|
||||
|
|
||||
LL | let x = {return {return {return;}}};
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
15
src/test/ui/reachable/expr_return_in_macro.rs
Normal file
15
src/test/ui/reachable/expr_return_in_macro.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Tests that we generate nice error messages
|
||||
// when an expression is unreachble due to control
|
||||
// flow inside of a macro expansion.
|
||||
#![deny(unreachable_code)]
|
||||
|
||||
macro_rules! early_return {
|
||||
() => {
|
||||
return ()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
return early_return!();
|
||||
//~^ ERROR unreachable expression
|
||||
}
|
22
src/test/ui/reachable/expr_return_in_macro.stderr
Normal file
22
src/test/ui/reachable/expr_return_in_macro.stderr
Normal file
@ -0,0 +1,22 @@
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_return_in_macro.rs:13:5
|
||||
|
|
||||
LL | return early_return!();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/expr_return_in_macro.rs:4:9
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_return_in_macro.rs:8:9
|
||||
|
|
||||
LL | return ()
|
||||
| ^^^^^^^^^
|
||||
...
|
||||
LL | return early_return!();
|
||||
| --------------- in this macro invocation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -9,24 +9,47 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_struct.rs:14:35
|
||||
|
|
||||
LL | let x = Foo { a: 22, b: 33, ..return };
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:19:33
|
||||
|
|
||||
LL | let x = Foo { a: return, b: 33, ..return };
|
||||
| ^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_struct.rs:19:22
|
||||
|
|
||||
LL | let x = Foo { a: return, b: 33, ..return };
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:24:39
|
||||
|
|
||||
LL | let x = Foo { a: 22, b: return, ..return };
|
||||
| ^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_struct.rs:24:29
|
||||
|
|
||||
LL | let x = Foo { a: 22, b: return, ..return };
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_struct.rs:29:13
|
||||
|
|
||||
LL | let x = Foo { a: 22, b: return };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_struct.rs:29:29
|
||||
|
|
||||
LL | let x = Foo { a: 22, b: return };
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_tup.rs:9:30
|
||||
|
|
||||
LL | let x: (usize, usize) = (return, 2);
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/expr_tup.rs:14:29
|
||||
|
|
||||
LL | let x: (usize, usize) = (2, return);
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_tup.rs:14:33
|
||||
|
|
||||
LL | let x: (usize, usize) = (2, return);
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_type.rs:9:14
|
||||
|
|
||||
LL | let x = {return}: !;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -15,6 +15,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_unary.rs:8:20
|
||||
|
|
||||
LL | let x: ! = ! { return; };
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -13,6 +13,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_while.rs:7:12
|
||||
|
|
||||
LL | while {return} {
|
||||
| ^^^^^^
|
||||
|
||||
error: unreachable block in `while` expression
|
||||
--> $DIR/expr_while.rs:22:20
|
||||
@ -23,6 +28,12 @@ LL | |
|
||||
LL | | println!("I am dead.");
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/expr_while.rs:22:12
|
||||
|
|
||||
LL | while {return} {
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -5,4 +5,9 @@ LL | if let _ = return true && false {};
|
||||
| ^^
|
||||
|
|
||||
= note: `#[warn(unreachable_code)]` on by default
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/protect-precedences.rs:13:20
|
||||
|
|
||||
LL | if let _ = return true && false {};
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unreachable-code.rs:5:3
|
||||
|
|
||||
LL | loop{}
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unreachable-in-call.rs:13:10
|
||||
|
|
||||
LL | call(diverge(),
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: unreachable call
|
||||
--> $DIR/unreachable-in-call.rs:17:5
|
||||
|
|
||||
LL | call(
|
||||
| ^^^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unreachable-in-call.rs:19:9
|
||||
|
|
||||
LL | diverge());
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -9,6 +9,11 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![warn(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unreachable-try-pattern.rs:19:36
|
||||
|
|
||||
LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?;
|
||||
| ^
|
||||
|
||||
warning: unreachable pattern
|
||||
--> $DIR/unreachable-try-pattern.rs:19:24
|
||||
|
@ -9,12 +9,23 @@ note: lint level defined here
|
||||
|
|
||||
LL | #![deny(unreachable_code)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unwarned-match-on-never.rs:8:11
|
||||
|
|
||||
LL | match x {}
|
||||
| ^
|
||||
|
||||
error: unreachable arm
|
||||
--> $DIR/unwarned-match-on-never.rs:15:15
|
||||
|
|
||||
LL | () => ()
|
||||
| ^^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unwarned-match-on-never.rs:14:11
|
||||
|
|
||||
LL | match (return) {
|
||||
| ^^^^^^^^
|
||||
|
||||
error: unreachable expression
|
||||
--> $DIR/unwarned-match-on-never.rs:21:5
|
||||
@ -23,6 +34,12 @@ LL | / match () {
|
||||
LL | | () => (),
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: any code following this expression is unreachable
|
||||
--> $DIR/unwarned-match-on-never.rs:20:5
|
||||
|
|
||||
LL | return;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user