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 10 pull requests #80866

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7438f43
Implement From<char> for u64 and u128.
Nov 28, 2020
0bf75fb
Use better symbol names for the drop glue
bjorn3 Dec 12, 2020
4a48d68
Simplify based on eddyb's comment
bjorn3 Dec 17, 2020
769fb8a
Fix safety comment
LingMan Jan 7, 2021
9a5dcaa
Use correct span for structured suggestion
estebank Jan 8, 2021
d72f580
Remove useless `fill_in` function
jyn514 Jan 8, 2021
4e3be7c
Use standard formatting for "rust-call" ABI message
camelid Jan 8, 2021
3338bdb
Add doc comment explaining what the second Array's field is about
GuillaumeGomez Jan 8, 2021
e8cb72c
Update the stabilisation version.
Jan 9, 2021
34d128a
Replace under-used ImplPolarity enum with a boolean
GuillaumeGomez Jan 8, 2021
15ade4d
Support `download-ci-llvm` on NixOS
nagisa Jan 8, 2021
d651fa7
Allow #[rustc_builtin_macro = "name"].
m-ou-se Jan 9, 2021
0aad91b
Formatting.
m-ou-se Jan 9, 2021
b293bba
Don't set builtin_name for builtin macro implementations.
m-ou-se Jan 9, 2021
befd153
Add comment to `Vec::truncate` explaining `>` vs `>=`
camelid Jan 9, 2021
4fa5e57
Rollup merge of #79502 - Julian-Wollersberger:from_char_for_u64, r=wi…
JohnTitor Jan 10, 2021
36d8242
Rollup merge of #79968 - bjorn3:better_drop_glue_debuginfo, r=matthew…
JohnTitor Jan 10, 2021
6f062df
Rollup merge of #80774 - LingMan:patch-1, r=nagisa
JohnTitor Jan 10, 2021
686715b
Rollup merge of #80801 - estebank:correct-binding-sugg-span, r=petroc…
JohnTitor Jan 10, 2021
fb2df5f
Rollup merge of #80803 - jyn514:cleanup-fill-in, r=GuillaumeGomez
JohnTitor Jan 10, 2021
f22afd0
Rollup merge of #80809 - camelid:rust-call-abi-msg, r=lcnr
JohnTitor Jan 10, 2021
ba20c2c
Rollup merge of #80820 - nagisa:nagisa/dcl-nixos, r=Mark-Simulacrum
JohnTitor Jan 10, 2021
8386a57
Rollup merge of #80825 - GuillaumeGomez:rustdoc-cleanup-bis-repetita,…
JohnTitor Jan 10, 2021
9256fdd
Rollup merge of #80850 - m-ou-se:rustc-builtin-macro-name, r=petroche…
JohnTitor Jan 10, 2021
44a118f
Rollup merge of #80857 - camelid:vec-truncate-comment, r=scottmcm
JohnTitor Jan 10, 2021
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
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Editi
let mut register = |name, kind| {
resolver.register_builtin_macro(
Ident::with_dummy_span(name),
SyntaxExtension { is_builtin: true, ..SyntaxExtension::default(kind, edition) },
SyntaxExtension::default(kind, edition),
)
};
macro register_bang($($name:ident: $f:expr,)*) {
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,7 @@ pub struct SyntaxExtension {
pub edition: Edition,
/// Built-in macros have a couple of special properties like availability
/// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
pub is_builtin: bool,
/// We have to identify macros providing a `Copy` impl early for compatibility reasons.
pub is_derive_copy: bool,
pub builtin_name: Option<Symbol>,
}

impl SyntaxExtension {
Expand Down Expand Up @@ -758,8 +756,7 @@ impl SyntaxExtension {
deprecation: None,
helper_attrs: Vec::new(),
edition,
is_builtin: false,
is_derive_copy: false,
builtin_name: None,
kind,
}
}
Expand All @@ -785,7 +782,9 @@ impl SyntaxExtension {
}
}

