diff options
| author | lcnr <rust@lcnr.de> | 2022-11-25 16:35:10 +0100 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2022-11-25 16:39:23 +0100 |
| commit | 4f07008419667eb7d9feea5ec391eda19d6d9338 (patch) | |
| tree | 78f4b67d340d0dccd27f087f2d4225e8e101c002 | |
| parent | a215b7b4dfef1d8f4161416838a0cd6abb348216 (diff) | |
| download | rust-4f07008419667eb7d9feea5ec391eda19d6d9338.tar.gz rust-4f07008419667eb7d9feea5ec391eda19d6d9338.zip | |
remove confusing comment
`?0: CoerceUnsized<SomeTy>` can definitely apply because `?0` matches any type, same for `SomeTy: CoerceUnsized<?0>`
| -rw-r--r-- | compiler/rustc_hir_typeck/src/coercion.rs | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 121dd4a1be1..e949f7ec34f 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -503,27 +503,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { target = self.shallow_resolve(target); debug!(?source, ?target); - // These 'if' statements require some explanation. - // The `CoerceUnsized` trait is special - it is only - // possible to write `impl CoerceUnsized<B> for A` where - // A and B have 'matching' fields. This rules out the following - // two types of blanket impls: - // - // `impl<T> CoerceUnsized<T> for SomeType` - // `impl<T> CoerceUnsized<SomeType> for T` - // - // Both of these trigger a special `CoerceUnsized`-related error (E0376) - // - // We can take advantage of this fact to avoid performing unnecessary work. - // If either `source` or `target` is a type variable, then any applicable impl - // would need to be generic over the self-type (`impl<T> CoerceUnsized<SomeType> for T`) - // or generic over the `CoerceUnsized` type parameter (`impl<T> CoerceUnsized<T> for - // SomeType`). - // - // However, these are exactly the kinds of impls which are forbidden by - // the compiler! Therefore, we can be sure that coercion will always fail - // when either the source or target type is a type variable. This allows us - // to skip performing any trait selection, and immediately bail out. + // We don't apply any coercions incase either the source or target + // aren't sufficiently well known but tend to instead just equate + // them both. if source.is_ty_var() { debug!("coerce_unsized: source is a TyVar, bailing out"); return Err(TypeError::Mismatch); |
