Skip to content

Commit a2bed4c

Browse files
committed
remove an unnecessary negation
I think in this case the early return is harder to read than just an if. "if fallback hasn't occured we don't do..."
1 parent 965feb1 commit a2bed4c

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,32 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
4949

5050
let fallback_occurred = self.fallback_types();
5151

52-
if !fallback_occurred {
53-
return;
52+
if fallback_occurred {
53+
// We now see if we can make progress. This might cause us to
54+
// unify inference variables for opaque types, since we may
55+
// have unified some other type variables during the first
56+
// phase of fallback. This means that we only replace
57+
// inference variables with their underlying opaque types as a
58+
// last resort.
59+
//
60+
// In code like this:
61+
//
62+
// ```rust
63+
// type MyType = impl Copy;
64+
// fn produce() -> MyType { true }
65+
// fn bad_produce() -> MyType { panic!() }
66+
// ```
67+
//
68+
// we want to unify the opaque inference variable in `bad_produce`
69+
// with the diverging fallback for `panic!` (e.g. `()` or `!`).
70+
// This will produce a nice error message about conflicting concrete
71+
// types for `MyType`.
72+
//
73+
// If we had tried to fallback the opaque inference variable to `MyType`,
74+
// we will generate a confusing type-check error that does not explicitly
75+
// refer to opaque types.
76+
self.select_obligations_where_possible(|_| {});
5477
}
55-
56-
// We now see if we can make progress. This might cause us to
57-
// unify inference variables for opaque types, since we may
58-
// have unified some other type variables during the first
59-
// phase of fallback. This means that we only replace
60-
// inference variables with their underlying opaque types as a
61-
// last resort.
62-
//
63-
// In code like this:
64-
//
65-
// ```rust
66-
// type MyType = impl Copy;
67-
// fn produce() -> MyType { true }
68-
// fn bad_produce() -> MyType { panic!() }
69-
// ```
70-
//
71-
// we want to unify the opaque inference variable in `bad_produce`
72-
// with the diverging fallback for `panic!` (e.g. `()` or `!`).
73-
// This will produce a nice error message about conflicting concrete
74-
// types for `MyType`.
75-
//
76-
// If we had tried to fallback the opaque inference variable to `MyType`,
77-
// we will generate a confusing type-check error that does not explicitly
78-
// refer to opaque types.
79-
self.select_obligations_where_possible(|_| {});
8078
}
8179

8280
fn fallback_types(&self) -> bool {

0 commit comments

Comments
 (0)