Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,16 @@ pub(super) fn note_and_explain_region<'tcx>(
alt_span: Option<Span>,
) {
let (description, span) = match *region {
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
msg_span_from_free_region(tcx, region, alt_span)
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => {
msg_span_from_named_region(tcx, region, alt_span)
}

ty::RePlaceholder(_) => 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
// and ReLateBound though.
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
(format!("lifetime {:?}", region), alt_span)
(format!("lifetime `{region}`"), alt_span)
}
};

Expand All @@ -157,12 +152,12 @@ fn explain_free_region<'tcx>(
region: ty::Region<'tcx>,
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);
}

fn msg_span_from_free_region<'tcx>(
fn msg_span_from_named_region<'tcx>(
tcx: TyCtxt<'tcx>,
region: ty::Region<'tcx>,
alt_span: Option<Span>,
Expand All @@ -173,6 +168,18 @@ fn msg_span_from_free_region<'tcx>(
(msg, Some(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),
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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`...
= note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
Expand Down