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 9 pull requests #69144

Merged
merged 36 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
953f6ec
fix lifetime shadowing check in GATs
basil-cow Feb 7, 2020
91b4a24
Enable use after scope detection in the new LLVM pass manager
tmiasko Feb 13, 2020
57a62f5
Add comment to SGX entry code
Feb 13, 2020
4f17dce
StripUnconfigured::in_cfg: simplify with slice patterns
Centril Dec 31, 2019
b8b32a9
simplify config::features
Centril Dec 31, 2019
64ea295
expand: extract error_derive_forbidden_on_non_adt
Centril Dec 31, 2019
10f342a
miri: fix exact_div
RalfJung Feb 13, 2020
acad033
expand: extract error_recursion_limit_reached
Centril Dec 31, 2019
7518492
expand: extract error_wrong_fragment_kind
Centril Dec 31, 2019
fcce5fa
expand: simplify classify_*
Centril Dec 31, 2019
dc6bd6a
expand: simplify flat_map_item
Centril Dec 31, 2019
ec43450
expand: simplify flat_map_item wrt. inline module detection
Centril Dec 31, 2019
9fed2d5
parser: extract common foreign item code for each kind
Centril Jan 31, 2020
7737d0f
parser: unify item list parsing.
Centril Jan 31, 2020
511dfdb
parser: extract `recover_missing_kw_before_item`
Centril Jan 31, 2020
73d5970
parser: introduce `parse_item_kind` as central `ItemInfo` logic.
Centril Jan 31, 2020
20ba687
parser_item_mod: avoid cloning outer attributes
Centril Jan 31, 2020
c202603
parser: remove `Option<Vec<Attribute>>` in `ItemInfo`.
Centril Jan 31, 2020
fd64b3b
parser: make `eat_macro_def` redundant.
Centril Jan 31, 2020
15e07a6
parser: fuse `trait` parsing & layer with `is_path_start_item`
Centril Jan 31, 2020
46d3ef5
parser: extract `recover_const_mut`.
Centril Jan 31, 2020
aaaf0ba
parser: misc small item related improvements & cleanups.
Centril Feb 1, 2020
ad72c3a
parser: inline parse_assoc_macro_invoc
Centril Feb 1, 2020
4706c38
Use HirId in TraitCandidate.
cjgillot Feb 12, 2020
2a899e2
Make TraitCandidate generic.
cjgillot Feb 13, 2020
026dec5
Spelling error "represening" to "representing"
drewrip Feb 13, 2020
23cb749
don't error on network failures
mark-i-m Feb 13, 2020
89f5dcf
Rollup merge of #68728 - Centril:towards-fn-merge, r=petrochenkov
Dylan-DPC Feb 13, 2020
998daf3
Rollup merge of #68938 - Areredify:gat_lifetime_shadowing, r=estebank
Dylan-DPC Feb 13, 2020
fc51170
Rollup merge of #69057 - Centril:clean-expand, r=petrochenkov
Dylan-DPC Feb 13, 2020
b5ee867
Rollup merge of #69108 - cjgillot:trait_candidate, r=Zoxc
Dylan-DPC Feb 13, 2020
8e2772c
Rollup merge of #69125 - jethrogb:jb/cleanup-sgx-entry, r=Dylan-DPC
Dylan-DPC Feb 13, 2020
c8343b8
Rollup merge of #69126 - RalfJung:exact-div, r=oli-obk
Dylan-DPC Feb 13, 2020
a8a2c14
Rollup merge of #69127 - tmiasko:new-pass-manager-use-after-scope, r=…
Dylan-DPC Feb 13, 2020
0bdf568
Rollup merge of #69135 - drewrip:drewrip-spelling, r=jonas-schievink
Dylan-DPC Feb 13, 2020
7704e59
Rollup merge of #69141 - mark-i-m:proper-linkcheck-2, r=Dylan-DPC
Dylan-DPC Feb 13, 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
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