Skip to content

Commit 75b1b69

Browse files
authored
Rollup merge of rust-lang#100940 - TaKO8Ki:do-not-suggest-adding-bound-to-opaque-type, r=fee1-dead
Do not suggest adding a bound to a opaque type fixes rust-lang#100442
2 parents a0fbfd8 + c57ecfa commit 75b1b69

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+3
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
281281
span: Span,
282282
region_name: &RegionName,
283283
) {
284+
if !span.is_desugaring(DesugaringKind::OpaqueTy) {
285+
return;
286+
}
284287
if let ConstraintCategory::OpaqueType = category {
285288
let suggestable_name =
286289
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub trait T {}
2+
3+
struct S<'a>(&'a ());
4+
5+
impl<'a> T for S<'a> {}
6+
7+
fn foo() -> impl T {
8+
let x = ();
9+
S(&x) //~ ERROR `x` does not live long enough
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0597]: `x` does not live long enough
2+
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:9:7
3+
|
4+
LL | S(&x)
5+
| --^^-
6+
| | |
7+
| | borrowed value does not live long enough
8+
| opaque type requires that `x` is borrowed for `'static`
9+
LL | }
10+
| - `x` dropped here while still borrowed
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)