Skip to content

Rollup of 6 pull requests #61880

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,10 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
cargo.env("CFG_LLVM_ROOT", s);
}
}
// Some LLVM linker flags (-L and -l) may be needed to link librustc_llvm.
if let Some(ref s) = builder.config.llvm_ldflags {
cargo.env("LLVM_LINKER_FLAGS", s);
}
// Building with a static libstdc++ is only supported on linux right now,
// not for MSVC or macOS
if builder.config.llvm_static_stdcpp &&
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ fn copy_src_dirs(builder: &Builder<'_>, src_dirs: &[&str], exclude_dirs: &[&str]

const LLVM_PROJECTS: &[&str] = &[
"llvm-project/clang", "llvm-project\\clang",
"llvm-project/libunwind", "llvm-project\\libunwind",
"llvm-project/lld", "llvm-project\\lld",
"llvm-project/lldb", "llvm-project\\lldb",
"llvm-project/llvm", "llvm-project\\llvm",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

let required_region_bounds = tcx.required_region_bounds(
opaque_type,
bounds.predicates.clone(),
bounds.predicates,
);
debug_assert!(!required_region_bounds.is_empty());

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.ir.tcx.lint_hir_note(
lint::builtin::UNUSED_VARIABLES,
hir_id,
spans.clone(),
spans,
&format!("variable `{}` is assigned to, but never used", name),
&format!("consider using `_{}` instead", name),
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn owned_ptr_base_path<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> &'a LoanPath<

return match helper(loan_path) {
Some(new_loan_path) => new_loan_path,
None => loan_path.clone()
None => loan_path,
};

fn helper<'a, 'tcx>(loan_path: &'a LoanPath<'tcx>) -> Option<&'a LoanPath<'tcx>> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
}
}));
serialized_modules.extend(cached_modules.into_iter().map(|(buffer, wp)| {
(buffer, CString::new(wp.cgu_name.clone()).unwrap())
(buffer, CString::new(wp.cgu_name).unwrap())
}));

// For all serialized bitcode files we parse them and link them in as we did
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl CodegenCx<'b, 'tcx> {
};
let f = self.declare_cfn(name, fn_ty);
llvm::SetUnnamedAddr(f, false);
self.intrinsics.borrow_mut().insert(name, f.clone());
self.intrinsics.borrow_mut().insert(name, f);
f
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ impl<'tcx> VariantInfo<'tcx> {
// with every variant, make each variant name be just the value
// of the discriminant. The struct name for the variant includes
// the actual variant description.
format!("{}", variant_index.as_usize()).to_string()
format!("{}", variant_index.as_usize())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl AnnotateSnippetEmitterWriter {
let converter = DiagnosticConverter {
source_map: self.source_map.clone(),
level: level.clone(),
message: message.clone(),
message,
code: code.clone(),
msp: msp.clone(),
children,
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ fn main() {
}
}

// Some LLVM linker flags (-L and -l) may be needed even when linking
// librustc_llvm, for example when using static libc++, we may need to
// manually specify the library search path and -ldl -lpthread as link
// dependencies.
let llvm_linker_flags = env::var_os("LLVM_LINKER_FLAGS");
if let Some(s) = llvm_linker_flags {
for lib in s.into_string().unwrap().split_whitespace() {
if lib.starts_with("-l") {
println!("cargo:rustc-link-lib={}", &lib[2..]);
} else if lib.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", &lib[2..]);
}
}
}

let llvm_static_stdcpp = env::var_os("LLVM_STATIC_STDCPP");
let llvm_use_libcxx = env::var_os("LLVM_USE_LIBCXX");

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'a> CrateLoader<'a> {
let host_lib = host_lib.unwrap();
self.load_derive_macros(
&host_lib.metadata.get_root(),
host_lib.dylib.clone().map(|p| p.0),
host_lib.dylib.map(|p| p.0),
span
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pat_span,
}))),
};
let for_arm_body = self.local_decls.push(local.clone());
let for_arm_body = self.local_decls.push(local);
let locals = if has_guard.0 {
let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
// This variable isn't mutated but has a name, so has to be
Expand Down
17 changes: 17 additions & 0 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,21 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
truncate(value, ty.size)
}

#[inline(always)]
pub fn force_ptr(
&self,
scalar: Scalar<M::PointerTag>,
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
self.memory.force_ptr(scalar)
}

#[inline(always)]
pub fn force_bits(
&self,
scalar: Scalar<M::PointerTag>,
size: Size
) -> InterpResult<'tcx, u128> {
self.memory.force_bits(scalar, size)
}
}
17 changes: 16 additions & 1 deletion src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use rustc::ty::{self, query::TyCtxtAt};

use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind,
InterpretCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer,
InterpErrorInfo, InterpError
};

/// Whether this kind of memory is allowed to leak
Expand Down Expand Up @@ -208,4 +209,18 @@ pub trait Machine<'mir, 'tcx>: Sized {
ecx: &mut InterpretCx<'mir, 'tcx, Self>,
extra: Self::FrameExtra,
) -> InterpResult<'tcx>;

fn int_to_ptr(
_int: u64,
_extra: &Self::MemoryExtra,
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
Err(InterpErrorInfo::from(InterpError::ReadBytesAsPointer))
}

fn ptr_to_int(
_ptr: Pointer<Self::PointerTag>,
_extra: &Self::MemoryExtra,
) -> InterpResult<'tcx, u64> {
Err(InterpErrorInfo::from(InterpError::ReadPointerAsBytes))
}
}
27 changes: 24 additions & 3 deletions src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
if size.bytes() == 0 {
Ok(&[])
} else {
let ptr = ptr.to_ptr()?;
let ptr = self.force_ptr(ptr)?;
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
}
}
Expand Down Expand Up @@ -714,8 +714,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
// non-NULLness which already happened.
return Ok(());
}
let src = src.to_ptr()?;
let dest = dest.to_ptr()?;
let src = self.force_ptr(src)?;
let dest = self.force_ptr(dest)?;

// first copy the relocations to a temporary buffer, because
// `get_bytes_mut` will clear the relocations, which is correct,
Expand Down Expand Up @@ -874,4 +874,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
}
Ok(())
}

pub fn force_ptr(
&self,
scalar: Scalar<M::PointerTag>,
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
match scalar {
Scalar::Ptr(ptr) => Ok(ptr),
_ => M::int_to_ptr(scalar.to_usize(self)?, &self.extra)
}
}

pub fn force_bits(
&self,
scalar: Scalar<M::PointerTag>,
size: Size
) -> InterpResult<'tcx, u128> {
match scalar.to_bits_or_ptr(size, self) {
Ok(bits) => Ok(bits),
Err(ptr) => Ok(M::ptr_to_int(ptr, &self.extra)? as u128)
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
}

// check for integer pointers before alignment to report better errors
let ptr = ptr.to_ptr()?;
let ptr = self.force_ptr(ptr)?;
self.memory.check_align(ptr.into(), ptr_align)?;
match mplace.layout.abi {
layout::Abi::Scalar(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
}
_ => {
assert!(layout.ty.is_integral());
let val = val.to_bits(layout.size)?;
let val = self.force_bits(val, layout.size)?;
let res = match un_op {
Not => !val,
Neg => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ where
let layout = self.layout_of(self.tcx.types.usize)?;
let n = self.access_local(self.frame(), local, Some(layout))?;
let n = self.read_scalar(n)?;
let n = n.to_bits(self.tcx.data_layout.pointer_size)?;
let n = self.force_bits(n.not_undef()?, self.tcx.data_layout.pointer_size)?;
self.mplace_field(base, u64::try_from(n).unwrap())?
}

Expand Down Expand Up @@ -753,7 +753,7 @@ where
}

// check for integer pointers before alignment to report better errors
let ptr = ptr.to_ptr()?;
let ptr = self.force_ptr(ptr)?;
self.memory.check_align(ptr.into(), ptr_align)?;
let tcx = &*self.tcx;
// FIXME: We should check that there are dest.layout.size many bytes available in
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> {
let (fn_def, abi) = match func.layout.ty.sty {
ty::FnPtr(sig) => {
let caller_abi = sig.abi();
let fn_ptr = self.read_scalar(func)?.to_ptr()?;
let fn_ptr = self.force_ptr(self.read_scalar(func)?.not_undef()?)?;
let instance = self.memory.get_fn(fn_ptr)?;
(instance, caller_abi)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// This is the size in bytes of the whole array.
let size = ty_size * len;

let ptr = mplace.ptr.to_ptr()?;
let ptr = self.ecx.force_ptr(mplace.ptr)?;

// NOTE: Keep this in sync with the handling of integer and float
// types above, in `visit_primitive`.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ fn receiver_is_valid<'fcx, 'tcx>(
};

let obligation = traits::Obligation::new(
cause.clone(),
cause,
fcx.param_env,
trait_ref.to_predicate()
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
// Ensure that rustdoc works even if rustc is feature-staged
unstable_features: UnstableFeatures::Allow,
actually_rustdoc: true,
debugging_opts: debugging_options.clone(),
debugging_opts: debugging_options,
error_format,
edition,
describe_lints,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ impl Tester for Collector {
debug!("Creating test {}: {}", name, test);
self.tests.push(testing::TestDescAndFn {
desc: testing::TestDesc {
name: testing::DynTestName(name.clone()),
name: testing::DynTestName(name),
ignore: config.ignore,
// compiler failures are test failures
should_panic: testing::ShouldPanic::No,
Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use log::debug;
use rustc_data_structures::fx::{FxHashMap};
use std::borrow::Cow;
use std::collections::hash_map::Entry;
use std::slice;

use rustc_data_structures::sync::Lrc;
use errors::Applicability;
Expand Down Expand Up @@ -359,10 +360,10 @@ pub fn compile(

// don't abort iteration early, so that errors for multiple lhses can be reported
for lhs in &lhses {
valid &= check_lhs_no_empty_seq(sess, &[lhs.clone()]);
valid &= check_lhs_no_empty_seq(sess, slice::from_ref(lhs));
valid &= check_lhs_duplicate_matcher_bindings(
sess,
&[lhs.clone()],
slice::from_ref(lhs),
&mut FxHashMap::default(),
def.id
);
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,10 @@ declare_features! (
// Allows the user of associated type bounds.
(active, associated_type_bounds, "1.34.0", Some(52662), None),

// Attributes on formal function params
// Attributes on formal function params.
(active, param_attrs, "1.36.0", Some(60406), None),

// Allows calling constructor functions in `const fn`
// FIXME Create issue
// Allows calling constructor functions in `const fn`.
(active, const_constructor, "1.37.0", Some(61456), None),

// #[repr(transparent)] on enums.
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt<'_>,
};

let fmt_str = &*fmt.node.0.as_str(); // for the suggestions below
let mut parser = parse::Parser::new(fmt_str, str_style, skips.clone(), append_newline);
let mut parser = parse::Parser::new(fmt_str, str_style, skips, append_newline);

let mut unverified_pieces = Vec::new();
while let Some(piece) = parser.next() {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ impl server::TokenStream for Rustc<'_> {
}
fn from_str(&mut self, src: &str) -> Self::TokenStream {
parse::parse_stream_from_source_str(
FileName::proc_macro_source_code(src.clone()),
FileName::proc_macro_source_code(src),
src.to_string(),
self.sess,
Some(self.call_site),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri