Skip to content

Commit e4931ea

Browse files
committed
Auto merge of #66141 - Centril:rollup-n2fcvp9, r=Centril
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
2 parents 1423bec + 35a5ffc commit e4931ea

File tree

96 files changed

+453
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+453
-466
lines changed

src/librustc/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ This works because `Box` is a pointer, so its size is well-known.
335335
"##,
336336

337337
E0080: r##"
338-
This error indicates that the compiler was unable to sensibly evaluate an
338+
This error indicates that the compiler was unable to sensibly evaluate a
339339
constant expression that had to be evaluated. Attempting to divide by 0
340340
or causing integer overflow are two ways to induce this error. For example:
341341

src/librustc/hir/lowering.rs

-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use syntax::ast;
6565
use syntax::ptr::P as AstP;
6666
use syntax::ast::*;
6767
use syntax::errors;
68-
use syntax::expand::SpecialDerives;
6968
use syntax::print::pprust;
7069
use syntax::parse::token::{self, Nonterminal, Token};
7170
use syntax::tokenstream::{TokenStream, TokenTree};
@@ -184,8 +183,6 @@ pub trait Resolver {
184183
ns: Namespace,
185184
) -> (ast::Path, Res<NodeId>);
186185

187-
fn has_derives(&self, node_id: NodeId, derives: SpecialDerives) -> bool;
188-
189186
fn lint_buffer(&mut self) -> &mut lint::LintBuffer;
190187
}
191188

src/librustc/hir/lowering/item.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use smallvec::SmallVec;
1818
use syntax::attr;
1919
use syntax::ast::*;
2020
use syntax::visit::{self, Visitor};
21-
use syntax::expand::SpecialDerives;
2221
use syntax::source_map::{respan, DesugaringKind, Spanned};
2322
use syntax::symbol::{kw, sym};
2423
use syntax_pos::Span;
@@ -227,13 +226,7 @@ impl LoweringContext<'_> {
227226
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
228227
let mut ident = i.ident;
229228
let mut vis = self.lower_visibility(&i.vis, None);
230-
let mut attrs = self.lower_attrs_extendable(&i.attrs);
231-
if self.resolver.has_derives(i.id, SpecialDerives::PARTIAL_EQ | SpecialDerives::EQ) {
232-
// Add `#[structural_match]` if the item derived both `PartialEq` and `Eq`.
233-
let ident = Ident::new(sym::structural_match, i.span);
234-
attrs.push(attr::mk_attr_outer(attr::mk_word_item(ident)));
235-
}
236-
let attrs = attrs.into();
229+
let attrs = self.lower_attrs(&i.attrs);
237230

