Skip to content

Commit 5e9ebf4

Browse files
committed
Auto merge of #70062 - Centril:rollup-synwle8, r=Centril
Rollup of 7 pull requests Successful merges: - #69811 (resolve: Print import chains on privacy errors) - #69870 (expand: Implement something similar to `#[cfg(accessible(path))]`) - #69881 (VariantSizeDifferences: bail on SizeOverflow) - #70000 (resolve: Fix regression in resolution of raw keywords in paths) - #70029 (Bump the bootstrap compiler) - #70046 (Use sublice patterns to avoid computing the len) - #70049 (Fiddle `ParamEnv` through to a place that used to use `ParamEnv::empty` in a buggy manner) Failed merges: r? @ghost
2 parents e24252a + f118fee commit 5e9ebf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+679
-271
lines changed

src/bootstrap/builder.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'a> Builder<'a> {
725725
self.clear_if_dirty(&my_out, &rustdoc);
726726
}
727727

728-
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd).arg("-Zconfig-profile");
728+
cargo.env("CARGO_TARGET_DIR", &out_dir).arg(cmd);
729729

730730
let profile_var = |name: &str| {
731731
let profile = if self.config.rust_optimize { "RELEASE" } else { "DEV" };
@@ -847,13 +847,7 @@ impl<'a> Builder<'a> {
847847
rustflags.arg("-Zforce-unstable-if-unmarked");
848848
}
849849

850-
// cfg(bootstrap): the flag was renamed from `-Zexternal-macro-backtrace`
851-
// to `-Zmacro-backtrace`, keep only the latter after beta promotion.
852-
if stage == 0 {
853-
rustflags.arg("-Zexternal-macro-backtrace");
854-
} else {
855-
rustflags.arg("-Zmacro-backtrace");
856-
}
850+
rustflags.arg("-Zmacro-backtrace");
857851

858852
let want_rustdoc = self.doc_tests != DocTests::No;
859853

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use build_helper::output;
1313
use crate::Build;
1414

1515
// The version number
16-
pub const CFG_RELEASE_NUM: &str = "1.43.0";
16+
pub const CFG_RELEASE_NUM: &str = "1.44.0";
1717

1818
pub struct GitInfo {
1919
inner: Option<Info>,

src/liballoc/boxed.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1105,29 +1105,6 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
11051105
#[stable(feature = "pin", since = "1.33.0")]
11061106
impl<T: ?Sized> Unpin for Box<T> {}
11071107

1108-
#[cfg(bootstrap)]
1109-
#[unstable(feature = "generator_trait", issue = "43122")]
1110-
impl<G: ?Sized + Generator + Unpin> Generator for Box<G> {
1111-
type Yield = G::Yield;
1112-
type Return = G::Return;
1113-
1114-
fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
1115-
G::resume(Pin::new(&mut *self))
1116-
}
1117-
}
1118-
1119-
#[cfg(bootstrap)]
1120-
#[unstable(feature = "generator_trait", issue = "43122")]
1121-
impl<G: ?Sized + Generator> Generator for Pin<Box<G>> {
1122-
type Yield = G::Yield;
1123-
type Return = G::Return;
1124-
1125-
fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
1126-
G::resume((*self).as_mut())
1127-
}
1128-
}
1129-
1130-
#[cfg(not(bootstrap))]
11311108
#[unstable(feature = "generator_trait", issue = "43122")]
11321109
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for Box<G> {
11331110
type Yield = G::Yield;
@@ -1138,7 +1115,6 @@ impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for Box<G> {
11381115
}
11391116
}
11401117

