-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Stability annotations on generic parameters (take 2) #72314
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
Changes from 1 commit
9c60c94
d1bd1bf
e357e65
af4969e
b8ebdf9
7b7b84f
a81a46f
734b08c
0c6affe
868ab1c
9662fd2
1680b33
ad1f406
03c1f14
61b2bff
61c8855
fc2e2d6
e1ea2c3
5c9b5bf
c1650b3
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 |
---|---|---|
|
@@ -280,9 +280,15 @@ impl<'tcx> TyCtxt<'tcx> { | |
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been | ||
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to | ||
/// `id`. | ||
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult { | ||
pub fn eval_stability( | ||
self, | ||
def_id: DefId, | ||
id: Option<HirId>, | ||
span: Span, | ||
check_deprecation: bool, | ||
Avi-D-coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> EvalResult { | ||
// Deprecated attributes apply in-crate and cross-crate. | ||
if let Some(id) = id { | ||
if let (Some(id), true) = (id, check_deprecation) { | ||
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) { | ||
let parent_def_id = self.hir().local_def_id(self.hir().get_parent_item(id)); | ||
let skip = self | ||
|
@@ -377,21 +383,39 @@ impl<'tcx> TyCtxt<'tcx> { | |
/// Additionally, this function will also check if the item is deprecated. If so, and `id` is | ||
/// not `None`, a deprecated lint attached to `id` will be emitted. | ||
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) { | ||
self.check_stability_internal(def_id, id, span, true, |span, def_id| { | ||
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. Why is this extra method necessary? 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. TLDR: many unfixable errors are produced if we call Generic parameters are not always marked stable. 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. Hmm, so the issue is that generic parameters are the only language feature that has optional stability: everything else is either not a |
||
// The API could be uncallable for other reasons, for example when a private module | ||
// was referenced. | ||
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id)); | ||
}) | ||
} | ||
|
||
/// Checks if an item is stable or error out. | ||
/// | ||
/// If the item defined by `def_id` is unstable and the corresponding `#![feature]` does not | ||
/// exist, emits an error. | ||
/// | ||
/// Additionally when `inherit_dep` is `true`, this function will also check if the item is deprecated. If so, and `id` is | ||
/// not `None`, a deprecated lint attached to `id` will be emitted. | ||
pub fn check_stability_internal( | ||
self, | ||
def_id: DefId, | ||
id: Option<HirId>, | ||
span: Span, | ||
check_deprecation: bool, | ||
unmarked: impl FnOnce(Span, DefId) -> (), | ||
) { | ||
let soft_handler = |lint, span, msg: &_| { | ||
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| { | ||
lint.build(msg).emit() | ||
}) | ||
}; | ||
match self.eval_stability(def_id, id, span) { | ||
match self.eval_stability(def_id, id, span, check_deprecation) { | ||
EvalResult::Allow => {} | ||
EvalResult::Deny { feature, reason, issue, is_soft } => { | ||
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler) | ||
} | ||
EvalResult::Unmarked => { | ||
// The API could be uncallable for other reasons, for example when a private module | ||
// was referenced. | ||
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id)); | ||
} | ||
EvalResult::Unmarked => unmarked(span, def_id), | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#![crate_type = "lib"] | ||
#![feature(staged_api)] | ||
|
||
#![stable(feature = "stable_test_feature", since = "1.0.0")] | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub trait Trait1<#[unstable(feature = "unstable_default", issue = "none")] T = ()> { | ||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
fn foo() -> T; | ||
} | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub trait Trait2<#[unstable(feature = "unstable_default", issue = "none")] T = usize> { | ||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
fn foo() -> T; | ||
} | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub trait Trait3<T = ()> { | ||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
fn foo() -> T; | ||
} | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub struct Struct1<#[unstable(feature = "unstable_default", issue = "none")] T = usize> { | ||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub field: T, | ||
} | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub struct Struct2<T = usize> { | ||
Avi-D-coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub field: T, | ||
} | ||
|
||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub const STRUCT1: Struct1 = Struct1 { field: 1 }; | ||
|
||
#[stable(feature = "stable_test_feature", since = "1.0.0")] | ||
pub const STRUCT2: Struct2 = Struct2 { field: 1 }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// aux-build:unstable_generic_param.rs | ||
Avi-D-coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
extern crate unstable_generic_param; | ||
|
||
use unstable_generic_param::*; | ||
|
||
struct R; | ||
|
||
impl Trait1 for S { | ||
fn foo() -> () { () } // ok | ||
} | ||
|
||
struct S; | ||
|
||
impl Trait1<usize> for S { //~ ERROR use of unstable library feature 'unstable_default' | ||
fn foo() -> usize { 0 } | ||
} | ||
|
||
impl Trait1<isize> for S { //~ ERROR use of unstable library feature 'unstable_default' | ||
fn foo() -> isize { 0 } | ||
} | ||
|
||
impl Trait2<usize> for S { //~ ERROR use of unstable library feature 'unstable_default' | ||
Aaron1011 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fn foo() -> usize { 0 } | ||
} | ||
|
||
impl Trait3<usize> for S { | ||
fn foo() -> usize { 0 } // ok | ||
} | ||
|
||
fn main() { | ||
// let _ = S; | ||
|
||
// let _ = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _: Struct1 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _: Struct1<isize> = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' | ||
|
||
// let _ = STRUCT1; // ok | ||
// let _: Struct1 = STRUCT1; // ok | ||
// let _: Struct1<usize> = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _: Struct1<usize> = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _ = STRUCT1.field; // ok | ||
// let _: usize = STRUCT1.field; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _ = STRUCT1.field + 1; //~ ERROR use of unstable library feature 'unstable_default' | ||
// let _ = STRUCT1.field + 1usize; //~ ERROR use of unstable library feature 'unstable_default' | ||
|
||
// let _ = Struct2 { field: 1 }; // ok | ||
// let _: Struct2 = Struct2 { field: 1 }; // ok | ||
// let _: Struct2<usize> = Struct2 { field: 1 }; // ok | ||
|
||
// let _ = STRUCT2; | ||
// let _: Struct2 = STRUCT2; // ok | ||
// let _: Struct2<usize> = STRUCT2; // ok | ||
// let _: Struct2<usize> = STRUCT2; // ok | ||
// let _ = STRUCT2.field; // ok | ||
// let _: usize = STRUCT2.field; // ok | ||
// let _ = STRUCT2.field + 1; // ok | ||
// let _ = STRUCT2.field + 1usize; // ok | ||
} |
Uh oh!
There was an error while loading. Please reload this page.