From 9c60c9420f3eef0ebce8b232687da54f66ea3013 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 17 May 2020 23:00:19 -0400 Subject: [PATCH 01/20] Stability annotations on generic trait parameters --- src/librustc_metadata/rmeta/encoder.rs | 4 + src/librustc_middle/middle/stability.rs | 40 ++++++++-- src/librustc_passes/stability.rs | 73 +++++++++++++++---- src/librustc_typeck/astconv.rs | 11 ++- src/librustc_typeck/check/method/probe.rs | 2 +- .../auxiliary/unstable_generic_param.rs | 41 +++++++++++ .../generics-default-stability.rs | 59 +++++++++++++++ .../generics-default-stability.stderr | 27 +++++++ 8 files changed, 233 insertions(+), 24 deletions(-) create mode 100644 src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs create mode 100644 src/test/ui/stability-attribute/generics-default-stability.rs create mode 100644 src/test/ui/stability-attribute/generics-default-stability.stderr diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 2589e162dffe2..47a59ea6499bc 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -1612,6 +1612,9 @@ impl EncodeContext<'tcx> { EntryKind::TypeParam, default.is_some(), ); + if default.is_some() { + self.encode_stability(def_id.to_def_id()); + } } GenericParamKind::Const { .. } => { self.encode_info_for_generic_param( @@ -1619,6 +1622,7 @@ impl EncodeContext<'tcx> { EntryKind::ConstParam, true, ); + // FIXME(const_generics:defaults) } } } diff --git a/src/librustc_middle/middle/stability.rs b/src/librustc_middle/middle/stability.rs index 54c05bca3bd2b..677039e67a066 100644 --- a/src/librustc_middle/middle/stability.rs +++ b/src/librustc_middle/middle/stability.rs @@ -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, span: Span) -> EvalResult { + pub fn eval_stability( + self, + def_id: DefId, + id: Option, + span: Span, + check_deprecation: bool, + ) -> 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, span: Span) { + self.check_stability_internal(def_id, id, span, true, |span, def_id| { + // 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, + 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), } } diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 054748c09fc44..8db6005985e60 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -55,12 +55,20 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, + inherit_deprecation: bool, visit_children: F, ) where F: FnOnce(&mut Self), { if !self.tcx.features().staged_api { - self.forbid_staged_api_attrs(hir_id, attrs, item_sp, kind, visit_children); + self.forbid_staged_api_attrs( + hir_id, + attrs, + item_sp, + kind, + inherit_deprecation, + visit_children, + ); return; } @@ -106,8 +114,11 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // If parent is deprecated and we're not, inherit this by merging // deprecated_since and its reason. if let Some(parent_stab) = self.parent_stab { - if parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() { - stab.rustc_depr = parent_stab.rustc_depr + if inherit_deprecation + && parent_stab.rustc_depr.is_some() + && stab.rustc_depr.is_none() + { + stab.rustc_depr = parent_stab.rustc_depr.clone() } } @@ -157,7 +168,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if stab.is_none() { debug!("annotate: stab not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { - if stab.level.is_unstable() { + if inherit_deprecation && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -200,6 +211,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, + inherit_deprecation: bool, visit_children: impl FnOnce(&mut Self), ) { // Emit errors for non-staged-api crates. @@ -227,7 +239,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // Propagate unstability. This can happen even for non-staged-api crates in case // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { - if stab.level.is_unstable() { + if inherit_deprecation && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -280,18 +292,25 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } hir::ItemKind::Struct(ref sd, _) => { if let Some(ctor_hir_id) = sd.ctor_hir_id() { - self.annotate(ctor_hir_id, &i.attrs, i.span, AnnotationKind::Required, |_| {}) + self.annotate( + ctor_hir_id, + &i.attrs, + i.span, + AnnotationKind::Required, + true, + |_| {}, + ) } } _ => {} } - self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| intravisit::walk_item(v, i)); + self.annotate(i.hir_id, &i.attrs, i.span, kind, true, |v| intravisit::walk_item(v, i)); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { - self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { + self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, true, |v| { intravisit::walk_trait_item(v, ti); }); } @@ -299,15 +318,22 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let kind = if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required }; - self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, true, |v| { intravisit::walk_impl_item(v, ii); }); } fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) { - self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, |v| { + self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, true, |v| { if let Some(ctor_hir_id) = var.data.ctor_hir_id() { - v.annotate(ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required, |_| {}); + v.annotate( + ctor_hir_id, + &var.attrs, + var.span, + AnnotationKind::Required, + true, + |_| {}, + ); } intravisit::walk_variant(v, var, g, item_id) @@ -315,19 +341,33 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { - self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { + self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, true, |v| { intravisit::walk_struct_field(v, s); }); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { - self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, true, |v| { intravisit::walk_foreign_item(v, i); }); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); + self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, true, |_| {}); + } + + fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { + let kind = match &p.kind { + // FIXME(const_generics:defaults) + hir::GenericParamKind::Type { default, .. } if default.is_some() => { + AnnotationKind::Container + } + _ => AnnotationKind::Prohibited, + }; + + self.annotate(p.hir_id, &p.attrs, p.span, kind, false, |v| { + intravisit::walk_generic_param(v, p); + }); } } @@ -401,6 +441,10 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { self.check_missing_stability(md.hir_id, md.span); } + + // Note that we don't need to `check_missing_stability` for default generic parameters, + // as we assume that any default generic parameters without attributes are automatically + // stable (assuming they have not inherited instability from their parent). } fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { @@ -464,6 +508,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { &krate.item.attrs, krate.item.span, AnnotationKind::Required, + true, |v| intravisit::walk_crate(v, krate), ); } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6529d784ad452..4fcce3e1c3127 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -776,7 +776,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { self.ast_region_to_region(<, Some(param)).into() } - (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => { + (GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => { + if *has_default { + tcx.check_stability_internal( + param.def_id, + Some(arg.id()), + arg.span(), + false, + |_, _| (), + ) + } if let (hir::TyKind::Infer, false) = (&ty.kind, self.allow_ty_infer()) { inferred_params.push(ty.span); tcx.types.err.into() diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 7f1d77e5b97d8..46468ecb49210 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1220,7 +1220,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { if let Some(uc) = unstable_candidates { applicable_candidates.retain(|&(p, _)| { if let stability::EvalResult::Deny { feature, .. } = - self.tcx.eval_stability(p.item.def_id, None, self.span) + self.tcx.eval_stability(p.item.def_id, None, self.span, true) { uc.push((p, feature)); return false; diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs new file mode 100644 index 0000000000000..7596fa07cbad4 --- /dev/null +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -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 { + #[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 { + #[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 }; diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs new file mode 100644 index 0000000000000..b8d6ad631022b --- /dev/null +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -0,0 +1,59 @@ +// aux-build:unstable_generic_param.rs + +extern crate unstable_generic_param; + +use unstable_generic_param::*; + +struct R; + +impl Trait1 for S { + fn foo() -> () { () } // ok +} + +struct S; + +impl Trait1 for S { //~ ERROR use of unstable library feature 'unstable_default' + fn foo() -> usize { 0 } +} + +impl Trait1 for S { //~ ERROR use of unstable library feature 'unstable_default' + fn foo() -> isize { 0 } +} + +impl Trait2 for S { //~ ERROR use of unstable library feature 'unstable_default' + fn foo() -> usize { 0 } +} + +impl Trait3 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 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' + + // let _ = STRUCT1; // ok + // let _: Struct1 = STRUCT1; // ok + // let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' + // let _: Struct1 = 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 = Struct2 { field: 1 }; // ok + + // let _ = STRUCT2; + // let _: Struct2 = STRUCT2; // ok + // let _: Struct2 = STRUCT2; // ok + // let _: Struct2 = STRUCT2; // ok + // let _ = STRUCT2.field; // ok + // let _: usize = STRUCT2.field; // ok + // let _ = STRUCT2.field + 1; // ok + // let _ = STRUCT2.field + 1usize; // ok +} diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr new file mode 100644 index 0000000000000..1b7f4b85b59ba --- /dev/null +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -0,0 +1,27 @@ +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:15:13 + | +LL | impl Trait1 for S { + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:19:13 + | +LL | impl Trait1 for S { + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:23:13 + | +LL | impl Trait2 for S { + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. From d1bd1bf560e0dbf837a69765a9002247289c1a4c Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 23 May 2020 16:19:18 -0400 Subject: [PATCH 02/20] ignore-tidy-linelength generic default stab test Co-authored-by: Tim Diekmann <21277928+TimDiekmann@users.noreply.github.com> --- src/test/ui/stability-attribute/generics-default-stability.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index b8d6ad631022b..b699ff5aae437 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -1,3 +1,4 @@ +// ignore-tidy-linelength // aux-build:unstable_generic_param.rs extern crate unstable_generic_param; From e357e659d4c65fbaaf09ebdb4599d304dd49fd9e Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 23 May 2020 18:12:33 -0400 Subject: [PATCH 03/20] Uncomment struct tests --- .../generics-default-stability.rs | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index b699ff5aae437..4d08e6f5b138a 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -30,31 +30,31 @@ impl Trait3 for S { } 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 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' - - // let _ = STRUCT1; // ok - // let _: Struct1 = STRUCT1; // ok - // let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' - // let _: Struct1 = 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 = Struct2 { field: 1 }; // ok - - // let _ = STRUCT2; - // let _: Struct2 = STRUCT2; // ok - // let _: Struct2 = STRUCT2; // ok - // let _: Struct2 = STRUCT2; // ok - // let _ = STRUCT2.field; // ok - // let _: usize = STRUCT2.field; // ok - // let _ = STRUCT2.field + 1; // ok - // let _ = STRUCT2.field + 1usize; // ok + 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 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' + + let _ = STRUCT1; // ok + let _: Struct1 = STRUCT1; // ok + let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' + let _: Struct1 = 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 = Struct2 { field: 1 }; // ok + + let _ = STRUCT2; + let _: Struct2 = STRUCT2; // ok + let _: Struct2 = STRUCT2; // ok + let _: Struct2 = STRUCT2; // ok + let _ = STRUCT2.field; // ok + let _: usize = STRUCT2.field; // ok + let _ = STRUCT2.field + 1; // ok + let _ = STRUCT2.field + 1usize; // ok } From af4969e25c8dbffa9609438fd01061fc70d2de07 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Tue, 26 May 2020 16:38:47 -0400 Subject: [PATCH 04/20] Comment out broken tests --- .../generics-default-stability.rs | 10 +++--- .../generics-default-stability.stderr | 32 ++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index 4d08e6f5b138a..f99ce6da198c8 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -32,8 +32,8 @@ impl Trait3 for S { 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 { 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 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' let _ = STRUCT1; // ok @@ -41,9 +41,9 @@ fn main() { let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' let _: Struct1 = 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 _: 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 diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 1b7f4b85b59ba..00ddc873cfb38 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:15:13 + --> $DIR/generics-default-stability.rs:16:13 | LL | impl Trait1 for S { | ^^^^^ @@ -7,7 +7,7 @@ LL | impl Trait1 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:19:13 + --> $DIR/generics-default-stability.rs:20:13 | LL | impl Trait1 for S { | ^^^^^ @@ -15,13 +15,37 @@ LL | impl Trait1 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:23:13 + --> $DIR/generics-default-stability.rs:24:13 | LL | impl Trait2 for S { | ^^^^^ | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -error: aborting due to 3 previous errors +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:37:20 + | +LL | let _: Struct1 = Struct1 { field: 1 }; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:41:20 + | +LL | let _: Struct1 = STRUCT1; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:42:20 + | +LL | let _: Struct1 = STRUCT1; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0658`. From b8ebdf9b06eb0705766f97ff05e44a395ff385fd Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Mon, 1 Jun 2020 11:51:35 -0400 Subject: [PATCH 05/20] Unstable default types leak in public fields --- .../generics-default-stability.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index f99ce6da198c8..bacbc64ab4748 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -32,18 +32,22 @@ impl Trait3 for S { 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 = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' let _ = STRUCT1; // ok let _: Struct1 = STRUCT1; // ok let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' - let _: Struct1 = 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 _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' + + // Instability is not enforced for generic type parameters used in public fields. + // Note how the unstable type default `usize` leaks, + // and can be used without the 'unstable_default' feature. + let _ = STRUCT1.field; + let _ = Struct1 { field: 1 }; + let _: Struct1 = Struct1 { field: 1 }; + let _: usize = STRUCT1.field; + let _ = STRUCT1.field + 1; + let _ = STRUCT1.field + 1usize; let _ = Struct2 { field: 1 }; // ok let _: Struct2 = Struct2 { field: 1 }; // ok From 7b7b84f8a05e402077b40867ae199d7ac7617cbc Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 20 Jun 2020 17:33:04 -0400 Subject: [PATCH 06/20] Fix tests --- .../ui/stability-attribute/generics-default-stability.rs | 4 ++-- .../stability-attribute/generics-default-stability.stderr | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index bacbc64ab4748..7f3f90c192628 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -37,7 +37,7 @@ fn main() { let _ = STRUCT1; // ok let _: Struct1 = STRUCT1; // ok let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' - let _: Struct1 = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default' + let _: Struct1 = Struct1 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default' // Instability is not enforced for generic type parameters used in public fields. // Note how the unstable type default `usize` leaks, @@ -56,7 +56,7 @@ fn main() { let _ = STRUCT2; let _: Struct2 = STRUCT2; // ok let _: Struct2 = STRUCT2; // ok - let _: Struct2 = STRUCT2; // ok + let _: Struct2 = Struct2 { field: 0 }; // ok let _ = STRUCT2.field; // ok let _: usize = STRUCT2.field; // ok let _ = STRUCT2.field + 1; // ok diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 00ddc873cfb38..6b405b557699f 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -23,7 +23,7 @@ LL | impl Trait2 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:37:20 + --> $DIR/generics-default-stability.rs:35:20 | LL | let _: Struct1 = Struct1 { field: 1 }; | ^^^^^ @@ -31,7 +31,7 @@ LL | let _: Struct1 = Struct1 { field: 1 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:41:20 + --> $DIR/generics-default-stability.rs:39:20 | LL | let _: Struct1 = STRUCT1; | ^^^^^ @@ -39,9 +39,9 @@ LL | let _: Struct1 = STRUCT1; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:42:20 + --> $DIR/generics-default-stability.rs:40:20 | -LL | let _: Struct1 = STRUCT1; +LL | let _: Struct1 = Struct1 { field: 0 }; | ^^^^^ | = help: add `#![feature(unstable_default)]` to the crate attributes to enable From a81a46ff64a9fb9945a2c49b8ecc02e43ca380a1 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Mon, 22 Jun 2020 00:08:54 -0400 Subject: [PATCH 07/20] Add more tests --- .../auxiliary/unstable_generic_param.rs | 10 +++++++ .../generics-default-stability-where.rs | 12 +++++++++ .../generics-default-stability-where.stderr | 11 ++++++++ .../generics-default-stability.rs | 15 +++++++++++ .../generics-default-stability.stderr | 26 ++++++++++++++++++- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/stability-attribute/generics-default-stability-where.rs create mode 100644 src/test/ui/stability-attribute/generics-default-stability-where.stderr diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs index 7596fa07cbad4..c38fb92905b3f 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -33,9 +33,19 @@ pub struct Struct2 { pub field: T, } +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Struct3 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub field1: A, + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub field2: B, +} #[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 }; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const STRUCT3: Struct3 = Struct3 { field1: 1, field2: 2 }; diff --git a/src/test/ui/stability-attribute/generics-default-stability-where.rs b/src/test/ui/stability-attribute/generics-default-stability-where.rs new file mode 100644 index 0000000000000..3fd14e25d0ef2 --- /dev/null +++ b/src/test/ui/stability-attribute/generics-default-stability-where.rs @@ -0,0 +1,12 @@ +// ignore-tidy-linelength +// aux-build:unstable_generic_param.rs + +extern crate unstable_generic_param; + +use unstable_generic_param::*; + +impl Trait3 for T where T: Trait2 { //~ ERROR use of unstable library feature 'unstable_default' + fn foo() -> usize { T::foo() } +} + +fn main() {} diff --git a/src/test/ui/stability-attribute/generics-default-stability-where.stderr b/src/test/ui/stability-attribute/generics-default-stability-where.stderr new file mode 100644 index 0000000000000..19fa09f311ba8 --- /dev/null +++ b/src/test/ui/stability-attribute/generics-default-stability-where.stderr @@ -0,0 +1,11 @@ +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability-where.rs:8:45 + | +LL | impl Trait3 for T where T: Trait2 { + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index 7f3f90c192628..063058c0f53fc 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -61,4 +61,19 @@ fn main() { let _: usize = STRUCT2.field; // ok let _ = STRUCT2.field + 1; // ok let _ = STRUCT2.field + 1usize; // ok + + let _ = STRUCT3; + let _: Struct3 = STRUCT3; // ok + let _: Struct3 = STRUCT3; //~ ERROR use of unstable library feature 'unstable_default' + let _: Struct3 = STRUCT3; // ok + let _: Struct3 = Struct3 { field1: 0, field2: 0 }; //~ ERROR use of unstable library feature 'unstable_default' + let _: Struct3 = Struct3 { field1: 0, field2: 0 }; //~ ERROR use of unstable library feature 'unstable_default' + let _ = STRUCT3.field1; // ok + let _: isize = STRUCT3.field1; // ok + let _ = STRUCT3.field1 + 1; // ok + // Note the aforementioned leak. + let _: usize = STRUCT3.field2; // ok + let _: Struct3 = Struct3 { field1: 0, field2: 0 }; // ok + let _ = STRUCT3.field2 + 1; // ok + let _ = STRUCT3.field2 + 1usize; // ok } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 6b405b557699f..eadcd2641d058 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -46,6 +46,30 @@ LL | let _: Struct1 = Struct1 { field: 0 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:67:27 + | +LL | let _: Struct3 = STRUCT3; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:69:27 + | +LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:70:27 + | +LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0658`. From 734b08c5484cdc3f939bf4ffd11d28254fcdc39b Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Thu, 25 Jun 2020 15:53:47 -0400 Subject: [PATCH 08/20] Test stability on default parameter of deprecated --- .../auxiliary/unstable_generic_param.rs | 20 +++ .../generics-default-stability.rs | 27 ++++ .../generics-default-stability.stderr | 124 +++++++++++++++++- 3 files changed, 170 insertions(+), 1 deletion(-) diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs index c38fb92905b3f..64d725e55edb8 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -41,6 +41,20 @@ pub struct Struct3 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub field: A, +} + +#[rustc_deprecated(since = "1.1.0", reason = "test")] +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Struct5<#[unstable(feature = "unstable_default", issue = "none")] A = usize> { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub field: A, +} + #[stable(feature = "stable_test_feature", since = "1.0.0")] pub const STRUCT1: Struct1 = Struct1 { field: 1 }; @@ -49,3 +63,9 @@ pub const STRUCT2: Struct2 = Struct2 { field: 1 }; #[stable(feature = "stable_test_feature", since = "1.0.0")] pub const STRUCT3: Struct3 = Struct3 { field1: 1, field2: 2 }; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const STRUCT4: Struct4 = Struct4 { field: 1 }; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const STRUCT5: Struct5 = Struct5 { field: 1 }; diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index 063058c0f53fc..de178eee1d769 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -76,4 +76,31 @@ fn main() { let _: Struct3 = Struct3 { field1: 0, field2: 0 }; // ok let _ = STRUCT3.field2 + 1; // ok let _ = STRUCT3.field2 + 1usize; // ok + + let _ = STRUCT4; + let _: Struct4 = Struct4 { field: 1 }; + //~^ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + //~^^ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + //~^^^ use of deprecated item 'unstable_generic_param::Struct4::field': test [deprecated] + let _ = STRUCT4; + let _: Struct4 = STRUCT4; //~ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + let _: Struct4 = STRUCT4; //~ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + let _: Struct4 = Struct4 { field: 0 }; + //~^ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + //~^^ use of deprecated item 'unstable_generic_param::Struct4': test [deprecated] + //~^^^ use of deprecated item 'unstable_generic_param::Struct4::field': test [deprecated] + + let _ = STRUCT5; + let _: Struct5 = Struct5 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] + let _ = STRUCT5; + let _: Struct5 = STRUCT5; //~ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + let _: Struct5 = STRUCT5; //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + let _: Struct5 = Struct5 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index eadcd2641d058..2bc98cc009587 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -22,6 +22,80 @@ LL | impl Trait2 for S { | = help: add `#![feature(unstable_default)]` to the crate attributes to enable +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:81:29 + | +LL | let _: Struct4 = Struct4 { field: 1 }; + | ^^^^^^^ + | + = note: `#[warn(deprecated)]` on by default + +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:81:12 + | +LL | let _: Struct4 = Struct4 { field: 1 }; + | ^^^^^^^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:86:12 + | +LL | let _: Struct4 = STRUCT4; + | ^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:87:12 + | +LL | let _: Struct4 = STRUCT4; + | ^^^^^^^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:88:29 + | +LL | let _: Struct4 = Struct4 { field: 0 }; + | ^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct4': test + --> $DIR/generics-default-stability.rs:88:12 + | +LL | let _: Struct4 = Struct4 { field: 0 }; + | ^^^^^^^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:94:29 + | +LL | let _: Struct5 = Struct5 { field: 1 }; + | ^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:94:12 + | +LL | let _: Struct5 = Struct5 { field: 1 }; + | ^^^^^^^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:99:12 + | +LL | let _: Struct5 = STRUCT5; + | ^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:100:12 + | +LL | let _: Struct5 = STRUCT5; + | ^^^^^^^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:102:29 + | +LL | let _: Struct5 = Struct5 { field: 0 }; + | ^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5': test + --> $DIR/generics-default-stability.rs:102:12 + | +LL | let _: Struct5 = Struct5 { field: 0 }; + | ^^^^^^^^^^^^^^ + error[E0658]: use of unstable library feature 'unstable_default' --> $DIR/generics-default-stability.rs:35:20 | @@ -70,6 +144,54 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -error: aborting due to 9 previous errors +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:94:20 + | +LL | let _: Struct5 = Struct5 { field: 1 }; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:100:20 + | +LL | let _: Struct5 = STRUCT5; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +error[E0658]: use of unstable library feature 'unstable_default' + --> $DIR/generics-default-stability.rs:102:20 + | +LL | let _: Struct5 = Struct5 { field: 0 }; + | ^^^^^ + | + = help: add `#![feature(unstable_default)]` to the crate attributes to enable + +warning: use of deprecated item 'unstable_generic_param::Struct4::field': test + --> $DIR/generics-default-stability.rs:81:39 + | +LL | let _: Struct4 = Struct4 { field: 1 }; + | ^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct4::field': test + --> $DIR/generics-default-stability.rs:88:39 + | +LL | let _: Struct4 = Struct4 { field: 0 }; + | ^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5::field': test + --> $DIR/generics-default-stability.rs:94:39 + | +LL | let _: Struct5 = Struct5 { field: 1 }; + | ^^^^^^^^ + +warning: use of deprecated item 'unstable_generic_param::Struct5::field': test + --> $DIR/generics-default-stability.rs:102:39 + | +LL | let _: Struct5 = Struct5 { field: 0 }; + | ^^^^^^^^ + +error: aborting due to 12 previous errors; 16 warnings emitted For more information about this error, try `rustc --explain E0658`. From 0c6affee0d645ebb7c50db11ec7a370e7da944ce Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Tue, 30 Jun 2020 19:05:14 -0400 Subject: [PATCH 09/20] Remove now unneeded check_stability argument --- src/librustc_middle/middle/stability.rs | 23 ++++++++--------------- src/librustc_typeck/astconv.rs | 1 - src/librustc_typeck/check/method/probe.rs | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/librustc_middle/middle/stability.rs b/src/librustc_middle/middle/stability.rs index 677039e67a066..3cfb11c3eb121 100644 --- a/src/librustc_middle/middle/stability.rs +++ b/src/librustc_middle/middle/stability.rs @@ -280,15 +280,9 @@ 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, - span: Span, - check_deprecation: bool, - ) -> EvalResult { + pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { // Deprecated attributes apply in-crate and cross-crate. - if let (Some(id), true) = (id, check_deprecation) { + if let Some(id) = id { 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 @@ -380,10 +374,10 @@ impl<'tcx> TyCtxt<'tcx> { /// If the item defined by `def_id` is unstable and the corresponding `#![feature]` does not /// exist, emits an error. /// - /// 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. + /// 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, span: Span) { - self.check_stability_internal(def_id, id, span, true, |span, def_id| { + self.check_stability_internal(def_id, id, span, |span, def_id| { // 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)); @@ -395,14 +389,13 @@ impl<'tcx> TyCtxt<'tcx> { /// 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. + /// 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, span: Span, - check_deprecation: bool, unmarked: impl FnOnce(Span, DefId) -> (), ) { let soft_handler = |lint, span, msg: &_| { @@ -410,7 +403,7 @@ impl<'tcx> TyCtxt<'tcx> { lint.build(msg).emit() }) }; - match self.eval_stability(def_id, id, span, check_deprecation) { + match self.eval_stability(def_id, id, span) { EvalResult::Allow => {} EvalResult::Deny { feature, reason, issue, is_soft } => { report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 4fcce3e1c3127..6e802475cc86a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -782,7 +782,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { param.def_id, Some(arg.id()), arg.span(), - false, |_, _| (), ) } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 46468ecb49210..7f1d77e5b97d8 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1220,7 +1220,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { if let Some(uc) = unstable_candidates { applicable_candidates.retain(|&(p, _)| { if let stability::EvalResult::Deny { feature, .. } = - self.tcx.eval_stability(p.item.def_id, None, self.span, true) + self.tcx.eval_stability(p.item.def_id, None, self.span) { uc.push((p, feature)); return false; From 868ab1c9d53f0473b47ad9a22a7e18cbff2de532 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Fri, 3 Jul 2020 21:16:59 -0400 Subject: [PATCH 10/20] Inherit type parameter deprecation from parent --- src/librustc_passes/stability.rs | 30 +++++++--------- .../generics-default-stability.rs | 3 ++ .../generics-default-stability.stderr | 34 ++++++++++++++----- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 8db6005985e60..11ba771587668 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -55,7 +55,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, - inherit_deprecation: bool, visit_children: F, ) where F: FnOnce(&mut Self), @@ -66,7 +65,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs, item_sp, kind, - inherit_deprecation, visit_children, ); return; @@ -114,8 +112,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // If parent is deprecated and we're not, inherit this by merging // deprecated_since and its reason. if let Some(parent_stab) = self.parent_stab { - if inherit_deprecation - && parent_stab.rustc_depr.is_some() + if + parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() { stab.rustc_depr = parent_stab.rustc_depr.clone() @@ -168,7 +166,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if stab.is_none() { debug!("annotate: stab not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { - if inherit_deprecation && stab.level.is_unstable() { + if stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -211,7 +209,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, - inherit_deprecation: bool, visit_children: impl FnOnce(&mut Self), ) { // Emit errors for non-staged-api crates. @@ -239,7 +236,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // Propagate unstability. This can happen even for non-staged-api crates in case // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { - if inherit_deprecation && stab.level.is_unstable() { + if stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -297,7 +294,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { &i.attrs, i.span, AnnotationKind::Required, - true, |_| {}, ) } @@ -305,12 +301,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => {} } - self.annotate(i.hir_id, &i.attrs, i.span, kind, true, |v| intravisit::walk_item(v, i)); + self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| intravisit::walk_item(v, i)); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { - self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, true, |v| { + self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { intravisit::walk_trait_item(v, ti); }); } @@ -318,20 +314,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let kind = if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required }; - self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, true, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| { intravisit::walk_impl_item(v, ii); }); } fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) { - self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, true, |v| { + self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, |v| { if let Some(ctor_hir_id) = var.data.ctor_hir_id() { v.annotate( ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required, - true, |_| {}, ); } @@ -341,19 +336,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { - self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, true, |v| { + self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { intravisit::walk_struct_field(v, s); }); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { - self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, true, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { intravisit::walk_foreign_item(v, i); }); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, true, |_| {}); + self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); } fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { @@ -365,7 +360,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => AnnotationKind::Prohibited, }; - self.annotate(p.hir_id, &p.attrs, p.span, kind, false, |v| { + self.annotate(p.hir_id, &p.attrs, p.span, kind, |v| { intravisit::walk_generic_param(v, p); }); } @@ -508,7 +503,6 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { &krate.item.attrs, krate.item.span, AnnotationKind::Required, - true, |v| intravisit::walk_crate(v, krate), ); } diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index de178eee1d769..dcec749558901 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -95,12 +95,15 @@ fn main() { //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] + //~^^^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] let _ = STRUCT5; let _: Struct5 = STRUCT5; //~ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] let _: Struct5 = STRUCT5; //~ ERROR use of unstable library feature 'unstable_default' //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] + //~^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] let _: Struct5 = Struct5 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default' //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] + //~^^^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 2bc98cc009587..4bd645ff6a685 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -73,25 +73,25 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:99:12 + --> $DIR/generics-default-stability.rs:100:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:100:12 + --> $DIR/generics-default-stability.rs:101:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:102:29 + --> $DIR/generics-default-stability.rs:104:29 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:102:12 + --> $DIR/generics-default-stability.rs:104:12 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^^^^^^^ @@ -144,6 +144,12 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable +warning: use of deprecated item 'unstable_generic_param::Struct5::A': test + --> $DIR/generics-default-stability.rs:94:20 + | +LL | let _: Struct5 = Struct5 { field: 1 }; + | ^^^^^ + error[E0658]: use of unstable library feature 'unstable_default' --> $DIR/generics-default-stability.rs:94:20 | @@ -152,16 +158,28 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable +warning: use of deprecated item 'unstable_generic_param::Struct5::A': test + --> $DIR/generics-default-stability.rs:101:20 + | +LL | let _: Struct5 = STRUCT5; + | ^^^^^ + error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:100:20 + --> $DIR/generics-default-stability.rs:101:20 | LL | let _: Struct5 = STRUCT5; | ^^^^^ | = help: add `#![feature(unstable_default)]` to the crate attributes to enable +warning: use of deprecated item 'unstable_generic_param::Struct5::A': test + --> $DIR/generics-default-stability.rs:104:20 + | +LL | let _: Struct5 = Struct5 { field: 0 }; + | ^^^^^ + error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:102:20 + --> $DIR/generics-default-stability.rs:104:20 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^ @@ -187,11 +205,11 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:102:39 + --> $DIR/generics-default-stability.rs:104:39 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ -error: aborting due to 12 previous errors; 16 warnings emitted +error: aborting due to 12 previous errors; 19 warnings emitted For more information about this error, try `rustc --explain E0658`. From 9662fd219fd931e2bc07c92547c246cf4ff0452f Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Fri, 3 Jul 2020 21:43:57 -0400 Subject: [PATCH 11/20] Revert "Inherit type parameter deprecation from parent" This reverts commit 868ab1c9d53f0473b47ad9a22a7e18cbff2de532. --- src/librustc_passes/stability.rs | 30 +++++++++------- .../generics-default-stability.rs | 3 -- .../generics-default-stability.stderr | 34 +++++-------------- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 11ba771587668..8db6005985e60 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -55,6 +55,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, + inherit_deprecation: bool, visit_children: F, ) where F: FnOnce(&mut Self), @@ -65,6 +66,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs, item_sp, kind, + inherit_deprecation, visit_children, ); return; @@ -112,8 +114,8 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // If parent is deprecated and we're not, inherit this by merging // deprecated_since and its reason. if let Some(parent_stab) = self.parent_stab { - if - parent_stab.rustc_depr.is_some() + if inherit_deprecation + && parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() { stab.rustc_depr = parent_stab.rustc_depr.clone() @@ -166,7 +168,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if stab.is_none() { debug!("annotate: stab not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { - if stab.level.is_unstable() { + if inherit_deprecation && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -209,6 +211,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, + inherit_deprecation: bool, visit_children: impl FnOnce(&mut Self), ) { // Emit errors for non-staged-api crates. @@ -236,7 +239,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // Propagate unstability. This can happen even for non-staged-api crates in case // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { - if stab.level.is_unstable() { + if inherit_deprecation && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -294,6 +297,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { &i.attrs, i.span, AnnotationKind::Required, + true, |_| {}, ) } @@ -301,12 +305,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => {} } - self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| intravisit::walk_item(v, i)); + self.annotate(i.hir_id, &i.attrs, i.span, kind, true, |v| intravisit::walk_item(v, i)); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { - self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { + self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, true, |v| { intravisit::walk_trait_item(v, ti); }); } @@ -314,19 +318,20 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let kind = if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required }; - self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, true, |v| { intravisit::walk_impl_item(v, ii); }); } fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) { - self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, |v| { + self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, true, |v| { if let Some(ctor_hir_id) = var.data.ctor_hir_id() { v.annotate( ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required, + true, |_| {}, ); } @@ -336,19 +341,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { - self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { + self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, true, |v| { intravisit::walk_struct_field(v, s); }); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { - self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, true, |v| { intravisit::walk_foreign_item(v, i); }); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); + self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, true, |_| {}); } fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { @@ -360,7 +365,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => AnnotationKind::Prohibited, }; - self.annotate(p.hir_id, &p.attrs, p.span, kind, |v| { + self.annotate(p.hir_id, &p.attrs, p.span, kind, false, |v| { intravisit::walk_generic_param(v, p); }); } @@ -503,6 +508,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { &krate.item.attrs, krate.item.span, AnnotationKind::Required, + true, |v| intravisit::walk_crate(v, krate), ); } diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index dcec749558901..de178eee1d769 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -95,15 +95,12 @@ fn main() { //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] - //~^^^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] let _ = STRUCT5; let _: Struct5 = STRUCT5; //~ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] let _: Struct5 = STRUCT5; //~ ERROR use of unstable library feature 'unstable_default' //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] - //~^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] let _: Struct5 = Struct5 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default' //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] - //~^^^^ use of deprecated item 'unstable_generic_param::Struct5::A': test [deprecated] } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 4bd645ff6a685..2bc98cc009587 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -73,25 +73,25 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:100:12 + --> $DIR/generics-default-stability.rs:99:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:101:12 + --> $DIR/generics-default-stability.rs:100:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:104:29 + --> $DIR/generics-default-stability.rs:102:29 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:104:12 + --> $DIR/generics-default-stability.rs:102:12 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^^^^^^^ @@ -144,12 +144,6 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -warning: use of deprecated item 'unstable_generic_param::Struct5::A': test - --> $DIR/generics-default-stability.rs:94:20 - | -LL | let _: Struct5 = Struct5 { field: 1 }; - | ^^^^^ - error[E0658]: use of unstable library feature 'unstable_default' --> $DIR/generics-default-stability.rs:94:20 | @@ -158,28 +152,16 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -warning: use of deprecated item 'unstable_generic_param::Struct5::A': test - --> $DIR/generics-default-stability.rs:101:20 - | -LL | let _: Struct5 = STRUCT5; - | ^^^^^ - error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:101:20 + --> $DIR/generics-default-stability.rs:100:20 | LL | let _: Struct5 = STRUCT5; | ^^^^^ | = help: add `#![feature(unstable_default)]` to the crate attributes to enable -warning: use of deprecated item 'unstable_generic_param::Struct5::A': test - --> $DIR/generics-default-stability.rs:104:20 - | -LL | let _: Struct5 = Struct5 { field: 0 }; - | ^^^^^ - error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:104:20 + --> $DIR/generics-default-stability.rs:102:20 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^ @@ -205,11 +187,11 @@ LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:104:39 + --> $DIR/generics-default-stability.rs:102:39 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ -error: aborting due to 12 previous errors; 19 warnings emitted +error: aborting due to 12 previous errors; 16 warnings emitted For more information about this error, try `rustc --explain E0658`. From 1680b33a7e45b3a4bb11cc8286f5f16aac403365 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 5 Jul 2020 19:02:30 -0400 Subject: [PATCH 12/20] Add documentation --- src/librustc_middle/middle/stability.rs | 7 +- src/librustc_passes/stability.rs | 117 +++++++++++++++++------- src/librustc_typeck/astconv.rs | 2 +- 3 files changed, 90 insertions(+), 36 deletions(-) diff --git a/src/librustc_middle/middle/stability.rs b/src/librustc_middle/middle/stability.rs index 3cfb11c3eb121..200f491d45b58 100644 --- a/src/librustc_middle/middle/stability.rs +++ b/src/librustc_middle/middle/stability.rs @@ -377,7 +377,7 @@ impl<'tcx> TyCtxt<'tcx> { /// 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, span: Span) { - self.check_stability_internal(def_id, id, span, |span, def_id| { + self.check_optional_stability(def_id, id, span, |span, def_id| { // 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)); @@ -391,7 +391,10 @@ impl<'tcx> TyCtxt<'tcx> { /// /// 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( + /// + /// The `unmarked` closure is called definitions without a stability annotation. + /// This is needed for generic parameters, since they may not be marked when used in a staged_api crate. + pub fn check_optional_stability( self, def_id: DefId, id: Option, diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 8db6005985e60..65e5310338d32 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -36,6 +36,20 @@ enum AnnotationKind { Container, } +/// Inheriting deprecations Nested items causes duplicate warnings. +/// Inheriting the deprecation of `Foo` onto the parameter `T`, would cause a duplicate warnings. +#[derive(PartialEq, Copy, Clone)] +enum InheritDeprecation { + Yes, + No, +} + +impl InheritDeprecation { + fn yes(&self) -> bool { + *self == InheritDeprecation::Yes + } +} + // A private tree-walker for producing an Index. struct Annotator<'a, 'tcx> { tcx: TyCtxt<'tcx>, @@ -55,7 +69,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, - inherit_deprecation: bool, + inherit_deprecation: InheritDeprecation, visit_children: F, ) where F: FnOnce(&mut Self), @@ -114,7 +128,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // If parent is deprecated and we're not, inherit this by merging // deprecated_since and its reason. if let Some(parent_stab) = self.parent_stab { - if inherit_deprecation + if inherit_deprecation.yes() && parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() { @@ -168,7 +182,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { if stab.is_none() { debug!("annotate: stab not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { - if inherit_deprecation && stab.level.is_unstable() { + if inherit_deprecation.yes() && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -211,7 +225,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, - inherit_deprecation: bool, + inherit_deprecation: InheritDeprecation, visit_children: impl FnOnce(&mut Self), ) { // Emit errors for non-staged-api crates. @@ -239,7 +253,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { // Propagate unstability. This can happen even for non-staged-api crates in case // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { - if inherit_deprecation && stab.level.is_unstable() { + if inherit_deprecation.yes() && stab.level.is_unstable() { self.index.stab_map.insert(hir_id, stab); } } @@ -297,7 +311,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { &i.attrs, i.span, AnnotationKind::Required, - true, + InheritDeprecation::Yes, |_| {}, ) } @@ -305,55 +319,92 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => {} } - self.annotate(i.hir_id, &i.attrs, i.span, kind, true, |v| intravisit::walk_item(v, i)); + self.annotate(i.hir_id, &i.attrs, i.span, kind, InheritDeprecation::Yes, |v| { + intravisit::walk_item(v, i) + }); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { - self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, true, |v| { - intravisit::walk_trait_item(v, ti); - }); + self.annotate( + ti.hir_id, + &ti.attrs, + ti.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |v| { + intravisit::walk_trait_item(v, ti); + }, + ); } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { let kind = if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required }; - self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, true, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, InheritDeprecation::Yes, |v| { intravisit::walk_impl_item(v, ii); }); } fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) { - self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, true, |v| { - if let Some(ctor_hir_id) = var.data.ctor_hir_id() { - v.annotate( - ctor_hir_id, - &var.attrs, - var.span, - AnnotationKind::Required, - true, - |_| {}, - ); - } + self.annotate( + var.id, + &var.attrs, + var.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |v| { + if let Some(ctor_hir_id) = var.data.ctor_hir_id() { + v.annotate( + ctor_hir_id, + &var.attrs, + var.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |_| {}, + ); + } - intravisit::walk_variant(v, var, g, item_id) - }) + intravisit::walk_variant(v, var, g, item_id) + }, + ) } fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) { - self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, true, |v| { - intravisit::walk_struct_field(v, s); - }); + self.annotate( + s.hir_id, + &s.attrs, + s.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |v| { + intravisit::walk_struct_field(v, s); + }, + ); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { - self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, true, |v| { - intravisit::walk_foreign_item(v, i); - }); + self.annotate( + i.hir_id, + &i.attrs, + i.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |v| { + intravisit::walk_foreign_item(v, i); + }, + ); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) { - self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, true, |_| {}); + self.annotate( + md.hir_id, + &md.attrs, + md.span, + AnnotationKind::Required, + InheritDeprecation::Yes, + |_| {}, + ); } fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { @@ -365,7 +416,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { _ => AnnotationKind::Prohibited, }; - self.annotate(p.hir_id, &p.attrs, p.span, kind, false, |v| { + self.annotate(p.hir_id, &p.attrs, p.span, kind, InheritDeprecation::No, |v| { intravisit::walk_generic_param(v, p); }); } @@ -508,7 +559,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> { &krate.item.attrs, krate.item.span, AnnotationKind::Required, - true, + InheritDeprecation::Yes, |v| intravisit::walk_crate(v, krate), ); } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6e802475cc86a..42aee8e0272a0 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -778,7 +778,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } (GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => { if *has_default { - tcx.check_stability_internal( + tcx.check_optional_stability( param.def_id, Some(arg.id()), arg.span(), From ad1f406d00955acc92b6d31fb20655c7e65bd322 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:31:48 -0400 Subject: [PATCH 13/20] Update src/librustc_passes/stability.rs Co-authored-by: varkor --- src/librustc_passes/stability.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index 65e5310338d32..a2f0cf983282f 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -36,8 +36,12 @@ enum AnnotationKind { Container, } -/// Inheriting deprecations Nested items causes duplicate warnings. -/// Inheriting the deprecation of `Foo` onto the parameter `T`, would cause a duplicate warnings. +/// Whether to inherit deprecation flags for nested items. In most cases, we do want to inherit +/// deprecation, because nested items rarely have individual deprecation attributes, and so +/// should be treated as deprecated if their parent is. However, default generic parameters +/// have separate deprecation attributes from their parents, so we do not wish to inherit +/// deprecation in this case. For example, inheriting deprecation for `T` in `Foo` +/// would cause a duplicate warning arising from both `Foo` and `T` being deprecated. #[derive(PartialEq, Copy, Clone)] enum InheritDeprecation { Yes, From 03c1f144e65a2282425fe7e1a8aa450520e214dc Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:32:11 -0400 Subject: [PATCH 14/20] Update src/librustc_typeck/astconv.rs Co-authored-by: varkor --- src/librustc_typeck/astconv.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 42aee8e0272a0..ba2c0581c9263 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -782,7 +782,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { param.def_id, Some(arg.id()), arg.span(), - |_, _| (), + |_, _| { + // Default generic parameters may not be marked + // with stability attributes, i.e. when the + // default parameter was defined at the same time + // as the rest of the type. As such, we ignore missing + // stability attributes. + }, ) } if let (hir::TyKind::Infer, false) = (&ty.kind, self.allow_ty_infer()) { From 61b2bff4cf392460b10a7df27ca56db63403fd74 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:32:58 -0400 Subject: [PATCH 15/20] Update src/librustc_middle/middle/stability.rs Co-authored-by: varkor --- src/librustc_middle/middle/stability.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/librustc_middle/middle/stability.rs b/src/librustc_middle/middle/stability.rs index 200f491d45b58..bcd14727630db 100644 --- a/src/librustc_middle/middle/stability.rs +++ b/src/librustc_middle/middle/stability.rs @@ -384,16 +384,10 @@ impl<'tcx> TyCtxt<'tcx> { }) } - /// 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. - /// - /// 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. - /// - /// The `unmarked` closure is called definitions without a stability annotation. - /// This is needed for generic parameters, since they may not be marked when used in a staged_api crate. + /// Like `check_stability`, except that we permit items to have custom behaviour for + /// missing stability attributes (not necessarily just emit a `bug!`). This is necessary + /// for default generic parameters, which only have stability attributes if they were + /// added after the type on which they're defined. pub fn check_optional_stability( self, def_id: DefId, From 61c8855ca5a1e3bf5ed04e7a2a9d1262f43ebafb Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:51:31 -0400 Subject: [PATCH 16/20] Update src/librustc_passes/stability.rs Co-authored-by: varkor --- src/librustc_passes/stability.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_passes/stability.rs b/src/librustc_passes/stability.rs index a2f0cf983282f..1830cfdd717e8 100644 --- a/src/librustc_passes/stability.rs +++ b/src/librustc_passes/stability.rs @@ -42,7 +42,6 @@ enum AnnotationKind { /// have separate deprecation attributes from their parents, so we do not wish to inherit /// deprecation in this case. For example, inheriting deprecation for `T` in `Foo` /// would cause a duplicate warning arising from both `Foo` and `T` being deprecated. -#[derive(PartialEq, Copy, Clone)] enum InheritDeprecation { Yes, No, @@ -50,7 +49,7 @@ enum InheritDeprecation { impl InheritDeprecation { fn yes(&self) -> bool { - *self == InheritDeprecation::Yes + matches!(self, InheritDeprecation::Yes) } } From fc2e2d608c004a18e6ddb8521831aec242ba0f9b Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 11 Jul 2020 19:08:05 -0400 Subject: [PATCH 17/20] Add test case demonstrating leak --- .../generics-default-stability.rs | 2 + .../generics-default-stability.stderr | 44 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index de178eee1d769..c44f3c32bbee3 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -44,6 +44,8 @@ fn main() { // and can be used without the 'unstable_default' feature. let _ = STRUCT1.field; let _ = Struct1 { field: 1 }; + let _ = Struct1 { field: () }; + let _ = Struct1 { field: 1isize }; let _: Struct1 = Struct1 { field: 1 }; let _: usize = STRUCT1.field; let _ = STRUCT1.field + 1; diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 2bc98cc009587..87ebe65dcfcfc 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -23,7 +23,7 @@ LL | impl Trait2 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:81:29 + --> $DIR/generics-default-stability.rs:83:29 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^ @@ -31,67 +31,67 @@ LL | let _: Struct4 = Struct4 { field: 1 }; = note: `#[warn(deprecated)]` on by default warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:81:12 + --> $DIR/generics-default-stability.rs:83:12 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:86:12 + --> $DIR/generics-default-stability.rs:88:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:87:12 + --> $DIR/generics-default-stability.rs:89:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:88:29 + --> $DIR/generics-default-stability.rs:90:29 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:88:12 + --> $DIR/generics-default-stability.rs:90:12 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:94:29 + --> $DIR/generics-default-stability.rs:96:29 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:94:12 + --> $DIR/generics-default-stability.rs:96:12 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:99:12 + --> $DIR/generics-default-stability.rs:101:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:100:12 + --> $DIR/generics-default-stability.rs:102:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:102:29 + --> $DIR/generics-default-stability.rs:104:29 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:102:12 + --> $DIR/generics-default-stability.rs:104:12 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL | let _: Struct1 = Struct1 { field: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:67:27 + --> $DIR/generics-default-stability.rs:69:27 | LL | let _: Struct3 = STRUCT3; | ^^^^^ @@ -129,7 +129,7 @@ LL | let _: Struct3 = STRUCT3; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:69:27 + --> $DIR/generics-default-stability.rs:71:27 | LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | ^^^^^ @@ -137,7 +137,7 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:70:27 + --> $DIR/generics-default-stability.rs:72:27 | LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | ^^^^^ @@ -145,7 +145,7 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:94:20 + --> $DIR/generics-default-stability.rs:96:20 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^ @@ -153,7 +153,7 @@ LL | let _: Struct5 = Struct5 { field: 1 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:100:20 + --> $DIR/generics-default-stability.rs:102:20 | LL | let _: Struct5 = STRUCT5; | ^^^^^ @@ -161,7 +161,7 @@ LL | let _: Struct5 = STRUCT5; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:102:20 + --> $DIR/generics-default-stability.rs:104:20 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^ @@ -169,25 +169,25 @@ LL | let _: Struct5 = Struct5 { field: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable warning: use of deprecated item 'unstable_generic_param::Struct4::field': test - --> $DIR/generics-default-stability.rs:81:39 + --> $DIR/generics-default-stability.rs:83:39 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4::field': test - --> $DIR/generics-default-stability.rs:88:39 + --> $DIR/generics-default-stability.rs:90:39 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:94:39 + --> $DIR/generics-default-stability.rs:96:39 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:102:39 + --> $DIR/generics-default-stability.rs:104:39 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ From e1ea2c36d74229f9d71e55a46f346aebbfeae589 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 11 Jul 2020 19:24:04 -0400 Subject: [PATCH 18/20] Add unstable default feature enabled test --- .../auxiliary/unstable_generic_param.rs | 6 ++ .../generics-default-stability.rs | 4 ++ .../generics-default-stability.stderr | 56 +++++++++---------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs index 64d725e55edb8..82eed9a38f9e5 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -55,6 +55,12 @@ pub struct Struct5<#[unstable(feature = "unstable_default", issue = "none")] A = pub field: A, } +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Struct6<#[unstable(feature = "unstable_default6", 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 const STRUCT1: Struct1 = Struct1 { field: 1 }; diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index c44f3c32bbee3..26f7692209f9c 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -1,5 +1,6 @@ // ignore-tidy-linelength // aux-build:unstable_generic_param.rs +#![feature(unstable_default6)] extern crate unstable_generic_param; @@ -105,4 +106,7 @@ fn main() { //~^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^ use of deprecated item 'unstable_generic_param::Struct5': test [deprecated] //~^^^ use of deprecated item 'unstable_generic_param::Struct5::field': test [deprecated] + + let _: Struct6 = Struct6 { field: 1 }; // ok + let _: Struct6 = Struct6 { field: 0 }; // ok } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index 87ebe65dcfcfc..d9e195c21d608 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:16:13 + --> $DIR/generics-default-stability.rs:17:13 | LL | impl Trait1 for S { | ^^^^^ @@ -7,7 +7,7 @@ LL | impl Trait1 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:20:13 + --> $DIR/generics-default-stability.rs:21:13 | LL | impl Trait1 for S { | ^^^^^ @@ -15,7 +15,7 @@ LL | impl Trait1 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:24:13 + --> $DIR/generics-default-stability.rs:25:13 | LL | impl Trait2 for S { | ^^^^^ @@ -23,7 +23,7 @@ LL | impl Trait2 for S { = help: add `#![feature(unstable_default)]` to the crate attributes to enable warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:83:29 + --> $DIR/generics-default-stability.rs:84:29 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^ @@ -31,73 +31,73 @@ LL | let _: Struct4 = Struct4 { field: 1 }; = note: `#[warn(deprecated)]` on by default warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:83:12 + --> $DIR/generics-default-stability.rs:84:12 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:88:12 + --> $DIR/generics-default-stability.rs:89:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:89:12 + --> $DIR/generics-default-stability.rs:90:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:90:29 + --> $DIR/generics-default-stability.rs:91:29 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4': test - --> $DIR/generics-default-stability.rs:90:12 + --> $DIR/generics-default-stability.rs:91:12 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:96:29 + --> $DIR/generics-default-stability.rs:97:29 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:96:12 + --> $DIR/generics-default-stability.rs:97:12 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:101:12 + --> $DIR/generics-default-stability.rs:102:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:102:12 + --> $DIR/generics-default-stability.rs:103:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:104:29 + --> $DIR/generics-default-stability.rs:105:29 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5': test - --> $DIR/generics-default-stability.rs:104:12 + --> $DIR/generics-default-stability.rs:105:12 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^^^^^^^ error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:35:20 + --> $DIR/generics-default-stability.rs:36:20 | LL | let _: Struct1 = Struct1 { field: 1 }; | ^^^^^ @@ -105,7 +105,7 @@ LL | let _: Struct1 = Struct1 { field: 1 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:39:20 + --> $DIR/generics-default-stability.rs:40:20 | LL | let _: Struct1 = STRUCT1; | ^^^^^ @@ -113,7 +113,7 @@ LL | let _: Struct1 = STRUCT1; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:40:20 + --> $DIR/generics-default-stability.rs:41:20 | LL | let _: Struct1 = Struct1 { field: 0 }; | ^^^^^ @@ -121,7 +121,7 @@ LL | let _: Struct1 = Struct1 { field: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:69:27 + --> $DIR/generics-default-stability.rs:70:27 | LL | let _: Struct3 = STRUCT3; | ^^^^^ @@ -129,7 +129,7 @@ LL | let _: Struct3 = STRUCT3; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:71:27 + --> $DIR/generics-default-stability.rs:72:27 | LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | ^^^^^ @@ -137,7 +137,7 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:72:27 + --> $DIR/generics-default-stability.rs:73:27 | LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; | ^^^^^ @@ -145,7 +145,7 @@ LL | let _: Struct3 = Struct3 { field1: 0, field2: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:96:20 + --> $DIR/generics-default-stability.rs:97:20 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^ @@ -153,7 +153,7 @@ LL | let _: Struct5 = Struct5 { field: 1 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:102:20 + --> $DIR/generics-default-stability.rs:103:20 | LL | let _: Struct5 = STRUCT5; | ^^^^^ @@ -161,7 +161,7 @@ LL | let _: Struct5 = STRUCT5; = help: add `#![feature(unstable_default)]` to the crate attributes to enable error[E0658]: use of unstable library feature 'unstable_default' - --> $DIR/generics-default-stability.rs:104:20 + --> $DIR/generics-default-stability.rs:105:20 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^ @@ -169,25 +169,25 @@ LL | let _: Struct5 = Struct5 { field: 0 }; = help: add `#![feature(unstable_default)]` to the crate attributes to enable warning: use of deprecated item 'unstable_generic_param::Struct4::field': test - --> $DIR/generics-default-stability.rs:83:39 + --> $DIR/generics-default-stability.rs:84:39 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct4::field': test - --> $DIR/generics-default-stability.rs:90:39 + --> $DIR/generics-default-stability.rs:91:39 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:96:39 + --> $DIR/generics-default-stability.rs:97:39 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test - --> $DIR/generics-default-stability.rs:104:39 + --> $DIR/generics-default-stability.rs:105:39 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ From 5c9b5bf121c212f38fc4d2945afb423443e9d24a Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 12 Jul 2020 20:56:37 -0400 Subject: [PATCH 19/20] Test unstable Alloc param on Box --- .../auxiliary/unstable_generic_param.rs | 36 ++++++++++++++++++- .../generics-default-stability.rs | 6 ++++ .../generics-default-stability.stderr | 10 +++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs index 82eed9a38f9e5..b26908c25e304 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -1,6 +1,5 @@ #![crate_type = "lib"] #![feature(staged_api)] - #![stable(feature = "stable_test_feature", since = "1.0.0")] #[stable(feature = "stable_test_feature", since = "1.0.0")] @@ -75,3 +74,38 @@ pub const STRUCT4: Struct4 = Struct4 { field: 1 }; #[stable(feature = "stable_test_feature", since = "1.0.0")] pub const STRUCT5: Struct5 = Struct5 { field: 1 }; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub trait Alloc {} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct System {} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +impl Alloc for System {} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Box1 { + ptr: *mut T, + alloc: A, +} + +impl Box1 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub fn new(mut t: T) -> Self { + unsafe { Self { ptr: &mut t, alloc: System {} } } + } +} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Box2 { + ptr: *mut T, + alloc: A, +} + +impl Box2 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub fn new(mut t: T) -> Self { + Self { ptr: &mut t, alloc: System {} } + } +} diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index 26f7692209f9c..d412aceb3a28c 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -109,4 +109,10 @@ fn main() { let _: Struct6 = Struct6 { field: 1 }; // ok let _: Struct6 = Struct6 { field: 0 }; // ok + + let _: Box1 = Box1::new(1); //~ ERROR use of unstable library feature 'box_alloc_param' + let _: Box1 = Box1::new(1); // ok + + let _: Box2 = Box2::new(1); // ok + let _: Box2 = Box2::new(1); // ok } diff --git a/src/test/ui/stability-attribute/generics-default-stability.stderr b/src/test/ui/stability-attribute/generics-default-stability.stderr index d9e195c21d608..37a809f8bca65 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -168,6 +168,14 @@ LL | let _: Struct5 = Struct5 { field: 0 }; | = help: add `#![feature(unstable_default)]` to the crate attributes to enable +error[E0658]: use of unstable library feature 'box_alloc_param' + --> $DIR/generics-default-stability.rs:113:24 + | +LL | let _: Box1 = Box1::new(1); + | ^^^^^^ + | + = help: add `#![feature(box_alloc_param)]` to the crate attributes to enable + warning: use of deprecated item 'unstable_generic_param::Struct4::field': test --> $DIR/generics-default-stability.rs:84:39 | @@ -192,6 +200,6 @@ warning: use of deprecated item 'unstable_generic_param::Struct5::field': test LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ -error: aborting due to 12 previous errors; 16 warnings emitted +error: aborting due to 13 previous errors; 16 warnings emitted For more information about this error, try `rustc --explain E0658`. From c1650b37575bc128d66290bf942da33a3a2ad60c Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 12 Jul 2020 21:02:47 -0400 Subject: [PATCH 20/20] Test removing unstable default parameter --- .../auxiliary/unstable_generic_param.rs | 12 ++++++++++++ .../generics-default-stability.rs | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs index b26908c25e304..b5490381a46b6 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -109,3 +109,15 @@ impl Box2 { Self { ptr: &mut t, alloc: System {} } } } + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub struct Box3 { + ptr: *mut T, +} + +impl Box3 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + pub fn new(mut t: T) -> Self { + Self { ptr: &mut t } + } +} diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index d412aceb3a28c..b68336da1a5f7 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -115,4 +115,6 @@ fn main() { let _: Box2 = Box2::new(1); // ok let _: Box2 = Box2::new(1); // ok + + let _: Box3 = Box3::new(1); // ok }