Skip to content

Commit c351775

Browse files
committed
Auto merge of rust-lang#77102 - Dylan-DPC:rollup-2jfrg3u, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - rust-lang#76898 (Record `tcx.def_span` instead of `item.span` in crate metadata) - rust-lang#76939 (emit errors during AbstractConst building) - rust-lang#76965 (Add cfg(target_has_atomic_equal_alignment) and use it for Atomic::from_mut.) - rust-lang#76993 (Changing the alloc() to accept &self instead of &mut self) - rust-lang#76994 (fix small typo in docs and comments) - rust-lang#77017 (Add missing examples on Vec iter types) - rust-lang#77042 (Improve documentation for ToSocketAddrs) - rust-lang#77047 (Miri: more informative deallocation error messages) - rust-lang#77055 (Add #[track_caller] to more panicking Cell functions) Failed merges: r? `@ghost`
2 parents 8b40853 + c3c03f2 commit c351775

File tree

42 files changed

+552
-199
lines changed

Some content is hidden

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

42 files changed

+552
-199
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const GATED_CFGS: &[GatedCfg] = &[
2626
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
2727
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
2828
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
29+
(
30+
sym::target_has_atomic_equal_alignment,
31+
sym::cfg_target_has_atomic,
32+
cfg_fn!(cfg_target_has_atomic),
33+
),
2934
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
3035
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
3136
];

compiler/rustc_lint/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ fn get_nullable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'t
733733
}
734734

735735
/// Check if this enum can be safely exported based on the "nullable pointer optimization". If it
736-
/// can, return the the type that `ty` can be safely converted to, otherwise return `None`.
736+
/// can, return the type that `ty` can be safely converted to, otherwise return `None`.
737737
/// Currently restricted to function pointers, boxes, references, `core::num::NonZero*`,
738738
/// `core::ptr::NonNull`, and `#[repr(transparent)]` newtypes.
739739
/// FIXME: This duplicates code in codegen.

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
1111
use rustc_data_structures::fx::FxHashMap;
1212
use rustc_data_structures::svh::Svh;
1313
use rustc_data_structures::sync::{AtomicCell, Lock, LockGuard, Lrc, OnceCell};
14+
use rustc_errors::ErrorReported;
1415
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
1516
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive};
1617
use rustc_hir as hir;
@@ -1201,13 +1202,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12011202
&self,
12021203
tcx: TyCtxt<'tcx>,
12031204
id: DefIndex,
1204-
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
1205+
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
12051206
self.root
12061207
.tables
12071208
.mir_abstract_consts
12081209
.get(self, id)
12091210
.filter(|_| !self.is_proc_macro(id))
1210-
.map_or(None, |v| Some(v.decode((self, tcx))))
1211+
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
12111212
}
12121213

