Member constraints already covered all of E0482 already, so that error never occurred anymore
This commit is contained in:
parent
2220fafa8c
commit
4413f8c709
4 changed files with 6 additions and 65 deletions
|
@ -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.
|
A lifetime of a returned value does not outlive the function call.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0482
|
```compile_fail,E0700
|
||||||
fn prefix<'a>(
|
fn prefix<'a>(
|
||||||
words: impl Iterator<Item = &'a str>
|
words: impl Iterator<Item = &'a str>
|
||||||
) -> impl Iterator<Item = String> { // error!
|
) -> impl Iterator<Item = String> { // error!
|
||||||
|
@ -41,7 +43,7 @@ fn prefix(
|
||||||
|
|
||||||
A similar lifetime problem might arise when returning closures:
|
A similar lifetime problem might arise when returning closures:
|
||||||
|
|
||||||
```compile_fail,E0482
|
```compile_fail,E0700
|
||||||
fn foo(
|
fn foo(
|
||||||
x: &mut Vec<i32>
|
x: &mut Vec<i32>
|
||||||
) -> impl FnMut(&mut Vec<i32>) -> &[i32] { // error!
|
) -> impl FnMut(&mut Vec<i32>) -> &[i32] { // error!
|
||||||
|
|
|
@ -53,9 +53,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
infer::RelateObjectBound(span) => {
|
infer::RelateObjectBound(span) => {
|
||||||
label_or_note(span, "...so that it can be closed over into an object");
|
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) => {
|
infer::DataBorrowed(ty, span) => {
|
||||||
label_or_note(
|
label_or_note(
|
||||||
span,
|
span,
|
||||||
|
@ -281,23 +278,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
err
|
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) => {
|
infer::DataBorrowed(ty, span) => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
|
|
|
@ -417,9 +417,6 @@ pub enum SubregionOrigin<'tcx> {
|
||||||
/// (&'a &'b T) where a >= b
|
/// (&'a &'b T) where a >= b
|
||||||
ReferenceOutlivesReferent(Ty<'tcx>, Span),
|
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
|
/// Comparing the signature and requirements of an impl method against
|
||||||
/// the containing trait.
|
/// the containing trait.
|
||||||
CompareImplMethodObligation {
|
CompareImplMethodObligation {
|
||||||
|
@ -1803,7 +1800,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
|
||||||
ReborrowUpvar(a, _) => a,
|
ReborrowUpvar(a, _) => a,
|
||||||
DataBorrowed(_, a) => a,
|
DataBorrowed(_, a) => a,
|
||||||
ReferenceOutlivesReferent(_, a) => a,
|
ReferenceOutlivesReferent(_, a) => a,
|
||||||
CallReturn(a) => a,
|
|
||||||
CompareImplMethodObligation { span, .. } => span,
|
CompareImplMethodObligation { span, .. } => span,
|
||||||
CompareImplTypeObligation { span, .. } => span,
|
CompareImplTypeObligation { span, .. } => span,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::error_reporting::unexpected_hidden_region_diagnostic;
|
||||||
use rustc_infer::infer::opaque_types::OpaqueTypeDecl;
|
use rustc_infer::infer::opaque_types::OpaqueTypeDecl;
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
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::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst};
|
||||||
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
|
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,
|
hir::OpaqueTyOrigin::TyAlias => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = tcx.def_span(def_id);
|
// The regions that appear in the hidden type must be equal to
|
||||||
|
|
||||||
// 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
|
|
||||||
// one of the regions in scope for the opaque type.
|
// one of the regions in scope for the opaque type.
|
||||||
self.generate_member_constraint(
|
self.generate_member_constraint(
|
||||||
concrete_ty,
|
concrete_ty,
|
||||||
|
@ -332,14 +303,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
opaque_type_key,
|
opaque_type_key,
|
||||||
first_own_region,
|
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
|
/// As a fallback, we sometimes generate an "in constraint". For
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue