Skip to content

Commit

Permalink
Auto merge of #92329 - matthiaskrgr:rollup-l3b4fl1, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #90586 (Relax priv-in-pub lint on generic bounds and where clauses of trait impls.)
 - #92112 (Fix the error of checking `base_expr` twice in type_changing_struct_update)
 - #92147 (rustc_builtin_macros: make asm mod public for rustfmt)
 - #92161 (resolve: Minor miscellaneous cleanups from #89059)
 - #92264 (Remove `maybe_uninit_extra` feature from Vec docs)
 - #92303 (Add test cases for issue #26186)
 - #92307 (Fix minor typos)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 27, 2021
2 parents f8abed9 + eab8129 commit 4ee34f3
Show file tree
Hide file tree
Showing 21 changed files with 437 additions and 118 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
})
}

pub fn expand_asm<'cx>(
pub(super) fn expand_asm<'cx>(
ecx: &'cx mut ExtCtxt<'_>,
sp: Span,
tts: TokenStream,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,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(),
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,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)
Expand Down
34 changes: 14 additions & 20 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # 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);
Expand Down Expand Up @@ -2102,7 +2102,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// #![feature(vec_split_at_spare, maybe_uninit_extra)]
/// #![feature(vec_split_at_spare)]
///
/// let mut v = vec![1, 1, 2];
///
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/io/readbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>]) -> ReadBuf<'a> {
ReadBuf { buf, filled: 0, initialized: 0 }
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ pub trait Trait {
fn assoc_fn() -> Self::AssocTy;
}

impl<const U: u8> Trait for Const<U>
//~^ WARN private type
//~| WARN this was previously
//~| WARN private type
//~| WARN this was previously

impl<const U: u8> Trait for Const<U> // OK, trait impl predicates
where
Const<{ my_const_fn(U) }>: ,
{
Expand Down
35 changes: 2 additions & 33 deletions src/test/ui/const-generics/generic_const_exprs/eval-privacy.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446)
--> $DIR/eval-privacy.rs:12:1
|
LL | / impl<const U: u8> Trait for Const<U>
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 <https://github.com/rust-lang/rust/issues/34537>

warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446)
--> $DIR/eval-privacy.rs:12:1
|
LL | / impl<const U: u8> Trait for Const<U>
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 <https://github.com/rust-lang/rust/issues/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
...
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`.
62 changes: 62 additions & 0 deletions src/test/ui/issues/issue-26186.rs
Original file line number Diff line number Diff line change
@@ -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<Box<dyn FnMut() -> u32>>,
}

impl FunctionIcon {
fn get_icon(&self) -> impl '_ + std::ops::DerefMut<Target=Box<dyn FnMut() -> 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<RefCell<dyn FnMut()>> = Rc::new(RefCell::new(||{}));
a.borrow_mut()();

//shepmaster example
let mut t = Foo;
t();
}
7 changes: 2 additions & 5 deletions src/test/ui/privacy/private-in-public-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ mod traits {
}
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
}

mod traits_where {
Expand All @@ -87,9 +86,7 @@ mod traits_where {
impl<T> Pub<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
impl<T> PubTr for Pub<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates
}

mod generics {
Expand Down
Loading

0 comments on commit 4ee34f3

Please sign in to comment.