Remove sub_types_or_anon

This commit is contained in:
Santiago Pastorino 2021-07-15 09:48:14 -03:00
parent a0e1291c2d
commit a002f4513b
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 2 additions and 113 deletions

View File

@ -1130,32 +1130,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.relate_types(sub, ty::Variance::Covariant, sup, locations, category)
}
/// Try to relate `sub <: sup`; if this fails, instantiate opaque
/// variables in `sub` with their inferred definitions and try
/// again. This is used for opaque types in places (e.g., `let x:
/// impl Foo = ..`).
fn sub_types_or_anon(
&mut self,
sub: Ty<'tcx>,
sup: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
if let Err(terr) = self.sub_types(sub, sup, locations, category) {
if let ty::Opaque(..) = sup.kind() {
// When you have `let x: impl Foo = ...` in a closure,
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id =
self.tcx().closure_base_def_id(self.body.source.def_id()).expect_local();
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
}
}
Ok(())
}
fn eq_types(
&mut self,
a: Ty<'tcx>,
@ -1490,7 +1464,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let rv_ty = rv.ty(body, tcx);
let rv_ty = self.normalize(rv_ty, location);
if let Err(terr) =
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
{
span_mirbug!(
self,
@ -1777,9 +1751,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let locations = term_location.to_locations();
if let Err(terr) =
self.sub_types_or_anon(sig.output(), dest_ty, locations, category)
{
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
span_mirbug!(
self,
term,

View File

@ -1,23 +0,0 @@
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![allow(incomplete_features)]
type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
//~^ ERROR: hidden type for `impl Trait` captures lifetime that does not appear in bounds
//~| ERROR: the type `&'<empty> str` does not fulfill the required lifetime
//~| ERROR: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
trait Output<'a> {}
impl<'a> Output<'a> for &'a str {}
fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
//~^ ERROR: concrete type differs from previous defining opaque type use
let out: OpaqueOutputImpl<'a> = arg;
arg
}
fn main() {
let s = String::from("wassup");
cool_fn(&s);
}

View File

@ -1,60 +0,0 @@
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
--> $DIR/issue-85113.rs:5:29
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^^^^^^^^^^^^^^^^^^^
|
note: hidden type `&'<empty> str` captures lifetime smaller than the function body
--> $DIR/issue-85113.rs:5:29
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^^^^^^^^^^^^^^^^^^^
error: concrete type differs from previous defining opaque type use
--> $DIR/issue-85113.rs:14:1
|
LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&'<empty> str`, got `&'a str`
|
note: previous use here
--> $DIR/issue-85113.rs:14:1
|
LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0477]: the type `&'<empty> str` does not fulfill the required lifetime
--> $DIR/issue-85113.rs:5:29
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the lifetime `'a` as defined on the item at 5:23
--> $DIR/issue-85113.rs:5:23
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> $DIR/issue-85113.rs:5:29
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^^^^^^^^^^^^^^^^^^^
|
= note: first, the lifetime cannot outlive the empty lifetime...
note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 5:23...
--> $DIR/issue-85113.rs:5:23
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^
note: ...so that the types are compatible
--> $DIR/issue-85113.rs:5:29
|
LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a;
| ^^^^^^^^^^^^^^^^^^^^
= note: expected `Output<'a>`
found `Output<'_>`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0477, E0495, E0700.
For more information about an error, try `rustc --explain E0477`.