Skip to content

Commit 34628e5

Browse files
committed
Auto merge of rust-lang#80867 - JohnTitor:rollup-tvqw555, r=JohnTitor
Rollup of 9 pull requests Successful merges: - rust-lang#79502 (Implement From<char> for u64 and u128.) - rust-lang#79968 (Improve core::ptr::drop_in_place debuginfo) - rust-lang#80774 (Fix safety comment) - rust-lang#80801 (Use correct span for structured suggestion) - rust-lang#80803 (Remove useless `fill_in` function) - rust-lang#80820 (Support `download-ci-llvm` on NixOS) - rust-lang#80825 (Remove under-used ImplPolarity enum) - rust-lang#80850 (Allow #[rustc_builtin_macro = "name"]) - rust-lang#80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7a19392 + 19b8c65 commit 34628e5

Some content is hidden

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

45 files changed

+299
-171
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Editi
4848
let mut register = |name, kind| {
4949
resolver.register_builtin_macro(
5050
Ident::with_dummy_span(name),
51-
SyntaxExtension { is_builtin: true, ..SyntaxExtension::default(kind, edition) },
51+
SyntaxExtension::default(kind, edition),
5252
)
5353
};
5454
macro register_bang($($name:ident: $f:expr,)*) {

compiler/rustc_expand/src/base.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,7 @@ pub struct SyntaxExtension {
728728
pub edition: Edition,
729729
/// Built-in macros have a couple of special properties like availability
730730
/// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
731-
pub is_builtin: bool,
732-
/// We have to identify macros providing a `Copy` impl early for compatibility reasons.
733-
pub is_derive_copy: bool,
731+
pub builtin_name: Option<Symbol>,
734732
}
735733

736734
impl SyntaxExtension {
@@ -758,8 +756,7 @@ impl SyntaxExtension {
758756
deprecation: None,
759757
helper_attrs: Vec::new(),
760758
edition,
761-
is_builtin: false,
762-
is_derive_copy: false,
759+
builtin_name: None,
763760
kind,
764761
}
765762
}
@@ -785,7 +782,9 @@ impl SyntaxExtension {
785782
}
786783
}
787784

788-
let is_builtin = sess.contains_name(attrs, sym::rustc_builtin_macro);
785+
let builtin_name = sess
786+
.find_by_name(attrs, sym::rustc_builtin_macro)
787+
.map(|a| a.value_str().unwrap_or(name));
789788
let (stability, const_stability) = attr::find_stability(&sess, attrs, span);
790789
if const_stability.is_some() {
791790
sess.parse_sess
@@ -803,8 +802,7 @@ impl SyntaxExtension {
803802
deprecation: attr::find_deprecation(&sess, attrs).map(|(d, _)| d),
804803
helper_attrs,
805804
edition,
806-
is_builtin,
807-
is_derive_copy: is_builtin && name == sym::Copy,
805+
builtin_name,
808806
}
809807
}
810808

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
442442
// Internal attributes, Macro related:
443443
// ==========================================================================
444444

