Skip to content

Commit

Permalink
Auto merge of #69144 - Dylan-DPC:rollup-apt6zjj, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #68728 (parse: merge `fn` syntax + cleanup item parsing)
 - #68938 (fix lifetime shadowing check in GATs)
 - #69057 (expand: misc cleanups and simplifications)
 - #69108 (Use HirId in TraitCandidate.)
 - #69125 (Add comment to SGX entry code)
 - #69126 (miri: fix exact_div)
 - #69127 (Enable use after scope detection in the new LLVM pass manager)
 - #69135 (Spelling error "represening" to "representing")
 - #69141 (Don't error on network failures)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Feb 13, 2020
2 parents 5d04ce6 + 7704e59 commit 1010408
Show file tree
Hide file tree
Showing 62 changed files with 754 additions and 866 deletions.
1 change: 0 additions & 1 deletion src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {

let import_keys = import_ids
.iter()
.map(|node_id| hcx.node_to_hir_id(*node_id))
.map(|hir_id| (hcx.local_def_path_hash(hir_id.owner), hir_id.local_id))
.collect();
(hcx.def_path_hash(*def_id), import_keys)
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,10 @@ impl<'tcx> TyCtxt<'tcx> {
for (k, v) in resolutions.trait_map {
let hir_id = hir.node_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| hir.definitions().node_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub struct ResolverOutputs {
pub definitions: hir_map::Definitions,
pub cstore: Box<CrateStoreDyn>,
pub extern_crate_map: NodeMap<CrateNum>,
pub trait_map: TraitMap,
pub trait_map: TraitMap<NodeId>,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
pub export_map: ExportMap<NodeId>,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ impl<'a> State<'a> {
self.print_where_clause(&generics.where_clause);
self.s.word(" ");
self.bopen();
self.print_inner_attributes(&item.attrs);
for trait_item in trait_items {
self.print_assoc_item(trait_item);
}
Expand Down
121 changes: 61 additions & 60 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,28 +451,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
_ => unreachable!(),
};
if !item.derive_allowed() {
let attr = attr::find_by_name(item.attrs(), sym::derive)
.expect("`derive` attribute should exist");
let span = attr.span;
let mut err = self.cx.struct_span_err(
span,
"`derive` may only be applied to structs, enums and unions",
);
if let ast::AttrStyle::Inner = attr.style {
let trait_list = derives
.iter()
.map(|t| pprust::path_to_string(t))
.collect::<Vec<_>>();
let suggestion = format!("#[derive({})]", trait_list.join(", "));
err.span_suggestion(
span,
"try an outer attribute",
suggestion,
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
Applicability::MaybeIncorrect,
);
}
err.emit();
self.error_derive_forbidden_on_non_adt(&derives, &item);
}

let mut item = self.fully_configure(item);
Expand Down Expand Up @@ -521,6 +500,27 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
fragment_with_placeholders
}

fn error_derive_forbidden_on_non_adt(&self, derives: &[Path], item: &Annotatable) {
let attr =
attr::find_by_name(item.attrs(), sym::derive).expect("`derive` attribute should exist");
let span = attr.span;
let mut err = self
.cx
.struct_span_err(span, "`derive` may only be applied to structs, enums and unions");
if let ast::AttrStyle::Inner = attr.style {
let trait_list = derives.iter().map(|t| pprust::path_to_string(t)).collect::<Vec<_>>();
let suggestion = format!("#[derive({})]", trait_list.join(", "));
err.span_suggestion(
span,
"try an outer attribute",
suggestion,
// We don't 𝑘𝑛𝑜𝑤 that the following item is an ADT
Applicability::MaybeIncorrect,
);
}
err.emit();
}

fn resolve_imports(&mut self) {
if self.monotonic {
self.cx.resolver.resolve_imports();
Expand Down Expand Up @@ -606,21 +606,38 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
}

fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
let expn_data = self.cx.current_expansion.id.expn_data();
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
let mut err = self.cx.struct_span_err(
fn error_recursion_limit_reached(&mut self) {
let expn_data = self.cx.current_expansion.id.expn_data();
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
self.cx
.struct_span_err(
expn_data.call_site,
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
);
err.help(&format!(
)
.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
suggested_limit, self.cx.ecfg.crate_name,
));
err.emit();
self.cx.trace_macros_diag();
FatalError.raise();
))
.emit();
self.cx.trace_macros_diag();
FatalError.raise();
}

/// A macro's expansion does not fit in this fragment kind.
/// For example, a non-type macro in a type position.
fn error_wrong_fragment_kind(&mut self, kind: AstFragmentKind, mac: &ast::Mac, span: Span) {
let msg = format!(
"non-{kind} macro in {kind} position: {path}",
kind = kind.name(),
path = pprust::path_to_string(&mac.path),
);
self.cx.span_err(span, &msg);
self.cx.trace_macros_diag();
}

fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
self.error_recursion_limit_reached();
}

let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
Expand All @@ -638,13 +655,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
result
} else {
let msg = format!(
"non-{kind} macro in {kind} position: {path}",
kind = fragment_kind.name(),
path = pprust::path_to_string(&mac.path),
);
self.cx.span_err(span, &msg);
self.cx.trace_macros_diag();
self.error_wrong_fragment_kind(fragment_kind, &mac, span);
fragment_kind.dummy(span)
};
self.cx.current_expansion.prior_type_ascription = prev;
Expand Down Expand Up @@ -867,7 +878,7 @@ pub fn parse_ast_fragment<'a>(
AstFragmentKind::ForeignItems => {
let mut items = SmallVec::new();
while this.token != token::Eof {
items.push(this.parse_foreign_item()?);
items.push(this.parse_foreign_item(&mut false)?);
}
AstFragment::ForeignItems(items)
}
Expand Down Expand Up @@ -1030,13 +1041,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
}

