Skip to content

Commit

Permalink
Auto merge of rust-lang#79220 - Dylan-DPC:rollup-5bpbygd, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - rust-lang#79119 (Clarify availability of atomic operations)
 - rust-lang#79123 (Add u128 and i128 integer tests)
 - rust-lang#79177 (Test drop order for (destructuring) assignments)
 - rust-lang#79181 (rustdoc: add [src] links to methods on a trait's page)
 - rust-lang#79183 (Make compiletest testing use the local sysroot)
 - rust-lang#79185 (expand/resolve: Pre-requisites to "Turn `#[derive]` into a regular macro attribute")
 - rust-lang#79193 (Revert rust-lang#78969 "Normalize function type during validation")
 - rust-lang#79194 (Make as{_mut,}_slice on array::IntoIter public)
 - rust-lang#79204 (Add jyn514 email alias to mailmap)
 - rust-lang#79212 (Move `rustc_ty` -> `rustc_ty_utils`)
 - rust-lang#79217 (Add the "memcpy" doc alias to slice::copy_from_slice)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 20, 2020
2 parents 09c9c9f + 5adc00f commit 4ec27e4
Show file tree
Hide file tree
Showing 61 changed files with 633 additions and 736 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Jorge Aparicio <japaric@linux.com> <japaricious@gmail.com>
Joseph Martin <pythoner6@gmail.com>
Joseph T. Lyons <JosephTLyons@gmail.com> <josephtlyons@gmail.com>
Joseph T. Lyons <JosephTLyons@gmail.com> <JosephTLyons@users.noreply.github.com>
Joshua Nelson <jyn514@gmail.com> <joshua@yottadb.com>
jumbatm <jumbatm@gmail.com> <30644300+jumbatm@users.noreply.github.com>
Junyoung Cho <june0.cho@samsung.com>
Jyun-Yan You <jyyou.tw@gmail.com> <jyyou@cs.nctu.edu.tw>
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3802,7 +3802,7 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_traits",
"rustc_ty",
"rustc_ty_utils",
"rustc_typeck",
"smallvec 1.4.2",
"tempfile",
Expand Down Expand Up @@ -4240,7 +4240,7 @@ dependencies = [
]

[[package]]
name = "rustc_ty"
name = "rustc_ty_utils"
version = "0.0.0"
dependencies = [
"rustc_data_structures",
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_builtin_macros/src/cfg_accessible.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of the `#[cfg_accessible(path)]` attribute macro.

use rustc_ast as ast;
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
use rustc_feature::AttributeTemplate;
use rustc_parse::validate_attr;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -31,7 +31,7 @@ impl MultiItemModifier for Expander {
fn expand(
&self,
ecx: &mut ExtCtxt<'_>,
_span: Span,
span: Span,
meta_item: &ast::MetaItem,
item: Annotatable,
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
Expand All @@ -49,11 +49,14 @@ impl MultiItemModifier for Expander {
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()),
Err(Indeterminate) if ecx.force_mode => {
ecx.span_err(span, "cannot determine whether the path is accessible or not");
ExpandResult::Ready(vec![item])
}
Err(Indeterminate) => ExpandResult::Retry(item),
}
}
}
15 changes: 2 additions & 13 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,7 @@ impl<'a> TraitDef<'a> {
_ => false,
})
}
_ => {
// Non-ADT derive is an error, but it should have been
// set earlier; see
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
// librustc_expand/base.rs:Annotatable::derive_allowed()
return;
}
_ => unreachable!(),
};
let container_id = cx.current_expansion.id.expn_data().parent;
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
Expand Down Expand Up @@ -475,12 +469,7 @@ impl<'a> TraitDef<'a> {
);
push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() })))
}
_ => {
// Non-Item derive is an error, but it should have been
// set earlier; see
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
// librustc_expand/base.rs:Annotatable::derive_allowed()
}
_ => unreachable!(),
}
}

Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_builtin_macros/src/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ fn inject_impl_of_structural_trait(
) {
let item = match *item {
Annotatable::Item(ref item) => item,
_ => {
// Non-Item derive is an error, but it should have been
// set earlier; see
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
// librustc_expand/base.rs:Annotatable::derive_allowed()
return;
}
_ => unreachable!(),
};

let generics = match item.kind {
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ pub enum ExpandResult<T, U> {
/// Expansion produced a result (possibly dummy).
Ready(T),
/// Expansion could not produce a result and needs to be retried.
/// The string is an explanation that will be printed if we are stuck in an infinite retry loop.
Retry(U, String),
Retry(U),
}

// `meta_item` is the attribute, and `item` is the item being modified.
Expand Down Expand Up @@ -889,8 +888,10 @@ pub trait ResolverExpand {
/// Some parent node that is close enough to the given macro call.
fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId;

// Resolver interfaces for specific built-in macros.
/// Does `#[derive(...)]` attribute with the given `ExpnId` have built-in `Copy` inside it?
fn has_derive_copy(&self, expn_id: ExpnId) -> bool;
fn add_derive_copy(&mut self, expn_id: ExpnId);
/// Path resolution logic for `#[cfg_accessible(path)]`.
fn cfg_accessible(&mut self, expn_id: ExpnId, path: &ast::Path) -> Result<bool, Indeterminate>;
}

Expand Down Expand Up @@ -919,6 +920,9 @@ pub struct ExtCtxt<'a> {
pub root_path: PathBuf,
pub resolver: &'a mut dyn ResolverExpand,
pub current_expansion: ExpansionData,
/// Error recovery mode entered when expansion is stuck
/// (or during eager expansion, but that's a hack).
pub force_mode: bool,
pub expansions: FxHashMap<Span, Vec<String>>,
/// Called directly after having parsed an external `mod foo;` in expansion.
pub(super) extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
Expand All @@ -945,6 +949,7 @@ impl<'a> ExtCtxt<'a> {
directory_ownership: DirectoryOwnership::Owned { relative: None },
prior_type_ascription: None,
},
force_mode: false,
expansions: FxHashMap::default(),
}
}
Expand Down
45 changes: 45 additions & 0 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Conditional compilation stripping.

