Skip to content

Commit 7f9451c

Browse files
committed
Remove carveouts.
1 parent 4397ee2 commit 7f9451c

File tree

10 files changed

+37
-83
lines changed

10 files changed

+37
-83
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-52
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
253253
// diverging expression (e.g. it arose from desugaring of `try { return }`),
254254
// we skip issuing a warning because it is autogenerated code.
255255
ExprKind::Call(..) if expr.span.is_desugaring(DesugaringKind::TryBlock) => {}
256-
ExprKind::Call(callee, _) => {
257-
let emit_warning = if let ExprKind::Path(ref qpath) = callee.kind {
258-
// Do not emit a warning for a call to a constructor.
259-
let res = self.typeck_results.borrow().qpath_res(qpath, callee.hir_id);
260-
!matches!(res, Res::Def(DefKind::Ctor(..), _))
261-
} else {
262-
true
263-
};
264-
if emit_warning {
265-
self.warn_if_unreachable(expr.hir_id, callee.span, "call")
266-
}
267-
}
256+
ExprKind::Call(callee, _) => self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
268257
ExprKind::MethodCall(segment, ..) => {
269258
self.warn_if_unreachable(expr.hir_id, segment.ident.span, "call")
270259
}
@@ -281,7 +270,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281270
if ty.is_never() {
282271
// Any expression that produces a value of type `!` must have diverged.
283272
self.diverges.set(Diverges::Always(DivergeReason::Other, expr));
284-
} else if expr_may_be_uninhabited(expr) && self.ty_is_uninhabited(ty) {
273+
} else if self.ty_is_uninhabited(ty) {
285274
// This expression produces a value of uninhabited type.
286275
// This means it has diverged somehow.
287276
self.diverges.set(Diverges::Always(DivergeReason::Uninhabited, expr));
@@ -3236,42 +3225,3 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32363225
self.tcx.types.usize
32373226
}
32383227
}
3239-
3240-
fn expr_may_be_uninhabited(expr: &hir::Expr<'_>) -> bool {
3241-
match expr.kind {
3242-
ExprKind::Call(..)
3243-
| ExprKind::MethodCall(..)
3244-
| ExprKind::Cast(..)
3245-
| ExprKind::Unary(hir::UnOp::Deref, _)
3246-
| ExprKind::Field(..)
3247-
| ExprKind::Path(..)
3248-
| ExprKind::Struct(..) => true,
3249-
ExprKind::ConstBlock(..)
3250-
| ExprKind::Array(..)
3251-
| ExprKind::Tup(..)
3252-
| ExprKind::Binary(..)
3253-
| ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, _)
3254-
| ExprKind::Lit(..)
3255-
| ExprKind::Type(..)
3256-
| ExprKind::DropTemps(..)
3257-
| ExprKind::OffsetOf(..)
3258-
| ExprKind::Let(..)
3259-
| ExprKind::If(..)
3260-
| ExprKind::Loop(..)
3261-
| ExprKind::Match(..)
3262-
| ExprKind::Closure(..)
3263-
| ExprKind::Block(..)
3264-
| ExprKind::Assign(..)
3265-
| ExprKind::AssignOp(..)
3266-
| ExprKind::Index(..)
3267-
| ExprKind::AddrOf(..)
3268-
| ExprKind::Break(..)
3269-
| ExprKind::Continue(..)
3270-
| ExprKind::Ret(..)
3271-
| ExprKind::Become(..)
3272-
| ExprKind::InlineAsm(..)
3273-
| ExprKind::Repeat(..)
3274-
| ExprKind::Yield(..)
3275-
| ExprKind::Err(_) => false,
3276-
}
3277-
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

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

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

5356
/// Number of errors that had been reported when we started

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

-25
This file was deleted.

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)