12131214
fn get_unused_generic_params(&self, id: DefIndex) -> FiniteBitSet<u32> {

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ impl EncodeContext<'a, 'tcx> {
11171117
}
11181118

11191119
let abstract_const = self.tcx.mir_abstract_const(def_id);
1120-
if let Some(abstract_const) = abstract_const {
1120+
if let Ok(Some(abstract_const)) = abstract_const {
11211121
record!(self.tables.mir_abstract_consts[def_id.to_def_id()] <- abstract_const);
11221122
}
11231123
}
@@ -1300,7 +1300,7 @@ impl EncodeContext<'a, 'tcx> {
13001300
});
13011301
record!(self.tables.visibility[def_id] <-
13021302
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
1303-
record!(self.tables.span[def_id] <- item.span);
1303+
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
13041304
record!(self.tables.attributes[def_id] <- item.attrs);
13051305
// FIXME(eddyb) there should be a nicer way to do this.
13061306
match item.kind {

compiler/rustc_middle/src/mir/interpret/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub enum ErrorHandled {
2323
TooGeneric,
2424
}
2525

26+
impl From<ErrorReported> for ErrorHandled {
27+
fn from(err: ErrorReported) -> ErrorHandled {
28+
ErrorHandled::Reported(err)
29+
}
30+
}
31+
2632
CloneTypeFoldableAndLiftImpls! {
2733
ErrorHandled,
2834
}

compiler/rustc_middle/src/mir/predecessors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl PredecessorCache {
3333
self.cache = OnceCell::new();
3434
}
3535

36-
/// Returns the the predecessor graph for this MIR.
36+
/// Returns the predecessor graph for this MIR.
3737
#[inline]
3838
pub(super) fn compute(
3939
&self,

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ rustc_queries! {
247247
/// Try to build an abstract representation of the given constant.
248248
query mir_abstract_const(
249249
key: DefId
250-
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
250+
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
251251
desc {
252252
|tcx| "building an abstract representation for {}", tcx.def_path_str(key),
253253
}
254254
}
255255
/// Try to build an abstract representation of the given constant.
256256
query mir_abstract_const_of_const_arg(
257257
key: (LocalDefId, DefId)
258-
) -> Option<&'tcx [mir::abstract_const::Node<'tcx>]> {
258+
) -> Result<Option<&'tcx [mir::abstract_const::Node<'tcx>]>, ErrorReported> {
259259
desc {
260260
|tcx|
261261
"building an abstract representation for the const argument {}",

compiler/rustc_mir/src/borrow_check/member_constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
7171
/// Pushes a member constraint into the set.
7272
///
7373
/// The input member constraint `m_c` is in the form produced by
74-
/// the the `rustc_middle::infer` code.
74+
/// the `rustc_middle::infer` code.
7575
///
7676
/// The `to_region_vid` callback fn is used to convert the regions
7777
/// within into `RegionVid` format -- it typically consults the

compiler/rustc_mir/src/interpret/memory.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
285285
None => {
286286
// Deallocating global memory -- always an error
287287
return Err(match self.tcx.get_global_alloc(ptr.alloc_id) {
288-
Some(GlobalAlloc::Function(..)) => err_ub_format!("deallocating a function"),
288+
Some(GlobalAlloc::Function(..)) => {
289+
err_ub_format!("deallocating {}, which is a function", ptr.alloc_id)
290+
}
289291
Some(GlobalAlloc::Static(..) | GlobalAlloc::Memory(..)) => {
290-
err_ub_format!("deallocating static memory")
292+
err_ub_format!("deallocating {}, which is static memory", ptr.alloc_id)
291293
}
292294
None => err_ub!(PointerUseAfterFree(ptr.alloc_id)),
293295
}
@@ -297,15 +299,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
297299

298300
if alloc_kind != kind {
299301
throw_ub_format!(
300-
"deallocating {} memory using {} deallocation operation",
302+
"deallocating {}, which is {} memory, using {} deallocation operation",
303+
ptr.alloc_id,
301304
alloc_kind,
302305
kind
303306
);
304307
}
305308
if let Some((size, align)) = old_size_and_align {
306309
if size != alloc.size || align != alloc.align {
307310
throw_ub_format!(
308-
"incorrect layout on deallocation: allocation has size {} and alignment {}, but gave size {} and alignment {}",
311+
"incorrect layout on deallocation: {} has size {} and alignment {}, but gave size {} and alignment {}",
312+
ptr.alloc_id,
309313
alloc.size.bytes(),
310314
alloc.align.bytes(),
311315
size.bytes(),

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
321321
let target_block = self.cfg.start_new_block();
322322
let mut schedule_drops = true;
323323
// We keep a stack of all of the bindings and type asciptions
324-
// from the the parent candidates that we visit, that also need to
324+
// from the parent candidates that we visit, that also need to
325325
// be bound for each candidate.
326326
traverse_candidate(
327327
candidate,

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a> Parser<'a> {
6767

6868
/// Parse a type suitable for a function or function pointer parameter.
6969
/// The difference from `parse_ty` is that this version allows `...`
70-
/// (`CVarArgs`) at the top level of the the type.
70+
/// (`CVarArgs`) at the top level of the type.
7171
pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, P<Ty>> {
7272
self.parse_ty_common(AllowPlus::Yes, RecoverQPath::Yes, AllowCVariadic::Yes)
7373
}

compiler/rustc_session/src/config.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::fx::FxHashSet;
1212
use rustc_data_structures::impl_stable_hash_via_hash;
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1414

15+
use rustc_target::abi::{Align, TargetDataLayout};
1516
use rustc_target::spec::{Target, TargetTriple};
1617

1718
use crate::parse::CrateConfig;
@@ -748,6 +749,9 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
748749
let min_atomic_width = sess.target.target.min_atomic_width();
749750
let max_atomic_width = sess.target.target.max_atomic_width();
750751
let atomic_cas = sess.target.target.options.atomic_cas;
752+
let layout = TargetDataLayout::parse(&sess.target.target).unwrap_or_else(|err| {
753+
sess.fatal(&err);
754+
});
751755

752756
let mut ret = FxHashSet::default();
753757
ret.reserve(6); // the minimum number of insertions
@@ -769,18 +773,27 @@ pub fn default_configuration(sess: &Session) -> CrateConfig {
769773
if sess.target.target.options.has_elf_tls {
770774
ret.insert((sym::target_thread_local, None));
771775
}
772-
for &i in &[8, 16, 32, 64, 128] {
776+
for &(i, align) in &[
777+
(8, layout.i8_align.abi),
778+
(16, layout.i16_align.abi),
779+
(32, layout.i32_align.abi),
780+
(64, layout.i64_align.abi),
781+
(128, layout.i128_align.abi),
782+
] {
773783
if i >= min_atomic_width && i <= max_atomic_width {
774-
let mut insert_atomic = |s| {
784+
let mut insert_atomic = |s, align: Align| {
775785
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
776786
if atomic_cas {
777787
ret.insert((sym::target_has_atomic, Some(Symbol::intern(s))));
778788
}
789+
if align.bits() == i {
790+
ret.insert((sym::target_has_atomic_equal_alignment, Some(Symbol::intern(s))));
791+
}
779792
};
780793
let s = i.to_string();
781-
insert_atomic(&s);
794+
insert_atomic(&s, align);
782795
if &s == wordsz {
783-
insert_atomic("ptr");
796+
insert_atomic("ptr", layout.pointer_align.abi);
784797
}
785798
}
786799
}

compiler/rustc_span/src/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ symbols! {
110110
// called `sym::proc_macro` because then it's easy to mistakenly think it
111111
// represents "proc_macro".
112112
//
113-
// As well as the symbols listed, there are symbols for the the strings
113+
// As well as the symbols listed, there are symbols for the strings
114114
// "0", "1", ..., "9", which are accessible via `sym::integer`.
115115
//
116116
// The proc macro will abort if symbols are not in alphabetical order (as
@@ -1071,6 +1071,7 @@ symbols! {
10711071
target_feature,
10721072
target_feature_11,
10731073
target_has_atomic,
1074+
target_has_atomic_equal_alignment,
10741075
target_has_atomic_load_store,
10751076
target_os,
10761077
target_pointer_width,

compiler/rustc_target/src/spec/wasm32_wasi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! ## No interop with C required
3131
//!
3232
//! By default the `crt-static` target feature is enabled, and when enabled
33-
//! this means that the the bundled version of `libc.a` found in `liblibc.rlib`
33+
//! this means that the bundled version of `libc.a` found in `liblibc.rlib`
3434
//! is used. This isn't intended really for interoperation with a C because it
3535
//! may be the case that Rust's bundled C library is incompatible with a
3636
//! foreign-compiled C library. In this use case, though, we use `rust-lld` and

compiler/rustc_trait_selection/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(drain_filter)]
1717
#![feature(in_band_lifetimes)]
18+
#![feature(never_type)]
1819
#![feature(crate_visibility_modifier)]
1920
#![feature(or_patterns)]
2021
#![recursion_limit = "512"] // For rustdoc

0 commit comments

Comments
 (0)