Member constraints already covered all of E0482 already, so that error never occurred anymore

This commit is contained in:
Oli Scherer 2021-10-16 13:54:08 +00:00
parent 2220fafa8c
commit 4413f8c709
4 changed files with 6 additions and 65 deletions

View File

@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.
A lifetime of a returned value does not outlive the function call.
Erroneous code example:
```compile_fail,E0482
```compile_fail,E0700
fn prefix<'a>(
words: impl Iterator<Item = &'a str>
) -> impl Iterator<Item = String> { // error!
@ -41,7 +43,7 @@ fn prefix(
A similar lifetime problem might arise when returning closures:
```compile_fail,E0482
```compile_fail,E0700
fn foo(
x: &mut Vec<i32>
) -> impl FnMut(&mut Vec<i32>) -> &[i32] { // error!

View File

@ -53,9 +53,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
infer::RelateObjectBound(span) => {
label_or_note(span, "...so that it can be closed over into an object");
}
infer::CallReturn(span) => {
label_or_note(span, "...so that return value is valid for the call");
}
infer::DataBorrowed(ty, span) => {
label_or_note(
span,
@ -281,23 +278,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
err
}
infer::CallReturn(span) => {
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0482,
"lifetime of return value does not outlive the function call"
);
note_and_explain_region(
self.tcx,
&mut err,
"the return value is only valid for ",
sup,
"",
None,
);
err
}
infer::DataBorrowed(ty, span) => {
let mut err = struct_span_err!(
self.tcx.sess,

View File

@ -417,9 +417,6 @@ pub enum SubregionOrigin<'tcx> {
/// (&'a &'b T) where a >= b
ReferenceOutlivesReferent(Ty<'tcx>, Span),
/// Region in return type of invoked fn must enclose call
CallReturn(Span),
/// Comparing the signature and requirements of an impl method against
/// the containing trait.
CompareImplMethodObligation {
@ -1803,7 +1800,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
ReborrowUpvar(a, _) => a,
DataBorrowed(_, a) => a,
ReferenceOutlivesReferent(_, a) => a,
CallReturn(a) => a,
CompareImplMethodObligation { span, .. } => span,
CompareImplTypeObligation { span, .. } => span,
}

View File

@ -6,7 +6,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
use rustc_infer::infer::opaque_types::OpaqueTypeDecl;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::{self, InferCtxt, InferOk};
use rustc_infer::infer::{InferCtxt, InferOk};
use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst};
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
@ -295,36 +295,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
hir::OpaqueTyOrigin::TyAlias => 0,
};
let span = tcx.def_span(def_id);
// Check if the `impl Trait` bounds include region bounds.
// For example, this would be true for:
//
// fn foo<'a, 'b, 'c>() -> impl Trait<'c> + 'a + 'b
//
// but false for:
//
// fn foo<'c>() -> impl Trait<'c>
//
// unless `Trait` was declared like:
//
// trait Trait<'c>: 'c
//
// in which case it would be true.
//
// This is used during regionck to decide whether we need to
// impose any additional constraints to ensure that region
// variables in `concrete_ty` wind up being constrained to
// something from `substs` (or, at minimum, things that outlive
// the fn body). (Ultimately, writeback is responsible for this
// check.)
let bounds = tcx.explicit_item_bounds(def_id);
debug!("{:#?}", bounds);
let bounds = bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs));
debug!("{:#?}", bounds);
let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);
// (A) The regions that appear in the hidden type must be equal to
// The regions that appear in the hidden type must be equal to
// one of the regions in scope for the opaque type.
self.generate_member_constraint(
concrete_ty,
@ -332,14 +303,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
opaque_type_key,
first_own_region,
);
// (B) We can also generate outlives bounds that must be enforced.
for required_region in required_region_bounds(tcx, opaque_type, bounds) {
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
tcx,
op: |r| self.sub_regions(infer::CallReturn(span), required_region, r),
});
}
}
/// As a fallback, we sometimes generate an "in constraint". For