1141-
#[cfg(not(bootstrap))]
11421118
#[unstable(feature = "generator_trait", issue = "43122")]
11431119
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<Box<G>> {
11441120
type Yield = G::Yield;

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
15691569
#[lang = "unsafe_cell"]
15701570
#[stable(feature = "rust1", since = "1.0.0")]
15711571
#[repr(transparent)]
1572-
#[cfg_attr(not(bootstrap), repr(no_niche))] // rust-lang/rust#68303.
1572+
#[repr(no_niche)] // rust-lang/rust#68303.
15731573
pub struct UnsafeCell<T: ?Sized> {
15741574
value: T,
15751575
}

src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
#![feature(associated_type_bounds)]
141141
#![feature(const_type_id)]
142142
#![feature(const_caller_location)]
143-
#![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303
143+
#![feature(no_niche)] // rust-lang/rust#68303
144144

145145
#[prelude_import]
146146
#[allow(unused)]

src/libcore/macros/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,18 @@ pub(crate) mod builtin {
14041404
/* compiler built-in */
14051405
}
14061406

1407+
/// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise.
1408+
#[cfg(not(bootstrap))]
1409+
#[unstable(
1410+
feature = "cfg_accessible",
1411+
issue = "64797",
1412+
reason = "`cfg_accessible` is not fully implemented"
1413+
)]
1414+
#[rustc_builtin_macro]
1415+
pub macro cfg_accessible($item:item) {
1416+
/* compiler built-in */
1417+
}
1418+
14071419
/// Unstable implementation detail of the `rustc` compiler, do not use.
14081420
#[rustc_builtin_macro]
14091421
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/ops/generator.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum GeneratorState<Y, R> {
6767
#[lang = "generator"]
6868
#[unstable(feature = "generator_trait", issue = "43122")]
6969
#[fundamental]
70-
pub trait Generator<#[cfg(not(bootstrap))] R = ()> {
70+
pub trait Generator<R = ()> {
7171
/// The type of value this generator yields.
7272
///
7373
/// This associated type corresponds to the `yield` expression and the
@@ -110,35 +110,9 @@ pub trait Generator<#[cfg(not(bootstrap))] R = ()> {
110110
/// been returned previously. While generator literals in the language are
111111
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
112112
/// for all implementations of the `Generator` trait.
113-
fn resume(
114-
self: Pin<&mut Self>,
115-
#[cfg(not(bootstrap))] arg: R,
116-
) -> GeneratorState<Self::Yield, Self::Return>;
113+
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
117114
}
118115

119-
#[cfg(bootstrap)]
120-
#[unstable(feature = "generator_trait", issue = "43122")]
121-
impl<G: ?Sized + Generator> Generator for Pin<&mut G> {
122-
type Yield = G::Yield;
123-
type Return = G::Return;
124-
125-
fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
126-
G::resume((*self).as_mut())
127-
}
128-
}
129-
130-
#[cfg(bootstrap)]
131-
#[unstable(feature = "generator_trait", issue = "43122")]
132-
impl<G: ?Sized + Generator + Unpin> Generator for &mut G {
133-
type Yield = G::Yield;
134-
type Return = G::Return;
135-
136-
fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
137-
G::resume(Pin::new(&mut *self))
138-
}
139-
}
140-
141-
#[cfg(not(bootstrap))]
142116
#[unstable(feature = "generator_trait", issue = "43122")]
143117
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
144118
type Yield = G::Yield;
@@ -149,7 +123,6 @@ impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
149123
}
150124
}
151125

152-
#[cfg(not(bootstrap))]
153126
#[unstable(feature = "generator_trait", issue = "43122")]
154127
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for &mut G {
155128
type Yield = G::Yield;

src/libcore/prelude/v1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ pub use crate::{
6767
pub use crate::macros::builtin::{
6868
bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,
6969
};
70+
71+
#[cfg(not(bootstrap))]
72+
#[unstable(
73+
feature = "cfg_accessible",
74+
issue = "64797",
75+
reason = "`cfg_accessible` is not fully implemented"
76+
)]
77+
#[doc(no_inline)]
78+
pub use crate::macros::builtin::cfg_accessible;

src/librustc/ty/inhabitedness/mod.rs

