Skip to content

Commit

Permalink
Auto merge of #66141 - Centril:rollup-n2fcvp9, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - #65892 (Remove `PartialEq` and `Eq` from the `SpecialDerives`.)
 - #66014 (Show type parameter name and definition in type mismatch error messages )
 - #66027 (Move has_panic_handler to query)
 - #66054 (syntax: Avoid span arithmetic for delimiter tokens)
 - #66068 (use silent emitter for rustdoc highlighting pass)
 - #66081 (let caller of check_ptr_access_align control the error message)
 - #66093 (Do not ICE with a precision flag in formatting str and no format arguments)
 - #66098 (Detect `::` -> `:` typo when involving turbofish)
 - #66101 (Tweak type mismatch caused by break on tail expr)
 - #66106 (Fix typo in explanation of `E0080`)
 - #66115 (rustc: remove "GlobalMetaData" dead code from hir::map::definitions.)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Nov 6, 2019
2 parents 1423bec + 35a5ffc commit e4931ea
Show file tree
Hide file tree
Showing 96 changed files with 453 additions and 466 deletions.
2 changes: 1 addition & 1 deletion src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ This works because `Box` is a pointer, so its size is well-known.
"##,

E0080: r##"
This error indicates that the compiler was unable to sensibly evaluate an
This error indicates that the compiler was unable to sensibly evaluate a
constant expression that had to be evaluated. Attempting to divide by 0
or causing integer overflow are two ways to induce this error. For example:
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use syntax::ast;
use syntax::ptr::P as AstP;
use syntax::ast::*;
use syntax::errors;
use syntax::expand::SpecialDerives;
use syntax::print::pprust;
use syntax::parse::token::{self, Nonterminal, Token};
use syntax::tokenstream::{TokenStream, TokenTree};
Expand Down Expand Up @@ -184,8 +183,6 @@ pub trait Resolver {
ns: Namespace,
) -> (ast::Path, Res<NodeId>);

fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;

fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
}

