Skip to content

Commit bfbc9e8

Browse files
committed
Remove carveouts.
1 parent 827be96 commit bfbc9e8

11 files changed

+63
-59
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-52
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
244244
// diverging expression (e.g. it arose from desugaring of `try { return }`),
245245
// we skip issuing a warning because it is autogenerated code.
246246
ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {}
247-
ExprKind::Call(callee, _) => {
248-
let emit_warning = if let ExprKind::Path(ref qpath) = callee.kind {
249-
// Do not emit a warning for a call to a constructor.
250-
let res = self.typeck_results.borrow().qpath_res(qpath, callee.hir_id);
251-
!matches!(res, Res::Def(DefKind::Ctor(..), _))
252-
} else {
253-
true
254-
};
255-
if emit_warning {
256-
self.warn_if_unreachable(expr.hir_id, callee.span, "call")
257-
}
258-
}
247+
ExprKind::Call(callee, _) => self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
259248
ExprKind::MethodCall(segment, ..) => {
260249
self.warn_if_unreachable(expr.hir_id, segment.ident.span, "call")
261250
}
@@ -272,7 +261,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
272261
if ty.is_never() {
273262
// Any expression that produces a value of type `!` must have diverged.
274263
self.diverges.set(Diverges::Always(DivergeReason::Other, expr.span));
275-
} else if expr_may_be_uninhabited(expr) && self.ty_is_uninhabited(ty) {
264+
} else if self.ty_is_uninhabited(ty) {
276265
// This expression produces a value of uninhabited type.
277266
// This means it has diverged somehow.
278267
self.diverges
@@ -3481,42 +3470,3 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34813470
self.tcx.types.usize
34823471
}
34833472
}
3484-
3485-
fn expr_may_be_uninhabited(expr: &hir::Expr<'_>) -> bool {
3486-
match expr.kind {
3487-
ExprKind::Call(..)
3488-
| ExprKind::MethodCall(..)
3489-
| ExprKind::Cast(..)
3490-
| ExprKind::Unary(hir::UnOp::Deref, _)
3491-
| ExprKind::Field(..)
3492-
| ExprKind::Path(..)
3493-
| ExprKind::Struct(..) => true,
3494-
ExprKind::ConstBlock(..)
3495-
| ExprKind::Array(..)
3496-
| ExprKind::Tup(..)
3497-
| ExprKind::Binary(..)
3498-
| ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, _)
3499-
| ExprKind::Lit(..)
3500-
| ExprKind::Type(..)
3501-
| ExprKind::DropTemps(..)
3502-
| ExprKind::OffsetOf(..)
3503-
| ExprKind::Let(..)
3504-
| ExprKind::If(..)
3505-
| ExprKind::Loop(..)
3506-
| ExprKind::Match(..)
3507-
| ExprKind::Closure(..)
3508-
| ExprKind::Block(..)
3509-
| ExprKind::Assign(..)
3510-
| ExprKind::AssignOp(..)
3511-
| ExprKind::Index(..)
3512-
| ExprKind::AddrOf(..)
3513-
| ExprKind::Break(..)
3514-
| ExprKind::Continue(..)
3515-
| ExprKind::Ret(..)
3516-
| ExprKind::Become(..)
3517-
| ExprKind::InlineAsm(..)
3518-
| ExprKind::Repeat(..)
3519-
| ExprKind::Yield(..)
3520-
| ExprKind::Err(_) => false,
3521-
}
3522-
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub 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-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
2+
#![allow(unreachable_code)]
33
#![allow(dead_code)]
44

55
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
|
@@ -31,5 +39,5 @@ warning: unreachable pattern
3139
LL | let y = (match x { Ok(n) => Ok(n), Err(e) => Err(e) })?;
3240
| ^^^^^^
3341

34-
warning: 3 warnings emitted
42+
warning: 4 warnings emitted
3543

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)