use crate::base::Annotatable;

use rustc_ast::attr::HasAttrs;
use rustc_ast::mut_visit::*;
use rustc_ast::ptr::P;
Expand Down Expand Up @@ -496,6 +498,49 @@ impl<'a> StripUnconfigured<'a> {
pub fn configure_fn_decl(&mut self, fn_decl: &mut ast::FnDecl) {
fn_decl.inputs.flat_map_in_place(|arg| self.configure(arg));
}

pub fn fully_configure(&mut self, item: Annotatable) -> Annotatable {
// Since the item itself has already been configured by the InvocationCollector,
// we know that fold result vector will contain exactly one element
match item {
Annotatable::Item(item) => Annotatable::Item(self.flat_map_item(item).pop().unwrap()),
Annotatable::TraitItem(item) => {
Annotatable::TraitItem(self.flat_map_trait_item(item).pop().unwrap())
}
Annotatable::ImplItem(item) => {
Annotatable::ImplItem(self.flat_map_impl_item(item).pop().unwrap())
}
Annotatable::ForeignItem(item) => {
Annotatable::ForeignItem(self.flat_map_foreign_item(item).pop().unwrap())
}
Annotatable::Stmt(stmt) => {
Annotatable::Stmt(stmt.map(|stmt| self.flat_map_stmt(stmt).pop().unwrap()))
}
Annotatable::Expr(mut expr) => Annotatable::Expr({
self.visit_expr(&mut expr);
expr
}),
Annotatable::Arm(arm) => Annotatable::Arm(self.flat_map_arm(arm).pop().unwrap()),
Annotatable::Field(field) => {
Annotatable::Field(self.flat_map_field(field).pop().unwrap())
}
Annotatable::FieldPat(fp) => {
Annotatable::FieldPat(self.flat_map_field_pattern(fp).pop().unwrap())
}
Annotatable::GenericParam(param) => {
Annotatable::GenericParam(self.flat_map_generic_param(param).pop().unwrap())
}
Annotatable::Param(param) => {
Annotatable::Param(self.flat_map_param(param).pop().unwrap())
}
Annotatable::StructField(sf) => {
Annotatable::StructField(self.flat_map_struct_field(sf).pop().unwrap())
}
Annotatable::Variant(v) => {
Annotatable::Variant(self.flat_map_variant(v).pop().unwrap())
}
}
}
}

impl<'a> MutVisitor for StripUnconfigured<'a> {
Expand Down
Loading

0 comments on commit 4ec27e4

Please sign in to comment.