let is_builtin = sess.contains_name(attrs, sym::rustc_builtin_macro);
let builtin_name = sess
.find_by_name(attrs, sym::rustc_builtin_macro)
.map(|a| a.value_str().unwrap_or(name));
let (stability, const_stability) = attr::find_stability(&sess, attrs, span);
if const_stability.is_some() {
sess.parse_sess
Expand All @@ -803,8 +802,7 @@ impl SyntaxExtension {
deprecation: attr::find_deprecation(&sess, attrs).map(|(d, _)| d),
helper_attrs,
edition,
is_builtin,
is_derive_copy: is_builtin && name == sym::Copy,
builtin_name,
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Internal attributes, Macro related:
// ==========================================================================

rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word), IMPL_DETAIL),
rustc_attr!(rustc_builtin_macro, AssumedUsed, template!(Word, NameValueStr: "name"), IMPL_DETAIL),
rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), INTERNAL_UNSTABLE),
rustc_attr!(
rustc_macro_transparency, AssumedUsed,
Expand Down
26 changes: 18 additions & 8 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,30 @@ impl<'a> Resolver<'a> {
err.help("use the `|| { ... }` closure form instead");
err
}
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg) => {
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, sugg, current) => {
let mut err = struct_span_err!(
self.session,
span,
E0435,
"attempt to use a non-constant value in a constant"
);
err.span_suggestion(
ident.span,
&sugg,
"".to_string(),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
// let foo =...
// ^^^ given this Span
// ------- get this Span to have an applicable suggestion
let sp =
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);
if sp.lo().0 == 0 {
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
} else {
let sp = sp.with_lo(BytePos(sp.lo().0 - current.len() as u32));
err.span_suggestion(
sp,
&format!("consider using `{}` instead of `{}`", sugg, current),
format!("{} {}", sugg, ident),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
}
err
}
ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => {
Expand Down
25 changes: 15 additions & 10 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ enum ResolutionError<'a> {
/// Error E0434: can't capture dynamic environment in a fn item.
CannotCaptureDynamicEnvironmentInFnItem,
/// Error E0435: attempt to use a non-constant value in a constant.
AttemptToUseNonConstantValueInConstant(Ident, String),
AttemptToUseNonConstantValueInConstant(
Ident,
/* suggestion */ &'static str,
/* current */ &'static str,
),
/// Error E0530: `X` bindings cannot shadow `Y`s.
BindingShadowsSomethingUnacceptable(&'static str, Symbol, &'a NameBinding<'a>),
/// Error E0128: type parameters with a default cannot use forward-declared identifiers.
Expand Down Expand Up @@ -1443,7 +1447,7 @@ impl<'a> Resolver<'a> {
}

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

fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
Expand Down Expand Up @@ -2010,7 +2014,7 @@ impl<'a> Resolver<'a> {
// The macro is a proc macro derive
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
let ext = self.get_macro_by_def_id(def_id);
if !ext.is_builtin
if ext.builtin_name.is_none()
&& ext.macro_kind() == MacroKind::Derive
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
{
Expand Down Expand Up @@ -2614,18 +2618,19 @@ impl<'a> Resolver<'a> {
ConstantItemKind::Const => "const",
ConstantItemKind::Static => "static",
};
let sugg = format!(
"consider using `let` instead of `{}`",
kind_str
);
(span, AttemptToUseNonConstantValueInConstant(ident, sugg))
(
span,
AttemptToUseNonConstantValueInConstant(
ident, "let", kind_str,
),
)
} else {
let sugg = "consider using `const` instead of `let`";
(
rib_ident.span,
AttemptToUseNonConstantValueInConstant(
original_rib_ident_def,
sugg.to_string(),
"const",
"let",
),
)
};
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
helper_attrs.extend(
ext.helper_attrs.iter().map(|name| Ident::new(*name, span)),
);
if ext.is_derive_copy {
if ext.builtin_name == Some(sym::Copy) {
self.containers_deriving_copy.insert(invoc_id);
}
ext
Expand Down Expand Up @@ -1089,9 +1089,9 @@ impl<'a> Resolver<'a> {
edition,
);

if result.is_builtin {
if let Some(builtin_name) = result.builtin_name {
// The macro was marked with `#[rustc_builtin_macro]`.
if let Some(builtin_macro) = self.builtin_macros.get_mut(&item.ident.name) {
if let Some(builtin_macro) = self.builtin_macros.get_mut(&builtin_name) {
// The macro is a built-in, replace its expander function
// while still taking everything else from the source code.
// If we already loaded this builtin macro, give a better error message than 'no such builtin macro'.
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,9 @@ impl SourceMap {
let pat = pat.to_owned() + ws;
if let Ok(prev_source) = self.span_to_prev_source(sp) {
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
if !prev_source.is_empty() && (!prev_source.contains('\n') || accept_newlines) {
if prev_source.is_empty() && sp.lo().0 != 0 {
return sp.with_lo(BytePos(sp.lo().0 - 1));
} else if !prev_source.contains('\n') || accept_newlines {
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
}
}
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ pub(super) fn mangle(
let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);

let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }
.print_def_path(def_id, &[])
.print_def_path(
def_id,
if let ty::InstanceDef::DropGlue(_, _) = instance.def {
// Add the name of the dropped type to the symbol name
&*instance.substs
} else {
&[]
},
)
.unwrap();

if let ty::InstanceDef::VtableShim(..) = instance.def {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub(super) fn check_fn<'a, 'tcx>(
};

if let Some(header) = item {
tcx.sess.span_err(header.span, "A function with the \"rust-call\" ABI must take a single non-self argument that is a tuple")
tcx.sess.span_err(header.span, "functions with the \"rust-call\" ABI must take a single non-self argument that is a tuple")
}
};

Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ impl<T, A: Allocator> Vec<T, A> {
// such that no value will be dropped twice in case `drop_in_place`
// were to panic once (if it panics twice, the program aborts).
unsafe {
// Note: It's intentional that this is `>` and not `>=`.
// Changing it to `>=` has negative performance
// implications in some cases. See #78884 for more.
if len > self.len {
return;
}
Expand Down
42 changes: 42 additions & 0 deletions library/core/src/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,48 @@ impl From<char> for u32 {
}
}

#[stable(feature = "more_char_conversions", since = "1.51.0")]
impl From<char> for u64 {
/// Converts a [`char`] into a [`u64`].
///
/// # Examples
///
/// ```
/// use std::mem;
///
/// let c = '👤';
/// let u = u64::from(c);
/// assert!(8 == mem::size_of_val(&u))
/// ```
#[inline]
fn from(c: char) -> Self {
// The char is casted to the value of the code point, then zero-extended to 64 bit.
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
c as u64
}
}

#[stable(feature = "more_char_conversions", since = "1.51.0")]
impl From<char> for u128 {
/// Converts a [`char`] into a [`u128`].
///
/// # Examples
///
/// ```
/// use std::mem;
///
/// let c = '⚙';
/// let u = u128::from(c);
/// assert!(16 == mem::size_of_val(&u))
/// ```
#[inline]
fn from(c: char) -> Self {
// The char is casted to the value of the code point, then zero-extended to 128 bit.
// See [https://doc.rust-lang.org/reference/expressions/operator-expr.html#semantics]
c as u128
}
}

/// Maps a byte in 0x00..=0xFF to a `char` whose code point has the same value, in U+0000..=U+00FF.
///
/// Unicode is designed such that this effectively decodes bytes
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ impl System {
match old_layout.size() {
0 => self.alloc_impl(new_layout, zeroed),

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

Expand Down
23 changes: 15 additions & 8 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def download_stage0(self):
lib_dir = "{}/lib".format(self.bin_root())
for lib in os.listdir(lib_dir):
if lib.endswith(".so"):
self.fix_bin_or_dylib("{}/{}".format(lib_dir, lib))
self.fix_bin_or_dylib(os.path.join(lib_dir, lib), rpath_libz=True)
with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(self.date)

Expand Down Expand Up @@ -451,10 +451,15 @@ def download_stage0(self):
"{}/src/bootstrap/download-ci-llvm-stamp".format(top_level),
]).decode(sys.getdefaultencoding()).strip()
llvm_assertions = self.get_toml('assertions', 'llvm') == 'true'
llvm_root = self.llvm_root()
llvm_lib = os.path.join(llvm_root, "lib")
if self.program_out_of_date(self.llvm_stamp(), llvm_sha + str(llvm_assertions)):
self._download_ci_llvm(llvm_sha, llvm_assertions)
for binary in ["llvm-config", "FileCheck"]:
self.fix_bin_or_dylib("{}/bin/{}".format(self.llvm_root(), binary))
self.fix_bin_or_dylib(os.path.join(llvm_root, "bin", binary), rpath_libz=True)
for lib in os.listdir(llvm_lib):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(llvm_lib, lib), rpath_libz=True)
with output(self.llvm_stamp()) as llvm_stamp:
llvm_stamp.write(llvm_sha + str(llvm_assertions))

Expand Down Expand Up @@ -501,7 +506,7 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
match="rust-dev",
verbose=self.verbose)

def fix_bin_or_dylib(self, fname):
def fix_bin_or_dylib(self, fname, rpath_libz=False):
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
or the RPATH section, to fix the dynamic library search path

Expand Down Expand Up @@ -571,20 +576,22 @@ def fix_bin_or_dylib(self, fname):
self.nix_deps_dir = nix_deps_dir

patchelf = "{}/patchelf/bin/patchelf".format(nix_deps_dir)
patchelf_args = []

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

try:
subprocess.check_output([patchelf] + patchelf_args + [fname])
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
new_generics
});

let polarity;
let negative_polarity;
let new_generics = match result {
AutoTraitResult::PositiveImpl(new_generics) => {
polarity = None;
negative_polarity = false;
new_generics
}
AutoTraitResult::NegativeImpl => {
polarity = Some(ImplPolarity::Negative);
negative_polarity = true;

// For negative impls, we use the generic params, but *not* the predicates,
// from the original type. Otherwise, the displayed impl appears to be a
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
for_: ty.clean(self.cx),
items: Vec::new(),
polarity,
negative_polarity,
synthetic: true,
blanket_impl: None,
}),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.in_definition_order()
.collect::<Vec<_>>()
.clean(self.cx),
polarity: None,
negative_polarity: false,
synthetic: false,
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
}),
Expand Down
Loading