-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
WF check lifetime bounds for locals with type params #149389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -547,7 +547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
| where | ||
| T: TypeVisitable<TyCtxt<'tcx>>, | ||
| { | ||
| t.has_free_regions() || t.has_aliases() || t.has_infer_types() | ||
| t.has_free_regions() || t.has_aliases() || t.has_infer_types() || t.has_param() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the perf cost of making this be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to test this in a separate PR maybe? could just open a draft for a perf run cc @ShoyuVanilla if u'd be up to open one, I'd then start a perf run
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll open one once I get home |
||
| } | ||
|
|
||
| pub(crate) fn node_ty(&self, id: HirId) -> Ty<'tcx> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // A regression test for https://github.com/rust-lang/rust/issues/115175. | ||
| // This used to compile without error despite of unsatisfied outlives bound `T: 'static` on local. | ||
|
|
||
| struct Static<T: 'static>(T); | ||
|
|
||
| fn test<T>() { | ||
| let _ = None::<Static<T>>; | ||
| //~^ ERROR the parameter type `T` may not live long enough | ||
| } | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| error[E0310]: the parameter type `T` may not live long enough | ||
| --> $DIR/wf-bound-region-in-local-issue-115175.rs:7:13 | ||
| | | ||
| LL | let _ = None::<Static<T>>; | ||
| | ^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | the parameter type `T` must be valid for the static lifetime... | ||
| | ...so that the type `T` will meet its required lifetime bounds | ||
| | | ||
| help: consider adding an explicit lifetime bound | ||
| | | ||
| LL | fn test<T: 'static>() { | ||
| | +++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0310`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // A regression test for https://github.com/rust-lang/rust/issues/148854. | ||
|
|
||
| use std::cell::OnceCell; | ||
| use std::fmt::Display; | ||
| use std::marker::PhantomData; | ||
| use std::rc::Rc; | ||
|
|
||
| type Storage = Rc<OnceCell<Box<dyn Display + 'static>>>; | ||
|
|
||
| trait IntoDyn<T> { | ||
| fn into_dyn(input: T, output: Storage); | ||
| } | ||
|
|
||
| struct Inner<T: Display + 'static>(PhantomData<T>); | ||
| impl<T: Display> IntoDyn<T> for Inner<T> { | ||
| fn into_dyn(input: T, output: Storage) { | ||
| output.set(Box::new(input)).ok().unwrap(); | ||
| } | ||
| } | ||
|
|
||
| struct Outer<T, U: IntoDyn<T>> { | ||
| input: Option<T>, | ||
| output: Storage, | ||
| _phantom: PhantomData<U>, | ||
| } | ||
| impl<T, U: IntoDyn<T>> Drop for Outer<T, U> { | ||
| fn drop(&mut self) { | ||
| U::into_dyn(self.input.take().unwrap(), self.output.clone()); | ||
| } | ||
| } | ||
|
|
||
| fn extend<T: Display>(x: T) -> Box<dyn Display + 'static> { | ||
| let storage = Rc::new(OnceCell::new()); | ||
| { | ||
| // This has to error due to an unsatisfied outlives bound on | ||
| // `Inner<T: 'static>` as its implicit drop relies on that | ||
| // bound. | ||
| let _ = | ||
| Outer::<T, Inner<T>> { input: Some(x), output: storage.clone(), _phantom: PhantomData }; | ||
| //~^ ERROR: the parameter type `T` may not live long enough | ||
| } | ||
| Rc::into_inner(storage).unwrap().into_inner().unwrap() | ||
| } | ||
|
|
||
| fn main() { | ||
| let wrong = { | ||
| let data = String::from("abc"); | ||
| extend::<&String>(&data) | ||
| }; | ||
| println!("{wrong}"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| error[E0310]: the parameter type `T` may not live long enough | ||
| --> $DIR/wf-bound-region-in-local-soundness-issue-148854.rs:39:13 | ||
| | | ||
| LL | Outer::<T, Inner<T>> { input: Some(x), output: storage.clone(), _phantom: PhantomData }; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | the parameter type `T` must be valid for the static lifetime... | ||
| | ...so that the type `T` will meet its required lifetime bounds | ||
| | | ||
| help: consider adding an explicit lifetime bound | ||
| | | ||
| LL | fn extend<T: Display + 'static>(x: T) -> Box<dyn Display + 'static> { | ||
| | +++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0310`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive by fixme xd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.has_infer():3