445-
rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word), IMPL_DETAIL),
445+
rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word, NameValueStr: "name"), IMPL_DETAIL),
446446
rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
447447
rustc_attr!(
448448
rustc_macro_transparency, AssumedUsed,

compiler/rustc_resolve/src/diagnostics.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -398,20 +398,30 @@ impl<'a> Resolver<'a> {
398398
err.help("use the `|| { ... }` closure form instead");
399399
err
400400
}
401-
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg) => {
401+
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg, current) => {
402402
let mut err = struct_span_err!(
403403
self.session,
404404
span,
405405
E0435,
406406
"attempt to use a non-constant value in a constant"
407407
);
408-
err.span_suggestion(
409-
ident.span,
410-
&sugg,
411-
"".to_string(),
412-
Applicability::MaybeIncorrect,
413-
);
414-
err.span_label(span, "non-constant value");
408+
// let foo =...
409+
// ^^^ given this Span
410+
// ------- get this Span to have an applicable suggestion
411+
let sp =
412+
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
413+
if sp.lo().0 == 0 {
414+
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
415+
} else {
416+
let sp = sp.with_lo(BytePos(sp.lo().0 - current.len() as u32));
417+
err.span_suggestion(
418+
sp,
419+
&format!("consider using `{}` instead of `{}`", sugg, current),
420+
format!("{} {}", sugg, ident),
421+
Applicability::MaybeIncorrect,
422+
);
423+
err.span_label(span, "non-constant value");
424+
}
415425
err
416426
}
417427
ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => {

compiler/rustc_resolve/src/lib.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ enum ResolutionError<'a> {
210210
/// Error E0434: can't capture dynamic environment in a fn item.
211211
CannotCaptureDynamicEnvironmentInFnItem,
212212
/// Error E0435: attempt to use a non-constant value in a constant.
213-
AttemptToUseNonConstantValueInConstant(Ident, String),
213+
AttemptToUseNonConstantValueInConstant(
214+
Ident,
215+
/* suggestion */ &'static str,
216+
/* current */ &'static str,
217+
),
214218
/// Error E0530: `X` bindings cannot shadow `Y`s.
215219
BindingShadowsSomethingUnacceptable(&'static str, Symbol, &'a NameBinding<'a>),
216220
/// Error E0128: type parameters with a default cannot use forward-declared identifiers.
@@ -1443,7 +1447,7 @@ impl<'a> Resolver<'a> {
14431447
}
14441448

14451449
fn is_builtin_macro(&mut self, res: Res) -> bool {
1446-
self.get_macro(res).map_or(false, |ext| ext.is_builtin)
1450+
self.get_macro(res).map_or(false, |ext| ext.builtin_name.is_some())
14471451
}
14481452

14491453
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
@@ -2010,7 +2014,7 @@ impl<'a> Resolver<'a> {
20102014
// The macro is a proc macro derive
20112015
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
20122016
let ext = self.get_macro_by_def_id(def_id);
2013-
if !ext.is_builtin
2017+
if ext.builtin_name.is_none()
20142018
&& ext.macro_kind() == MacroKind::Derive
20152019
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
20162020
{
@@ -2614,18 +2618,19 @@ impl<'a> Resolver<'a> {
26142618
ConstantItemKind::Const => "const",
26152619
ConstantItemKind::Static => "static",
26162620
};
2617-
let sugg = format!(
2618-
"consider using `let` instead of `{}`",
2619-
kind_str
2620-
);
2621-
(span, AttemptToUseNonConstantValueInConstant(ident, sugg))
2621+
(
2622+
span,
2623+
AttemptToUseNonConstantValueInConstant(
2624+
ident, "let", kind_str,
2625+
),
2626+
)
26222627
} else {
2623-
let sugg = "consider using `const` instead of `let`";
26242628
(
26252629
rib_ident.span,
26262630
AttemptToUseNonConstantValueInConstant(
26272631
original_rib_ident_def,
2628-
sugg.to_string(),
2632+
"const",
2633+
"let",
26292634
),
26302635
)
26312636
};

compiler/rustc_resolve/src/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
285285
helper_attrs.extend(
286286
ext.helper_attrs.iter().map(|name| Ident::new(*name, span)),
287287
);
288-
if ext.is_derive_copy {
288+
if ext.builtin_name == Some(sym::Copy) {
289289
self.containers_deriving_copy.insert(invoc_id);
290290
}
291291
ext
@@ -1089,9 +1089,9 @@ impl<'a> Resolver<'a> {
10891089
edition,
10901090
);
10911091

1092-
if result.is_builtin {
1092+
if let Some(builtin_name) = result.builtin_name {
10931093
// The macro was marked with `#[rustc_builtin_macro]`.
1094-
if let Some(builtin_macro) = self.builtin_macros.get_mut(&item.ident.name) {
1094+
if let Some(builtin_macro) = self.builtin_macros.get_mut(&builtin_name) {
10951095
// The macro is a built-in, replace its expander function
10961096
// while still taking everything else from the source code.
10971097
// If we already loaded this builtin macro, give a better error message than 'no such builtin macro'.

compiler/rustc_span/src/source_map.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ impl SourceMap {
671671
let pat = pat.to_owned() + ws;
672672
if let Ok(prev_source) = self.span_to_prev_source(sp) {
673673
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
674-
if !prev_source.is_empty() && (!prev_source.contains('\n') || accept_newlines) {
674+
if prev_source.is_empty() && sp.lo().0 != 0 {
675+
return sp.with_lo(BytePos(sp.lo().0 - 1));
676+
} else if !prev_source.contains('\n') || accept_newlines {
675677
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
676678
}
677679
}

compiler/rustc_symbol_mangling/src/legacy.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ pub(super) fn mangle(
5656
let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);
5757

5858
let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }
59-
.print_def_path(def_id, &[])
59+
.print_def_path(
60+
def_id,
61+
if let ty::InstanceDef::DropGlue(_, _) = instance.def {
62+
// Add the name of the dropped type to the symbol name
63+
&*instance.substs
64+
} else {
65+
&[]
66+
},
67+
)
6068
.unwrap();
6169

6270
if let ty::InstanceDef::VtableShim(..) = instance.def {

library/alloc/src/vec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ impl<T, A: Allocator> Vec<T, A> {
990990
// such that no value will be dropped twice in case `drop_in_place`
991991
// were to panic once (if it panics twice, the program aborts).
992992
unsafe {
993+
// Note: It's intentional that this is `>` and not `>=`.
994+
// Changing it to `>=` has negative performance
995+
// implications in some cases. See #78884 for more.
993996
if len > self.len {
994997
return;
995998
}

library/core/src/char/convert.rs

+42
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,48 @@ impl From<char> for u32 {
113113
}
114114
}
115115

116+
#[stable(feature = "more_char_conversions", since = "1.51.0")]
117+
impl From<char> for u64 {
118+
/// Converts a [`char`] into a [`u64`].
119+
///
120+
/// # Examples
121+
///
122+
/// ```
123+
/// use std::mem;
124+
///
125+
/// let c = '👤';
126+
/// let u = u64::from(c);
127+
/// assert!(8 == mem::size_of_val(&u))
128+
/// ```
129+
#[inline]
130+
fn from(c: char) -> Self {
131+
// The char is casted to the value of the code point, then zero-extended to 64 bit.
132+
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
133+
c as u64
134+
}
135+
}
136+
137+
#[stable(feature = "more_char_conversions", since = "1.51.0")]
138+
impl From<char> for u128 {
139+
/// Converts a [`char`] into a [`u128`].
140+
///
141+
/// # Examples
142+
///
143+
/// ```
144+
/// use std::mem;
145+
///
146+
/// let c = '⚙';
147+
/// let u = u128::from(c);
148+
/// assert!(16 == mem::size_of_val(&u))
149+
/// ```
150+
#[inline]
151+
fn from(c: char) -> Self {
152+
// The char is casted to the value of the code point, then zero-extended to 128 bit.
153+
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
154+
c as u128
155+
}
156+
}
157+
116158
/// Maps a byte in 0x00..=0xFF to a `char` whose code point has the same value, in U+0000..=U+00FF.
117159
///
118160
/// Unicode is designed such that this effectively decodes bytes

library/std/src/alloc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ impl System {
166166
match old_layout.size() {
167167
0 => self.alloc_impl(new_layout, zeroed),
168168

169-
// SAFETY: `new_size` is non-zero as `old_size` is greater than or equal to `new_size`
170-
// as required by safety conditions. Other conditions must be upheld by the caller
169+
// SAFETY: `new_size` is non-zero as `new_size` is greater than or equal to `old_size`
170+
// as required by safety conditions and the `old_size == 0` case was handled in the
171+
// previous match arm. Other conditions must be upheld by the caller
171172
old_size if old_layout.align() == new_layout.align() => unsafe {
172173
let new_size = new_layout.size();
173174

src/bootstrap/bootstrap.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def download_stage0(self):
413413
lib_dir = "{}/lib".format(self.bin_root())
414414
for lib in os.listdir(lib_dir):
415415
if lib.endswith(".so"):
416-
self.fix_bin_or_dylib("{}/{}".format(lib_dir, lib))
416+
self.fix_bin_or_dylib(os.path.join(lib_dir, lib), rpath_libz=True)
417417
with output(self.rustc_stamp()) as rust_stamp:
418418
rust_stamp.write(self.date)
419419

@@ -451,10 +451,15 @@ def download_stage0(self):
451451
"{}/src/bootstrap/download-ci-llvm-stamp".format(top_level),
452452
]).decode(sys.getdefaultencoding()).strip()
453453
llvm_assertions = self.get_toml('assertions', 'llvm') == 'true'
454+
llvm_root = self.llvm_root()
455+
llvm_lib = os.path.join(llvm_root, "lib")
454456
if self.program_out_of_date(self.llvm_stamp(), llvm_sha + str(llvm_assertions)):
455457
self._download_ci_llvm(llvm_sha, llvm_assertions)
456458
for binary in ["llvm-config", "FileCheck"]:
457-
self.fix_bin_or_dylib("{}/bin/{}".format(self.llvm_root(), binary))
459+
self.fix_bin_or_dylib(os.path.join(llvm_root, "bin", binary), rpath_libz=True)
460+
for lib in os.listdir(llvm_lib):
461+
if lib.endswith(".so"):
462+
self.fix_bin_or_dylib(os.path.join(llvm_lib, lib), rpath_libz=True)
458463
with output(self.llvm_stamp()) as llvm_stamp:
459464
llvm_stamp.write(llvm_sha + str(llvm_assertions))
460465

@@ -501,7 +506,7 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
501506
match="rust-dev",
502507
verbose=self.verbose)
503508

504-
def fix_bin_or_dylib(self, fname):
509+
def fix_bin_or_dylib(self, fname, rpath_libz=False):
505510
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
506511
or the RPATH section, to fix the dynamic library search path
507512
@@ -571,20 +576,22 @@ def fix_bin_or_dylib(self, fname):
571576
self.nix_deps_dir = nix_deps_dir
572577

573578
patchelf = "{}/patchelf/bin/patchelf".format(nix_deps_dir)
579+
patchelf_args = []
574580

575-
if fname.endswith(".so"):
576-
# Dynamic library, patch RPATH to point to system dependencies.
581+
if rpath_libz:
582+
# Patch RPATH to add `zlib` dependency that stems from LLVM
577583
dylib_deps = ["zlib"]
578584
rpath_entries = [
579585
# Relative default, all binary and dynamic libraries we ship
580586
# appear to have this (even when `../lib` is redundant).
581587
"$ORIGIN/../lib",
582588
] + ["{}/{}/lib".format(nix_deps_dir, dep) for dep in dylib_deps]
583-
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
584-
else:
589+
patchelf_args += ["--set-rpath", ":".join(rpath_entries)]
590+
if not fname.endswith(".so"):
591+
# Finally, set the corret .interp for binaries
585592
bintools_dir = "{}/stdenv.cc.bintools".format(nix_deps_dir)
586593
with open("{}/nix-support/dynamic-linker".format(bintools_dir)) as dynamic_linker:
587-
patchelf_args = ["--set-interpreter", dynamic_linker.read().rstrip()]
594+
patchelf_args += ["--set-interpreter", dynamic_linker.read().rstrip()]
588595

589596
try:
590597
subprocess.check_output([patchelf] + patchelf_args + [fname])

src/librustdoc/clean/auto_trait.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
8484
new_generics
8585
});
8686

87-
let polarity;
87+
let negative_polarity;
8888
let new_generics = match result {
8989
AutoTraitResult::PositiveImpl(new_generics) => {
90-
polarity = None;
90+
negative_polarity = false;
9191
new_generics
9292
}
9393
AutoTraitResult::NegativeImpl => {
94-
polarity = Some(ImplPolarity::Negative);
94+
negative_polarity = true;
9595

9696
// For negative impls, we use the generic params, but *not* the predicates,
9797
// from the original type. Otherwise, the displayed impl appears to be a
@@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
130130
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
131131
for_: ty.clean(self.cx),
132132
items: Vec::new(),
133-
polarity,
133+
negative_polarity,
134134
synthetic: true,
135135
blanket_impl: None,
136136
}),

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
131131
.in_definition_order()
132132
.collect::<Vec<_>>()
133133
.clean(self.cx),
134-
polarity: None,
134+
negative_polarity: false,
135135
synthetic: false,
136136
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
137137
}),

0 commit comments

Comments
 (0)