Skip to content

Commit 270f45e

Browse files
authored
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.
2 parents 6a21237 + 2895731 commit 270f45e

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,16 @@ pub(super) fn note_and_explain_region<'tcx>(
129129
alt_span: Option<Span>,
130130
) {
131131
let (description, span) = match *region {
132-
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
133-
msg_span_from_free_region(tcx, region, alt_span)
132+
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => {
133+
msg_span_from_named_region(tcx, region, alt_span)
134134
}
135135

136-
ty::RePlaceholder(_) => return,
137-
138136
ty::ReError(_) => return,
139137

140-
// FIXME(#13998) RePlaceholder should probably print like
141-
// ReFree rather than dumping Debug output on the user.
142-
//
143138
// We shouldn't really be having unification failures with ReVar
144139
// and ReLateBound though.
145140
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
146-
(format!("lifetime {:?}", region), alt_span)
141+
(format!("lifetime `{region}`"), alt_span)
147142
}
148143
};
149144

@@ -157,12 +152,12 @@ fn explain_free_region<'tcx>(
157152
region: ty::Region<'tcx>,
158153
suffix: &str,
159154
) {
160-
let (description, span) = msg_span_from_free_region(tcx, region, None);
155+
let (description, span) = msg_span_from_named_region(tcx, region, None);
161156

162157
label_msg_span(err, prefix, description, span, suffix);
163158
}
164159

165-
fn msg_span_from_free_region<'tcx>(
160+
fn msg_span_from_named_region<'tcx>(
166161
tcx: TyCtxt<'tcx>,
167162
region: ty::Region<'tcx>,
168163
alt_span: Option<Span>,
@@ -173,6 +168,18 @@ fn msg_span_from_free_region<'tcx>(
173168
(msg, Some(span))
174169
}
175170
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
171+
ty::RePlaceholder(ty::PlaceholderRegion {
172+
name: ty::BoundRegionKind::BrNamed(def_id, name),
173+
..
174+
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
175+
ty::RePlaceholder(ty::PlaceholderRegion {
176+
name: ty::BoundRegionKind::BrAnon(_, Some(span)),
177+
..
178+
}) => (format!("the anonymous lifetime defined here"), Some(span)),
179+
ty::RePlaceholder(ty::PlaceholderRegion {
180+
name: ty::BoundRegionKind::BrAnon(_, None),
181+
..
182+
}) => (format!("an anonymous lifetime"), None),
176183
_ => bug!("{:?}", region),
177184
}
178185
}

tests/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr

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

0 commit comments

Comments
 (0)