Skip to content

Commit

Permalink
Member constraints already covered all of E0482 already, so that erro…
Browse files Browse the repository at this point in the history
…r never occurred anymore
  • Loading branch information
oli-obk committed Oct 18, 2021
1 parent 2220faf commit 4413f8c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 65 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0482.md
@@ -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!
Expand Down Expand Up @@ -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!
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
Expand Down
41 changes: 2 additions & 39 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -295,51 +295,14 @@ 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,
opaque_defn,
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
Expand Down

0 comments on commit 4413f8c

Please sign in to comment.