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 #70008

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Mateusz Mikuła <matti@marinelayer.io> <mati865@gmail.com>
Mateusz Mikuła <matti@marinelayer.io> <mati865@users.noreply.github.com>
Matt Brubeck <mbrubeck@limpet.net> <mbrubeck@cs.hmc.edu>
Matthew Auld <matthew.auld@intel.com>
Matthew Kraai <kraai@ftbfs.org>
Matthew Kraai <kraai@ftbfs.org> <matt.kraai@abbott.com>
Matthew Kraai <kraai@ftbfs.org> <mkraai@its.jnj.com>
Matthew McPherrin <matthew@mcpherrin.ca> <matt@mcpherrin.ca>
Matthijs Hofstra <thiezz@gmail.com>
Melody Horn <melody@boringcactus.com> <mathphreak@gmail.com>
Expand Down
53 changes: 7 additions & 46 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,37 +220,6 @@ impl<S: Sip> Hasher<S> {
self.state.v3 = self.k1 ^ 0x7465646279746573;
self.ntail = 0;
}

// Specialized write function that is only valid for buffers with len <= 8.
// It's used to force inlining of write_u8 and write_usize, those would normally be inlined
// except for composite types (that includes slices and str hashing because of delimiter).
// Without this extra push the compiler is very reluctant to inline delimiter writes,
// degrading performance substantially for the most common use cases.
#[inline]
fn short_write(&mut self, msg: &[u8]) {
debug_assert!(msg.len() <= 8);
let length = msg.len();
self.length += length;

let needed = 8 - self.ntail;
let fill = cmp::min(length, needed);
if fill == 8 {
self.tail = unsafe { load_int_le!(msg, 0, u64) };
} else {
self.tail |= unsafe { u8to64_le(msg, 0, fill) } << (8 * self.ntail);
if length < needed {
self.ntail += length;
return;
}
}
self.state.v3 ^= self.tail;
S::c_rounds(&mut self.state);
self.state.v0 ^= self.tail;

// Buffered tail is now flushed, process new input.
self.ntail = length - needed;
self.tail = unsafe { u8to64_le(msg, needed, self.ntail) };
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -280,21 +249,13 @@ impl super::Hasher for SipHasher13 {
}

impl<S: Sip> super::Hasher for Hasher<S> {
// see short_write comment for explanation
#[inline]
fn write_usize(&mut self, i: usize) {
let bytes = unsafe {
crate::slice::from_raw_parts(&i as *const usize as *const u8, mem::size_of::<usize>())
};
self.short_write(bytes);
}

// see short_write comment for explanation
#[inline]
fn write_u8(&mut self, i: u8) {
self.short_write(&[i]);
}

// Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
// for this type. We could add them, copy the `short_write` implementation
// in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
// methods to `SipHasher`, `SipHasher13`, and `DefaultHasher`. This would
// greatly speed up integer hashing by those hashers, at the cost of
// slightly slowing down compile speeds on some benchmarks. See #69152 for
// details.
#[inline]
fn write(&mut self, msg: &[u8]) {
let length = msg.len();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ impl MacDelimiter {
}

/// Represents a macro definition.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct MacroDef {
pub body: P<MacArgs>,
/// `true` if macro was defined with `macro_rules`.
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc::bug;
use rustc_ast::ast::*;
use rustc_ast::attr;
use rustc_ast::node_id::NodeMap;
use rustc_ast::ptr::P;
use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
Expand Down Expand Up @@ -219,18 +220,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut vis = self.lower_visibility(&i.vis, None);
let attrs = self.lower_attrs(&i.attrs);

if let ItemKind::MacroDef(ref def) = i.kind {
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
let body = self.lower_token_stream(def.body.inner_tokens());
if let ItemKind::MacroDef(MacroDef { ref body, legacy }) = i.kind {
if !legacy || attr::contains_name(&i.attrs, sym::macro_export) {
let hir_id = self.lower_node_id(i.id);
let body = P(self.lower_mac_args(body));
self.exported_macros.push(hir::MacroDef {
name: ident.name,
ident,
vis,
attrs,
hir_id,
span: i.span,
body,
legacy: def.legacy,
ast: MacroDef { body, legacy },
});
} else {
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ E0689: include_str!("./error_codes/E0689.md"),
E0690: include_str!("./error_codes/E0690.md"),
E0691: include_str!("./error_codes/E0691.md"),
E0692: include_str!("./error_codes/E0692.md"),
E0693: include_str!("./error_codes/E0693.md"),
E0695: include_str!("./error_codes/E0695.md"),
E0697: include_str!("./error_codes/E0697.md"),
E0698: include_str!("./error_codes/E0698.md"),
Expand Down Expand Up @@ -595,7 +596,6 @@ E0748: include_str!("./error_codes/E0748.md"),
E0667, // `impl Trait` in projections
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0693, // incorrect `repr(align)` attribute format
// E0694, // an unknown tool name found in scoped attributes
E0696, // `continue` pointing to a labeled block
// E0702, // replaced with a generic attribute input check
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0117.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `Drop` trait was implemented on a non-struct type.
Only traits defined in the current crate can be implemented for arbitrary types.

Erroneous code example:

Expand Down
19 changes: 19 additions & 0 deletions src/librustc_error_codes/error_codes/E0693.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
`align` representation hint was incorrectly declared.

Erroneous code examples:

```compile_fail,E0693
#[repr(align=8)] // error!
struct Align8(i8);

#[repr(align="8")] // error!
struct Align8(i8);
```

This is a syntax error at the level of attribute declarations. The proper
syntax for `align` representation hint is the following:

```
#[repr(align(8))] // ok!
struct Align8(i8);
```
4 changes: 2 additions & 2 deletions src/librustc_hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ impl DefKind {
DefKind::Union => "union",
DefKind::Trait => "trait",
DefKind::ForeignTy => "foreign type",
// FIXME: Update the description to "assoc fn"
DefKind::AssocFn => "method",
DefKind::AssocFn => "associated function",
DefKind::Const => "constant",
DefKind::AssocConst => "associated constant",
DefKind::TyParam => "type parameter",
Expand All @@ -123,6 +122,7 @@ impl DefKind {
DefKind::AssocTy
| DefKind::AssocConst
| DefKind::AssocOpaqueTy
| DefKind::AssocFn
| DefKind::Enum
| DefKind::OpaqueTy => "an",
DefKind::Macro(macro_kind) => macro_kind.article(),
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rustc_ast::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyl
pub use rustc_ast::ast::{BorrowKind, ImplPolarity, IsAuto};
pub use rustc_ast::ast::{CaptureBy, Movability, Mutability};
use rustc_ast::node_id::NodeMap;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
Expand Down Expand Up @@ -722,13 +721,12 @@ impl Crate<'_> {
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub struct MacroDef<'hir> {
pub name: Name,
pub ident: Ident,
pub vis: Visibility<'hir>,
pub attrs: &'hir [Attribute],
pub hir_id: HirId,
pub span: Span,
pub body: TokenStream,
pub legacy: bool,
pub ast: ast::MacroDef,
}

/// A block of statements `{ .. }`, which may have a label (in this case the
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {

pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
visitor.visit_id(macro_def.hir_id);
visitor.visit_name(macro_def.span, macro_def.name);
visitor.visit_ident(macro_def.ident);
walk_list!(visitor, visit_attribute, macro_def.attrs);
}

Expand Down
16 changes: 4 additions & 12 deletions src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use rustc::ty::{self, TyCtxt};
use rustc_ast::ast;
use rustc_ast::attr;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::ptr::P;
use rustc_ast::tokenstream::DelimSpan;
use rustc_data_structures::svh::Svh;
use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
Expand Down Expand Up @@ -415,34 +413,28 @@ impl CStore {
}

let span = data.get_span(id.index, sess);
let dspan = DelimSpan::from_single(span);
let rmeta::MacroDef { body, legacy } = data.get_macro(id.index, sess);

// Mark the attrs as used
let attrs = data.get_item_attrs(id.index, sess);
for attr in attrs.iter() {
attr::mark_used(attr);
}

let name = data
let ident = data
.def_key(id.index)
.disambiguated_data
.data
.get_opt_name()
.map(ast::Ident::with_dummy_span) // FIXME: cross-crate hygiene
.expect("no name in load_macro");
sess.imported_macro_spans.borrow_mut().insert(span, (name.to_string(), span));

LoadedMacro::MacroDef(
ast::Item {
// FIXME: cross-crate hygiene
ident: ast::Ident::with_dummy_span(name),
ident,
id: ast::DUMMY_NODE_ID,
span,
attrs: attrs.iter().cloned().collect(),
kind: ast::ItemKind::MacroDef(ast::MacroDef {
body: P(ast::MacArgs::Delimited(dspan, ast::MacDelimiter::Brace, body)),
legacy,
}),
kind: ast::ItemKind::MacroDef(data.get_macro(id.index, sess)),
vis: source_map::respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
tokens: None,
},
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,7 @@ impl EncodeContext<'tcx> {
/// Serialize the text of exported macros
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(MacroDef {
body: macro_def.body.clone(),
legacy: macro_def.legacy,
})));
record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);
record!(self.per_def.span[def_id] <- macro_def.span);
record!(self.per_def.attributes[def_id] <- macro_def.attrs);
Expand Down
9 changes: 1 addition & 8 deletions src/librustc_metadata/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use rustc::mir;
use rustc::session::config::SymbolManglingVersion;
use rustc::session::CrateDisambiguator;
use rustc::ty::{self, ReprOptions, Ty};
use rustc_ast::ast;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::ast::{self, MacroDef};
use rustc_attr as attr;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::MetadataRef;
Expand Down Expand Up @@ -323,12 +322,6 @@ struct ModData {
reexports: Lazy<[Export<hir::HirId>]>,
}

#[derive(RustcEncodable, RustcDecodable)]
struct MacroDef {
body: TokenStream,
legacy: bool,
}

#[derive(RustcEncodable, RustcDecodable)]
struct FnData {
asyncness: hir::IsAsync,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
}

fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
if attr::find_transparency(&md.attrs, md.legacy).0 != Transparency::Opaque {
if attr::find_transparency(&md.attrs, md.ast.legacy).0 != Transparency::Opaque {
self.update(md.hir_id, Some(AccessLevel::Public));
return;
}
Expand Down
13 changes: 0 additions & 13 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,19 +794,6 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => return None,
};

// If the callee is an imported macro from an external crate, need to get
// the source span and name from the session, as their spans are localized
// when read in, and no longer correspond to the source.
if let Some(mac) = self.tcx.sess.imported_macro_spans.borrow().get(&callee.def_site) {
let &(ref mac_name, mac_span) = mac;
let mac_span = self.span_from_span(mac_span);
return Some(MacroRef {
span: callsite_span,
qualname: mac_name.clone(), // FIXME: generate the real qualname
callee_span: mac_span,
});
}

let callee_span = self.span_from_span(callee.def_site);
Some(MacroRef {
span: callsite_span,
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ pub struct Session {
/// The maximum blocks a const expression can evaluate.
pub const_eval_limit: Once<usize>,

/// Map from imported macro spans (which consist of
/// the localized span for the macro body) to the
/// macro name and definition span in the source crate.
pub imported_macro_spans: OneThread<RefCell<FxHashMap<Span, (String, Span)>>>,

incr_comp_session: OneThread<RefCell<IncrCompSession>>,
/// Used for incremental compilation tests. Will only be populated if
/// `-Zquery-dep-graph` is specified.
Expand Down Expand Up @@ -1080,7 +1075,6 @@ fn build_session_(
recursion_limit: Once::new(),
type_length_limit: Once::new(),
const_eval_limit: Once::new(),
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker,
prof,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
}

fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef) {
self.visit_testable(macro_def.name.to_string(), &macro_def.attrs, |_| ());
self.visit_testable(macro_def.ident.to_string(), &macro_def.attrs, |_| ());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,16 +620,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
def: &'tcx hir::MacroDef,
renamed: Option<ast::Name>,
) -> Macro<'tcx> {
debug!("visit_local_macro: {}", def.name);
let tts = def.body.trees().collect::<Vec<_>>();
debug!("visit_local_macro: {}", def.ident);
let tts = def.ast.body.inner_tokens().trees().collect::<Vec<_>>();
// Extract the spans of all matchers. They represent the "interface" of the macro.
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();

Macro {
hid: def.hir_id,
def_id: self.cx.tcx.hir().local_def_id(def.hir_id),
attrs: &def.attrs,
name: renamed.unwrap_or(def.name),
name: renamed.unwrap_or(def.ident.name),
whence: def.span,
matchers,
imported_from: None,
Expand Down
12 changes: 8 additions & 4 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,14 @@ fn print_to<T>(
{
let result = local_s
.try_with(|s| {
if let Ok(mut borrowed) = s.try_borrow_mut() {
if let Some(w) = borrowed.as_mut() {
return w.write_fmt(args);
}
// Note that we completely remove a local sink to write to in case
// our printing recursively panics/prints, so the recursive
// panic/print goes to the global sink instead of our local sink.
let prev = s.borrow_mut().take();
if let Some(mut w) = prev {
let result = w.write_fmt(args);
*s.borrow_mut() = Some(w);
return result;
}
global_s().write_fmt(args)
})
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-item/associated-item-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | Enum::mispellable();
| ^^^^^^^^^^^
| |
| variant or associated item not found in `Enum`
| help: there is a method with a similar name: `misspellable`
| help: there is an associated function with a similar name: `misspellable`

error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:18:11
Expand Down
Loading