-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
add static_in_const feature gate #36332
Changes from 1 commit
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 |
---|---|---|
|
@@ -213,6 +213,45 @@ impl RegionScope for ElidableRscope { | |
} | ||
} | ||
|
||
/// A scope that behaves as an ElidabeRscope with a `'static` default region | ||
/// that should also warn if the `static_in_const` feature is unset. | ||
#[derive(Copy, Clone)] | ||
pub struct StaticRscope<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { | ||
tcx: &'a ty::TyCtxt<'a, 'gcx, 'tcx>, | ||
} | ||
|
||
impl<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> StaticRscope<'a, 'gcx, 'tcx> { | ||
/// create a new StaticRscope from a reference to the `TyCtxt` | ||
pub fn new(tcx: &'a ty::TyCtxt<'a, 'gcx, 'tcx>) -> Self { | ||
StaticRscope { tcx: tcx } | ||
} | ||
} | ||
|
||
impl<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> RegionScope for StaticRscope<'a, 'gcx, 'tcx> { | ||
fn anon_regions(&self, | ||
_span: Span, | ||
count: usize) | ||
-> Result<Vec<ty::Region>, Option<Vec<ElisionFailureInfo>>> { | ||
Ok(vec![ty::ReStatic; count]) | ||
} | ||
|
||
fn object_lifetime_default(&self, span: Span) -> Option<ty::Region> { | ||
Some(self.base_object_lifetime_default(span)) | ||
} | ||
|
||
fn base_object_lifetime_default(&self, span: Span) -> ty::Region { | ||
if !self.tcx.sess.features.borrow().static_in_const { | ||
self.tcx | ||
.sess | ||
.struct_span_warn(span, | ||
"This needs a `'static` lifetime or the \ | ||
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. Nit: it should be |
||
`static_in_const` feature, see #35897") | ||
.emit(); | ||
} | ||
ty::ReStatic | ||
} | ||
} | ||
|
||
/// A scope in which we generate anonymous, late-bound regions for | ||
/// omitted regions. This occurs in function signatures. | ||
pub struct BindingRscope { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,9 @@ declare_features! ( | |
|
||
// Allows untagged unions `union U { ... }` | ||
(active, untagged_unions, "1.13.0", Some(32836)), | ||
|
||
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.
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. Thanks for the heads-up, added. |
||
// elide `'static` lifetimes in `static`s and `const`s | ||
(active, static_in_const, "1.13.0", Some(35897)), | ||
); | ||
|
||
declare_features! ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ fn main() { | |
static foo: Fn() -> u32 = || -> u32 { | ||
//~^ ERROR: mismatched types | ||
//~| ERROR: `std::ops::Fn() -> u32 + 'static: std::marker::Sized` is not satisfied | ||
|
||
//~| WARNING: This needs a `'static` lifetime or the `static_in_const` feature | ||
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. These cases seem like bugs -- see my comment above. |
||
0 | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(static_in_const)] | ||
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. Nit: can you make another test that specifically uses the feature w/o the feature gate and check that it reports an error 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. Sure thing. |
||
#![allow(dead_code)] | ||
|
||
fn non_elidable<'a, 'b>(a: &'a u8, b: &'b u8) -> &'a u8 { | ||
|
This file was deleted.
This file was deleted.
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.
Ah, I see the problem; these routines should be the same as for elidable rscope:
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.
Should I report the error in
anon_regions(..)
then?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.
Yes.
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.
Ok, done.