Skip to content
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

Remove the infer_static_outlives_requirements feature #97875

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,6 @@ declare_features! (
(active, if_let_guard, "1.47.0", Some(51114), None),
/// Allows using imported `main` function
(active, imported_main, "1.53.0", Some(28937), None),
/// Allows inferring `'static` outlives requirements (RFC 2093).
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
/// Allows associated types in inherent impls.
(incomplete, inherent_associated_types, "1.52.0", Some(8995), None),
/// Allow anonymous constants from an inline `const` block
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ declare_features! (
/// Allows in-band quantification of lifetime bindings (e.g., `fn foo(x: &'a u8) -> &'a u8`).
(removed, in_band_lifetimes, "1.23.0", Some(44524), None,
Some("removed due to unsolved ergonomic questions and added lifetime resolution complexity")),
/// Allows inferring `'static` outlives requirements (RFC 2093).
(removed, infer_static_outlives_requirements, "1.63.0", Some(54185), None,
Some("removed as it caused some confusion and discussion was inactive for years")),
/// Lazily evaluate constants. This allows constants to depend on type parameters.
(removed, lazy_normalization_consts, "1.46.0", Some(72219), None, Some("superseded by `generic_const_exprs`")),
/// Allows using the `#[link_args]` attribute.
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,6 @@ impl ExplicitOutlivesRequirements {
tcx: TyCtxt<'tcx>,
bounds: &hir::GenericBounds<'_>,
inferred_outlives: &[ty::Region<'tcx>],
infer_static: bool,
) -> Vec<(usize, Span)> {
use rustc_middle::middle::resolve_lifetime::Region;

Expand All @@ -2123,9 +2122,6 @@ impl ExplicitOutlivesRequirements {
.filter_map(|(i, bound)| {
if let hir::GenericBound::Outlives(lifetime) = bound {
let is_inferred = match tcx.named_region(lifetime.hir_id) {
Some(Region::Static) if infer_static => {
inferred_outlives.iter().any(|r| matches!(**r, ty::ReStatic))
}
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
if let ty::ReEarlyBound(ebr) = **r { ebr.index == index } else { false }
}),
Expand Down Expand Up @@ -2201,7 +2197,6 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
use rustc_middle::middle::resolve_lifetime::Region;

let infer_static = cx.tcx.features().infer_static_outlives_requirements;
let def_id = item.def_id;
if let hir::ItemKind::Struct(_, ref hir_generics)
| hir::ItemKind::Enum(_, ref hir_generics)
Expand Down Expand Up @@ -2262,12 +2257,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
continue;
}

let bound_spans = self.collect_outlives_bound_spans(
cx.tcx,
bounds,
&relevant_lifetimes,
infer_static,
);
let bound_spans =
self.collect_outlives_bound_spans(cx.tcx, bounds, &relevant_lifetimes);
bound_count += bound_spans.len();

let drop_predicate = bound_spans.len() == bounds.len();
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_typeck/src/outlives/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn insert_outlives_predicate<'tcx>(
) {
// If the `'a` region is bound within the field type itself, we
// don't want to propagate this constraint to the header.
if !is_free_region(tcx, outlived_region) {
if !is_free_region(outlived_region) {
return;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn insert_outlives_predicate<'tcx>(
}

GenericArgKind::Lifetime(r) => {
if !is_free_region(tcx, r) {
if !is_free_region(r) {
return;
}
required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)).or_insert(span);
Expand All @@ -131,7 +131,7 @@ pub fn insert_outlives_predicate<'tcx>(
}
}

fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
fn is_free_region(region: Region<'_>) -> bool {
// First, screen for regions that might appear in a type header.
match *region {
// These correspond to `T: 'a` relationships:
Expand All @@ -144,13 +144,12 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
ty::ReEarlyBound(_) => true,

// These correspond to `T: 'static` relationships which can be
// rather surprising. We are therefore putting this behind a
// feature flag:
// rather surprising.
//
// struct Foo<'a, T> {
// field: &'static T, // this would generate a ReStatic
// }
ty::ReStatic => tcx.sess.features_untracked().infer_static_outlives_requirements,
ty::ReStatic => false,

// Late-bound regions can appear in `fn` types:
//
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions src/test/ui/rfc-2093-infer-outlives/dont-infer-static.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* We don't infer `T: 'static` outlives relationships by default.
* Instead an additional feature gate `infer_static_outlives_requirements`
* is required.
* We don't infer `T: 'static` outlives relationships.
*/

struct Foo<U> {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/rfc-2093-infer-outlives/dont-infer-static.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0310]: the parameter type `U` may not live long enough
--> $DIR/dont-infer-static.rs:8:10
--> $DIR/dont-infer-static.rs:6:10
|
LL | bar: Bar<U>
| ^^^^^^ ...so that the type `U` will meet its required lifetime bounds...
|
note: ...that is required by this bound
--> $DIR/dont-infer-static.rs:10:15
--> $DIR/dont-infer-static.rs:8:15
|
LL | struct Bar<T: 'static> {
| ^^^^^^^
Expand Down
12 changes: 0 additions & 12 deletions src/test/ui/rfc-2093-infer-outlives/infer-static.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/rfc-2093-infer-outlives/infer-static.stderr

This file was deleted.