mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Auto merge of #107652 - estebank:re_error, r=oli-obk
Introduce `ReError` CC #69314 r? `@nagisa`
This commit is contained in:
commit
d1ac43a9b9
@ -364,7 +364,11 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
|||||||
ty::BoundRegionKind::BrAnon(..) => None,
|
ty::BoundRegionKind::BrAnon(..) => None,
|
||||||
},
|
},
|
||||||
|
|
||||||
ty::ReLateBound(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => None,
|
ty::ReLateBound(..)
|
||||||
|
| ty::ReVar(..)
|
||||||
|
| ty::RePlaceholder(..)
|
||||||
|
| ty::ReErased
|
||||||
|
| ty::ReError(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +91,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
subst_regions.push(vid);
|
subst_regions.push(vid);
|
||||||
infcx.tcx.sess.delay_span_bug(
|
infcx.tcx.re_error_with_message(
|
||||||
concrete_type.span,
|
concrete_type.span,
|
||||||
"opaque type with non-universal region substs",
|
"opaque type with non-universal region substs",
|
||||||
);
|
)
|
||||||
infcx.tcx.lifetimes.re_static
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -167,6 +167,9 @@ struct UniversalRegionIndices<'tcx> {
|
|||||||
/// contains an entry for `ReStatic` -- it might be nice to just
|
/// contains an entry for `ReStatic` -- it might be nice to just
|
||||||
/// use a substs, and then handle `ReStatic` another way.
|
/// use a substs, and then handle `ReStatic` another way.
|
||||||
indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
|
indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
|
||||||
|
|
||||||
|
/// The vid assigned to `'static`. Used only for diagnostics.
|
||||||
|
pub fr_static: RegionVid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -609,7 +612,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||||||
let subst_mapping =
|
let subst_mapping =
|
||||||
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.to_region_vid()));
|
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.to_region_vid()));
|
||||||
|
|
||||||
UniversalRegionIndices { indices: global_mapping.chain(subst_mapping).collect() }
|
UniversalRegionIndices { indices: global_mapping.chain(subst_mapping).collect(), fr_static }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_inputs_and_output(
|
fn compute_inputs_and_output(
|
||||||
@ -821,6 +824,11 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
|||||||
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
||||||
if let ty::ReVar(..) = *r {
|
if let ty::ReVar(..) = *r {
|
||||||
r.to_region_vid()
|
r.to_region_vid()
|
||||||
|
} else if r.is_error() {
|
||||||
|
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
|
||||||
|
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
|
||||||
|
// errors are being emitted and 2) it leaves the happy path unaffected.
|
||||||
|
self.fr_static
|
||||||
} else {
|
} else {
|
||||||
*self
|
*self
|
||||||
.indices
|
.indices
|
||||||
|
@ -263,11 +263,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
// elision. `resolve_lifetime` should have
|
// elision. `resolve_lifetime` should have
|
||||||
// reported an error in this case -- but if
|
// reported an error in this case -- but if
|
||||||
// not, let's error out.
|
// not, let's error out.
|
||||||
tcx.sess.delay_span_bug(lifetime.ident.span, "unelided lifetime in signature");
|
tcx.re_error_with_message(lifetime.ident.span, "unelided lifetime in signature")
|
||||||
|
|
||||||
// Supply some dummy value. We don't have an
|
|
||||||
// `re_error`, annoyingly, so use `'static`.
|
|
||||||
tcx.lifetimes.re_static
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -481,11 +477,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
debug!(?param, "unelided lifetime in signature");
|
debug!(?param, "unelided lifetime in signature");
|
||||||
|
|
||||||
// This indicates an illegal lifetime in a non-assoc-trait position
|
// This indicates an illegal lifetime in a non-assoc-trait position
|
||||||
tcx.sess.delay_span_bug(self.span, "unelided lifetime in signature");
|
tcx.re_error_with_message(self.span, "unelided lifetime in signature")
|
||||||
|
|
||||||
// Supply some dummy value. We don't have an
|
|
||||||
// `re_error`, annoyingly, so use `'static`.
|
|
||||||
tcx.lifetimes.re_static
|
|
||||||
})
|
})
|
||||||
.into(),
|
.into(),
|
||||||
GenericParamDefKind::Type { has_default, .. } => {
|
GenericParamDefKind::Type { has_default, .. } => {
|
||||||
@ -1622,14 +1614,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
"the lifetime bound for this object type cannot be deduced \
|
"the lifetime bound for this object type cannot be deduced \
|
||||||
from context; please supply an explicit bound"
|
from context; please supply an explicit bound"
|
||||||
);
|
);
|
||||||
if borrowed {
|
let e = if borrowed {
|
||||||
// We will have already emitted an error E0106 complaining about a
|
// We will have already emitted an error E0106 complaining about a
|
||||||
// missing named lifetime in `&dyn Trait`, so we elide this one.
|
// missing named lifetime in `&dyn Trait`, so we elide this one.
|
||||||
err.delay_as_bug();
|
err.delay_as_bug()
|
||||||
} else {
|
} else {
|
||||||
err.emit();
|
err.emit()
|
||||||
}
|
};
|
||||||
tcx.lifetimes.re_static
|
tcx.re_error(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -786,13 +786,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||||||
}
|
}
|
||||||
let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind())
|
let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind())
|
||||||
else {
|
else {
|
||||||
tcx
|
return tcx.re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
|
||||||
.sess
|
|
||||||
.delay_span_bug(
|
|
||||||
return_span,
|
|
||||||
"expected ReFree to map to ReEarlyBound"
|
|
||||||
);
|
|
||||||
return tcx.lifetimes.re_static;
|
|
||||||
};
|
};
|
||||||
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||||
def_id: e.def_id,
|
def_id: e.def_id,
|
||||||
|
@ -170,6 +170,8 @@ fn is_free_region(region: Region<'_>) -> bool {
|
|||||||
// ignore it. We can't put it on the struct header anyway.
|
// ignore it. We can't put it on the struct header anyway.
|
||||||
ty::ReLateBound(..) => false,
|
ty::ReLateBound(..) => false,
|
||||||
|
|
||||||
|
ty::ReError(_) => false,
|
||||||
|
|
||||||
// These regions don't appear in types from type declarations:
|
// These regions don't appear in types from type declarations:
|
||||||
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
|
ty::ReErased | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReFree(..) => {
|
||||||
bug!("unexpected region in outlives inference: {:?}", region);
|
bug!("unexpected region in outlives inference: {:?}", region);
|
||||||
|
@ -409,6 +409,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||||||
// way early-bound regions do, so we skip them here.
|
// way early-bound regions do, so we skip them here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ty::ReError(_) => {}
|
||||||
|
|
||||||
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
|
ty::ReFree(..) | ty::ReVar(..) | ty::RePlaceholder(..) | ty::ReErased => {
|
||||||
// We don't expect to see anything but 'static or bound
|
// We don't expect to see anything but 'static or bound
|
||||||
// regions when visiting member types or method types.
|
// regions when visiting member types or method types.
|
||||||
|
@ -31,6 +31,8 @@ impl<'a> DescriptionCtx<'a> {
|
|||||||
|
|
||||||
ty::RePlaceholder(_) => return None,
|
ty::RePlaceholder(_) => return None,
|
||||||
|
|
||||||
|
ty::ReError(_) => return None,
|
||||||
|
|
||||||
// FIXME(#13998) RePlaceholder should probably print like
|
// FIXME(#13998) RePlaceholder should probably print like
|
||||||
// ReFree rather than dumping Debug output on the user.
|
// ReFree rather than dumping Debug output on the user.
|
||||||
//
|
//
|
||||||
|
@ -369,6 +369,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
|
|||||||
|
|
||||||
ty::ReStatic
|
ty::ReStatic
|
||||||
| ty::ReEarlyBound(..)
|
| ty::ReEarlyBound(..)
|
||||||
|
| ty::ReError(_)
|
||||||
| ty::ReFree(_)
|
| ty::ReFree(_)
|
||||||
| ty::RePlaceholder(..)
|
| ty::RePlaceholder(..)
|
||||||
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
|
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
|
||||||
|
@ -705,6 +705,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||||||
return Ok(r);
|
return Ok(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ty::ReError(_) => {
|
||||||
|
return Ok(r);
|
||||||
|
}
|
||||||
|
|
||||||
ty::RePlaceholder(..)
|
ty::RePlaceholder(..)
|
||||||
| ty::ReVar(..)
|
| ty::ReVar(..)
|
||||||
| ty::ReStatic
|
| ty::ReStatic
|
||||||
@ -861,7 +865,7 @@ impl<'tcx> FallibleTypeFolder<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||||||
match *r {
|
match *r {
|
||||||
// Never make variables for regions bound within the type itself,
|
// Never make variables for regions bound within the type itself,
|
||||||
// nor for erased regions.
|
// nor for erased regions.
|
||||||
ty::ReLateBound(..) | ty::ReErased => {
|
ty::ReLateBound(..) | ty::ReErased | ty::ReError(_) => {
|
||||||
return Ok(r);
|
return Ok(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,8 @@ pub(super) fn note_and_explain_region<'tcx>(
|
|||||||
|
|
||||||
ty::RePlaceholder(_) => return,
|
ty::RePlaceholder(_) => return,
|
||||||
|
|
||||||
|
ty::ReError(_) => return,
|
||||||
|
|
||||||
// FIXME(#13998) RePlaceholder should probably print like
|
// FIXME(#13998) RePlaceholder should probably print like
|
||||||
// ReFree rather than dumping Debug output on the user.
|
// ReFree rather than dumping Debug output on the user.
|
||||||
//
|
//
|
||||||
@ -313,6 +315,9 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ty::ReError(_) => {
|
||||||
|
err.delay_as_bug();
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Ugh. This is a painful case: the hidden region is not one
|
// Ugh. This is a painful case: the hidden region is not one
|
||||||
// that we can easily summarize or explain. This can happen
|
// that we can easily summarize or explain. This can happen
|
||||||
@ -2546,7 +2551,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
err.note_expected_found(&"", sup_expected, &"", sup_found);
|
err.note_expected_found(&"", sup_expected, &"", sup_found);
|
||||||
|
if sub_region.is_error() | sup_region.is_error() {
|
||||||
|
err.delay_as_bug();
|
||||||
|
} else {
|
||||||
err.emit();
|
err.emit();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2562,8 +2571,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
self.note_region_origin(&mut err, &sub_origin);
|
self.note_region_origin(&mut err, &sub_origin);
|
||||||
|
if sub_region.is_error() | sup_region.is_error() {
|
||||||
|
err.delay_as_bug();
|
||||||
|
} else {
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Determine whether an error associated with the given span and definition
|
/// Determine whether an error associated with the given span and definition
|
||||||
/// should be treated as being caused by the implicit `From` conversion
|
/// should be treated as being caused by the implicit `From` conversion
|
||||||
|
@ -78,7 +78,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
sub: Region<'tcx>,
|
sub: Region<'tcx>,
|
||||||
sup: Region<'tcx>,
|
sup: Region<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
match origin {
|
let mut err = match origin {
|
||||||
infer::Subtype(box trace) => {
|
infer::Subtype(box trace) => {
|
||||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||||
let mut err = self.report_and_explain_type_error(trace, terr);
|
let mut err = self.report_and_explain_type_error(trace, terr);
|
||||||
@ -299,7 +299,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
);
|
);
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if sub.is_error() || sup.is_error() {
|
||||||
|
err.delay_as_bug();
|
||||||
}
|
}
|
||||||
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn suggest_copy_trait_method_bounds(
|
pub fn suggest_copy_trait_method_bounds(
|
||||||
|
@ -126,6 +126,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
|
|||||||
| ty::ReFree(_)
|
| ty::ReFree(_)
|
||||||
| ty::ReVar(_)
|
| ty::ReVar(_)
|
||||||
| ty::RePlaceholder(..)
|
| ty::RePlaceholder(..)
|
||||||
|
| ty::ReError(_)
|
||||||
| ty::ReErased => {
|
| ty::ReErased => {
|
||||||
// replace all free regions with 'erased
|
// replace all free regions with 'erased
|
||||||
self.tcx().lifetimes.re_erased
|
self.tcx().lifetimes.re_erased
|
||||||
|
@ -17,7 +17,7 @@ use rustc_index::vec::{Idx, IndexVec};
|
|||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::TypeFoldable;
|
||||||
use rustc_middle::ty::PlaceholderRegion;
|
use rustc_middle::ty::PlaceholderRegion;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_middle::ty::{ReEarlyBound, ReErased, ReFree, ReStatic};
|
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
|
||||||
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
|
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
|
||||||
use rustc_middle::ty::{Region, RegionVid};
|
use rustc_middle::ty::{Region, RegionVid};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -216,6 +216,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
Ok(self.tcx().lifetimes.re_static)
|
Ok(self.tcx().lifetimes.re_static)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReError(_) => Ok(a_region),
|
||||||
|
|
||||||
ReEarlyBound(_) | ReFree(_) => {
|
ReEarlyBound(_) | ReFree(_) => {
|
||||||
// All empty regions are less than early-bound, free,
|
// All empty regions are less than early-bound, free,
|
||||||
// and scope regions.
|
// and scope regions.
|
||||||
@ -436,7 +438,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
(VarValue::Value(a), VarValue::Empty(_)) => {
|
(VarValue::Value(a), VarValue::Empty(_)) => {
|
||||||
match *a {
|
match *a {
|
||||||
ReLateBound(..) | ReErased => {
|
ReLateBound(..) | ReErased | ReError(_) => {
|
||||||
bug!("cannot relate region: {:?}", a);
|
bug!("cannot relate region: {:?}", a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +467,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
|
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
|
||||||
match *b {
|
match *b {
|
||||||
ReLateBound(..) | ReErased => {
|
ReLateBound(..) | ReErased | ReError(_) => {
|
||||||
bug!("cannot relate region: {:?}", b);
|
bug!("cannot relate region: {:?}", b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,6 +548,10 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(ReError(_), _) => a,
|
||||||
|
|
||||||
|
(_, ReError(_)) => b,
|
||||||
|
|
||||||
(ReStatic, _) | (_, ReStatic) => {
|
(ReStatic, _) | (_, ReStatic) => {
|
||||||
// nothing lives longer than `'static`
|
// nothing lives longer than `'static`
|
||||||
self.tcx().lifetimes.re_static
|
self.tcx().lifetimes.re_static
|
||||||
@ -1040,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
|||||||
ty::ReVar(rid) => match self.values[rid] {
|
ty::ReVar(rid) => match self.values[rid] {
|
||||||
VarValue::Empty(_) => r,
|
VarValue::Empty(_) => r,
|
||||||
VarValue::Value(r) => r,
|
VarValue::Value(r) => r,
|
||||||
VarValue::ErrorValue => tcx.lifetimes.re_static,
|
VarValue::ErrorValue => tcx.re_error_misc(),
|
||||||
},
|
},
|
||||||
_ => r,
|
_ => r,
|
||||||
};
|
};
|
||||||
|
@ -696,9 +696,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||||||
|
|
||||||
pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
|
pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
|
||||||
match *region {
|
match *region {
|
||||||
ty::ReStatic | ty::ReErased | ty::ReFree(..) | ty::ReEarlyBound(..) => {
|
ty::ReStatic
|
||||||
ty::UniverseIndex::ROOT
|
| ty::ReErased
|
||||||
}
|
| ty::ReFree(..)
|
||||||
|
| ty::ReEarlyBound(..)
|
||||||
|
| ty::ReError(_) => ty::UniverseIndex::ROOT,
|
||||||
ty::RePlaceholder(placeholder) => placeholder.universe,
|
ty::RePlaceholder(placeholder) => placeholder.universe,
|
||||||
ty::ReVar(vid) => self.var_universe(vid),
|
ty::ReVar(vid) => self.var_universe(vid),
|
||||||
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
|
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
|
||||||
|
@ -661,6 +661,30 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
self.mk_ty(Error(reported))
|
self.mk_ty(Error(reported))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constructs a `RegionKind::ReError` lifetime.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
|
||||||
|
self.mk_region(ty::ReError(reported))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
|
||||||
|
/// gets used.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn re_error_misc(self) -> Region<'tcx> {
|
||||||
|
self.re_error_with_message(
|
||||||
|
DUMMY_SP,
|
||||||
|
"RegionKind::ReError constructed but no error reported",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
|
||||||
|
/// `msg` to ensure it gets used.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
|
||||||
|
let reported = self.sess.delay_span_bug(span, msg);
|
||||||
|
self.re_error(reported)
|
||||||
|
}
|
||||||
|
|
||||||
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error_with_guaranteed(
|
pub fn const_error_with_guaranteed(
|
||||||
|
@ -100,7 +100,7 @@ impl GenericParamDef {
|
|||||||
preceding_substs: &[ty::GenericArg<'tcx>],
|
preceding_substs: &[ty::GenericArg<'tcx>],
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
|
ty::GenericParamDefKind::Lifetime => tcx.re_error_misc().into(),
|
||||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
||||||
ty::GenericParamDefKind::Const { .. } => {
|
ty::GenericParamDefKind::Const { .. } => {
|
||||||
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
||||||
|
@ -109,6 +109,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
// them.
|
// them.
|
||||||
ty::ReErased => return r,
|
ty::ReErased => return r,
|
||||||
|
|
||||||
|
ty::ReError(_) => return r,
|
||||||
|
|
||||||
// The regions that we expect from borrow checking.
|
// The regions that we expect from borrow checking.
|
||||||
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
|
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
|
||||||
|
|
||||||
@ -125,7 +127,8 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
|
Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
|
||||||
None if self.do_not_error => self.tcx.lifetimes.re_static,
|
None if self.do_not_error => self.tcx.lifetimes.re_static,
|
||||||
None => {
|
None => {
|
||||||
self.tcx
|
let e = self
|
||||||
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
.struct_span_err(self.span, "non-defining opaque type use in defining scope")
|
.struct_span_err(self.span, "non-defining opaque type use in defining scope")
|
||||||
.span_label(
|
.span_label(
|
||||||
@ -138,7 +141,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
|
|||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
self.tcx().lifetimes.re_static
|
self.tcx().re_error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2114,7 +2114,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||||||
|
|
||||||
ty::ReVar(_) if identify_regions => true,
|
ty::ReVar(_) if identify_regions => true,
|
||||||
|
|
||||||
ty::ReVar(_) | ty::ReErased => false,
|
ty::ReVar(_) | ty::ReErased | ty::ReError(_) => false,
|
||||||
|
|
||||||
ty::ReStatic => true,
|
ty::ReStatic => true,
|
||||||
}
|
}
|
||||||
@ -2194,6 +2194,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
ty::ReVar(_) => {}
|
ty::ReVar(_) => {}
|
||||||
ty::ReErased => {}
|
ty::ReErased => {}
|
||||||
|
ty::ReError(_) => {}
|
||||||
ty::ReStatic => {
|
ty::ReStatic => {
|
||||||
p!("'static");
|
p!("'static");
|
||||||
return Ok(self);
|
return Ok(self);
|
||||||
|
@ -1623,9 +1623,15 @@ impl<'tcx> Region<'tcx> {
|
|||||||
ty::ReVar(..) => false,
|
ty::ReVar(..) => false,
|
||||||
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
|
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
|
||||||
ty::ReErased => false,
|
ty::ReErased => false,
|
||||||
|
ty::ReError(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_error(self) -> bool {
|
||||||
|
matches!(*self, ty::ReError(_))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_static(self) -> bool {
|
pub fn is_static(self) -> bool {
|
||||||
matches!(*self, ty::ReStatic)
|
matches!(*self, ty::ReStatic)
|
||||||
@ -1686,6 +1692,7 @@ impl<'tcx> Region<'tcx> {
|
|||||||
ty::ReErased => {
|
ty::ReErased => {
|
||||||
flags = flags | TypeFlags::HAS_RE_ERASED;
|
flags = flags | TypeFlags::HAS_RE_ERASED;
|
||||||
}
|
}
|
||||||
|
ty::ReError(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("type_flags({:?}) = {:?}", self, flags);
|
debug!("type_flags({:?}) = {:?}", self, flags);
|
||||||
|
@ -1725,7 +1725,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||||||
!segment.has_generic_args,
|
!segment.has_generic_args,
|
||||||
elided_lifetime_span,
|
elided_lifetime_span,
|
||||||
);
|
);
|
||||||
err.note("assuming a `'static` lifetime...");
|
|
||||||
err.emit();
|
err.emit();
|
||||||
should_lint = false;
|
should_lint = false;
|
||||||
|
|
||||||
|
@ -299,6 +299,7 @@ fn encode_region<'tcx>(
|
|||||||
RegionKind::ReEarlyBound(..)
|
RegionKind::ReEarlyBound(..)
|
||||||
| RegionKind::ReFree(..)
|
| RegionKind::ReFree(..)
|
||||||
| RegionKind::ReStatic
|
| RegionKind::ReStatic
|
||||||
|
| RegionKind::ReError(_)
|
||||||
| RegionKind::ReVar(..)
|
| RegionKind::ReVar(..)
|
||||||
| RegionKind::RePlaceholder(..) => {
|
| RegionKind::RePlaceholder(..) => {
|
||||||
bug!("encode_region: unexpected `{:?}`", region.kind());
|
bug!("encode_region: unexpected `{:?}`", region.kind());
|
||||||
|
@ -493,6 +493,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||||||
ty::ReEarlyBound(_) => {
|
ty::ReEarlyBound(_) => {
|
||||||
panic!("Should have already been substituted.");
|
panic!("Should have already been substituted.");
|
||||||
}
|
}
|
||||||
|
ty::ReError(_) => {
|
||||||
|
panic!("Error lifetime should not have already been lowered.");
|
||||||
|
}
|
||||||
ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
|
ty::ReLateBound(db, br) => chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
|
||||||
chalk_ir::DebruijnIndex::new(db.as_u32()),
|
chalk_ir::DebruijnIndex::new(db.as_u32()),
|
||||||
br.var.as_usize(),
|
br.var.as_usize(),
|
||||||
|
@ -960,6 +960,9 @@ pub enum RegionKind<I: Interner> {
|
|||||||
|
|
||||||
/// Erased region, used by trait selection, in MIR and during codegen.
|
/// Erased region, used by trait selection, in MIR and during codegen.
|
||||||
ReErased,
|
ReErased,
|
||||||
|
|
||||||
|
/// A region that resulted from some other error. Used exclusively for diagnostics.
|
||||||
|
ReError(I::ErrorGuaranteed),
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is manually implemented for `RegionKind` because `std::mem::discriminant`
|
// This is manually implemented for `RegionKind` because `std::mem::discriminant`
|
||||||
@ -974,6 +977,7 @@ const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
|
|||||||
ReVar(_) => 4,
|
ReVar(_) => 4,
|
||||||
RePlaceholder(_) => 5,
|
RePlaceholder(_) => 5,
|
||||||
ReErased => 6,
|
ReErased => 6,
|
||||||
|
ReError(_) => 7,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -985,6 +989,7 @@ where
|
|||||||
I::FreeRegion: Copy,
|
I::FreeRegion: Copy,
|
||||||
I::RegionVid: Copy,
|
I::RegionVid: Copy,
|
||||||
I::PlaceholderRegion: Copy,
|
I::PlaceholderRegion: Copy,
|
||||||
|
I::ErrorGuaranteed: Copy,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,6 +1004,7 @@ impl<I: Interner> Clone for RegionKind<I> {
|
|||||||
ReVar(r) => ReVar(r.clone()),
|
ReVar(r) => ReVar(r.clone()),
|
||||||
RePlaceholder(r) => RePlaceholder(r.clone()),
|
RePlaceholder(r) => RePlaceholder(r.clone()),
|
||||||
ReErased => ReErased,
|
ReErased => ReErased,
|
||||||
|
ReError(r) => ReError(r.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1016,10 +1022,11 @@ impl<I: Interner> PartialEq for RegionKind<I> {
|
|||||||
(ReVar(a_r), ReVar(b_r)) => a_r == b_r,
|
(ReVar(a_r), ReVar(b_r)) => a_r == b_r,
|
||||||
(RePlaceholder(a_r), RePlaceholder(b_r)) => a_r == b_r,
|
(RePlaceholder(a_r), RePlaceholder(b_r)) => a_r == b_r,
|
||||||
(ReErased, ReErased) => true,
|
(ReErased, ReErased) => true,
|
||||||
|
(ReError(_), ReError(_)) => true,
|
||||||
_ => {
|
_ => {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
false,
|
false,
|
||||||
"This branch must be unreachable, maybe the match is missing an arm? self = self = {self:?}, other = {other:?}"
|
"This branch must be unreachable, maybe the match is missing an arm? self = {self:?}, other = {other:?}"
|
||||||
);
|
);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -1077,6 +1084,7 @@ impl<I: Interner> hash::Hash for RegionKind<I> {
|
|||||||
ReVar(r) => r.hash(state),
|
ReVar(r) => r.hash(state),
|
||||||
RePlaceholder(r) => r.hash(state),
|
RePlaceholder(r) => r.hash(state),
|
||||||
ReErased => (),
|
ReErased => (),
|
||||||
|
ReError(_) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1100,6 +1108,8 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
|
|||||||
RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"),
|
RePlaceholder(placeholder) => write!(f, "RePlaceholder({placeholder:?})"),
|
||||||
|
|
||||||
ReErased => f.write_str("ReErased"),
|
ReErased => f.write_str("ReErased"),
|
||||||
|
|
||||||
|
ReError(_) => f.write_str("ReError"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1134,6 +1144,7 @@ where
|
|||||||
a.encode(e);
|
a.encode(e);
|
||||||
}),
|
}),
|
||||||
ReErased => e.emit_enum_variant(disc, |_| {}),
|
ReErased => e.emit_enum_variant(disc, |_| {}),
|
||||||
|
ReError(_) => e.emit_enum_variant(disc, |_| {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1146,6 +1157,7 @@ where
|
|||||||
I::FreeRegion: Decodable<D>,
|
I::FreeRegion: Decodable<D>,
|
||||||
I::RegionVid: Decodable<D>,
|
I::RegionVid: Decodable<D>,
|
||||||
I::PlaceholderRegion: Decodable<D>,
|
I::PlaceholderRegion: Decodable<D>,
|
||||||
|
I::ErrorGuaranteed: Decodable<D>,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut D) -> Self {
|
fn decode(d: &mut D) -> Self {
|
||||||
match Decoder::read_usize(d) {
|
match Decoder::read_usize(d) {
|
||||||
@ -1156,6 +1168,7 @@ where
|
|||||||
4 => ReVar(Decodable::decode(d)),
|
4 => ReVar(Decodable::decode(d)),
|
||||||
5 => RePlaceholder(Decodable::decode(d)),
|
5 => RePlaceholder(Decodable::decode(d)),
|
||||||
6 => ReErased,
|
6 => ReErased,
|
||||||
|
7 => ReError(Decodable::decode(d)),
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"{}",
|
"{}",
|
||||||
format!(
|
format!(
|
||||||
@ -1184,7 +1197,7 @@ where
|
|||||||
) {
|
) {
|
||||||
std::mem::discriminant(self).hash_stable(hcx, hasher);
|
std::mem::discriminant(self).hash_stable(hcx, hasher);
|
||||||
match self {
|
match self {
|
||||||
ReErased | ReStatic => {
|
ReErased | ReStatic | ReError(_) => {
|
||||||
// No variant fields to hash for these ...
|
// No variant fields to hash for these ...
|
||||||
}
|
}
|
||||||
ReLateBound(d, r) => {
|
ReLateBound(d, r) => {
|
||||||
|
@ -242,6 +242,7 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Life
|
|||||||
ty::ReLateBound(..)
|
ty::ReLateBound(..)
|
||||||
| ty::ReFree(..)
|
| ty::ReFree(..)
|
||||||
| ty::ReVar(..)
|
| ty::ReVar(..)
|
||||||
|
| ty::ReError(_)
|
||||||
| ty::RePlaceholder(..)
|
| ty::RePlaceholder(..)
|
||||||
| ty::ReErased => {
|
| ty::ReErased => {
|
||||||
debug!("cannot clean region {:?}", region);
|
debug!("cannot clean region {:?}", region);
|
||||||
|
@ -16,10 +16,10 @@ error[E0308]: mismatched types
|
|||||||
LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() }
|
LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()> { x.next() }
|
||||||
| ----------------------------- -------------- ^^^^^^^^ expected `Option<&()>`, found `Option<impl Iterator<Item = &'_ ()>>`
|
| ----------------------------- -------------- ^^^^^^^^ expected `Option<&()>`, found `Option<impl Iterator<Item = &'_ ()>>`
|
||||||
| | |
|
| | |
|
||||||
| | expected `Option<&'static ()>` because of return type
|
| | expected `Option<&()>` because of return type
|
||||||
| this type parameter
|
| this type parameter
|
||||||
|
|
|
|
||||||
= note: expected enum `Option<&'static ()>`
|
= note: expected enum `Option<&()>`
|
||||||
found enum `Option<impl Iterator<Item = &'_ ()>>`
|
found enum `Option<impl Iterator<Item = &'_ ()>>`
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
@ -4,7 +4,6 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||||||
LL | async fn error(lt: HasLifetime) {
|
LL | async fn error(lt: HasLifetime) {
|
||||||
| ^^^^^^^^^^^ expected lifetime parameter
|
| ^^^^^^^^^^^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
= note: assuming a `'static` lifetime...
|
|
||||||
help: indicate the anonymous lifetime
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | async fn error(lt: HasLifetime<'_>) {
|
LL | async fn error(lt: HasLifetime<'_>) {
|
||||||
|
@ -28,7 +28,7 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
|
|||||||
LL | fn bar<const N: &u8>() {}
|
LL | fn bar<const N: &u8>() {}
|
||||||
| ^ explicit lifetime name needed here
|
| ^ explicit lifetime name needed here
|
||||||
|
|
||||||
error: `&'static u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:9:19
|
--> $DIR/const-param-elided-lifetime.rs:9:19
|
||||||
|
|
|
|
||||||
LL | struct A<const N: &u8>;
|
LL | struct A<const N: &u8>;
|
||||||
@ -37,7 +37,7 @@ LL | struct A<const N: &u8>;
|
|||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||||
|
|
||||||
error: `&'static u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:14:15
|
--> $DIR/const-param-elided-lifetime.rs:14:15
|
||||||
|
|
|
|
||||||
LL | impl<const N: &u8> A<N> {
|
LL | impl<const N: &u8> A<N> {
|
||||||
@ -46,7 +46,7 @@ LL | impl<const N: &u8> A<N> {
|
|||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||||
|
|
||||||
error: `&'static u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:22:15
|
--> $DIR/const-param-elided-lifetime.rs:22:15
|
||||||
|
|
|
|
||||||
LL | impl<const N: &u8> B for A<N> {}
|
LL | impl<const N: &u8> B for A<N> {}
|
||||||
@ -55,7 +55,7 @@ LL | impl<const N: &u8> B for A<N> {}
|
|||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||||
|
|
||||||
error: `&'static u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:26:17
|
--> $DIR/const-param-elided-lifetime.rs:26:17
|
||||||
|
|
|
|
||||||
LL | fn bar<const N: &u8>() {}
|
LL | fn bar<const N: &u8>() {}
|
||||||
@ -64,7 +64,7 @@ LL | fn bar<const N: &u8>() {}
|
|||||||
= note: the only supported types are integers, `bool` and `char`
|
= note: the only supported types are integers, `bool` and `char`
|
||||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||||
|
|
||||||
error: `&'static u8` is forbidden as the type of a const generic parameter
|
error: `&u8` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/const-param-elided-lifetime.rs:17:21
|
--> $DIR/const-param-elided-lifetime.rs:17:21
|
||||||
|
|
|
|
||||||
LL | fn foo<const M: &u8>(&self) {}
|
LL | fn foo<const M: &u8>(&self) {}
|
||||||
|
@ -8,23 +8,23 @@
|
|||||||
|
|
||||||
struct A<const N: &u8>;
|
struct A<const N: &u8>;
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&'static u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
trait B {}
|
trait B {}
|
||||||
|
|
||||||
impl<const N: &u8> A<N> {
|
impl<const N: &u8> A<N> {
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&'static u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
fn foo<const M: &u8>(&self) {}
|
fn foo<const M: &u8>(&self) {}
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&'static u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: &u8> B for A<N> {}
|
impl<const N: &u8> B for A<N> {}
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&'static u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
|
|
||||||
fn bar<const N: &u8>() {}
|
fn bar<const N: &u8>() {}
|
||||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||||
//[min]~^^ ERROR `&'static u8` is forbidden
|
//[min]~^^ ERROR `&u8` is forbidden
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -6,7 +6,7 @@ LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
|||||||
|
|
|
|
||||||
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052>
|
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052>
|
||||||
|
|
||||||
error: `&'static str` is forbidden as the type of a const generic parameter
|
error: `&str` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/issue-56445-1.rs:9:25
|
--> $DIR/issue-56445-1.rs:9:25
|
||||||
|
|
|
|
||||||
LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
||||||
|
@ -8,6 +8,6 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>);
|
||||||
//~^ ERROR: use of non-static lifetime `'a` in const generic
|
//~^ ERROR: use of non-static lifetime `'a` in const generic
|
||||||
//[min]~| ERROR: `&'static str` is forbidden as the type of a const generic parameter
|
//[min]~| ERROR: `&str` is forbidden as the type of a const generic parameter
|
||||||
|
|
||||||
impl Bug<'_, ""> {}
|
impl Bug<'_, ""> {}
|
||||||
|
@ -8,7 +8,6 @@ fn should_error<T>() where T : Into<&u32> {}
|
|||||||
trait X<'a, K: 'a> {
|
trait X<'a, K: 'a> {
|
||||||
fn foo<'b, L: X<&'b Nested<K>>>();
|
fn foo<'b, L: X<&'b Nested<K>>>();
|
||||||
//~^ ERROR missing lifetime specifier [E0106]
|
//~^ ERROR missing lifetime specifier [E0106]
|
||||||
//~| ERROR the type `&'b Nested<K>` does not fulfill the required lifetime
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
||||||
|
@ -29,7 +29,7 @@ LL | fn foo<'b, L: X<'lifetime, &'b Nested<K>>>();
|
|||||||
| ++++++++++
|
| ++++++++++
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0106]: missing lifetime specifier
|
||||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:14:16
|
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:13:16
|
||||||
|
|
|
|
||||||
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
||||||
| ^ expected named lifetime parameter
|
| ^ expected named lifetime parameter
|
||||||
@ -39,19 +39,7 @@ help: consider using the `'b` lifetime
|
|||||||
LL | fn bar<'b, L: X<'b, &'b Nested<i32>>>(){}
|
LL | fn bar<'b, L: X<'b, &'b Nested<i32>>>(){}
|
||||||
| +++
|
| +++
|
||||||
|
|
||||||
error[E0477]: the type `&'b Nested<K>` does not fulfill the required lifetime
|
error: aborting due to 3 previous errors
|
||||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:19
|
|
||||||
|
|
|
||||||
LL | fn foo<'b, L: X<&'b Nested<K>>>();
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: type must satisfy the static lifetime as required by this binding
|
|
||||||
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:8:16
|
|
||||||
|
|
|
||||||
LL | trait X<'a, K: 'a> {
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
Some errors have detailed explanations: E0106, E0637.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0106, E0477, E0637.
|
|
||||||
For more information about an error, try `rustc --explain E0106`.
|
For more information about an error, try `rustc --explain E0106`.
|
||||||
|
@ -4,7 +4,6 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||||||
LL | impl MyTrait for Foo {
|
LL | impl MyTrait for Foo {
|
||||||
| ^^^ expected lifetime parameter
|
| ^^^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
= note: assuming a `'static` lifetime...
|
|
||||||
help: indicate the anonymous lifetime
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | impl MyTrait for Foo<'_> {
|
LL | impl MyTrait for Foo<'_> {
|
||||||
|
@ -4,7 +4,6 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||||||
LL | impl MyTrait for u32 {}
|
LL | impl MyTrait for u32 {}
|
||||||
| ^^^^^^^ expected lifetime parameter
|
| ^^^^^^^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
= note: assuming a `'static` lifetime...
|
|
||||||
help: indicate the anonymous lifetime
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | impl MyTrait<'_> for u32 {}
|
LL | impl MyTrait<'_> for u32 {}
|
||||||
|
@ -2,12 +2,12 @@ error: `impl` item signature doesn't match `trait` item signature
|
|||||||
--> $DIR/signature-mismatch.rs:15:5
|
--> $DIR/signature-mismatch.rs:15:5
|
||||||
|
|
|
|
||||||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
|
||||||
| ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
|
| ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3`
|
||||||
...
|
...
|
||||||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
|
||||||
|
|
|
|
||||||
= note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
|
= note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3`
|
||||||
found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
|
found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
|
||||||
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
|
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
|
||||||
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
|
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
|
||||||
|
@ -2,9 +2,7 @@ use std::marker::PhantomData;
|
|||||||
struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
|
struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
|
||||||
where
|
where
|
||||||
Foo<'short, 'out, T>: Convert<'a, 'b>;
|
Foo<'short, 'out, T>: Convert<'a, 'b>;
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR use of undeclared lifetime name
|
||||||
//~^^ ERROR mismatched types
|
|
||||||
//~^^^ ERROR use of undeclared lifetime name
|
|
||||||
//~| ERROR use of undeclared lifetime name `'out`
|
//~| ERROR use of undeclared lifetime name `'out`
|
||||||
|
|
||||||
trait Convert<'a, 'b>: Sized {
|
trait Convert<'a, 'b>: Sized {
|
||||||
@ -13,19 +11,15 @@ trait Convert<'a, 'b>: Sized {
|
|||||||
impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
||||||
//~^ ERROR use of undeclared lifetime name
|
//~^ ERROR use of undeclared lifetime name
|
||||||
//~^^ ERROR use of undeclared lifetime name `'out`
|
//~^^ ERROR use of undeclared lifetime name `'out`
|
||||||
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter
|
|
||||||
fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
||||||
//~^ ERROR use of undeclared lifetime name
|
//~^ ERROR use of undeclared lifetime name
|
||||||
//~| ERROR cannot infer an appropriate lifetime for lifetime parameter
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
||||||
//~^ ERROR use of undeclared lifetime name
|
//~^ ERROR use of undeclared lifetime name
|
||||||
//~^^ ERROR incompatible lifetime on type
|
sadness.cast() //~ ERROR mismatched types
|
||||||
//~| ERROR `x` has lifetime `'in_` but it needs to satisfy a `'static` lifetime requirement
|
|
||||||
sadness.cast()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -30,7 +30,7 @@ LL | struct Foo<'out, 'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
|
|||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
error[E0261]: use of undeclared lifetime name `'b`
|
error[E0261]: use of undeclared lifetime name `'b`
|
||||||
--> $DIR/issue-107090.rs:13:47
|
--> $DIR/issue-107090.rs:11:47
|
||||||
|
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
||||||
| - ^^ undeclared lifetime
|
| - ^^ undeclared lifetime
|
||||||
@ -38,13 +38,13 @@ LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T>
|
|||||||
| help: consider introducing lifetime `'b` here: `'b,`
|
| help: consider introducing lifetime `'b` here: `'b,`
|
||||||
|
|
||||||
error[E0261]: use of undeclared lifetime name `'out`
|
error[E0261]: use of undeclared lifetime name `'out`
|
||||||
--> $DIR/issue-107090.rs:13:67
|
--> $DIR/issue-107090.rs:11:67
|
||||||
|
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
||||||
| - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime
|
| - help: consider introducing lifetime `'out` here: `'out,` ^^^^ undeclared lifetime
|
||||||
|
|
||||||
error[E0261]: use of undeclared lifetime name `'out`
|
error[E0261]: use of undeclared lifetime name `'out`
|
||||||
--> $DIR/issue-107090.rs:17:49
|
--> $DIR/issue-107090.rs:14:49
|
||||||
|
|
|
|
||||||
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
||||||
| ^^^^ undeclared lifetime
|
| ^^^^ undeclared lifetime
|
||||||
@ -59,7 +59,7 @@ LL | impl<'out, 'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'ou
|
|||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
error[E0261]: use of undeclared lifetime name `'short`
|
error[E0261]: use of undeclared lifetime name `'short`
|
||||||
--> $DIR/issue-107090.rs:24:68
|
--> $DIR/issue-107090.rs:20:68
|
||||||
|
|
|
|
||||||
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
||||||
| - ^^^^^^ undeclared lifetime
|
| - ^^^^^^ undeclared lifetime
|
||||||
@ -67,107 +67,18 @@ LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short,
|
|||||||
| help: consider introducing lifetime `'short` here: `'short,`
|
| help: consider introducing lifetime `'short` here: `'short,`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/issue-107090.rs:4:27
|
--> $DIR/issue-107090.rs:22:5
|
||||||
|
|
|
||||||
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
|
|
||||||
| ^^^^^^^^^^^^^^^ lifetime mismatch
|
|
||||||
|
|
|
||||||
= note: expected trait `Convert<'static, 'static>`
|
|
||||||
found trait `Convert<'a, 'b>`
|
|
||||||
note: the lifetime `'a` as defined here...
|
|
||||||
--> $DIR/issue-107090.rs:2:12
|
|
||||||
|
|
|
||||||
LL | struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
|
|
||||||
| ^^
|
|
||||||
= note: ...does not necessarily outlive the static lifetime
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/issue-107090.rs:4:27
|
|
||||||
|
|
|
||||||
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
|
|
||||||
| ^^^^^^^^^^^^^^^ lifetime mismatch
|
|
||||||
|
|
|
||||||
= note: expected trait `Convert<'static, 'static>`
|
|
||||||
found trait `Convert<'a, 'b>`
|
|
||||||
note: the lifetime `'b` as defined here...
|
|
||||||
--> $DIR/issue-107090.rs:2:16
|
|
||||||
|
|
|
||||||
LL | struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>)
|
|
||||||
| ^^
|
|
||||||
= note: ...does not necessarily outlive the static lifetime
|
|
||||||
|
|
||||||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'long` due to conflicting requirements
|
|
||||||
--> $DIR/issue-107090.rs:13:55
|
|
||||||
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: first, the lifetime cannot outlive the lifetime `'short` as defined here...
|
|
||||||
--> $DIR/issue-107090.rs:13:21
|
|
||||||
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^
|
|
||||||
= note: ...but the lifetime must also be valid for the static lifetime...
|
|
||||||
note: ...so that the types are compatible
|
|
||||||
--> $DIR/issue-107090.rs:13:55
|
|
||||||
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
= note: expected `Convert<'short, 'static>`
|
|
||||||
found `Convert<'_, 'static>`
|
|
||||||
|
|
||||||
error: incompatible lifetime on type
|
|
||||||
--> $DIR/issue-107090.rs:24:29
|
|
||||||
|
|
|
|
||||||
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| - this type parameter ------- expected `&'out T` because of return type
|
||||||
|
LL |
|
||||||
|
LL | sadness.cast()
|
||||||
|
| ^^^^^^^^^^^^^^ expected `&T`, found `&Foo<'_, '_, T>`
|
||||||
|
|
|
|
||||||
note: because this has an unmet lifetime requirement
|
= note: expected reference `&'out T`
|
||||||
--> $DIR/issue-107090.rs:4:27
|
found reference `&Foo<'_, '_, T>`
|
||||||
|
|
|
||||||
LL | Foo<'short, 'out, T>: Convert<'a, 'b>;
|
|
||||||
| ^^^^^^^^^^^^^^^ introduces a `'static` lifetime requirement
|
|
||||||
note: the lifetime `'out` as defined here...
|
|
||||||
--> $DIR/issue-107090.rs:24:17
|
|
||||||
|
|
|
||||||
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
|
||||||
| ^^^^
|
|
||||||
note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
|
|
||||||
--> $DIR/issue-107090.rs:13:1
|
|
||||||
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error[E0759]: `x` has lifetime `'in_` but it needs to satisfy a `'static` lifetime requirement
|
error: aborting due to 7 previous errors
|
||||||
--> $DIR/issue-107090.rs:24:29
|
|
||||||
|
|
|
||||||
LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ Foo<'short, 'out, T>) -> &'out T {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
| |
|
|
||||||
| this data with lifetime `'in_`...
|
|
||||||
| ...is used and required to live as long as `'static` here
|
|
||||||
|
|
||||||
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'long` due to conflicting requirements
|
Some errors have detailed explanations: E0261, E0308.
|
||||||
--> $DIR/issue-107090.rs:17:13
|
|
||||||
|
|
|
||||||
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: first, the lifetime cannot outlive the lifetime `'short` as defined here...
|
|
||||||
--> $DIR/issue-107090.rs:13:21
|
|
||||||
|
|
|
||||||
LL | impl<'long: 'short, 'short, T> Convert<'long, 'b> for Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^
|
|
||||||
= note: ...but the lifetime must also be valid for the static lifetime...
|
|
||||||
note: ...so that the types are compatible
|
|
||||||
--> $DIR/issue-107090.rs:17:13
|
|
||||||
|
|
|
||||||
LL | fn cast(&'long self) -> &'short Foo<'short, 'out, T> {
|
|
||||||
| ^^^^^^^^^^^
|
|
||||||
= note: expected `Convert<'short, 'static>`
|
|
||||||
found `Convert<'_, 'static>`
|
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0261, E0308, E0495, E0759.
|
|
||||||
For more information about an error, try `rustc --explain E0261`.
|
For more information about an error, try `rustc --explain E0261`.
|
||||||
|
@ -46,7 +46,6 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||||||
LL | impl<'self> Serializable<str> for &'self str {
|
LL | impl<'self> Serializable<str> for &'self str {
|
||||||
| ^^^^^^^^^^^^^^^^^ expected lifetime parameter
|
| ^^^^^^^^^^^^^^^^^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
= note: assuming a `'static` lifetime...
|
|
||||||
help: indicate the anonymous lifetime
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | impl<'self> Serializable<'_, str> for &'self str {
|
LL | impl<'self> Serializable<'_, str> for &'self str {
|
||||||
|
@ -40,9 +40,9 @@ error[E0308]: mismatched types
|
|||||||
LL | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() }
|
LL | fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next() }
|
||||||
| ---- ^^^^^^^^^^^ expected `&str`, found `Option<&str>`
|
| ---- ^^^^^^^^^^^ expected `&str`, found `Option<&str>`
|
||||||
| |
|
| |
|
||||||
| expected `&'static str` because of return type
|
| expected `&str` because of return type
|
||||||
|
|
|
|
||||||
= note: expected reference `&'static str`
|
= note: expected reference `&str`
|
||||||
found enum `Option<&str>`
|
found enum `Option<&str>`
|
||||||
|
|
||||||
error[E0061]: this function takes 1 argument but 0 arguments were supplied
|
error[E0061]: this function takes 1 argument but 0 arguments were supplied
|
||||||
|
22
tests/ui/lifetimes/issue-69314.fixed
Normal file
22
tests/ui/lifetimes/issue-69314.fixed
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// run-rustfix
|
||||||
|
// edition:2021
|
||||||
|
#![allow(dead_code, unused_mut, unused_variables)]
|
||||||
|
struct A {}
|
||||||
|
struct Msg<'a> {
|
||||||
|
s: &'a [i32],
|
||||||
|
}
|
||||||
|
impl A {
|
||||||
|
async fn g(buf: &[i32]) -> Msg<'_> {
|
||||||
|
Msg { s: &buf[0..1] }
|
||||||
|
}
|
||||||
|
async fn f() {
|
||||||
|
let mut buf = [0; 512];
|
||||||
|
let m2 = &buf[..]; //~ ERROR `buf` does not live long enough
|
||||||
|
let m = Self::g(m2).await;
|
||||||
|
Self::f2(m).await;
|
||||||
|
}
|
||||||
|
async fn f2(m: Msg<'_>) {}
|
||||||
|
//~^ ERROR implicit elided lifetime not allowed here
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
22
tests/ui/lifetimes/issue-69314.rs
Normal file
22
tests/ui/lifetimes/issue-69314.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// run-rustfix
|
||||||
|
// edition:2021
|
||||||
|
#![allow(dead_code, unused_mut, unused_variables)]
|
||||||
|
struct A {}
|
||||||
|
struct Msg<'a> {
|
||||||
|
s: &'a [i32],
|
||||||
|
}
|
||||||
|
impl A {
|
||||||
|
async fn g(buf: &[i32]) -> Msg<'_> {
|
||||||
|
Msg { s: &buf[0..1] }
|
||||||
|
}
|
||||||
|
async fn f() {
|
||||||
|
let mut buf = [0; 512];
|
||||||
|
let m2 = &buf[..]; //~ ERROR `buf` does not live long enough
|
||||||
|
let m = Self::g(m2).await;
|
||||||
|
Self::f2(m).await;
|
||||||
|
}
|
||||||
|
async fn f2(m: Msg) {}
|
||||||
|
//~^ ERROR implicit elided lifetime not allowed here
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
26
tests/ui/lifetimes/issue-69314.stderr
Normal file
26
tests/ui/lifetimes/issue-69314.stderr
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
error[E0726]: implicit elided lifetime not allowed here
|
||||||
|
--> $DIR/issue-69314.rs:18:20
|
||||||
|
|
|
||||||
|
LL | async fn f2(m: Msg) {}
|
||||||
|
| ^^^ expected lifetime parameter
|
||||||
|
|
|
||||||
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
||||||
|
LL | async fn f2(m: Msg<'_>) {}
|
||||||
|
| ++++
|
||||||
|
|
||||||
|
error[E0597]: `buf` does not live long enough
|
||||||
|
--> $DIR/issue-69314.rs:14:19
|
||||||
|
|
|
||||||
|
LL | let m2 = &buf[..];
|
||||||
|
| ^^^ borrowed value does not live long enough
|
||||||
|
LL | let m = Self::g(m2).await;
|
||||||
|
| ----------- argument requires that `buf` is borrowed for `'static`
|
||||||
|
LL | Self::f2(m).await;
|
||||||
|
LL | }
|
||||||
|
| - `buf` dropped here while still borrowed
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0597, E0726.
|
||||||
|
For more information about an error, try `rustc --explain E0597`.
|
@ -23,6 +23,6 @@ fn c<T = u8()>() {}
|
|||||||
// Elided lifetime in path in ConstGeneric
|
// Elided lifetime in path in ConstGeneric
|
||||||
fn d<const C: S>() {}
|
fn d<const C: S>() {}
|
||||||
//~^ ERROR missing lifetime specifier
|
//~^ ERROR missing lifetime specifier
|
||||||
//~| ERROR `S<'static>` is forbidden as the type of a const generic parameter
|
//~| ERROR `S<'_>` is forbidden as the type of a const generic parameter
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -46,7 +46,7 @@ LL | fn a() -> [u8; foo::()] {
|
|||||||
= note: expected type `usize`
|
= note: expected type `usize`
|
||||||
found fn item `fn() {foo}`
|
found fn item `fn() {foo}`
|
||||||
|
|
||||||
error: `S<'static>` is forbidden as the type of a const generic parameter
|
error: `S<'_>` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/unusual-rib-combinations.rs:24:15
|
--> $DIR/unusual-rib-combinations.rs:24:15
|
||||||
|
|
|
|
||||||
LL | fn d<const C: S>() {}
|
LL | fn d<const C: S>() {}
|
||||||
|
@ -16,9 +16,9 @@ LL | fn next(&mut self) -> Option<IteratorChunk<T, S>> {
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
|
||||||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
||||||
|
|
|
|
||||||
= note: expected `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'static, T, S>>`
|
= note: expected `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'2, T, S>>`
|
||||||
|
|
|
|
||||||
= note: expected signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'static, T, S>>`
|
= note: expected signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'2, T, S>>`
|
||||||
found signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
|
found signature `fn(&'1 mut ChunkingIterator<T, S>) -> Option<IteratorChunk<'1, T, S>>`
|
||||||
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
|
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
|
||||||
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
|
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
|
||||||
|
@ -4,7 +4,7 @@ fn main() {
|
|||||||
let y = 42;
|
let y = 42;
|
||||||
let x = wrong_generic(&y);
|
let x = wrong_generic(&y);
|
||||||
let z: i32 = x;
|
let z: i32 = x;
|
||||||
//~^ ERROR expected generic type parameter, found `&'static i32
|
//~^ ERROR expected generic type parameter, found `&i32`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WrongGeneric<T> = impl 'static;
|
type WrongGeneric<T> = impl 'static;
|
||||||
|
@ -4,7 +4,7 @@ error: at least one trait must be specified
|
|||||||
LL | type WrongGeneric<T> = impl 'static;
|
LL | type WrongGeneric<T> = impl 'static;
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0792]: expected generic type parameter, found `&'static i32`
|
error[E0792]: expected generic type parameter, found `&i32`
|
||||||
--> $DIR/generic_type_does_not_live_long_enough.rs:6:18
|
--> $DIR/generic_type_does_not_live_long_enough.rs:6:18
|
||||||
|
|
|
|
||||||
LL | let z: i32 = x;
|
LL | let z: i32 = x;
|
||||||
|
@ -13,5 +13,5 @@ pub struct Ref<'a>(&'a u8);
|
|||||||
impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here
|
impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn repro(_: Wrapper<Ref>); //~ ERROR: incompatible lifetime on type
|
pub fn repro(_: Wrapper<Ref>);
|
||||||
}
|
}
|
||||||
|
@ -4,34 +4,11 @@ error[E0726]: implicit elided lifetime not allowed here
|
|||||||
LL | impl Trait for Ref {}
|
LL | impl Trait for Ref {}
|
||||||
| ^^^ expected lifetime parameter
|
| ^^^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
= note: assuming a `'static` lifetime...
|
|
||||||
help: indicate the anonymous lifetime
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | impl Trait for Ref<'_> {}
|
LL | impl Trait for Ref<'_> {}
|
||||||
| ++++
|
| ++++
|
||||||
|
|
||||||
error: incompatible lifetime on type
|
error: aborting due to previous error
|
||||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21
|
|
||||||
|
|
|
||||||
LL | pub fn repro(_: Wrapper<Ref>);
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
note: because this has an unmet lifetime requirement
|
|
||||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:8:23
|
|
||||||
|
|
|
||||||
LL | pub struct Wrapper<T: Trait>(T);
|
|
||||||
| ^^^^^ introduces a `'static` lifetime requirement
|
|
||||||
note: the anonymous lifetime as defined here...
|
|
||||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:29
|
|
||||||
|
|
|
||||||
LL | pub fn repro(_: Wrapper<Ref>);
|
|
||||||
| ^^^
|
|
||||||
note: ...does not necessarily outlive the static lifetime introduced by the compatible `impl`
|
|
||||||
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:1
|
|
||||||
|
|
|
||||||
LL | impl Trait for Ref {}
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0726`.
|
For more information about this error, try `rustc --explain E0726`.
|
||||||
|
Loading…
Reference in New Issue
Block a user