Skip to content

Commit

Permalink
do not suggest adding a bound to a opaque type
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Aug 24, 2022
1 parent 87991d5 commit 3855e03
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
_ => {}
}
}
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(

fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
err: &mut Diagnostic,
category: &ConstraintCategory<'tcx>,
span: Span,
region_name: &RegionName,
) {
if !span.is_desugaring(DesugaringKind::OpaqueTy) {
return;
}
if let ConstraintCategory::OpaqueType = category {
let suggestable_name =
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/regions/do-not-suggest-adding-bound-to-opaque-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![feature(allocator_api)]

use std::{
alloc::{AllocError, Allocator, Layout},
ptr::NonNull,
};

struct GhostBump;

unsafe impl Allocator for &GhostBump {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
todo!()
}

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
todo!()
}
}

fn foo() -> impl Iterator<Item = usize> {
let arena = GhostBump;
let mut vec = Vec::new_in(&arena); //~ ERROR `arena` does not live long enough
vec.push(1);
vec.push(2);
vec.push(3);
vec.into_iter()
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0597]: `arena` does not live long enough
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:22:31
|
LL | let mut vec = Vec::new_in(&arena);
| ^^^^^^ borrowed value does not live long enough
...
LL | vec.into_iter()
| --------------- opaque type requires that `arena` is borrowed for `'static`
LL | }
| - `arena` dropped here while still borrowed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.

0 comments on commit 3855e03

Please sign in to comment.