From a7a20860537ddd05f802598866681a6f9cc3413c 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 --- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 ++ compiler/rustc_middle/src/middle/stability.rs | 40 ++++++++--- compiler/rustc_passes/src/stability.rs | 68 ++++++++++++++----- compiler/rustc_typeck/src/astconv/mod.rs | 11 ++- .../rustc_typeck/src/check/method/probe.rs | 2 +- .../auxiliary/unstable_generic_param.rs | 41 +++++++++++ .../generics-default-stability.rs | 59 ++++++++++++++++ .../generics-default-stability.stderr | 27 ++++++++ 8 files changed, 226 insertions(+), 26 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/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index eb091d86b82c6..9ef17a934232c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1756,6 +1756,9 @@ impl EncodeContext<'a, '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( @@ -1763,6 +1766,7 @@ impl EncodeContext<'a, 'tcx> { EntryKind::ConstParam, true, ); + // FIXME(const_generics:defaults) } } } diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 27658d50d4582..4c0e513e75ce1 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -293,9 +293,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 @@ -395,21 +401,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/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 4ca52f405fb94..d658a58aeab1a 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -56,6 +56,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), @@ -63,7 +64,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { debug!("annotate(id = {:?}, attrs = {:?})", hir_id, attrs); let mut did_error = false; if !self.tcx.features().staged_api { - did_error = self.forbid_staged_api_attrs(hir_id, attrs); + did_error = self.forbid_staged_api_attrs(hir_id, attrs, inherit_deprecation); } let depr = @@ -80,9 +81,11 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { let depr_entry = DeprecationEntry::local(depr.clone(), hir_id); self.index.depr_map.insert(hir_id, depr_entry); } else if let Some(parent_depr) = self.parent_depr.clone() { - is_deprecated = true; - info!("tagging child {:?} as deprecated from parent", hir_id); - self.index.depr_map.insert(hir_id, parent_depr); + if inherit_deprecation { + is_deprecated = true; + info!("tagging child {:?} as deprecated from parent", hir_id); + self.index.depr_map.insert(hir_id, parent_depr); + } } if self.tcx.features().staged_api { @@ -186,7 +189,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); } } @@ -237,7 +240,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } // returns true if an error occurred, used to suppress some spurious errors - fn forbid_staged_api_attrs(&mut self, hir_id: HirId, attrs: &[Attribute]) -> bool { + fn forbid_staged_api_attrs(&mut self, hir_id: HirId, attrs: &[Attribute], inherit_deprecation: bool) -> bool { // Emit errors for non-staged-api crates. let unstable_attrs = [ sym::unstable, @@ -265,7 +268,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); } } @@ -301,18 +304,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); }); } @@ -320,15 +330,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) @@ -336,19 +353,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); + }); } } @@ -422,6 +453,10 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'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> { @@ -484,6 +519,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/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index a743dc1cd2086..c4f1ee2e6f6d6 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -360,7 +360,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.ty_error().into() diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 8a62031ec887c..07e75594195ea 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1227,7 +1227,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 a9d6da576bbc4b80337c14cb3d0fcb2967a934f4 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 8b81a17d7353a75e4b2d29f96c2c0c8fb1713fec 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 88b77b6534d5353a16e597451a22322cc7d92063 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 eb7abb9e32a2ba10d0c083b13bb1a2dcd1d22b5d 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 cb7264b22a45b993df57bd17e869a472a5c12b47 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 f665ccd3a2f5e58c6ac3828e34f5c8e94f71811c 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 a1892f1a798f8b0c24136d0be65fa4cc23e0ff74 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 3947591ee82702f124af9248463036155b83b907 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 --- compiler/rustc_middle/src/middle/stability.rs | 23 +++++++------------ compiler/rustc_typeck/src/astconv/mod.rs | 1 - .../rustc_typeck/src/check/method/probe.rs | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 4c0e513e75ce1..0fb73db83e8c5 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -293,15 +293,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 @@ -398,10 +392,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)); @@ -413,14 +407,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: &_| { @@ -428,7 +421,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/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index c4f1ee2e6f6d6..ad4c28928fc63 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -366,7 +366,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { param.def_id, Some(arg.id()), arg.span(), - false, |_, _| (), ) } diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 07e75594195ea..8a62031ec887c 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1227,7 +1227,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 19e90843a4eb99d528dea62f793ad6d523c4af6c Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 5 Jul 2020 19:02:30 -0400 Subject: [PATCH 10/20] Add documentation --- compiler/rustc_middle/src/middle/stability.rs | 7 +- compiler/rustc_passes/src/stability.rs | 117 +++++++++++++----- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- 3 files changed, 90 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 0fb73db83e8c5..28d139faa59b0 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -395,7 +395,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)); @@ -409,7 +409,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/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index d658a58aeab1a..d34363e057726 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -37,6 +37,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>, @@ -56,7 +70,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), @@ -81,7 +95,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { let depr_entry = DeprecationEntry::local(depr.clone(), hir_id); self.index.depr_map.insert(hir_id, depr_entry); } else if let Some(parent_depr) = self.parent_depr.clone() { - if inherit_deprecation { + if inherit_deprecation.yes() { is_deprecated = true; info!("tagging child {:?} as deprecated from parent", hir_id); self.index.depr_map.insert(hir_id, parent_depr); @@ -189,7 +203,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); } } @@ -240,7 +254,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } // returns true if an error occurred, used to suppress some spurious errors - fn forbid_staged_api_attrs(&mut self, hir_id: HirId, attrs: &[Attribute], inherit_deprecation: bool) -> bool { + fn forbid_staged_api_attrs(&mut self, hir_id: HirId, attrs: &[Attribute], inherit_deprecation: InheritDeprecation) -> bool { // Emit errors for non-staged-api crates. let unstable_attrs = [ sym::unstable, @@ -268,7 +282,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); } } @@ -309,7 +323,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { &i.attrs, i.span, AnnotationKind::Required, - true, + InheritDeprecation::Yes, |_| {}, ) } @@ -317,55 +331,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>) { @@ -377,7 +428,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); }); } @@ -519,7 +570,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/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index ad4c28928fc63..3c95184c35feb 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -362,7 +362,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 41eec9065aef513cc41d8e2297c4f469fd7029b7 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:31:48 -0400 Subject: [PATCH 11/20] Update src/librustc_passes/stability.rs Co-authored-by: varkor --- compiler/rustc_passes/src/stability.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index d34363e057726..dd453f2855420 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -37,8 +37,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 9eb595705e754c970de76375060455bc3f576296 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:32:11 -0400 Subject: [PATCH 12/20] Update src/librustc_typeck/astconv.rs Co-authored-by: varkor --- compiler/rustc_typeck/src/astconv/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 3c95184c35feb..46b8b2e14c736 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -366,7 +366,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 25dba40cbee4161709fba653c5f3915a7ac87537 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:32:58 -0400 Subject: [PATCH 13/20] Update src/librustc_middle/middle/stability.rs Co-authored-by: varkor --- compiler/rustc_middle/src/middle/stability.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 28d139faa59b0..7e2415fd544d4 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -402,16 +402,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 2793da3f39033d7f0b2c07a3556d68ccd4d03d4e Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Wed, 8 Jul 2020 15:51:31 -0400 Subject: [PATCH 14/20] Update src/librustc_passes/stability.rs Co-authored-by: varkor --- compiler/rustc_passes/src/stability.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index dd453f2855420..5b0df9e884ff6 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -43,7 +43,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, @@ -51,7 +50,7 @@ enum InheritDeprecation { impl InheritDeprecation { fn yes(&self) -> bool { - *self == InheritDeprecation::Yes + matches!(self, InheritDeprecation::Yes) } } From af19d4492124a9681c1e3bc9c9effe1641ad7d20 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 11 Jul 2020 19:08:05 -0400 Subject: [PATCH 15/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 7616b30bff843ff279fae9ae4eea44b87d46b310 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sat, 11 Jul 2020 19:24:04 -0400 Subject: [PATCH 16/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 a73e7d0a4df305e8b8237163e5ac7755cf488af8 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 12 Jul 2020 20:56:37 -0400 Subject: [PATCH 17/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 d281620d8f630346ea96c8c65b9fd7f5b7f1da9e Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Sun, 12 Jul 2020 21:02:47 -0400 Subject: [PATCH 18/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 } From 3f1b4b39e3dbff49d3298af1acaa526310b255a7 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Tue, 22 Sep 2020 22:54:52 -0400 Subject: [PATCH 19/20] Fix compilation & test failures --- compiler/rustc_passes/src/stability.rs | 10 ++++-- .../generics-default-stability.rs | 32 +++++++++---------- .../generics-default-stability.stderr | 32 +++++++++---------- 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 5b0df9e884ff6..b807dff5fd25d 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -43,6 +43,7 @@ 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(Clone)] enum InheritDeprecation { Yes, No, @@ -81,7 +82,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { debug!("annotate(id = {:?}, attrs = {:?})", hir_id, attrs); let mut did_error = false; if !self.tcx.features().staged_api { - did_error = self.forbid_staged_api_attrs(hir_id, attrs, inherit_deprecation); + did_error = self.forbid_staged_api_attrs(hir_id, attrs, inherit_deprecation.clone()); } let depr = @@ -257,7 +258,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> { } // returns true if an error occurred, used to suppress some spurious errors - fn forbid_staged_api_attrs(&mut self, hir_id: HirId, attrs: &[Attribute], inherit_deprecation: InheritDeprecation) -> bool { + fn forbid_staged_api_attrs( + &mut self, + hir_id: HirId, + attrs: &[Attribute], + inherit_deprecation: InheritDeprecation, + ) -> bool { // Emit errors for non-staged-api crates. let unstable_attrs = [ sym::unstable, diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index b68336da1a5f7..461b1d405cb10 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -82,30 +82,30 @@ fn main() { 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] + //~^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated] + //~^^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated] + //~^^^ use of deprecated field `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; //~ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated] + let _: Struct4 = STRUCT4; //~ use of deprecated struct `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] + //~^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated] + //~^^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated] + //~^^^ use of deprecated field `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] + //~^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated] + //~^^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated] + //~^^^ use of deprecated field `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; //~ use of deprecated struct `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 struct `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] + //~^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated] + //~^^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated] + //~^^^ use of deprecated field `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 37a809f8bca65..d9b238f8841bd 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -22,7 +22,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 +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:84:29 | LL | let _: Struct4 = Struct4 { field: 1 }; @@ -30,67 +30,67 @@ LL | let _: Struct4 = Struct4 { field: 1 }; | = note: `#[warn(deprecated)]` on by default -warning: use of deprecated item 'unstable_generic_param::Struct4': test +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:84:12 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct4': test +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:89:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct4': test +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:90:12 | LL | let _: Struct4 = STRUCT4; | ^^^^^^^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct4': test +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:91:29 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct4': test +warning: use of deprecated struct `unstable_generic_param::Struct4`: test --> $DIR/generics-default-stability.rs:91:12 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:97:29 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:97:12 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:102:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:103:12 | LL | let _: Struct5 = STRUCT5; | ^^^^^^^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:105:29 | LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5': test +warning: use of deprecated struct `unstable_generic_param::Struct5`: test --> $DIR/generics-default-stability.rs:105:12 | LL | let _: Struct5 = Struct5 { field: 0 }; @@ -176,25 +176,25 @@ 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 +warning: use of deprecated field `unstable_generic_param::Struct4::field`: test --> $DIR/generics-default-stability.rs:84:39 | LL | let _: Struct4 = Struct4 { field: 1 }; | ^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct4::field': test +warning: use of deprecated field `unstable_generic_param::Struct4::field`: test --> $DIR/generics-default-stability.rs:91:39 | LL | let _: Struct4 = Struct4 { field: 0 }; | ^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5::field': test +warning: use of deprecated field `unstable_generic_param::Struct5::field`: test --> $DIR/generics-default-stability.rs:97:39 | LL | let _: Struct5 = Struct5 { field: 1 }; | ^^^^^^^^ -warning: use of deprecated item 'unstable_generic_param::Struct5::field': test +warning: use of deprecated field `unstable_generic_param::Struct5::field`: test --> $DIR/generics-default-stability.rs:105:39 | LL | let _: Struct5 = Struct5 { field: 0 }; From 98eab09cf4ee1a35290a2061ee0e7a19703923a8 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Wed, 23 Sep 2020 02:14:42 -0400 Subject: [PATCH 20/20] Add enum and type alias tests for generic default stability --- .../auxiliary/unstable_generic_param.rs | 106 +++++++ .../generics-default-stability.rs | 144 +++++++++ .../generics-default-stability.stderr | 292 +++++++++++++++++- 3 files changed, 540 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 b5490381a46b6..231ab966558f9 100644 --- a/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs +++ b/src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs @@ -75,6 +75,112 @@ 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 enum Enum1<#[unstable(feature = "unstable_default", issue = "none")] T = usize> { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Some(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + None, +} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub enum Enum2 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Some(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + None, +} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub enum Enum3 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Ok(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Err(#[stable(feature = "stable_test_feature", since = "1.0.0")] E), +} + +#[rustc_deprecated(since = "1.1.0", reason = "test")] +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub enum Enum4 { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Some(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + None, +} + +#[rustc_deprecated(since = "1.1.0", reason = "test")] +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub enum Enum5<#[unstable(feature = "unstable_default", issue = "none")] T = usize> { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Some(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + None, +} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub enum Enum6<#[unstable(feature = "unstable_default6", issue = "none")] T = usize> { + #[stable(feature = "stable_test_feature", since = "1.0.0")] + Some(#[stable(feature = "stable_test_feature", since = "1.0.0")] T), + #[stable(feature = "stable_test_feature", since = "1.0.0")] + None, +} + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM1: Enum1 = Enum1::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM2: Enum2 = Enum2::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM3: Enum3 = Enum3::Ok(1); +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM3B: Enum3 = Enum3::Err(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM4: Enum4 = Enum4::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ENUM5: Enum5 = Enum5::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias1<#[unstable(feature = "unstable_default", issue = "none")] T = usize> = Option; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias2 = Option; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias3 = + Result; + +#[rustc_deprecated(since = "1.1.0", reason = "test")] +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias4 = Option; + +#[rustc_deprecated(since = "1.1.0", reason = "test")] +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias5<#[unstable(feature = "unstable_default", issue = "none")] T = usize> = Option; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub type Alias6<#[unstable(feature = "unstable_default6", issue = "none")] T = usize> = Option; + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS1: Alias1 = Alias1::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS2: Alias2 = Alias2::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS3: Alias3 = Alias3::Ok(1); +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS3B: Alias3 = Alias3::Err(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS4: Alias4 = Alias4::Some(1); + +#[stable(feature = "stable_test_feature", since = "1.0.0")] +pub const ALIAS5: Alias5 = Alias5::Some(1); + + #[stable(feature = "stable_test_feature", since = "1.0.0")] pub trait Alloc {} diff --git a/src/test/ui/stability-attribute/generics-default-stability.rs b/src/test/ui/stability-attribute/generics-default-stability.rs index 461b1d405cb10..d6f28e3e447e2 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.rs +++ b/src/test/ui/stability-attribute/generics-default-stability.rs @@ -110,6 +110,150 @@ fn main() { let _: Struct6 = Struct6 { field: 1 }; // ok let _: Struct6 = Struct6 { field: 0 }; // ok + let _: Alias1 = Alias1::Some(1); //~ ERROR use of unstable library feature 'unstable_default' + + let _ = ALIAS1; // ok + let _: Alias1 = ALIAS1; // ok + let _: Alias1 = ALIAS1; //~ ERROR use of unstable library feature 'unstable_default' + let _: Alias1 = Alias1::Some(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, + // and can be used without the 'unstable_default' feature. + let _ = Alias1::Some(1); + let _ = Alias1::Some(()); + let _ = Alias1::Some(1isize); + let _: Alias1 = Alias1::Some(1); + let _: usize = ALIAS1.unwrap(); + let _ = ALIAS1.unwrap() + 1; + let _ = ALIAS1.unwrap() + 1usize; + + let _ = Alias2::Some(1); // ok + let _: Alias2 = Alias2::Some(1); // ok + let _: Alias2 = Alias2::Some(1); // ok + + let _ = ALIAS2; + let _: Alias2 = ALIAS2; // ok + let _: Alias2 = ALIAS2; // ok + let _: Alias2 = Alias2::Some(0); // ok + let _ = ALIAS2.unwrap(); // ok + let _: usize = ALIAS2.unwrap(); // ok + let _ = ALIAS2.unwrap() + 1; // ok + let _ = ALIAS2.unwrap() + 1usize; // ok + + let _ = ALIAS3; + let _: Alias3 = ALIAS3; // ok + let _: Alias3 = ALIAS3; //~ ERROR use of unstable library feature 'unstable_default' + let _: Alias3 = ALIAS3; // ok + let _: Alias3 = Alias3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default' + let _: Alias3 = Alias3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default' + let _ = ALIAS3.unwrap(); // ok + let _: isize = ALIAS3.unwrap(); // ok + let _ = ALIAS3.unwrap() + 1; // ok + // Note the aforementioned leak. + let _: usize = ALIAS3B.unwrap_err(); // ok + let _: Alias3 = Alias3::Err(0); // ok + let _ = ALIAS3B.unwrap_err() + 1; // ok + let _ = ALIAS3B.unwrap_err() + 1usize; // ok + + let _ = ALIAS4; + let _: Alias4 = Alias4::Some(1); + //~^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + //~^^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + let _ = ALIAS4; + let _: Alias4 = ALIAS4; //~ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + let _: Alias4 = ALIAS4; //~ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + let _: Alias4 = Alias4::Some(0); + //~^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + //~^^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated] + + let _ = ALIAS5; + let _: Alias5 = Alias5::Some(1); //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + //~^^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + let _ = ALIAS5; + let _: Alias5 = ALIAS5; //~ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + let _: Alias5 = ALIAS5; //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + let _: Alias5 = Alias5::Some(0); //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + //~^^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated] + + let _: Alias6 = Alias6::Some(1); // ok + let _: Alias6 = Alias6::Some(0); // ok + + let _: Enum1 = Enum1::Some(1); //~ ERROR use of unstable library feature 'unstable_default' + + let _ = ENUM1; // ok + let _: Enum1 = ENUM1; // ok + let _: Enum1 = ENUM1; //~ ERROR use of unstable library feature 'unstable_default' + let _: Enum1 = Enum1::Some(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, + // and can be used without the 'unstable_default' feature. + let _ = Enum1::Some(1); + let _ = Enum1::Some(()); + let _ = Enum1::Some(1isize); + let _: Enum1 = Enum1::Some(1); + if let Enum1::Some(x) = ENUM1 {let _: usize = x;} + if let Enum1::Some(x) = ENUM1 {let _ = x + 1;} + if let Enum1::Some(x) = ENUM1 {let _ = x + 1usize;} + + let _ = Enum2::Some(1); // ok + let _: Enum2 = Enum2::Some(1); // ok + let _: Enum2 = Enum2::Some(1); // ok + + let _ = ENUM2; + let _: Enum2 = ENUM2; // ok + let _: Enum2 = ENUM2; // ok + let _: Enum2 = Enum2::Some(0); // ok + if let Enum2::Some(x) = ENUM2 {let _ = x;} // ok + if let Enum2::Some(x) = ENUM2 {let _: usize = x;} // ok + if let Enum2::Some(x) = ENUM2 {let _ = x + 1;} // ok + if let Enum2::Some(x) = ENUM2 {let _ = x + 1usize;} // ok + + let _ = ENUM3; + let _: Enum3 = ENUM3; // ok + let _: Enum3 = ENUM3; //~ ERROR use of unstable library feature 'unstable_default' + let _: Enum3 = ENUM3; // ok + let _: Enum3 = Enum3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default' + let _: Enum3 = Enum3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default' + if let Enum3::Ok(x) = ENUM3 {let _ = x;} // ok + if let Enum3::Ok(x) = ENUM3 {let _: isize = x;} // ok + if let Enum3::Ok(x) = ENUM3 {let _ = x + 1;} // ok + // Note the aforementioned leak. + if let Enum3::Err(x) = ENUM3B {let _: usize = x;} // ok + let _: Enum3 = Enum3::Err(0); // ok + if let Enum3::Err(x) = ENUM3B {let _ = x + 1;} // ok + if let Enum3::Err(x) = ENUM3B {let _ = x + 1usize;} // ok + + let _ = ENUM4; + let _: Enum4 = Enum4::Some(1); + //~^ use of deprecated variant `unstable_generic_param::Enum4::Some`: test [deprecated] + //~^^ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated] + let _ = ENUM4; + let _: Enum4 = ENUM4; //~ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated] + let _: Enum4 = ENUM4; //~ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated] + let _: Enum4 = Enum4::Some(0); + //~^ use of deprecated variant `unstable_generic_param::Enum4::Some`: test [deprecated] + //~^^ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated] + + let _ = ENUM5; + let _: Enum5 = Enum5::Some(1); //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated variant `unstable_generic_param::Enum5::Some`: test [deprecated] + //~^^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated] + let _ = ENUM5; + let _: Enum5 = ENUM5; //~ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated] + let _: Enum5 = ENUM5; //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated] + let _: Enum5 = Enum5::Some(0); //~ ERROR use of unstable library feature 'unstable_default' + //~^ use of deprecated variant `unstable_generic_param::Enum5::Some`: test [deprecated] + //~^^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated] + + let _: Enum6 = Enum6::Some(1); // ok + let _: Enum6 = Enum6::Some(0); // ok + let _: Box1 = Box1::new(1); //~ ERROR use of unstable library feature 'box_alloc_param' let _: Box1 = Box1::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 d9b238f8841bd..a5df70bb8b3dd 100644 --- a/src/test/ui/stability-attribute/generics-default-stability.stderr +++ b/src/test/ui/stability-attribute/generics-default-stability.stderr @@ -96,6 +96,150 @@ warning: use of deprecated struct `unstable_generic_param::Struct5`: test LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^^^^^^^ +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:160:28 + | +LL | let _: Alias4 = Alias4::Some(1); + | ^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:160:12 + | +LL | let _: Alias4 = Alias4::Some(1); + | ^^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:164:12 + | +LL | let _: Alias4 = ALIAS4; + | ^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:165:12 + | +LL | let _: Alias4 = ALIAS4; + | ^^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:166:28 + | +LL | let _: Alias4 = Alias4::Some(0); + | ^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias4`: test + --> $DIR/generics-default-stability.rs:166:12 + | +LL | let _: Alias4 = Alias4::Some(0); + | ^^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:171:28 + | +LL | let _: Alias5 = Alias5::Some(1); + | ^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:171:12 + | +LL | let _: Alias5 = Alias5::Some(1); + | ^^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:175:12 + | +LL | let _: Alias5 = ALIAS5; + | ^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:176:12 + | +LL | let _: Alias5 = ALIAS5; + | ^^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:178:28 + | +LL | let _: Alias5 = Alias5::Some(0); + | ^^^^^^^^^^^^ + +warning: use of deprecated type alias `unstable_generic_param::Alias5`: test + --> $DIR/generics-default-stability.rs:178:12 + | +LL | let _: Alias5 = Alias5::Some(0); + | ^^^^^^^^^^^^^ + +warning: use of deprecated variant `unstable_generic_param::Enum4::Some`: test + --> $DIR/generics-default-stability.rs:232:27 + | +LL | let _: Enum4 = Enum4::Some(1); + | ^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum4`: test + --> $DIR/generics-default-stability.rs:232:12 + | +LL | let _: Enum4 = Enum4::Some(1); + | ^^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum4`: test + --> $DIR/generics-default-stability.rs:236:12 + | +LL | let _: Enum4 = ENUM4; + | ^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum4`: test + --> $DIR/generics-default-stability.rs:237:12 + | +LL | let _: Enum4 = ENUM4; + | ^^^^^^^^^^^^ + +warning: use of deprecated variant `unstable_generic_param::Enum4::Some`: test + --> $DIR/generics-default-stability.rs:238:27 + | +LL | let _: Enum4 = Enum4::Some(0); + | ^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum4`: test + --> $DIR/generics-default-stability.rs:238:12 + | +LL | let _: Enum4 = Enum4::Some(0); + | ^^^^^^^^^^^^ + +warning: use of deprecated variant `unstable_generic_param::Enum5::Some`: test + --> $DIR/generics-default-stability.rs:243:27 + | +LL | let _: Enum5 = Enum5::Some(1); + | ^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum5`: test + --> $DIR/generics-default-stability.rs:243:12 + | +LL | let _: Enum5 = Enum5::Some(1); + | ^^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum5`: test + --> $DIR/generics-default-stability.rs:247:12 + | +LL | let _: Enum5 = ENUM5; + | ^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum5`: test + --> $DIR/generics-default-stability.rs:248:12 + | +LL | let _: Enum5 = ENUM5; + | ^^^^^^^^^^^^ + +warning: use of deprecated variant `unstable_generic_param::Enum5::Some`: test + --> $DIR/generics-default-stability.rs:250:27 + | +LL | let _: Enum5 = Enum5::Some(0); + | ^^^^^^^^^^^ + +warning: use of deprecated enum `unstable_generic_param::Enum5`: test + --> $DIR/generics-default-stability.rs:250:12 + | +LL | let _: Enum5 = Enum5::Some(0); + | ^^^^^^^^^^^^ + error[E0658]: use of unstable library feature 'unstable_default' --> $DIR/generics-default-stability.rs:36:20 | @@ -168,8 +312,152 @@ LL | let _: Struct5 = Struct5 { 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:113:19 + | +LL | let _: Alias1 = Alias1::Some(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:117:19 + | +LL | let _: Alias1 = ALIAS1; + | ^^^^^ + | + = 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:118:19 + | +LL | let _: Alias1 = Alias1::Some(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:146:26 + | +LL | let _: Alias3 = ALIAS3; + | ^^^^^ + | + = 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:148:26 + | +LL | let _: Alias3 = Alias3::Ok(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:149:26 + | +LL | let _: Alias3 = Alias3::Ok(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:171:19 + | +LL | let _: Alias5 = Alias5::Some(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:176:19 + | +LL | let _: Alias5 = ALIAS5; + | ^^^^^ + | + = 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:178:19 + | +LL | let _: Alias5 = Alias5::Some(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:185:18 + | +LL | let _: Enum1 = Enum1::Some(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:189:18 + | +LL | let _: Enum1 = ENUM1; + | ^^^^^ + | + = 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:190:18 + | +LL | let _: Enum1 = Enum1::Some(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:218:25 + | +LL | let _: Enum3 = ENUM3; + | ^^^^^ + | + = 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:220:25 + | +LL | let _: Enum3 = Enum3::Ok(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:221:25 + | +LL | let _: Enum3 = Enum3::Ok(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:243:18 + | +LL | let _: Enum5 = Enum5::Some(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:248:18 + | +LL | let _: Enum5 = ENUM5; + | ^^^^^ + | + = 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:250:18 + | +LL | let _: Enum5 = Enum5::Some(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 + --> $DIR/generics-default-stability.rs:257:24 | LL | let _: Box1 = Box1::new(1); | ^^^^^^ @@ -200,6 +488,6 @@ warning: use of deprecated field `unstable_generic_param::Struct5::field`: test LL | let _: Struct5 = Struct5 { field: 0 }; | ^^^^^^^^ -error: aborting due to 13 previous errors; 16 warnings emitted +error: aborting due to 31 previous errors; 40 warnings emitted For more information about this error, try `rustc --explain E0658`.