From 5b2a7606aeabfc2c78e0475f18d24d6c9e6910e8 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Mon, 20 Dec 2021 10:21:07 +0800 Subject: [PATCH 1/9] Fix the error of checking `base_expr` twice in type_changing_struct_update --- compiler/rustc_typeck/src/check/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 096c4fcf47207..8d370e440eaf1 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1508,7 +1508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } else { self.check_expr_has_type_or_error(base_expr, adt_ty, |_| { - let base_ty = self.check_expr(base_expr); + let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id); let same_adt = match (adt_ty.kind(), base_ty.kind()) { (ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true, _ => false, From 643484416b6f09cf40c7583b4259e685c1e30f03 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Mon, 20 Dec 2021 10:39:02 +0800 Subject: [PATCH 2/9] add test files --- .../issue-92010-trait-bound-not-satisfied.rs | 12 ++++++++++++ .../issue-92010-trait-bound-not-satisfied.stderr | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs create mode 100644 src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr diff --git a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs new file mode 100644 index 0000000000000..f1a54ee5867c5 --- /dev/null +++ b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs @@ -0,0 +1,12 @@ +#[derive(Clone)] +struct P { + x: T, + y: f64, +} + +impl P { + fn y(&self, y: f64) -> Self { P{y, .. self.clone() } } + //~^ mismatched types [E0308] +} + +fn main() {} diff --git a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr new file mode 100644 index 0000000000000..5957ea7c9efdd --- /dev/null +++ b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-92010-trait-bound-not-satisfied.rs:8:43 + | +LL | fn y(&self, y: f64) -> Self { P{y, .. self.clone() } } + | ^^^^^^^^^^^^ expected struct `P`, found `&P` + | + = note: expected struct `P` + found reference `&P` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 13241008005f2471b3e4bae464ff81b2c2e2258f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 21 Dec 2021 20:11:36 +0800 Subject: [PATCH 3/9] resolve: Minor miscellaneous cleanups from #89059 --- .../src/rmeta/decoder/cstore_impl.rs | 8 ++--- compiler/rustc_resolve/src/lib.rs | 34 ++++++++----------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 4e5d21049a0d9..875bea2b9c38e 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -417,16 +417,12 @@ impl CStore { let span = data.get_span(id.index, sess); - let attrs = data.get_item_attrs(id.index, sess).collect(); - - let ident = data.item_ident(id.index, sess); - LoadedMacro::MacroDef( ast::Item { - ident, + ident: data.item_ident(id.index, sess), id: ast::DUMMY_NODE_ID, span, - attrs, + attrs: data.get_item_attrs(id.index, sess).collect(), kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)), vis: ast::Visibility { span: span.shrink_to_lo(), diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 84ce492ba7203..26344080381da 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -3419,27 +3419,21 @@ impl<'a> Resolver<'a> { return v.clone(); } - let parse_attrs = || { - let attrs = self.cstore().item_attrs(def_id, self.session); - let attr = - attrs.iter().find(|a| a.has_name(sym::rustc_legacy_const_generics))?; - let mut ret = vec![]; - for meta in attr.meta_item_list()? { - match meta.literal()?.kind { - LitKind::Int(a, _) => { - ret.push(a as usize); - } - _ => panic!("invalid arg index"), - } + let attr = self + .cstore() + .item_attrs(def_id, self.session) + .into_iter() + .find(|a| a.has_name(sym::rustc_legacy_const_generics))?; + let mut ret = Vec::new(); + for meta in attr.meta_item_list()? { + match meta.literal()?.kind { + LitKind::Int(a, _) => ret.push(a as usize), + _ => panic!("invalid arg index"), } - Some(ret) - }; - - // Cache the lookup to avoid parsing attributes for an iterm - // multiple times. - let ret = parse_attrs(); - self.legacy_const_generic_args.insert(def_id, ret.clone()); - return ret; + } + // Cache the lookup to avoid parsing attributes for an iterm multiple times. + self.legacy_const_generic_args.insert(def_id, Some(ret.clone())); + return Some(ret); } } None From 63c2edefda6d5f522e3c8a695a3dfe2fe1b386dc Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Mon, 20 Dec 2021 22:05:17 -0600 Subject: [PATCH 4/9] rustc_builtin_macros: make asm mod public for rustfmt --- compiler/rustc_builtin_macros/src/asm.rs | 4 ++-- compiler/rustc_builtin_macros/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 418567619169f..1a93b9be99ead 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -809,7 +809,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option( +pub(super) fn expand_asm<'cx>( ecx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream, @@ -836,7 +836,7 @@ pub fn expand_asm<'cx>( } } -pub fn expand_global_asm<'cx>( +pub(super) fn expand_global_asm<'cx>( ecx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream, diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 3e8b43fea8a50..8c3ef2864f485 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -19,7 +19,6 @@ use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind}; use rustc_expand::proc_macro::BangProcMacro; use rustc_span::symbol::sym; -mod asm; mod assert; mod cfg; mod cfg_accessible; @@ -42,6 +41,7 @@ mod test; mod trace_macros; mod util; +pub mod asm; pub mod cmdline_attrs; pub mod proc_macro_harness; pub mod standard_library_imports; From 584e88d41dadb955dec5ef1e5db275a0d2f42123 Mon Sep 17 00:00:00 2001 From: Shadlock0133 Date: Fri, 24 Dec 2021 23:04:10 +0100 Subject: [PATCH 5/9] Remove `maybe_uninit_extra` feature from Vec docs In `Vec`, two doc tests are using `MaybeUninit::write` , stabilized in 1.55. This makes docs' usage of `maybe_uninit_extra` feature unnecessary. --- library/alloc/src/vec/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 16df293108017..2863da059329a 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2043,7 +2043,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(vec_spare_capacity, maybe_uninit_extra)] + /// #![feature(vec_spare_capacity)] /// /// // Allocate vector big enough for 10 elements. /// let mut v = Vec::with_capacity(10); @@ -2102,7 +2102,7 @@ impl Vec { /// # Examples /// /// ``` - /// #![feature(vec_split_at_spare, maybe_uninit_extra)] + /// #![feature(vec_split_at_spare)] /// /// let mut v = vec![1, 1, 2]; /// From fe8012409858a137556af7870a6d4344f52cd091 Mon Sep 17 00:00:00 2001 From: PFPoitras Date: Sun, 26 Dec 2021 16:59:25 -0400 Subject: [PATCH 6/9] Add test cases for issue #26186 --- src/test/ui/issues/issue-26186.rs | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/test/ui/issues/issue-26186.rs diff --git a/src/test/ui/issues/issue-26186.rs b/src/test/ui/issues/issue-26186.rs new file mode 100644 index 0000000000000..f93869352ea61 --- /dev/null +++ b/src/test/ui/issues/issue-26186.rs @@ -0,0 +1,62 @@ +// check-pass +use std::sync::Mutex; +use std::cell::RefCell; +use std::rc::Rc; +use std::ops::*; + +//eefriedman example +struct S<'a, T:FnMut() + 'static + ?Sized>(&'a mut T); +impl<'a, T:?Sized + FnMut() + 'static> DerefMut for S<'a, T> { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } +} +impl<'a, T:?Sized + FnMut() + 'static> Deref for S<'a, T> { + type Target = dyn FnMut() + 'a; + fn deref(&self) -> &Self::Target { &self.0 } +} + +//Ossipal example +struct FunctionIcon { + get_icon: Mutex u32>>, +} + +impl FunctionIcon { + fn get_icon(&self) -> impl '_ + std::ops::DerefMut u32>> { + self.get_icon.lock().unwrap() + } + + fn load_icon(&self) { + let mut get_icon = self.get_icon(); + let _rgba_icon = (*get_icon)(); + } +} + +//shepmaster example +struct Foo; + +impl Deref for Foo { + type Target = dyn FnMut() + 'static; + fn deref(&self) -> &Self::Target { + unimplemented!() + } +} + +impl DerefMut for Foo { + fn deref_mut(&mut self) -> &mut Self::Target { + unimplemented!() + } +} + +fn main() { + //eefriedman example + let mut f = ||{}; + let mut s = S(&mut f); + s(); + + //Diggsey/Mark-Simulacrum example + let a: Rc> = Rc::new(RefCell::new(||{})); + a.borrow_mut()(); + + //shepmaster example + let mut t = Foo; + t(); +} From ebef8a8ceec0173b98fcc842bb319788e7d38562 Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Thu, 4 Nov 2021 16:31:18 +0000 Subject: [PATCH 7/9] relax priv-in-pub lint on generic bounds and where clauses in trait impls --- compiler/rustc_privacy/src/lib.rs | 6 +- .../generic_const_exprs/eval-privacy.rs | 7 +- .../generic_const_exprs/eval-privacy.stderr | 35 +------- src/test/ui/privacy/private-in-public-warn.rs | 7 +- .../ui/privacy/private-in-public-warn.stderr | 56 ++++-------- src/test/ui/privacy/where-priv-type.rs | 90 +++++++++++++++++++ src/test/ui/privacy/where-priv-type.stderr | 82 +++++++++++++++++ .../where-pub-type-impls-priv-trait.rs | 56 ++++++++++++ .../where-pub-type-impls-priv-trait.stderr | 68 ++++++++++++++ 9 files changed, 325 insertions(+), 82 deletions(-) create mode 100644 src/test/ui/privacy/where-priv-type.rs create mode 100644 src/test/ui/privacy/where-priv-type.stderr create mode 100644 src/test/ui/privacy/where-pub-type-impls-priv-trait.rs create mode 100644 src/test/ui/privacy/where-pub-type-impls-priv-trait.stderr diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index fa34b9abc1e6c..639b23568ec01 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -2069,7 +2069,11 @@ impl<'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'tcx> { // Subitems of trait impls have inherited publicity. hir::ItemKind::Impl(ref impl_) => { let impl_vis = ty::Visibility::of_impl(item.def_id, tcx, &Default::default()); - self.check(item.def_id, impl_vis).generics().predicates(); + // check that private components do not appear in the generics or predicates of inherent impls + // this check is intentionally NOT performed for impls of traits, per #90586 + if impl_.of_trait.is_none() { + self.check(item.def_id, impl_vis).generics().predicates(); + } for impl_item_ref in impl_.items { let impl_item_vis = if impl_.of_trait.is_none() { min(tcx.visibility(impl_item_ref.id.def_id), impl_vis, tcx) diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs index 80d0662f1f498..8023b998a4099 100644 --- a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -9,12 +9,7 @@ pub trait Trait { fn assoc_fn() -> Self::AssocTy; } -impl Trait for Const -//~^ WARN private type -//~| WARN this was previously -//~| WARN private type -//~| WARN this was previously - +impl Trait for Const // OK, trait impl predicates where Const<{ my_const_fn(U) }>: , { diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr index 842c22c5c6775..c6b0ce931450d 100644 --- a/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -1,36 +1,5 @@ -warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) - --> $DIR/eval-privacy.rs:12:1 - | -LL | / impl Trait for Const -LL | | -LL | | -LL | | -... | -LL | | } -LL | | } - | |_^ - | - = note: `#[warn(private_in_public)]` on by default - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 - -warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) - --> $DIR/eval-privacy.rs:12:1 - | -LL | / impl Trait for Const -LL | | -LL | | -LL | | -... | -LL | | } -LL | | } - | |_^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 - error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface - --> $DIR/eval-privacy.rs:21:5 + --> $DIR/eval-privacy.rs:16:5 | LL | type AssocTy = Const<{ my_const_fn(U) }>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type @@ -38,6 +7,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>; LL | const fn my_const_fn(val: u8) -> u8 { | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private -error: aborting due to previous error; 2 warnings emitted +error: aborting due to previous error For more information about this error, try `rustc --explain E0446`. diff --git a/src/test/ui/privacy/private-in-public-warn.rs b/src/test/ui/privacy/private-in-public-warn.rs index 09afa04501ea0..0fa1de975b040 100644 --- a/src/test/ui/privacy/private-in-public-warn.rs +++ b/src/test/ui/privacy/private-in-public-warn.rs @@ -63,8 +63,7 @@ mod traits { } impl Pub {} //~ ERROR private trait `traits::PrivTr` in public interface //~^ WARNING hard error - impl PubTr for Pub {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + impl PubTr for Pub {} // OK, trait impl predicates } mod traits_where { @@ -87,9 +86,7 @@ mod traits_where { impl Pub where T: PrivTr {} //~^ ERROR private trait `traits_where::PrivTr` in public interface //~| WARNING hard error - impl PubTr for Pub where T: PrivTr {} - //~^ ERROR private trait `traits_where::PrivTr` in public interface - //~| WARNING hard error + impl PubTr for Pub where T: PrivTr {} // OK, trait impl predicates } mod generics { diff --git a/src/test/ui/privacy/private-in-public-warn.stderr b/src/test/ui/privacy/private-in-public-warn.stderr index f51cfc836a8d5..a72d824779279 100644 --- a/src/test/ui/privacy/private-in-public-warn.stderr +++ b/src/test/ui/privacy/private-in-public-warn.stderr @@ -156,17 +156,8 @@ LL | impl Pub {} = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 -error: private trait `traits::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:66:5 - | -LL | impl PubTr for Pub {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 - error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:75:5 + --> $DIR/private-in-public-warn.rs:74:5 | LL | pub type Alias where T: PrivTr = T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -175,7 +166,7 @@ LL | pub type Alias where T: PrivTr = T; = note: for more information, see issue #34537 error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:79:5 + --> $DIR/private-in-public-warn.rs:78:5 | LL | pub trait Tr2 where T: PrivTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -184,7 +175,7 @@ LL | pub trait Tr2 where T: PrivTr {} = note: for more information, see issue #34537 error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:83:9 + --> $DIR/private-in-public-warn.rs:82:9 | LL | fn f(arg: T) where T: PrivTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +184,7 @@ LL | fn f(arg: T) where T: PrivTr {} = note: for more information, see issue #34537 error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:87:5 + --> $DIR/private-in-public-warn.rs:86:5 | LL | impl Pub where T: PrivTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,17 +192,8 @@ LL | impl Pub where T: PrivTr {} = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 -error: private trait `traits_where::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:90:5 - | -LL | impl PubTr for Pub where T: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #34537 - error: private trait `generics::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:101:5 + --> $DIR/private-in-public-warn.rs:98:5 | LL | pub trait Tr1: PrivTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -220,7 +202,7 @@ LL | pub trait Tr1: PrivTr {} = note: for more information, see issue #34537 error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:104:5 + --> $DIR/private-in-public-warn.rs:101:5 | LL | pub trait Tr2: PubTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +211,7 @@ LL | pub trait Tr2: PubTr {} = note: for more information, see issue #34537 error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:106:5 + --> $DIR/private-in-public-warn.rs:103:5 | LL | pub trait Tr3: PubTr<[Priv; 1]> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -238,7 +220,7 @@ LL | pub trait Tr3: PubTr<[Priv; 1]> {} = note: for more information, see issue #34537 error: private type `generics::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:108:5 + --> $DIR/private-in-public-warn.rs:105:5 | LL | pub trait Tr4: PubTr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -247,7 +229,7 @@ LL | pub trait Tr4: PubTr> {} = note: for more information, see issue #34537 error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public-warn.rs:135:9 + --> $DIR/private-in-public-warn.rs:132:9 | LL | struct Priv; | ------------ `impls::Priv` declared as private @@ -256,7 +238,7 @@ LL | type Alias = Priv; | ^^^^^^^^^^^^^^^^^^ can't leak private type error: private type `aliases_pub::Priv` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:206:9 + --> $DIR/private-in-public-warn.rs:203:9 | LL | pub fn f(arg: Priv) {} | ^^^^^^^^^^^^^^^^^^^ @@ -265,7 +247,7 @@ LL | pub fn f(arg: Priv) {} = note: for more information, see issue #34537 error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:210:9 + --> $DIR/private-in-public-warn.rs:207:9 | LL | struct Priv; | ------------ `aliases_pub::Priv` declared as private @@ -274,7 +256,7 @@ LL | type Check = Priv; | ^^^^^^^^^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:213:9 + --> $DIR/private-in-public-warn.rs:210:9 | LL | struct Priv; | ------------ `aliases_pub::Priv` declared as private @@ -283,7 +265,7 @@ LL | type Check = Priv; | ^^^^^^^^^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:216:9 + --> $DIR/private-in-public-warn.rs:213:9 | LL | struct Priv; | ------------ `aliases_pub::Priv` declared as private @@ -292,7 +274,7 @@ LL | type Check = Priv; | ^^^^^^^^^^^^^^^^^^ can't leak private type error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public-warn.rs:219:9 + --> $DIR/private-in-public-warn.rs:216:9 | LL | struct Priv; | ------------ `aliases_pub::Priv` declared as private @@ -301,7 +283,7 @@ LL | type Check = Priv; | ^^^^^^^^^^^^^^^^^^ can't leak private type error: private trait `PrivTr1` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:249:5 + --> $DIR/private-in-public-warn.rs:246:5 | LL | pub trait Tr1: PrivUseAliasTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -310,7 +292,7 @@ LL | pub trait Tr1: PrivUseAliasTr {} = note: for more information, see issue #34537 error: private trait `PrivTr1` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:252:5 + --> $DIR/private-in-public-warn.rs:249:5 | LL | pub trait Tr2: PrivUseAliasTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -319,7 +301,7 @@ LL | pub trait Tr2: PrivUseAliasTr {} = note: for more information, see issue #34537 error: private type `Priv2` in public interface (error E0446) - --> $DIR/private-in-public-warn.rs:252:5 + --> $DIR/private-in-public-warn.rs:249:5 | LL | pub trait Tr2: PrivUseAliasTr {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -341,7 +323,7 @@ LL + pub type Alias = T; | warning: where clauses are not enforced in type aliases - --> $DIR/private-in-public-warn.rs:75:29 + --> $DIR/private-in-public-warn.rs:74:29 | LL | pub type Alias where T: PrivTr = T; | ^^^^^^^^^ @@ -352,6 +334,6 @@ LL - pub type Alias where T: PrivTr = T; LL + pub type Alias = T; | -error: aborting due to 36 previous errors; 2 warnings emitted +error: aborting due to 34 previous errors; 2 warnings emitted For more information about this error, try `rustc --explain E0446`. diff --git a/src/test/ui/privacy/where-priv-type.rs b/src/test/ui/privacy/where-priv-type.rs new file mode 100644 index 0000000000000..66ee9c4bbd883 --- /dev/null +++ b/src/test/ui/privacy/where-priv-type.rs @@ -0,0 +1,90 @@ +// priv-in-pub lint tests where the private type appears in the +// `where` clause of a public item + +#![crate_type = "lib"] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + + +struct PrivTy; +trait PrivTr {} +pub struct PubTy; +pub struct PubTyGeneric(T); +pub trait PubTr {} +impl PubTr for PrivTy {} +pub trait PubTrWithAssocTy { type AssocTy; } +impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } + + +pub struct S +//~^ WARNING private type `PrivTy` in public interface +//~| WARNING hard error +where + PrivTy: +{} + + +pub enum E +//~^ WARNING private type `PrivTy` in public interface +//~| WARNING hard error +where + PrivTy: +{} + + +pub fn f() +//~^ WARNING private type `PrivTy` in public interface +//~| WARNING hard error +where + PrivTy: +{} + + +impl S +//~^ ERROR private type `PrivTy` in public interface +where + PrivTy: +{ + pub fn f() + //~^ WARNING private type `PrivTy` in public interface + //~| WARNING hard error + where + PrivTy: + {} +} + + +impl PubTr for PubTy +where + PrivTy: +{} + + +impl PubTr for PubTyGeneric +where + T: PubTrWithAssocTy +{} + + +pub struct Const; + +pub trait Trait { + type AssocTy; + fn assoc_fn() -> Self::AssocTy; +} + +impl Trait for Const +where + Const<{ my_const_fn(U) }>: , +{ + type AssocTy = Const<{ my_const_fn(U) }>; + //~^ ERROR private type + fn assoc_fn() -> Self::AssocTy { + Const + } +} + +const fn my_const_fn(val: u8) -> u8 { + // body of this function doesn't matter + val +} diff --git a/src/test/ui/privacy/where-priv-type.stderr b/src/test/ui/privacy/where-priv-type.stderr new file mode 100644 index 0000000000000..378c14810d92d --- /dev/null +++ b/src/test/ui/privacy/where-priv-type.stderr @@ -0,0 +1,82 @@ +warning: private type `PrivTy` in public interface (error E0446) + --> $DIR/where-priv-type.rs:19:1 + | +LL | / pub struct S +LL | | +LL | | +LL | | where +LL | | PrivTy: +LL | | {} + | |__^ + | + = note: `#[warn(private_in_public)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +warning: private type `PrivTy` in public interface (error E0446) + --> $DIR/where-priv-type.rs:27:1 + | +LL | / pub enum E +LL | | +LL | | +LL | | where +LL | | PrivTy: +LL | | {} + | |__^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +warning: private type `PrivTy` in public interface (error E0446) + --> $DIR/where-priv-type.rs:35:1 + | +LL | / pub fn f() +LL | | +LL | | +LL | | where +LL | | PrivTy: + | |___________^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +error[E0446]: private type `PrivTy` in public interface + --> $DIR/where-priv-type.rs:43:1 + | +LL | struct PrivTy; + | -------------- `PrivTy` declared as private +... +LL | / impl S +LL | | +LL | | where +LL | | PrivTy: +... | +LL | | {} +LL | | } + | |_^ can't leak private type + +warning: private type `PrivTy` in public interface (error E0446) + --> $DIR/where-priv-type.rs:48:5 + | +LL | / pub fn f() +LL | | +LL | | +LL | | where +LL | | PrivTy: + | |_______________^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface + --> $DIR/where-priv-type.rs:80:5 + | +LL | type AssocTy = Const<{ my_const_fn(U) }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type +... +LL | const fn my_const_fn(val: u8) -> u8 { + | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private + +error: aborting due to 2 previous errors; 4 warnings emitted + +For more information about this error, try `rustc --explain E0446`. diff --git a/src/test/ui/privacy/where-pub-type-impls-priv-trait.rs b/src/test/ui/privacy/where-pub-type-impls-priv-trait.rs new file mode 100644 index 0000000000000..87c211df16937 --- /dev/null +++ b/src/test/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -0,0 +1,56 @@ +// priv-in-pub lint tests where the private trait bounds a public type + +#![crate_type = "lib"] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + + +struct PrivTy; +trait PrivTr {} +pub struct PubTy; +pub struct PubTyGeneric(T); +pub trait PubTr {} +impl PubTr for PrivTy {} +impl PrivTr for PubTy {} +pub trait PubTrWithAssocTy { type AssocTy; } +impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; } + + +pub struct S +//~^ ERROR private trait `PrivTr` in public interface +where + PubTy: PrivTr +{} + + +pub enum E +//~^ ERROR private trait `PrivTr` in public interface +where + PubTy: PrivTr +{} + + +pub fn f() +//~^ ERROR private trait `PrivTr` in public interface +where + PubTy: PrivTr +{} + + +impl S +//~^ ERROR private trait `PrivTr` in public interface +where + PubTy: PrivTr +{ + pub fn f() + //~^ ERROR private trait `PrivTr` in public interface + where + PubTy: PrivTr + {} +} + + +impl PubTr for PubTy +where + PubTy: PrivTr +{} diff --git a/src/test/ui/privacy/where-pub-type-impls-priv-trait.stderr b/src/test/ui/privacy/where-pub-type-impls-priv-trait.stderr new file mode 100644 index 0000000000000..9ce7b9a139f5e --- /dev/null +++ b/src/test/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -0,0 +1,68 @@ +error[E0445]: private trait `PrivTr` in public interface + --> $DIR/where-pub-type-impls-priv-trait.rs:19:1 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | / pub struct S +LL | | +LL | | where +LL | | PubTy: PrivTr +LL | | {} + | |__^ can't leak private trait + +error[E0445]: private trait `PrivTr` in public interface + --> $DIR/where-pub-type-impls-priv-trait.rs:26:1 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | / pub enum E +LL | | +LL | | where +LL | | PubTy: PrivTr +LL | | {} + | |__^ can't leak private trait + +error[E0445]: private trait `PrivTr` in public interface + --> $DIR/where-pub-type-impls-priv-trait.rs:33:1 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | / pub fn f() +LL | | +LL | | where +LL | | PubTy: PrivTr + | |_________________^ can't leak private trait + +error[E0445]: private trait `PrivTr` in public interface + --> $DIR/where-pub-type-impls-priv-trait.rs:40:1 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | / impl S +LL | | +LL | | where +LL | | PubTy: PrivTr +... | +LL | | {} +LL | | } + | |_^ can't leak private trait + +error[E0445]: private trait `PrivTr` in public interface + --> $DIR/where-pub-type-impls-priv-trait.rs:45:5 + | +LL | trait PrivTr {} + | ------------ `PrivTr` declared as private +... +LL | / pub fn f() +LL | | +LL | | where +LL | | PubTy: PrivTr + | |_____________________^ can't leak private trait + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0445`. From 7ddad349b188c9ae29ca63baf5fb1d5dfbe2d0bb Mon Sep 17 00:00:00 2001 From: Hiroshi Kori Date: Sun, 26 Dec 2021 16:03:17 -0800 Subject: [PATCH 8/9] fix typo: the use f.pad -> then use f.pad --- library/std/src/net/ip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index da95fe21ac9af..4029125a375df 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1826,7 +1826,7 @@ impl fmt::Display for Ipv6Addr { } } } else { - // Slow path: write the address to a local buffer, the use f.pad. + // Slow path: write the address to a local buffer, then use f.pad. // Defined recursively by using the fast path to write to the // buffer. From 7a3a668bc92eef153973dca63b38f8d620d461b9 Mon Sep 17 00:00:00 2001 From: Hiroshi Kori Date: Sun, 26 Dec 2021 16:20:38 -0800 Subject: [PATCH 9/9] fix typo: intialized -> initialized --- library/std/src/io/readbuf.rs | 4 ++-- src/test/ui/closures/2229_closure_analysis/wild_patterns.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/readbuf.rs b/library/std/src/io/readbuf.rs index d84a500e07800..c655bc889308c 100644 --- a/library/std/src/io/readbuf.rs +++ b/library/std/src/io/readbuf.rs @@ -52,7 +52,7 @@ impl<'a> ReadBuf<'a> { /// Creates a new `ReadBuf` from a fully uninitialized buffer. /// - /// Use `assume_init` if part of the buffer is known to be already inintialized. + /// Use `assume_init` if part of the buffer is known to be already initialized. #[inline] pub fn uninit(buf: &'a mut [MaybeUninit]) -> ReadBuf<'a> { ReadBuf { buf, filled: 0, initialized: 0 } @@ -145,7 +145,7 @@ impl<'a> ReadBuf<'a> { byte.write(0); } - // SAFETY: we just inintialized uninit bytes, and the previous bytes were already init + // SAFETY: we just initialized uninit bytes, and the previous bytes were already init unsafe { self.assume_init(n); } diff --git a/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs b/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs index 7843c251666c5..a795088a1d945 100644 --- a/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs +++ b/src/test/ui/closures/2229_closure_analysis/wild_patterns.rs @@ -3,7 +3,7 @@ #![feature(rustc_attrs)] // Test to ensure that we can handle cases where -// let statements create no bindings are intialized +// let statements create no bindings are initialized // using a Place expression // // Note: Currently when feature `capture_disjoint_fields` is enabled