Skip to content

Commit 3855e03

Browse files
committed
do not suggest adding a bound to a opaque type
1 parent 87991d5 commit 3855e03

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
273273
_ => {}
274274
}
275275
}
276-
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
276+
277+
fn add_lifetime_bound_suggestion_to_diagnostic(
277278
&self,
278279
err: &mut Diagnostic,
279280
category: &ConstraintCategory<'tcx>,
280281
span: Span,
281282
region_name: &RegionName,
282283
) {
284+
if !span.is_desugaring(DesugaringKind::OpaqueTy) {
285+
return;
286+
}
283287
if let ConstraintCategory::OpaqueType = category {
284288
let suggestable_name =
285289
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(allocator_api)]
2+
3+
use std::{
4+
alloc::{AllocError, Allocator, Layout},
5+
ptr::NonNull,
6+
};
7+
8+
struct GhostBump;
9+
10+
unsafe impl Allocator for &GhostBump {
11+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
12+
todo!()
13+
}
14+
15+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
16+
todo!()
17+
}
18+
}
19+
20+
fn foo() -> impl Iterator<Item = usize> {
21+
let arena = GhostBump;
22+
let mut vec = Vec::new_in(&arena); //~ ERROR `arena` does not live long enough
23+
vec.push(1);
24+
vec.push(2);
25+
vec.push(3);
26+
vec.into_iter()
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0597]: `arena` does not live long enough
2+
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:22:31
3+
|
4+
LL | let mut vec = Vec::new_in(&arena);
5+
| ^^^^^^ borrowed value does not live long enough
6+
...
7+
LL | vec.into_iter()
8+
| --------------- opaque type requires that `arena` is borrowed for `'static`
9+
LL | }
10+
| - `arena` 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)