Rollup merge of #108289 - compiler-errors:name-placeholder, r=petrochenkov

Name placeholder in some region errors

Also don't print `ReVar` or `ReLateBound` as debug... these error messages are super uncommon anyways, but in the case they do trigger, let's be slightly more helpful.
This commit is contained in:
Dylan DPC 2023-02-21 14:20:01 +05:30 committed by GitHub
commit 270f45e172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View file

@ -129,21 +129,16 @@ pub(super) fn note_and_explain_region<'tcx>(
alt_span: Option<Span>, alt_span: Option<Span>,
) { ) {
let (description, span) = match *region { let (description, span) = match *region {
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => { ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => {
msg_span_from_free_region(tcx, region, alt_span) msg_span_from_named_region(tcx, region, alt_span)
} }
ty::RePlaceholder(_) => return,
ty::ReError(_) => return, ty::ReError(_) => return,
// FIXME(#13998) RePlaceholder should probably print like
// ReFree rather than dumping Debug output on the user.
//
// We shouldn't really be having unification failures with ReVar // We shouldn't really be having unification failures with ReVar
// and ReLateBound though. // and ReLateBound though.
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => { ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
(format!("lifetime {:?}", region), alt_span) (format!("lifetime `{region}`"), alt_span)
} }
}; };
@ -157,12 +152,12 @@ fn explain_free_region<'tcx>(
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
suffix: &str, suffix: &str,
) { ) {
let (description, span) = msg_span_from_free_region(tcx, region, None); let (description, span) = msg_span_from_named_region(tcx, region, None);
label_msg_span(err, prefix, description, span, suffix); label_msg_span(err, prefix, description, span, suffix);
} }
fn msg_span_from_free_region<'tcx>( fn msg_span_from_named_region<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>, region: ty::Region<'tcx>,
alt_span: Option<Span>, alt_span: Option<Span>,
@ -173,6 +168,18 @@ fn msg_span_from_free_region<'tcx>(
(msg, Some(span)) (msg, Some(span))
} }
ty::ReStatic => ("the static lifetime".to_owned(), alt_span), ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrNamed(def_id, name),
..
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrAnon(_, Some(span)),
..
}) => (format!("the anonymous lifetime defined here"), Some(span)),
ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BoundRegionKind::BrAnon(_, None),
..
}) => (format!("an anonymous lifetime"), None),
_ => bug!("{:?}", region), _ => bug!("{:?}", region),
} }
} }

View file

@ -1,5 +1,10 @@
error[E0311]: the parameter type `Self` may not live long enough error[E0311]: the parameter type `Self` may not live long enough
| |
note: the parameter type `Self` must be valid for the lifetime `'a` as defined here...
--> $DIR/object-safety-supertrait-mentions-GAT.rs:9:26
|
LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
| ^^
= help: consider adding an explicit lifetime bound `Self: 'a`... = help: consider adding an explicit lifetime bound `Self: 'a`...
= note: ...so that the type `Self` will meet its required lifetime bounds... = note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound note: ...that is required by this bound