238231
if let ItemKind::MacroDef(ref def) = i.kind {
239232
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {

src/librustc/hir/map/definitions.rs

+3-87
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::hash::Hash;
1919
use syntax::ast;
2020
use syntax_pos::symbol::{Symbol, sym};
2121
use syntax_pos::hygiene::ExpnId;
22-
use syntax_pos::{Span, DUMMY_SP};
22+
use syntax_pos::Span;
2323

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

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

447-
// Allocate some other `DefIndex`es that always must exist.
448-
GlobalMetaDataKind::allocate_def_indices(self);
449-
450443
root_index
451444
}
452445

@@ -553,8 +546,7 @@ impl DefPathData {
553546
TypeNs(name) |
554547
ValueNs(name) |
555548
MacroNs(name) |
556-
LifetimeNs(name) |
557-
GlobalMetaData(name) => Some(name),
549+
LifetimeNs(name) => Some(name),
558550

559551
Impl |
560552
CrateRoot |
@@ -572,8 +564,7 @@ impl DefPathData {
572564
TypeNs(name) |
573565
ValueNs(name) |
574566
MacroNs(name) |
575-
LifetimeNs(name) |
576-
GlobalMetaData(name) => {
567+
LifetimeNs(name) => {
577568
name
578569
}
579570
// Note that this does not show up in user print-outs.
@@ -591,78 +582,3 @@ impl DefPathData {
591582
self.as_symbol().to_string()
592583
}
593584
}
594-
595-
// We define the `GlobalMetaDataKind` enum with this macro because we want to
596-
// make sure that we exhaustively iterate over all variants when registering
597-
// the corresponding `DefIndex`es in the `DefTable`.
598-
macro_rules! define_global_metadata_kind {
599-
(pub enum GlobalMetaDataKind {
600-
$($variant:ident),*
601-
}) => (
602-
pub enum GlobalMetaDataKind {
603-
$($variant),*
604-
}
605-
606-
impl GlobalMetaDataKind {
607-
fn allocate_def_indices(definitions: &mut Definitions) {
608-
$({
609-
let instance = GlobalMetaDataKind::$variant;
610-
definitions.create_def_with_parent(
611-
CRATE_DEF_INDEX,
612-
ast::DUMMY_NODE_ID,
613-
DefPathData::GlobalMetaData(instance.name()),
614-
ExpnId::root(),
615-
DUMMY_SP
616-
);
617-
618-
// Make sure calling `def_index` does not crash.
619-
instance.def_index(&definitions.table);
620-
})*
621-
}
622-
623-
pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex {
624-
let def_key = DefKey {
625-
parent: Some(CRATE_DEF_INDEX),
626-
disambiguated_data: DisambiguatedDefPathData {
627-
data: DefPathData::GlobalMetaData(self.name()),
628-
disambiguator: 0,
629-
}
630-
};
631-
632-
// These `DefKey`s are all right after the root,
633-
// so a linear search is fine.
634-
let index = def_path_table.index_to_key
635-
.iter()
636-
.position(|k| *k == def_key)
637-
.unwrap();
638-
639-
DefIndex::from(index)
640-
}
641-
642-
fn name(&self) -> Symbol {
643-
644-
let string = match *self {
645-
$(
646-
GlobalMetaDataKind::$variant => {
647-
concat!("{{GlobalMetaData::", stringify!($variant), "}}")
648-
}
649-
)*
650-
};
651-
652-
Symbol::intern(string)
653-
}
654-
}
655-
)
656-
}
657-
658-
define_global_metadata_kind!(pub enum GlobalMetaDataKind {
659-
Krate,
660-
CrateDeps,
661-
DylibDependencyFormats,
662-
LangItems,
663-
LangItemsMissing,
664-
NativeLibraries,
665-
SourceMap,
666-
Impls,
667-
ExportedSymbols
668-
});

src/librustc/infer/error_reporting/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1234,8 +1234,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12341234
}
12351235
}
12361236

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

12401248
// It reads better to have the error origin as the final
12411249
// thing.

src/librustc/session/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ pub struct Session {
148148
/// Metadata about the allocators for the current crate being compiled.
149149
pub has_global_allocator: Once<bool>,
150150

151-
/// Metadata about the panic handlers for the current crate being compiled.
152-
pub has_panic_handler: Once<bool>,
153-
154151
/// Cap lint level specified by a driver specifically.
155152
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
156153

@@ -1211,7 +1208,6 @@ fn build_session_(
12111208
print_fuel,
12121209
jobserver: jobserver::client(),
12131210
has_global_allocator: Once::new(),
1214-
has_panic_handler: Once::new(),
12151211
driver_lint_caps,
12161212
trait_methods_not_found: Lock::new(Default::default()),
12171213
confused_type_with_std_module: Lock::new(Default::default()),

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12311231
fn suggest_fn_call(
12321232
&self,
12331233
obligation: &PredicateObligation<'tcx>,
1234-
err: &mut DiagnosticBuilder<'tcx>,
1234+
err: &mut DiagnosticBuilder<'_>,
12351235
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
12361236
points_at_arg: bool,
12371237
) {

src/librustc/ty/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3045,4 +3045,9 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30453045
assert_eq!(cnum, LOCAL_CRATE);
30463046
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
30473047
};
3048+
providers.has_panic_handler = |tcx, cnum| {
3049+
assert_eq!(cnum, LOCAL_CRATE);
3050+
// We want to check if the panic handler was defined in this crate
3051+
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
3052+
};
30483053
}

src/librustc/ty/error.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'tcx> ty::TyS<'tcx> {
241241
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
242242
ty::Projection(_) => "associated type".into(),
243243
ty::UnnormalizedProjection(_) => "non-normalized associated type".into(),
244-
ty::Param(_) => "type parameter".into(),
244+
ty::Param(p) => format!("type parameter `{}`", p).into(),
245245
ty::Opaque(..) => "opaque type".into(),
246246
ty::Error => "type error".into(),
247247
}
@@ -254,6 +254,7 @@ impl<'tcx> TyCtxt<'tcx> {
254254
db: &mut DiagnosticBuilder<'_>,
255255
err: &TypeError<'tcx>,
256256
sp: Span,
257+
body_owner_def_id: DefId,
257258
) {
258259
use self::TypeError::*;
259260

@@ -288,7 +289,16 @@ impl<'tcx> TyCtxt<'tcx> {
288289
);
289290
}
290291
},
291-
(ty::Param(_), ty::Param(_)) => {
292+
(ty::Param(expected), ty::Param(found)) => {
293+
let generics = self.generics_of(body_owner_def_id);
294+
let e_span = self.def_span(generics.type_param(expected, self).def_id);
295+
if !sp.contains(e_span) {
296+
db.span_label(e_span, "expected type parameter");
297+
}
298+
let f_span = self.def_span(generics.type_param(found, self).def_id);
299+
if !sp.contains(f_span) {
300+
db.span_label(f_span, "found type parameter");
301+
}
292302
db.note("a type parameter was expected, but a different one was found; \
293303
you might be missing a type parameter or trait bound");
294304
db.note("for more information, visit \
@@ -301,7 +311,12 @@ impl<'tcx> TyCtxt<'tcx> {
301311
(ty::Param(_), ty::Projection(_)) | (ty::Projection(_), ty::Param(_)) => {
302312
db.note("you might be missing a type parameter or trait bound");
303313
}
304-
(ty::Param(_), _) | (_, ty::Param(_)) => {
314+
(ty::Param(p), _) | (_, ty::Param(p)) => {
315+
let generics = self.generics_of(body_owner_def_id);
316+
let p_span = self.def_span(generics.type_param(p, self).def_id);
317+
if !sp.contains(p_span) {
318+
db.span_label(p_span, "this type parameter");
319+
}
305320
db.help("type parameters must be constrained to match other types");
306321
if self.sess.teach(&db.get_code().unwrap()) {
307322
db.help("given a type parameter `T` and a method `foo`:

src/librustc_codegen_utils/symbol_names/v0.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
601601
| DefPathData::Misc
602602
| DefPathData::Impl
603603
| DefPathData::MacroNs(_)
604-
| DefPathData::LifetimeNs(_)
605-
| DefPathData::GlobalMetaData(_) => {
604+
| DefPathData::LifetimeNs(_) => {
606605
bug!("symbol_names: unexpected DefPathData: {:?}", disambiguated_data.data)
607606
}
608607
};

src/librustc_errors/emitter.rs

+8
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ impl Emitter for EmitterWriter {
424424
}
425425
}
426426

427+
/// An emitter that does nothing when emitting a diagnostic.
428+
pub struct SilentEmitter;
429+
430+
impl Emitter for SilentEmitter {
431+
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
432+
fn emit_diagnostic(&mut self, _: &Diagnostic) {}
433+
}
434+
427435
/// maximum number of lines we will print for each error; arbitrary.
428436
pub const MAX_HIGHLIGHT_LINES: usize = 6;
429437
/// maximum number of suggestions to be shown

src/librustc_interface/interface.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ use std::sync::{Arc, Mutex};
1717
use syntax::{self, parse};
1818
use syntax::ast::{self, MetaItemKind};
1919
use syntax::parse::token;
20-
use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap};
20+
use syntax::source_map::{FileName, FileLoader, SourceMap};
2121
use syntax::sess::ParseSess;
2222
use syntax_pos::edition;
23-
use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn};
2423

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

@@ -63,18 +62,9 @@ impl Compiler {
6362

6463
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
6564
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
66-
struct NullEmitter;
67-
impl Emitter for NullEmitter {
68-
fn emit_diagnostic(&mut self, _: &Diagnostic) {}
69-
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
70-
}
71-
7265
syntax::with_default_globals(move || {
7366
let cfg = cfgspecs.into_iter().map(|s| {
74-
75-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
76-
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
77-
let sess = ParseSess::with_span_handler(handler, cm);
67+
let sess = ParseSess::with_silent_emitter();
7868
let filename = FileName::cfg_spec_source_code(&s);
7969
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
8070

src/librustc_metadata/encoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ impl<'tcx> EncodeContext<'tcx> {
542542
let attrs = tcx.hir().krate_attrs();
543543
let has_default_lib_allocator = attr::contains_name(&attrs, sym::default_lib_allocator);
544544
let has_global_allocator = *tcx.sess.has_global_allocator.get();
545-
let has_panic_handler = *tcx.sess.has_panic_handler.try_get().unwrap_or(&false);
546545

547546
let root = self.lazy(CrateRoot {
548547
name: tcx.crate_name(LOCAL_CRATE),
@@ -553,7 +552,7 @@ impl<'tcx> EncodeContext<'tcx> {
553552
panic_strategy: tcx.sess.panic_strategy(),
554553
edition: tcx.sess.edition(),
555554
has_global_allocator: has_global_allocator,
556-
has_panic_handler: has_panic_handler,
555+
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
557556
has_default_lib_allocator: has_default_lib_allocator,
558557
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
559558
proc_macro_decls_static: if is_proc_macro {

src/librustc_mir/interpret/memory.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
314314
align: Align,
315315
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
316316
let align = if M::CHECK_ALIGN { Some(align) } else { None };
317-
self.check_ptr_access_align(sptr, size, align)
317+
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
318318
}
319319

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

0 commit comments

Comments
 (0)