Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #70062

Merged
merged 19 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
eafeb9a
expand/builtin_macros: Minor cleanup
petrochenkov Dec 30, 2019
552a887
expand: Implement support for retrying macro expansions
petrochenkov Mar 9, 2020
2e65289
builtin_macros: Add attribute macro `#[cfg_accessible(path)]`
petrochenkov Mar 9, 2020
71ebc61
resolve: Simplify `fn report_privacy_error`
petrochenkov Mar 7, 2020
580c6a2
resolve: Print import chains on privacy errors
petrochenkov Mar 7, 2020
f4083c6
Add the "consider importing it directly" label to public imports as well
petrochenkov Mar 11, 2020
e80cb20
resolve: Fix regression in resolution of raw keywords in paths
petrochenkov Mar 14, 2020
81099c2
VariantSizeDifferences: bail on SizeOverflow
Centril Mar 10, 2020
f53f9a8
Bump the bootstrap compiler
jonas-schievink Mar 15, 2020
ce5e49f
Use sublice patterns to avoid computing the len
tesuji Mar 16, 2020
e1bc9af
Fix wrong deref
tesuji Mar 16, 2020
7894509
Fiddle `ParamEnv` through to a place that used to use `ParamEnv::empt…
oli-obk Mar 16, 2020
b691145
Rollup merge of #69811 - petrochenkov:privdiag2, r=estebank
Centril Mar 17, 2020
9fc5c2d
Rollup merge of #69870 - petrochenkov:cfgacc, r=matthewjasper
Centril Mar 17, 2020
1b0c73b
Rollup merge of #69881 - Centril:fix-69485, r=oli-obk
Centril Mar 17, 2020
3d25622
Rollup merge of #70000 - petrochenkov:rawkeypars, r=davidtwco
Centril Mar 17, 2020
f907598
Rollup merge of #70029 - jonas-schievink:bootstrap, r=Centril
Centril Mar 17, 2020
4d7ec70
Rollup merge of #70046 - lzutao:patch-1, r=Centril
Centril Mar 17, 2020
f118fee
Rollup merge of #70049 - oli-obk:param_env_empty_considered_unimpleme…
Centril Mar 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl<'a> Builder<'a> {
self.clear_if_dirty(&my_out, &rustdoc);
}

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use build_helper::output;
use crate::Build;

// The version number
pub const CFG_RELEASE_NUM: &str = "1.43.0";
pub const CFG_RELEASE_NUM: &str = "1.44.0";

pub struct GitInfo {
inner: Option<Info>,
Expand Down
24 changes: 0 additions & 24 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,29 +1105,6 @@ impl<T: ?Sized> AsMut<T> for Box<T> {
#[stable(feature = "pin", since = "1.33.0")]
impl<T: ?Sized> Unpin for Box<T> {}

#[cfg(bootstrap)]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator + Unpin> Generator for Box<G> {
type Yield = G::Yield;
type Return = G::Return;

fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
G::resume(Pin::new(&mut *self))
}
}

#[cfg(bootstrap)]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator> Generator for Pin<Box<G>> {
type Yield = G::Yield;
type Return = G::Return;

fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
G::resume((*self).as_mut())
}
}

#[cfg(not(bootstrap))]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for Box<G> {
type Yield = G::Yield;
Expand All @@ -1138,7 +1115,6 @@ impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for Box<G> {
}
}

#[cfg(not(bootstrap))]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<Box<G>> {
type Yield = G::Yield;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
#[lang = "unsafe_cell"]
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
#[cfg_attr(not(bootstrap), repr(no_niche))] // rust-lang/rust#68303.
#[repr(no_niche)] // rust-lang/rust#68303.
pub struct UnsafeCell<T: ?Sized> {
value: T,
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![cfg_attr(not(bootstrap), feature(no_niche))] // rust-lang/rust#68303
#![feature(no_niche)] // rust-lang/rust#68303

#[prelude_import]
#[allow(unused)]
Expand Down
12 changes: 12 additions & 0 deletions src/libcore/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,18 @@ pub(crate) mod builtin {
/* compiler built-in */
}

/// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise.
#[cfg(not(bootstrap))]
#[unstable(
feature = "cfg_accessible",
issue = "64797",
reason = "`cfg_accessible` is not fully implemented"
)]
#[rustc_builtin_macro]
pub macro cfg_accessible($item:item) {
/* compiler built-in */
}

/// Unstable implementation detail of the `rustc` compiler, do not use.
#[rustc_builtin_macro]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
31 changes: 2 additions & 29 deletions src/libcore/ops/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub enum GeneratorState<Y, R> {
#[lang = "generator"]
#[unstable(feature = "generator_trait", issue = "43122")]
#[fundamental]
pub trait Generator<#[cfg(not(bootstrap))] R = ()> {
pub trait Generator<R = ()> {
/// The type of value this generator yields.
///
/// This associated type corresponds to the `yield` expression and the
Expand Down Expand Up @@ -110,35 +110,9 @@ pub trait Generator<#[cfg(not(bootstrap))] R = ()> {
/// been returned previously. While generator literals in the language are
/// guaranteed to panic on resuming after `Complete`, this is not guaranteed
/// for all implementations of the `Generator` trait.
fn resume(
self: Pin<&mut Self>,
#[cfg(not(bootstrap))] arg: R,
) -> GeneratorState<Self::Yield, Self::Return>;
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
}

#[cfg(bootstrap)]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator> Generator for Pin<&mut G> {
type Yield = G::Yield;
type Return = G::Return;

fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
G::resume((*self).as_mut())
}
}

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

fn resume(mut self: Pin<&mut Self>) -> GeneratorState<Self::Yield, Self::Return> {
G::resume(Pin::new(&mut *self))
}
}

#[cfg(not(bootstrap))]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
type Yield = G::Yield;
Expand All @@ -149,7 +123,6 @@ impl<G: ?Sized + Generator<R>, R> Generator<R> for Pin<&mut G> {
}
}

#[cfg(not(bootstrap))]
#[unstable(feature = "generator_trait", issue = "43122")]
impl<G: ?Sized + Generator<R> + Unpin, R> Generator<R> for &mut G {
type Yield = G::Yield;
Expand Down
9 changes: 9 additions & 0 deletions src/libcore/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ pub use crate::{
pub use crate::macros::builtin::{
bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,
};

#[cfg(not(bootstrap))]
#[unstable(
feature = "cfg_accessible",
issue = "64797",
reason = "`cfg_accessible` is not fully implemented"
)]
#[doc(no_inline)]
pub use crate::macros::builtin::cfg_accessible;
49 changes: 34 additions & 15 deletions src/librustc/ty/inhabitedness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,46 @@ impl<'tcx> TyCtxt<'tcx> {
/// ```
/// This code should only compile in modules where the uninhabitedness of Foo is
/// visible.
pub fn is_ty_uninhabited_from(self, module: DefId, ty: Ty<'tcx>) -> bool {
pub fn is_ty_uninhabited_from(
self,
module: DefId,
ty: Ty<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
// To check whether this type is uninhabited at all (not just from the
// given node), you could check whether the forest is empty.
// ```
// forest.is_empty()
// ```
ty.uninhabited_from(self).contains(self, module)
ty.uninhabited_from(self, param_env).contains(self, module)
}

pub fn is_ty_uninhabited_from_any_module(self, ty: Ty<'tcx>) -> bool {
!ty.uninhabited_from(self).is_empty()
pub fn is_ty_uninhabited_from_any_module(
self,
ty: Ty<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
!ty.uninhabited_from(self, param_env).is_empty()
}
}

impl<'tcx> AdtDef {
/// Calculates the forest of `DefId`s from which this ADT is visibly uninhabited.
fn uninhabited_from(&self, tcx: TyCtxt<'tcx>, substs: SubstsRef<'tcx>) -> DefIdForest {
fn uninhabited_from(
&self,
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> DefIdForest {
// Non-exhaustive ADTs from other crates are always considered inhabited.
if self.is_variant_list_non_exhaustive() && !self.did.is_local() {
DefIdForest::empty()
} else {
DefIdForest::intersection(
tcx,
self.variants.iter().map(|v| v.uninhabited_from(tcx, substs, self.adt_kind())),
self.variants
.iter()
.map(|v| v.uninhabited_from(tcx, substs, self.adt_kind(), param_env)),
)
}
}
Expand All @@ -126,6 +142,7 @@ impl<'tcx> VariantDef {
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
adt_kind: AdtKind,
param_env: ty::ParamEnv<'tcx>,
) -> DefIdForest {
let is_enum = match adt_kind {
// For now, `union`s are never considered uninhabited.
Expand All @@ -140,7 +157,7 @@ impl<'tcx> VariantDef {
} else {
DefIdForest::union(
tcx,
self.fields.iter().map(|f| f.uninhabited_from(tcx, substs, is_enum)),
self.fields.iter().map(|f| f.uninhabited_from(tcx, substs, is_enum, param_env)),
)
}
}
Expand All @@ -153,8 +170,9 @@ impl<'tcx> FieldDef {
tcx: TyCtxt<'tcx>,
substs: SubstsRef<'tcx>,
is_enum: bool,
param_env: ty::ParamEnv<'tcx>,
) -> DefIdForest {
let data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(tcx);
let data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(tcx, param_env);
// FIXME(canndrew): Currently enum fields are (incorrectly) stored with
// `Visibility::Invisible` so we need to override `self.vis` if we're
// dealing with an enum.
Expand All @@ -176,20 +194,21 @@ impl<'tcx> FieldDef {

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

Never => DefIdForest::full(tcx),

Tuple(ref tys) => {
DefIdForest::union(tcx, tys.iter().map(|ty| ty.expect_ty().uninhabited_from(tcx)))
}
Tuple(ref tys) => DefIdForest::union(
tcx,
tys.iter().map(|ty| ty.expect_ty().uninhabited_from(tcx, param_env)),
),

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

Expand Down
54 changes: 54 additions & 0 deletions src/librustc_builtin_macros/cfg_accessible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Implementation of the `#[cfg_accessible(path)]` attribute macro.

use rustc_ast::ast;
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
use rustc_feature::AttributeTemplate;
use rustc_parse::validate_attr;
use rustc_span::symbol::sym;
use rustc_span::Span;

crate struct Expander;

fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> {
match mi.meta_item_list() {
None => {}
Some([]) => ecx.span_err(mi.span, "`cfg_accessible` path is not specified"),
Some([_, .., l]) => ecx.span_err(l.span(), "multiple `cfg_accessible` paths are specified"),
Some([nmi]) => match nmi.meta_item() {
None => ecx.span_err(nmi.span(), "`cfg_accessible` path cannot be a literal"),
Some(mi) => {
if !mi.is_word() {
ecx.span_err(mi.span, "`cfg_accessible` path cannot accept arguments");
}
return Some(&mi.path);
}
},
}
None
}

impl MultiItemModifier for Expander {
fn expand(
&self,
ecx: &mut ExtCtxt<'_>,
_span: Span,
meta_item: &ast::MetaItem,
item: Annotatable,
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
let attr = &ecx.attribute(meta_item.clone());
validate_attr::check_builtin_attribute(ecx.parse_sess, attr, sym::cfg_accessible, template);

let path = match validate_input(ecx, meta_item) {
Some(path) => path,
None => return ExpandResult::Ready(Vec::new()),
};

let failure_msg = "cannot determine whether the path is accessible or not";
match ecx.resolver.cfg_accessible(ecx.current_expansion.id, path) {
Ok(true) => ExpandResult::Ready(vec![item]),
Ok(false) => ExpandResult::Ready(Vec::new()),
Err(_) => ExpandResult::Retry(item, failure_msg.into()),
}
}
}
6 changes: 3 additions & 3 deletions src/librustc_builtin_macros/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rustc_ast::ast::{self, ItemKind, MetaItem};
use rustc_ast::ptr::P;
use rustc_expand::base::{Annotatable, ExtCtxt, MultiItemModifier};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span;

Expand Down Expand Up @@ -48,13 +48,13 @@ impl MultiItemModifier for BuiltinDerive {
span: Span,
meta_item: &MetaItem,
item: Annotatable,
) -> Vec<Annotatable> {
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
// FIXME: Built-in derives often forget to give spans contexts,
// so we are doing it here in a centralized way.
let span = ecx.with_def_site_ctxt(span);
let mut items = Vec::new();
(self.0)(ecx, span, meta_item, &item, &mut |a| items.push(a));
items
ExpandResult::Ready(items)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_builtin_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_span::symbol::sym;
mod asm;
mod assert;
mod cfg;
mod cfg_accessible;
mod compile_error;
mod concat;
mod concat_idents;
Expand Down Expand Up @@ -85,6 +86,7 @@ pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) {

register_attr! {
bench: test::expand_bench,
cfg_accessible: cfg_accessible::Expander,
global_allocator: global_allocator::expand,
test: test::expand_test,
test_case: test::expand_test_case,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_span::Symbol;

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