/// If `item` is an attr invocation, remove and return the macro attribute and derive traits.
fn classify_item<T>(
fn classify_item(
&mut self,
item: &mut T,
) -> (Option<ast::Attribute>, Vec<Path>, /* after_derive */ bool)
where
T: HasAttrs,
{
item: &mut impl HasAttrs,
) -> (Option<ast::Attribute>, Vec<Path>, /* after_derive */ bool) {
let (mut attr, mut traits, mut after_derive) = (None, Vec::new(), false);

item.visit_attrs(|mut attrs| {
Expand All @@ -1050,9 +1058,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
/// Alternative to `classify_item()` that ignores `#[derive]` so invocations fallthrough
/// to the unused-attributes lint (making it an error on statements and expressions
/// is a breaking change)
fn classify_nonitem<T: HasAttrs>(
fn classify_nonitem(
&mut self,
nonitem: &mut T,
nonitem: &mut impl HasAttrs,
) -> (Option<ast::Attribute>, /* after_derive */ bool) {
let (mut attr, mut after_derive) = (None, false);

Expand Down Expand Up @@ -1375,21 +1383,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
_ => unreachable!(),
})
}
ast::ItemKind::Mod(ast::Mod { inner, .. }) => {
if item.ident == Ident::invalid() {
return noop_flat_map_item(item, self);
}

ast::ItemKind::Mod(ast::Mod { inner, inline, .. })
if item.ident != Ident::invalid() =>
{
let orig_directory_ownership = self.cx.current_expansion.directory_ownership;
let mut module = (*self.cx.current_expansion.module).clone();
module.mod_path.push(item.ident);

// Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`).
// In the non-inline case, `inner` is never the dummy span (cf. `parse_item_mod`).
// Thus, if `inner` is the dummy span, we know the module is inline.
let inline_module = item.span.contains(inner) || inner.is_dummy();

if inline_module {
if inline {
if let Some(path) = attr::first_attr_value_str_by_name(&item.attrs, sym::path) {
self.cx.current_expansion.directory_ownership =
DirectoryOwnership::Owned { relative: None };
Expand Down
19 changes: 15 additions & 4 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{MultiSpan, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name, NodeId};
use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name};
use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto};
pub use syntax::ast::{CaptureBy, Movability, Mutability};
Expand Down Expand Up @@ -2608,13 +2608,24 @@ pub type CaptureModeMap = NodeMap<CaptureBy>;
// has length > 0 if the trait is found through an chain of imports, starting with the
// import/use statement in the scope where the trait is used.
#[derive(Clone, Debug)]
pub struct TraitCandidate {
pub struct TraitCandidate<ID = HirId> {
pub def_id: DefId,
pub import_ids: SmallVec<[NodeId; 1]>,
pub import_ids: SmallVec<[ID; 1]>,
}

impl<ID> TraitCandidate<ID> {
pub fn map_import_ids<F, T>(self, f: F) -> TraitCandidate<T>
where
F: Fn(ID) -> T,
{
let TraitCandidate { def_id, import_ids } = self;
let import_ids = import_ids.into_iter().map(f).collect();
TraitCandidate { def_id, import_ids }
}
}

// Trait method resolution
pub type TraitMap = NodeMap<Vec<TraitCandidate>>;
pub type TraitMap<ID = HirId> = NodeMap<Vec<TraitCandidate<ID>>>;

// Map from the NodeId of a glob import to a list of items which are actually
// imported.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Token {
}
}

/// Enum represening common lexeme types.
/// Enum representing common lexeme types.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum TokenKind {
// Multi-char tokens:
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_mir/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx> {
// Performs an exact division, resulting in undefined behavior where
// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`.
// First, check x % y != 0.
if self.binary_op(BinOp::Rem, a, b)?.to_bits()? != 0 {
// First, check x % y != 0 (or if that computation overflows).
let (res, overflow, _ty) = self.overflowing_binary_op(BinOp::Rem, a, b)?;
if overflow || res.to_bits(a.layout.size)? != 0 {
// Then, check if `b` is -1, which is the "min_value / -1" case.
let minus1 = Scalar::from_int(-1, dest.layout.size);
let b_scalar = b.to_scalar().unwrap();
Expand All @@ -395,6 +396,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
throw_ub_format!("exact_div: {} cannot be divided by {} without remainder", a, b,)
}
}
// `Rem` says this is all right, so we can let `Div` do its job.
self.binop_ignore_overflow(BinOp::Div, a, b, dest)
}
}
Loading

0 comments on commit 1010408

Please sign in to comment.