Expand Down
9 changes: 1 addition & 8 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use smallvec::SmallVec;
use syntax::attr;
use syntax::ast::*;
use syntax::visit::{self, Visitor};
use syntax::expand::SpecialDerives;
use syntax::source_map::{respan, DesugaringKind, Spanned};
use syntax::symbol::{kw, sym};
use syntax_pos::Span;
Expand Down Expand Up @@ -227,13 +226,7 @@ impl LoweringContext<'_> {
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
let mut ident = i.ident;
let mut vis = self.lower_visibility(&i.vis, None);
let mut attrs = self.lower_attrs_extendable(&i.attrs);
if self.resolver.has_derives(i.id, SpecialDerives::PARTIAL_EQ | SpecialDerives::EQ) {
// Add `#[structural_match]` if the item derived both `PartialEq` and `Eq`.
let ident = Ident::new(sym::structural_match, i.span);
attrs.push(attr::mk_attr_outer(attr::mk_word_item(ident)));
}
let attrs = attrs.into();
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) {
Expand Down
90 changes: 3 additions & 87 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::hash::Hash;
use syntax::ast;
use syntax_pos::symbol::{Symbol, sym};
use syntax_pos::hygiene::ExpnId;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::Span;

/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
Expand Down Expand Up @@ -310,10 +310,6 @@ pub enum DefPathData {
AnonConst,
/// An `impl Trait` type node.
ImplTrait,
/// Identifies a piece of crate metadata that is global to a whole crate
/// (as opposed to just one item). `GlobalMetaData` components are only
/// supposed to show up right below the crate root.
GlobalMetaData(Symbol),
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
Expand Down Expand Up @@ -444,9 +440,6 @@ impl Definitions {
self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index);
self.set_invocation_parent(ExpnId::root(), root_index);

// Allocate some other `DefIndex`es that always must exist.
GlobalMetaDataKind::allocate_def_indices(self);

root_index
}

Expand Down Expand Up @@ -553,8 +546,7 @@ impl DefPathData {
TypeNs(name) |
ValueNs(name) |
MacroNs(name) |
LifetimeNs(name) |
GlobalMetaData(name) => Some(name),
LifetimeNs(name) => Some(name),

Impl |
CrateRoot |
Expand All @@ -572,8 +564,7 @@ impl DefPathData {
TypeNs(name) |
ValueNs(name) |
MacroNs(name) |
LifetimeNs(name) |
GlobalMetaData(name) => {
LifetimeNs(name) => {
name
}
// Note that this does not show up in user print-outs.
Expand All @@ -591,78 +582,3 @@ impl DefPathData {
self.as_symbol().to_string()
}
}

// We define the `GlobalMetaDataKind` enum with this macro because we want to
// make sure that we exhaustively iterate over all variants when registering
// the corresponding `DefIndex`es in the `DefTable`.
macro_rules! define_global_metadata_kind {
(pub enum GlobalMetaDataKind {
$($variant:ident),*
}) => (
pub enum GlobalMetaDataKind {
$($variant),*
}

impl GlobalMetaDataKind {
fn allocate_def_indices(definitions: &mut Definitions) {
$({
let instance = GlobalMetaDataKind::$variant;
definitions.create_def_with_parent(
CRATE_DEF_INDEX,
ast::DUMMY_NODE_ID,
DefPathData::GlobalMetaData(instance.name()),
ExpnId::root(),
DUMMY_SP
);

// Make sure calling `def_index` does not crash.
instance.def_index(&definitions.table);
})*
}

pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex {
let def_key = DefKey {
parent: Some(CRATE_DEF_INDEX),
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::GlobalMetaData(self.name()),
disambiguator: 0,
}
};

// These `DefKey`s are all right after the root,
// so a linear search is fine.
let index = def_path_table.index_to_key
.iter()
.position(|k| *k == def_key)
.unwrap();

DefIndex::from(index)
}

fn name(&self) -> Symbol {

let string = match *self {
$(
GlobalMetaDataKind::$variant => {
concat!("{{GlobalMetaData::", stringify!($variant), "}}")
}
)*
};

Symbol::intern(string)
}
}
)
}

define_global_metadata_kind!(pub enum GlobalMetaDataKind {
Krate,
CrateDeps,
DylibDependencyFormats,
LangItems,
LangItemsMissing,
NativeLibraries,
SourceMap,
Impls,
ExportedSymbols
});
10 changes: 9 additions & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

// In some (most?) cases cause.body_id points to actual body, but in some cases
// it's a actual definition. According to the comments (e.g. in
// librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter
// is relied upon by some other code. This might (or might not) need cleanup.
let body_owner_def_id = self.tcx.hir().opt_local_def_id(cause.body_id)
.unwrap_or_else(|| {
self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
});
self.check_and_note_conflicting_crates(diag, terr, span);
self.tcx.note_and_explain_type_err(diag, terr, span);
self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);

// It reads better to have the error origin as the final
// thing.
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ pub struct Session {
/// Metadata about the allocators for the current crate being compiled.
pub has_global_allocator: Once<bool>,

/// Metadata about the panic handlers for the current crate being compiled.
pub has_panic_handler: Once<bool>,

/// Cap lint level specified by a driver specifically.
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,

Expand Down Expand Up @@ -1211,7 +1208,6 @@ fn build_session_(
print_fuel,
jobserver: jobserver::client(),
has_global_allocator: Once::new(),
has_panic_handler: Once::new(),
driver_lint_caps,
trait_methods_not_found: Lock::new(Default::default()),
confused_type_with_std_module: Lock::new(Default::default()),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn suggest_fn_call(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut DiagnosticBuilder<'tcx>,
err: &mut DiagnosticBuilder<'_>,
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
points_at_arg: bool,
) {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE);
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
};
providers.has_panic_handler = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
// We want to check if the panic handler was defined in this crate
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
};
}
21 changes: 18 additions & 3 deletions src/librustc/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
ty::Projection(_) => "associated type".into(),
ty::UnnormalizedProjection(_) => "non-normalized associated type".into(),
ty::Param(_) => "type parameter".into(),
ty::Param(p) => format!("type parameter `{}`", p).into(),
ty::Opaque(..) => "opaque type".into(),
ty::Error => "type error".into(),
}
Expand All @@ -254,6 +254,7 @@ impl<'tcx> TyCtxt<'tcx> {
db: &mut DiagnosticBuilder<'_>,
err: &TypeError<'tcx>,
sp: Span,
body_owner_def_id: DefId,
) {
use self::TypeError::*;

Expand Down Expand Up @@ -288,7 +289,16 @@ impl<'tcx> TyCtxt<'tcx> {
);
}
},
(ty::Param(_), ty::Param(_)) => {
(ty::Param(expected), ty::Param(found)) => {
let generics = self.generics_of(body_owner_def_id);
let e_span = self.def_span(generics.type_param(expected, self).def_id);
if !sp.contains(e_span) {
db.span_label(e_span, "expected type parameter");
}
let f_span = self.def_span(generics.type_param(found, self).def_id);
if !sp.contains(f_span) {
db.span_label(f_span, "found type parameter");
}
db.note("a type parameter was expected, but a different one was found; \
you might be missing a type parameter or trait bound");
db.note("for more information, visit \
Expand All @@ -301,7 +311,12 @@ impl<'tcx> TyCtxt<'tcx> {
(ty::Param(_), ty::Projection(_)) | (ty::Projection(_), ty::Param(_)) => {
db.note("you might be missing a type parameter or trait bound");
}
(ty::Param(_), _) | (_, ty::Param(_)) => {
(ty::Param(p), _) | (_, ty::Param(p)) => {
let generics = self.generics_of(body_owner_def_id);
let p_span = self.def_span(generics.type_param(p, self).def_id);
if !sp.contains(p_span) {
db.span_label(p_span, "this type parameter");
}
db.help("type parameters must be constrained to match other types");
if self.sess.teach(&db.get_code().unwrap()) {
db.help("given a type parameter `T` and a method `foo`:
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_utils/symbol_names/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
| DefPathData::Misc
| DefPathData::Impl
| DefPathData::MacroNs(_)
| DefPathData::LifetimeNs(_)
| DefPathData::GlobalMetaData(_) => {
| DefPathData::LifetimeNs(_) => {
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
}
};
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ impl Emitter for EmitterWriter {
}
}

/// An emitter that does nothing when emitting a diagnostic.
pub struct SilentEmitter;

impl Emitter for SilentEmitter {
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
fn emit_diagnostic(&mut self, _: &Diagnostic) {}
}

/// maximum number of lines we will print for each error; arbitrary.
pub const MAX_HIGHLIGHT_LINES: usize = 6;
/// maximum number of suggestions to be shown
Expand Down
14 changes: 2 additions & 12 deletions src/librustc_interface/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ use std::sync::{Arc, Mutex};
use syntax::{self, parse};
use syntax::ast::{self, MetaItemKind};
use syntax::parse::token;
use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap};
use syntax::source_map::{FileName, FileLoader, SourceMap};
use syntax::sess::ParseSess;
use syntax_pos::edition;
use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn};

pub type Result<T> = result::Result<T, ErrorReported>;

Expand Down Expand Up @@ -63,18 +62,9 @@ impl Compiler {

/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
struct NullEmitter;
impl Emitter for NullEmitter {
fn emit_diagnostic(&mut self, _: &Diagnostic) {}
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
}

syntax::with_default_globals(move || {
let cfg = cfgspecs.into_iter().map(|s| {

let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
let sess = ParseSess::with_span_handler(handler, cm);
let sess = ParseSess::with_silent_emitter();
let filename = FileName::cfg_spec_source_code(&s);
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> {
let attrs = tcx.hir().krate_attrs();
let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator);
let has_global_allocator = *tcx.sess.has_global_allocator.get();
let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false);

let root = self.lazy(CrateRoot {
name: tcx.crate_name(LOCAL_CRATE),
Expand All @@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> {
panic_strategy: tcx.sess.panic_strategy(),
edition: tcx.sess.edition(),
has_global_allocator: has_global_allocator,
has_panic_handler: has_panic_handler,
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
has_default_lib_allocator: has_default_lib_allocator,
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
proc_macro_decls_static: if is_proc_macro {
Expand Down
10 changes: 6 additions & 4 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
align: Align,
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
let align = if M::CHECK_ALIGN { Some(align) } else { None };
self.check_ptr_access_align(sptr, size, align)
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
}

/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
/// is `Some` (overriding `M::CHECK_ALIGN`).
pub(super) fn check_ptr_access_align(
/// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
/// the error message for the out-of-bounds case.
pub fn check_ptr_access_align(
&self,
sptr: Scalar<M::PointerTag>,
size: Size,
align: Option<Align>,
msg: CheckInAllocMsg,
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> {
if offset % align.bytes() == 0 {
Expand Down Expand Up @@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// It is sufficient to check this for the end pointer. The addition
// checks for overflow.
let end_ptr = ptr.offset(size, self)?;
end_ptr.check_inbounds_alloc(allocation_size, CheckInAllocMsg::MemoryAccessTest)?;
end_ptr.check_inbounds_alloc(allocation_size, msg)?;
// Test align. Check this last; if both bounds and alignment are violated
// we want the error to be about the bounds.
if let Some(align) = align {
Expand Down
Loading

0 comments on commit e4931ea

Please sign in to comment.