+34-15
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,46 @@ impl<'tcx> TyCtxt<'tcx> {
9090
/// ```
9191
/// This code should only compile in modules where the uninhabitedness of Foo is
9292
/// visible.
93-
pub fn is_ty_uninhabited_from(self, module: DefId, ty: Ty<'tcx>) -> bool {
93+
pub fn is_ty_uninhabited_from(
94+
self,
95+
module: DefId,
96+
ty: Ty<'tcx>,
97+
param_env: ty::ParamEnv<'tcx>,
98+
) -> bool {
9499
// To check whether this type is uninhabited at all (not just from the
95100
// given node), you could check whether the forest is empty.
96101
// ```
97102
// forest.is_empty()
98103
// ```
99-
ty.uninhabited_from(self).contains(self, module)
104+
ty.uninhabited_from(self, param_env).contains(self, module)
100105
}
101106

102-
pub fn is_ty_uninhabited_from_any_module(self, ty: Ty<'tcx>) -> bool {
103-
!ty.uninhabited_from(self).is_empty()
107+
pub fn is_ty_uninhabited_from_any_module(
108+
self,
109+
ty: Ty<'tcx>,
110+
param_env: ty::ParamEnv<'tcx>,
111+
) -> bool {
112+
!ty.uninhabited_from(self, param_env).is_empty()
104113
}
105114
}
106115

107116
impl<'tcx> AdtDef {
108117
/// Calculates the forest of `DefId`s from which this ADT is visibly uninhabited.
109-
fn uninhabited_from(&self, tcx: TyCtxt<'tcx>, substs: SubstsRef<'tcx>) -> DefIdForest {
118+
fn uninhabited_from(
119+
&self,
120+
tcx: TyCtxt<'tcx>,
121+
substs: SubstsRef<'tcx>,
122+
param_env: ty::ParamEnv<'tcx>,
123+
) -> DefIdForest {
110124
// Non-exhaustive ADTs from other crates are always considered inhabited.
111125
if self.is_variant_list_non_exhaustive() && !self.did.is_local() {
112126
DefIdForest::empty()
113127
} else {
114128
DefIdForest::intersection(
115129
tcx,
116-
self.variants.iter().map(|v| v.uninhabited_from(tcx, substs, self.adt_kind())),
130+
self.variants
131+
.iter()
132+
.map(|v| v.uninhabited_from(tcx, substs, self.adt_kind(), param_env)),
117133
)
118134
}
119135
}
@@ -126,6 +142,7 @@ impl<'tcx> VariantDef {
126142
tcx: TyCtxt<'tcx>,
127143
substs: SubstsRef<'tcx>,
128144
adt_kind: AdtKind,
145+
param_env: ty::ParamEnv<'tcx>,
129146
) -> DefIdForest {
130147
let is_enum = match adt_kind {
131148
// For now, `union`s are never considered uninhabited.
@@ -140,7 +157,7 @@ impl<'tcx> VariantDef {
140157
} else {
141158
DefIdForest::union(
142159
tcx,
143-
self.fields.iter().map(|f| f.uninhabited_from(tcx, substs, is_enum)),
160+
self.fields.iter().map(|f| f.uninhabited_from(tcx, substs, is_enum, param_env)),
144161
)
145162
}
146163
}
@@ -153,8 +170,9 @@ impl<'tcx> FieldDef {
153170
tcx: TyCtxt<'tcx>,
154171
substs: SubstsRef<'tcx>,
155172
is_enum: bool,
173+
param_env: ty::ParamEnv<'tcx>,
156174
) -> DefIdForest {
157-
let data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(tcx);
175+
let data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(tcx, param_env);
158176
// FIXME(canndrew): Currently enum fields are (incorrectly) stored with
159177
// `Visibility::Invisible` so we need to override `self.vis` if we're
160178
// dealing with an enum.
@@ -176,20 +194,21 @@ impl<'tcx> FieldDef {
176194

177195
impl<'tcx> TyS<'tcx> {
178196
/// Calculates the forest of `DefId`s from which this type is visibly uninhabited.
179-
fn uninhabited_from(&self, tcx: TyCtxt<'tcx>) -> DefIdForest {
197+
fn uninhabited_from(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> DefIdForest {
180198
match self.kind {
181-
Adt(def, substs) => def.uninhabited_from(tcx, substs),
199+
Adt(def, substs) => def.uninhabited_from(tcx, substs, param_env),
182200

183201
Never => DefIdForest::full(tcx),
184202

185-
Tuple(ref tys) => {
186-
DefIdForest::union(tcx, tys.iter().map(|ty| ty.expect_ty().uninhabited_from(tcx)))
187-
}
203+
Tuple(ref tys) => DefIdForest::union(
204+
tcx,
205+
tys.iter().map(|ty| ty.expect_ty().uninhabited_from(tcx, param_env)),
206+
),
188207

189-
Array(ty, len) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
208+
Array(ty, len) => match len.try_eval_usize(tcx, param_env) {
190209
// If the array is definitely non-empty, it's uninhabited if
191210
// the type of its elements is uninhabited.
192-
Some(n) if n != 0 => ty.uninhabited_from(tcx),
211+
Some(n) if n != 0 => ty.uninhabited_from(tcx, param_env),
193212
_ => DefIdForest::empty(),
194213
},
195214

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Implementation of the `#[cfg_accessible(path)]` attribute macro.
2+
3+
use rustc_ast::ast;
4+
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
5+
use rustc_feature::AttributeTemplate;
6+
use rustc_parse::validate_attr;
7+
use rustc_span::symbol::sym;
8+
use rustc_span::Span;
9+
10+
crate struct Expander;
11+
12+
fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
13+
match mi.meta_item_list() {
14+
None => {}
15+
Some([]) => ecx.span_err(mi.span, "`cfg_accessible` path is not specified"),
16+
Some([_, .., l]) => ecx.span_err(l.span(), "multiple `cfg_accessible` paths are specified"),
17+
Some([nmi]) => match nmi.meta_item() {
18+
None => ecx.span_err(nmi.span(), "`cfg_accessible` path cannot be a literal"),
19+
Some(mi) => {
20+
if !mi.is_word() {
21+
ecx.span_err(mi.span, "`cfg_accessible` path cannot accept arguments");
22+
}
23+
return Some(&mi.path);
24+
}
25+
},
26+
}
27+
None
28+
}
29+
30+
impl MultiItemModifier for Expander {
31+
fn expand(
32+
&self,
33+
ecx: &mut ExtCtxt<'_>,
34+
_span: Span,
35+
meta_item: &ast::MetaItem,
36+
item: Annotatable,
37+
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
38+
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
39+
let attr = &ecx.attribute(meta_item.clone());
40+
validate_attr::check_builtin_attribute(ecx.parse_sess, attr, sym::cfg_accessible, template);
41+
42+
let path = match validate_input(ecx, meta_item) {
43+
Some(path) => path,
44+
None => return ExpandResult::Ready(Vec::new()),
45+
};
46+
47+
let failure_msg = "cannot determine whether the path is accessible or not";
48+
match ecx.resolver.cfg_accessible(ecx.current_expansion.id, path) {
49+
Ok(true) => ExpandResult::Ready(vec![item]),
50+
Ok(false) => ExpandResult::Ready(Vec::new()),
51+
Err(_) => ExpandResult::Retry(item, failure_msg.into()),
52+
}
53+
}
54+
}

src/librustc_builtin_macros/deriving/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_ast::ast::{self, ItemKind, MetaItem};
44
use rustc_ast::ptr::P;
5-
use rustc_expand::base::{Annotatable, ExtCtxt, MultiItemModifier};
5+
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
66
use rustc_span::symbol::{sym, Symbol};
77
use rustc_span::Span;
88

@@ -48,13 +48,13 @@ impl MultiItemModifier for BuiltinDerive {
4848
span: Span,
4949
meta_item: &MetaItem,
5050
item: Annotatable,
51-
) -> Vec<Annotatable> {
51+
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
5252
// FIXME: Built-in derives often forget to give spans contexts,
5353
// so we are doing it here in a centralized way.
5454
let span = ecx.with_def_site_ctxt(span);
5555
let mut items = Vec::new();
5656
(self.0)(ecx, span, meta_item, &item, &mut |a| items.push(a));
57-
items
57+
ExpandResult::Ready(items)
5858
}
5959
}
6060

src/librustc_builtin_macros/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_span::symbol::sym;
2222
mod asm;
2323
mod assert;
2424
mod cfg;
25+
mod cfg_accessible;
2526
mod compile_error;
2627
mod concat;
2728
mod concat_idents;
@@ -85,6 +86,7 @@ pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) {
8586

8687
register_attr! {
8788
bench: test::expand_bench,
89+
cfg_accessible: cfg_accessible::Expander,
8890
global_allocator: global_allocator::expand,
8991
test: test::expand_test,
9092
test_case: test::expand_test_case,

src/librustc_builtin_macros/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::Symbol;
66

77
pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) {
88
// All the built-in macro attributes are "words" at the moment.
9-
let template = AttributeTemplate::only_word();
9+
let template = AttributeTemplate { word: true, ..Default::default() };
1010
let attr = ecx.attribute(meta_item.clone());
1111
validate_attr::check_builtin_attribute(ecx.parse_sess, &attr, name, template);
1212
}

0 commit comments

Comments
 (0)