Skip to content

Commit 06b713c

Browse files
committed
Remove carveouts.
1 parent 446a159 commit 06b713c

11 files changed

+63
-58
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-52
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
230230
// diverging expression (e.g. it arose from desugaring of `try { return }`),
231231
// we skip issuing a warning because it is autogenerated code.
232232
ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {}
233-
ExprKind::Call(callee, _) => {
234-
let emit_warning = if let ExprKind::Path(ref qpath) = callee.kind {
235-
// Do not emit a warning for a call to a constructor.
236-
let res = self.typeck_results.borrow().qpath_res(qpath, callee.hir_id);
237-
!matches!(res, Res::Def(DefKind::Ctor(..), _))
238-
} else {
239-
true
240-
};
241-
if emit_warning {
242-
self.warn_if_unreachable(expr.hir_id, callee.span, "call")
243-
}
244-
}
233+
ExprKind::Call(callee, _) => self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
245234
ExprKind::MethodCall(segment, ..) => {
246235
self.warn_if_unreachable(expr.hir_id, segment.ident.span, "call")
247236
}
@@ -258,7 +247,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
258247
if ty.is_never() {
259248
// Any expression that produces a value of type `!` must have diverged.
260249
self.diverges.set(Diverges::Always(DivergeReason::Other, expr.span));
261-
} else if expr_may_be_uninhabited(expr) && self.ty_is_uninhabited(ty) {
250+
} else if self.ty_is_uninhabited(ty) {
262251
// This expression produces a value of uninhabited type.
263252
// This means it has diverged somehow.
264253
self.diverges
@@ -3554,42 +3543,3 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35543543
self.tcx.types.usize
35553544
}
35563545
}
3557-
3558-
fn expr_may_be_uninhabited(expr: &hir::Expr<'_>) -> bool {
3559-
match expr.kind {
3560-
ExprKind::Call(..)
3561-
| ExprKind::MethodCall(..)
3562-
| ExprKind::Cast(..)
3563-
| ExprKind::Unary(hir::UnOp::Deref, _)
3564-
| ExprKind::Field(..)
3565-
| ExprKind::Path(..)
3566-
| ExprKind::Struct(..) => true,
3567-
ExprKind::ConstBlock(..)
3568-
| ExprKind::Array(..)
3569-
| ExprKind::Tup(..)
3570-
| ExprKind::Binary(..)
3571-
| ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, _)
3572-
| ExprKind::Lit(..)
3573-
| ExprKind::Type(..)
3574-
| ExprKind::DropTemps(..)
3575-
| ExprKind::OffsetOf(..)
3576-
| ExprKind::Let(..)
3577-
| ExprKind::If(..)
3578-
| ExprKind::Loop(..)
3579-
| ExprKind::Match(..)
3580-
| ExprKind::Closure(..)
3581-
| ExprKind::Block(..)
3582-
| ExprKind::Assign(..)
3583-
| ExprKind::AssignOp(..)
3584-
| ExprKind::Index(..)
3585-
| ExprKind::AddrOf(..)
3586-
| ExprKind::Break(..)
3587-
| ExprKind::Continue(..)
3588-
| ExprKind::Ret(..)
3589-
| ExprKind::Become(..)
3590-
| ExprKind::InlineAsm(..)
3591-
| ExprKind::Repeat(..)
3592-
| ExprKind::Yield(..)
3593-
| ExprKind::Err(_) => false,
3594-
}
3595-
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub(crate) struct FnCtxt<'a, 'tcx> {
4949
/// eventually).
5050
pub(super) param_env: ty::ParamEnv<'tcx>,
5151

52+
/// The module in which the current function is defined. This
53+
/// is used to compute type inhabitedness, which accounts for
54+
/// visibility information.
5255
pub(super) parent_module: DefId,
5356

5457
/// If `Some`, this stores coercion information for returned

tests/ui/consts/const-eval/write-to-uninhabited-enum-variant.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-pass
22
#![allow(unreachable_patterns)]
3+
#![allow(unreachable_code)]
34
#![allow(dead_code)]
45

56
enum Empty {}

tests/ui/enum-discriminant/issue-46519.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum SystemFont {}
1919

2020
impl FontLanguageOverride {
2121
fn system_font(f: SystemFont) -> Self {
22-
FontLanguageOverride::System(f)
22+
FontLanguageOverride::System(f) //~ unreachable call
2323
}
2424
}
2525

tests/ui/enum-discriminant/issue-46519.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ LL | FontLanguageOverride::system_font(SystemFont::new());
88
|
99
= note: `#[warn(unreachable_code)]` on by default
1010

11-
warning: 1 warning emitted
11+
warning: unreachable call
12+
--> $DIR/issue-46519.rs:22:9
13+
|
14+
LL | FontLanguageOverride::System(f)
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - this expression has type `SystemFont`, which is uninhabited
16+
| |
17+
| unreachable call
18+
19+
warning: 2 warnings emitted
1220

tests/ui/reachable/type-dependent-ctor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Verify that we do not warn on type-dependent constructors (`Self::A` below).
2-
//@ check-pass
32
#![deny(unreachable_code)]
43

54
enum Void {}
@@ -11,10 +10,12 @@ enum Foo {
1110
impl Foo {
1211
fn wrap(x: Void) -> Self {
1312
Self::A(x)
13+
//~^ ERROR unreachable call
1414
}
1515

1616
fn make() -> Self {
1717
Self::A(produce())
18+
//~^ ERROR unreachable call
1819
}
1920
}
2021

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: unreachable call
2+
--> $DIR/type-dependent-ctor.rs:12:9
3+
|
4+
LL | Self::A(x)
5+
| ^^^^^^^ - this expression has type `Void`, which is uninhabited
6+
| |
7+
| unreachable call
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/type-dependent-ctor.rs:2:9
11+
|
12+
LL | #![deny(unreachable_code)]
13+
| ^^^^^^^^^^^^^^^^
14+
15+
error: unreachable call
16+
--> $DIR/type-dependent-ctor.rs:17:9
17+
|
18+
LL | Self::A(produce())
19+
| ^^^^^^^ --------- this expression has type `Void`, which is uninhabited
20+
| |
21+
| unreachable call
22+
23+
error: aborting due to 2 previous errors
24+

tests/ui/reachable/unreachable-try-pattern.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn qux(x: Result<u32, Void>) -> Result<u32, i32> {
2929
fn vom(x: Result<u32, Void>) -> Result<u32, i32> {
3030
let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?;
3131
//~^ WARN unreachable pattern
32+
//~| WARN unreachable call
3233
Ok(y)
3334
}
3435

tests/ui/reachable/unreachable-try-pattern.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ note: the lint level is defined here
1313
LL | #![warn(unreachable_code)]
1414
| ^^^^^^^^^^^^^^^^
1515

16+
warning: unreachable call
17+
--> $DIR/unreachable-try-pattern.rs:30:50
18+
|
19+
LL | let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?;
20+
| ^^^ - this expression has type `Void`, which is uninhabited
21+
| |
22+
| unreachable call
23+
1624
warning: unreachable pattern
1725
--> $DIR/unreachable-try-pattern.rs:19:24
1826
|
@@ -34,5 +42,5 @@ LL | let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?;
3442
|
3543
= note: this pattern matches no values because `Void` is uninhabited
3644

37-
warning: 3 warnings emitted
45+
warning: 4 warnings emitted
3846

tests/ui/try-block/try-block-unreachable-code-lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn test_try_block_after_divergent_stmt() {
5050
fn test_wrapped_divergent_expr() {
5151
let _: Result<u32, ()> = {
5252
Err(return)
53+
//~^ WARN unreachable call
5354
};
5455
}
5556

tests/ui/try-block/try-block-unreachable-code-lint.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ note: the lint level is defined here
1717
LL | #![warn(unreachable_code)]
1818
| ^^^^^^^^^^^^^^^^
1919

20+
warning: unreachable call
21+
--> $DIR/try-block-unreachable-code-lint.rs:52:9
22+
|
23+
LL | Err(return)
24+
| ^^^ ------ any code following this expression is unreachable
25+
| |
26+
| unreachable call
27+
2028
warning: unreachable expression
21-
--> $DIR/try-block-unreachable-code-lint.rs:62:9
29+
--> $DIR/try-block-unreachable-code-lint.rs:63:9
2230
|
2331
LL | / loop {
2432
LL | | err()?;
@@ -28,5 +36,5 @@ LL |
2836
LL | 42
2937
| ^^ unreachable expression
3038

31-
warning: 2 warnings emitted
39+
warning: 3 warnings emitted
3240

0 commit comments

Comments
 (0)