Skip to content

Commit 4ee34f3

Browse files
committed
Auto merge of #92329 - matthiaskrgr:rollup-l3b4fl1, r=matthiaskrgr
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
2 parents f8abed9 + eab8129 commit 4ee34f3

File tree

21 files changed

+437
-118
lines changed

21 files changed

+437
-118
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
809809
})
810810
}
811811

812-
pub fn expand_asm<'cx>(
812+
pub(super) fn expand_asm<'cx>(
813813
ecx: &'cx mut ExtCtxt<'_>,
814814
sp: Span,
815815
tts: TokenStream,
@@ -836,7 +836,7 @@ pub fn expand_asm<'cx>(
836836
}
837837
}
838838

839-
pub fn expand_global_asm<'cx>(
839+
pub(super) fn expand_global_asm<'cx>(
840840
ecx: &'cx mut ExtCtxt<'_>,
841841
sp: Span,
842842
tts: TokenStream,

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind};
1919
use rustc_expand::proc_macro::BangProcMacro;
2020
use rustc_span::symbol::sym;
2121

22-
mod asm;
2322
mod assert;
2423
mod cfg;
2524
mod cfg_accessible;
@@ -42,6 +41,7 @@ mod test;
4241
mod trace_macros;
4342
mod util;
4443

44+
pub mod asm;
4545
pub mod cmdline_attrs;
4646
pub mod proc_macro_harness;
4747
pub mod standard_library_imports;

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,12 @@ impl CStore {
415415

416416
let span = data.get_span(id.index, sess);
417417

418-
let attrs = data.get_item_attrs(id.index, sess).collect();
419-
420-
let ident = data.item_ident(id.index, sess);
421-
422418
LoadedMacro::MacroDef(
423419
ast::Item {
424-
ident,
420+
ident: data.item_ident(id.index, sess),
425421
id: ast::DUMMY_NODE_ID,
426422
span,
427-
attrs,
423+
attrs: data.get_item_attrs(id.index, sess).collect(),
428424
kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)),
429425
vis: ast::Visibility {
430426
span: span.shrink_to_lo(),

compiler/rustc_privacy/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,11 @@ impl<'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'tcx> {
20642064
// Subitems of trait impls have inherited publicity.
20652065
hir::ItemKind::Impl(ref impl_) => {
20662066
let impl_vis = ty::Visibility::of_impl(item.def_id, tcx, &Default::default());
2067-
self.check(item.def_id, impl_vis).generics().predicates();
2067+
// check that private components do not appear in the generics or predicates of inherent impls
2068+
// this check is intentionally NOT performed for impls of traits, per #90586
2069+
if impl_.of_trait.is_none() {
2070+
self.check(item.def_id, impl_vis).generics().predicates();
2071+
}
20682072
for impl_item_ref in impl_.items {
20692073
let impl_item_vis = if impl_.of_trait.is_none() {
20702074
min(tcx.visibility(impl_item_ref.id.def_id), impl_vis, tcx)

compiler/rustc_resolve/src/lib.rs

+14-20
Original file line numberDiff line numberDiff line change
@@ -3419,27 +3419,21 @@ impl<'a> Resolver<'a> {
34193419
return v.clone();
34203420
}
34213421

3422-
let parse_attrs = || {
3423-
let attrs = self.cstore().item_attrs(def_id, self.session);
3424-
let attr =
3425-
attrs.iter().find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
3426-
let mut ret = vec![];
3427-
for meta in attr.meta_item_list()? {
3428-
match meta.literal()?.kind {
3429-
LitKind::Int(a, _) => {
3430-
ret.push(a as usize);
3431-
}
3432-
_ => panic!("invalid arg index"),
3433-
}
3422+
let attr = self
3423+
.cstore()
3424+
.item_attrs(def_id, self.session)
3425+
.into_iter()
3426+
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
3427+
let mut ret = Vec::new();
3428+
for meta in attr.meta_item_list()? {
3429+
match meta.literal()?.kind {
3430+
LitKind::Int(a, _) => ret.push(a as usize),
3431+
_ => panic!("invalid arg index"),
34343432
}
3435-
Some(ret)
3436-
};
3437-
3438-
// Cache the lookup to avoid parsing attributes for an iterm
3439-
// multiple times.
3440-
let ret = parse_attrs();
3441-
self.legacy_const_generic_args.insert(def_id, ret.clone());
3442-
return ret;
3433+
}
3434+
// Cache the lookup to avoid parsing attributes for an iterm multiple times.
3435+
self.legacy_const_generic_args.insert(def_id, Some(ret.clone()));
3436+
return Some(ret);
34433437
}
34443438
}
34453439
None

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15081508
}
15091509
} else {
15101510
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
1511-
let base_ty = self.check_expr(base_expr);
1511+
let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id);
15121512
let same_adt = match (adt_ty.kind(), base_ty.kind()) {
15131513
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true,
15141514
_ => false,

library/alloc/src/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ impl<T, A: Allocator> Vec<T, A> {
20432043
/// # Examples
20442044
///
20452045
/// ```
2046-
/// #![feature(vec_spare_capacity, maybe_uninit_extra)]
2046+
/// #![feature(vec_spare_capacity)]
20472047
///
20482048
/// // Allocate vector big enough for 10 elements.
20492049
/// let mut v = Vec::with_capacity(10);
@@ -2102,7 +2102,7 @@ impl<T, A: Allocator> Vec<T, A> {
21022102
/// # Examples
21032103
///
21042104
/// ```
2105-
/// #![feature(vec_split_at_spare, maybe_uninit_extra)]
2105+
/// #![feature(vec_split_at_spare)]
21062106
///
21072107
/// let mut v = vec![1, 1, 2];
21082108
///

library/std/src/io/readbuf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a> ReadBuf<'a> {
5252

5353
/// Creates a new `ReadBuf` from a fully uninitialized buffer.
5454
///
55-
/// Use `assume_init` if part of the buffer is known to be already inintialized.
55+
/// Use `assume_init` if part of the buffer is known to be already initialized.
5656
#[inline]
5757
pub fn uninit(buf: &'a mut [MaybeUninit<u8>]) -> ReadBuf<'a> {
5858
ReadBuf { buf, filled: 0, initialized: 0 }
@@ -145,7 +145,7 @@ impl<'a> ReadBuf<'a> {
145145
byte.write(0);
146146
}
147147

148-
// SAFETY: we just inintialized uninit bytes, and the previous bytes were already init
148+
// SAFETY: we just initialized uninit bytes, and the previous bytes were already init
149149
unsafe {
150150
self.assume_init(n);
151151
}

library/std/src/net/ip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ impl fmt::Display for Ipv6Addr {
18261826
}
18271827
}
18281828
} else {
1829-
// Slow path: write the address to a local buffer, the use f.pad.
1829+
// Slow path: write the address to a local buffer, then use f.pad.
18301830
// Defined recursively by using the fast path to write to the
18311831
// buffer.
18321832

src/test/ui/closures/2229_closure_analysis/wild_patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(rustc_attrs)]
44

55
// Test to ensure that we can handle cases where
6-
// let statements create no bindings are intialized
6+
// let statements create no bindings are initialized
77
// using a Place expression
88
//
99
// Note: Currently when feature `capture_disjoint_fields` is enabled

src/test/ui/const-generics/generic_const_exprs/eval-privacy.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ pub trait Trait {
99
fn assoc_fn() -> Self::AssocTy;
1010
}
1111

12-
impl<const U: u8> Trait for Const<U>
13-
//~^ WARN private type
14-
//~| WARN this was previously
15-
//~| WARN private type
16-
//~| WARN this was previously
17-
12+
impl<const U: u8> Trait for Const<U> // OK, trait impl predicates
1813
where
1914
Const<{ my_const_fn(U) }>: ,
2015
{
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,12 @@
1-
warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446)
2-
--> $DIR/eval-privacy.rs:12:1
3-
|
4-
LL | / impl<const U: u8> Trait for Const<U>
5-
LL | |
6-
LL | |
7-
LL | |
8-
... |
9-
LL | | }
10-
LL | | }
11-
| |_^
12-
|
13-
= note: `#[warn(private_in_public)]` on by default
14-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
15-
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
16-
17-
warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446)
18-
--> $DIR/eval-privacy.rs:12:1
19-
|
20-
LL | / impl<const U: u8> Trait for Const<U>
21-
LL | |
22-
LL | |
23-
LL | |
24-
... |
25-
LL | | }
26-
LL | | }
27-
| |_^
28-
|
29-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30-
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
31-
321
error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface
33-
--> $DIR/eval-privacy.rs:21:5
2+
--> $DIR/eval-privacy.rs:16:5
343
|
354
LL | type AssocTy = Const<{ my_const_fn(U) }>;
365
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
376
...
387
LL | const fn my_const_fn(val: u8) -> u8 {
398
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
409

41-
error: aborting due to previous error; 2 warnings emitted
10+
error: aborting due to previous error
4211

4312
For more information about this error, try `rustc --explain E0446`.

src/test/ui/issues/issue-26186.rs

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// check-pass
2+
use std::sync::Mutex;
3+
use std::cell::RefCell;
4+
use std::rc::Rc;
5+
use std::ops::*;
6+
7+
//eefriedman example
8+
struct S<'a, T:FnMut() + 'static + ?Sized>(&'a mut T);
9+
impl<'a, T:?Sized + FnMut() + 'static> DerefMut for S<'a, T> {
10+
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
11+
}
12+
impl<'a, T:?Sized + FnMut() + 'static> Deref for S<'a, T> {
13+
type Target = dyn FnMut() + 'a;
14+
fn deref(&self) -> &Self::Target { &self.0 }
15+
}
16+
17+
//Ossipal example
18+
struct FunctionIcon {
19+
get_icon: Mutex<Box<dyn FnMut() -> u32>>,
20+
}
21+
22+
impl FunctionIcon {
23+
fn get_icon(&self) -> impl '_ + std::ops::DerefMut<Target=Box<dyn FnMut() -> u32>> {
24+
self.get_icon.lock().unwrap()
25+
}
26+
27+
fn load_icon(&self) {
28+
let mut get_icon = self.get_icon();
29+
let _rgba_icon = (*get_icon)();
30+
}
31+
}
32+
33+
//shepmaster example
34+
struct Foo;
35+
36+
impl Deref for Foo {
37+
type Target = dyn FnMut() + 'static;
38+
fn deref(&self) -> &Self::Target {
39+
unimplemented!()
40+
}
41+
}
42+
43+
impl DerefMut for Foo {
44+
fn deref_mut(&mut self) -> &mut Self::Target {
45+
unimplemented!()
46+
}
47+
}
48+
49+
fn main() {
50+
//eefriedman example
51+
let mut f = ||{};
52+
let mut s = S(&mut f);
53+
s();
54+
55+
//Diggsey/Mark-Simulacrum example
56+
let a: Rc<RefCell<dyn FnMut()>> = Rc::new(RefCell::new(||{}));
57+
a.borrow_mut()();
58+
59+
//shepmaster example
60+
let mut t = Foo;
61+
t();
62+
}

src/test/ui/privacy/private-in-public-warn.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ mod traits {
6363
}
6464
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
6565
//~^ WARNING hard error
66-
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
67-
//~^ WARNING hard error
66+
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
6867
}
6968

7069
mod traits_where {
@@ -87,9 +86,7 @@ mod traits_where {
8786
impl<T> Pub<T> where T: PrivTr {}
8887
//~^ ERROR private trait `traits_where::PrivTr` in public interface
8988
//~| WARNING hard error
90-
impl<T> PubTr for Pub<T> where T: PrivTr {}
91-
//~^ ERROR private trait `traits_where::PrivTr` in public interface
92-
//~| WARNING hard error
89+
impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates
9390
}
9491

9592
mod generics {

0 commit comments

Comments
 (0)