Skip to content

Commit 215f2d3

Browse files
committed
Auto merge of #72464 - RalfJung:rollup-xhm7w7u, r=RalfJung
Rollup of 7 pull requests Successful merges: - #71829 (Fix suggestion to borrow in struct) - #72123 (Stabilize process_set_argv0 feature for Unix) - #72235 (Clean up E0590 explanation) - #72345 (Clean up E0593 explanation) - #72376 ([self-profling] Record the cgu name when doing codegen for a module) - #72399 (Add fast-path optimization for Ipv4Addr::fmt) - #72435 (rustllvm: Fix warnings about unused function parameters) Failed merges: r? @ghost
2 parents a9ca1ec + e7503ca commit 215f2d3

File tree

18 files changed

+89
-72
lines changed

18 files changed

+89
-72
lines changed

src/librustc_codegen_llvm/back/write.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::back::profiling::{
66
use crate::base;
77
use crate::common;
88
use crate::consts;
9-
use crate::context::all_outputs_are_pic_executables;
109
use crate::llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
1110
use crate::llvm_util;
1211
use crate::type_::Type;
@@ -150,7 +149,6 @@ pub fn target_machine_factory(
150149
let features = features.join(",");
151150
let features = CString::new(features).unwrap();
152151
let abi = SmallCStr::new(&sess.target.target.options.llvm_abiname);
153-
let pic_is_pie = all_outputs_are_pic_executables(sess);
154152
let trap_unreachable = sess.target.target.options.trap_unreachable;
155153
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
156154

@@ -174,7 +172,6 @@ pub fn target_machine_factory(
174172
reloc_model,
175173
opt_level,
176174
use_softfp,
177-
pic_is_pie,
178175
ffunction_sections,
179176
fdata_sections,
180177
trap_unreachable,

src/librustc_codegen_llvm/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn compile_codegen_unit(
100100
tcx: TyCtxt<'tcx>,
101101
cgu_name: Symbol,
102102
) -> (ModuleCodegen<ModuleLlvm>, u64) {
103-
let prof_timer = tcx.prof.generic_activity("codegen_module");
103+
let prof_timer = tcx.prof.generic_activity_with_arg("codegen_module", cgu_name.to_string());
104104
let start_time = Instant::now();
105105

106106
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);

src/librustc_codegen_llvm/context.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,6 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
9797
}
9898
}
9999

100-
/// PIE is potentially more effective than PIC, but can only be used in executables.
101-
/// If all our outputs are executables, then we can relax PIC to PIE when producing object code.
102-
/// If the list of crate types is not yet known we conservatively return `false`.
103-
pub fn all_outputs_are_pic_executables(sess: &Session) -> bool {
104-
sess.relocation_model() == RelocModel::Pic
105-
&& sess
106-
.crate_types
107-
.try_get()
108-
.map_or(false, |crate_types| crate_types.iter().all(|ty| *ty == CrateType::Executable))
109-
}
110-
111100
fn strip_function_ptr_alignment(data_layout: String) -> String {
112101
// FIXME: Make this more general.
113102
data_layout.replace("-Fi8-", "-")
@@ -183,10 +172,11 @@ pub unsafe fn create_module(
183172

184173
if sess.relocation_model() == RelocModel::Pic {
185174
llvm::LLVMRustSetModulePICLevel(llmod);
186-
}
187-
188-
if all_outputs_are_pic_executables(sess) {
189-
llvm::LLVMRustSetModulePIELevel(llmod);
175+
// PIE is potentially more effective than PIC, but can only be used in executables.
176+
// If all our outputs are executables, then we can relax PIC to PIE.
177+
if sess.crate_types.get().iter().all(|ty| *ty == CrateType::Executable) {
178+
llvm::LLVMRustSetModulePIELevel(llmod);
179+
}
190180
}
191181

192182
// If skipping the PLT is enabled, we need to add some module metadata

src/librustc_codegen_llvm/debuginfo/metadata.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ fn subroutine_type_metadata(
447447
unsafe {
448448
llvm::LLVMRustDIBuilderCreateSubroutineType(
449449
DIB(cx),
450-
unknown_file_metadata(cx),
451450
create_DIArray(DIB(cx), &signature_metadata[..]),
452451
)
453452
},
@@ -635,14 +634,12 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
635634
// anything reading the debuginfo for a recursive
636635
// type is going to see *something* weird - the only
637636
// question is what exactly it will see.
638-
let (size, align) = cx.size_and_align_of(t);
639637
let name = "<recur_type>";
640638
llvm::LLVMRustDIBuilderCreateBasicType(
641639
DIB(cx),
642640
name.as_ptr().cast(),
643641
name.len(),
644-
size.bits(),
645-
align.bits() as u32,
642+
cx.size_of(t).bits(),
646643
DW_ATE_unsigned,
647644
)
648645
}
@@ -841,14 +838,12 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
841838
_ => bug!("debuginfo::basic_type_metadata - `t` is invalid type"),
842839
};
843840

844-
let (size, align) = cx.size_and_align_of(t);
845841
let ty_metadata = unsafe {
846842
llvm::LLVMRustDIBuilderCreateBasicType(
847843
DIB(cx),
848844
name.as_ptr().cast(),
849845
name.len(),
850-
size.bits(),
851-
align.bits() as u32,
846+
cx.size_of(t).bits(),
852847
encoding,
853848
)
854849
};
@@ -2187,9 +2182,6 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'
21872182
name.as_ptr().cast(),
21882183
name.len(),
21892184
actual_type_metadata,
2190-
unknown_file_metadata(cx),
2191-
0,
2192-
0,
21932185
))
21942186
})
21952187
} else {

src/librustc_codegen_llvm/debuginfo/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
252252

253253
let function_type_metadata = unsafe {
254254
let fn_signature = get_function_signature(self, fn_abi);
255-
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), file_metadata, fn_signature)
255+
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), fn_signature)
256256
};
257257

258258
// Find the enclosing function, in case this is a closure.
@@ -265,8 +265,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
265265
// name if necessary.
266266
let generics = self.tcx().generics_of(enclosing_fn_def_id);
267267
let substs = instance.substs.truncate_to(self.tcx(), generics);
268-
let template_parameters =
269-
get_template_parameters(self, &generics, substs, file_metadata, &mut name);
268+
let template_parameters = get_template_parameters(self, &generics, substs, &mut name);
270269

271270
// Get the linkage_name, which is just the symbol name
272271
let linkage_name = mangled_name_of_instance(self, instance);
@@ -388,7 +387,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
388387
cx: &CodegenCx<'ll, 'tcx>,
389388
generics: &ty::Generics,
390389
substs: SubstsRef<'tcx>,
391-
file_metadata: &'ll DIFile,
392390
name_to_append_suffix_to: &mut String,
393391
) -> &'ll DIArray {
394392
if substs.types().next().is_none() {
@@ -429,9 +427,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
429427
name.as_ptr().cast(),
430428
name.len(),
431429
actual_type_metadata,
432-
file_metadata,
433-
0,
434-
0,
435430
))
436431
})
437432
} else {

src/librustc_codegen_llvm/llvm/ffi.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,6 @@ extern "C" {
16551655

16561656
pub fn LLVMRustDIBuilderCreateSubroutineType(
16571657
Builder: &DIBuilder<'a>,
1658-
File: &'a DIFile,
16591658
ParameterTypes: &'a DIArray,
16601659
) -> &'a DICompositeType;
16611660

@@ -1682,7 +1681,6 @@ extern "C" {
16821681
Name: *const c_char,
16831682
NameLen: size_t,
16841683
SizeInBits: u64,
1685-
AlignInBits: u32,
16861684
Encoding: c_uint,
16871685
) -> &'a DIBasicType;
16881686

@@ -1880,9 +1878,6 @@ extern "C" {
18801878
Name: *const c_char,
18811879
NameLen: size_t,
18821880
Ty: &'a DIType,
1883-
File: &'a DIFile,
1884-
LineNo: c_uint,
1885-
ColumnNo: c_uint,
18861881
) -> &'a DITemplateTypeParameter;
18871882

18881883
pub fn LLVMRustDIBuilderCreateNameSpace(
@@ -1948,7 +1943,6 @@ extern "C" {
19481943
Reloc: RelocModel,
19491944
Level: CodeGenOptLevel,
19501945
UseSoftFP: bool,
1951-
PositionIndependentExecutable: bool,
19521946
FunctionSections: bool,
19531947
DataSections: bool,
19541948
TrapUnreachable: bool,
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
`break` or `continue` must include a label when used in the condition of a
2-
`while` loop.
1+
`break` or `continue` keywords were used in a condition of a `while` loop
2+
without a label.
33

4-
Example of erroneous code:
4+
Erroneous code code:
55

66
```compile_fail,E0590
77
while break {}
88
```
99

10+
`break` or `continue` must include a label when used in the condition of a
11+
`while` loop.
12+
1013
To fix this, add a label specifying which loop is being broken out of:
14+
1115
```
1216
'foo: while break 'foo {}
1317
```

src/librustc_error_codes/error_codes/E0593.md

+11
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ fn main() {
1111
foo(|y| { });
1212
}
1313
```
14+
15+
You have to provide the same number of arguments as expected by the `Fn`-based
16+
type. So to fix the previous example, we need to remove the `y` argument:
17+
18+
```
19+
fn foo<F: Fn()>(x: F) { }
20+
21+
fn main() {
22+
foo(|| { }); // ok!
23+
}
24+
```

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
631631
param_env,
632632
new_trait_ref.without_const().to_predicate(self.tcx),
633633
);
634+
634635
if self.predicate_must_hold_modulo_regions(&new_obligation) {
635636
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
636637
// We have a very specific type of error, where just borrowing this argument
637638
// might solve the problem. In cases like this, the important part is the
638639
// original type obligation, not the last one that failed, which is arbitrary.
639640
// Because of this, we modify the error to refer to the original obligation and
640641
// return early in the caller.
642+
641643
let msg = format!(
642644
"the trait bound `{}: {}` is not satisfied",
643645
found,
@@ -660,12 +662,23 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
660662
obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
661663
),
662664
);
663-
err.span_suggestion(
664-
span,
665-
"consider borrowing here",
666-
format!("&{}", snippet),
667-
Applicability::MaybeIncorrect,
668-
);
665+
666+
// This if is to prevent a special edge-case
667+
if !span.from_expansion() {
668+
// We don't want a borrowing suggestion on the fields in structs,
669+
// ```
670+
// struct Foo {
671+
// the_foos: Vec<Foo>
672+
// }
673+
// ```
674+
675+
err.span_suggestion(
676+
span,
677+
"consider borrowing here",
678+
format!("&{}", snippet),
679+
Applicability::MaybeIncorrect,
680+
);
681+
}
669682
return true;
670683
}
671684
}

src/libstd/net/ip.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -856,16 +856,23 @@ impl From<Ipv6Addr> for IpAddr {
856856
#[stable(feature = "rust1", since = "1.0.0")]
857857
impl fmt::Display for Ipv4Addr {
858858
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
859-
const IPV4_BUF_LEN: usize = 15; // Long enough for the longest possible IPv4 address
860-
let mut buf = [0u8; IPV4_BUF_LEN];
861-
let mut buf_slice = &mut buf[..];
862859
let octets = self.octets();
863-
// Note: The call to write should never fail, hence the unwrap
864-
write!(buf_slice, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap();
865-
let len = IPV4_BUF_LEN - buf_slice.len();
866-
// This unsafe is OK because we know what is being written to the buffer
867-
let buf = unsafe { crate::str::from_utf8_unchecked(&buf[..len]) };
868-
fmt.pad(buf)
860+
// Fast Path: if there's no alignment stuff, write directly to the buffer
861+
if fmt.precision().is_none() && fmt.width().is_none() {
862+
write!(fmt, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3])
863+
} else {
864+
const IPV4_BUF_LEN: usize = 15; // Long enough for the longest possible IPv4 address
865+
let mut buf = [0u8; IPV4_BUF_LEN];
866+
let mut buf_slice = &mut buf[..];
867+
868+
// Note: The call to write should never fail, hence the unwrap
869+
write!(buf_slice, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap();
870+
let len = IPV4_BUF_LEN - buf_slice.len();
871+
872+
// This unsafe is OK because we know what is being written to the buffer
873+
let buf = unsafe { crate::str::from_utf8_unchecked(&buf[..len]) };
874+
fmt.pad(buf)
875+
}
869876
}
870877
}
871878

src/libstd/sys/unix/ext/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub trait CommandExt {
111111
///
112112
/// Set the first process argument, `argv[0]`, to something other than the
113113
/// default executable path.
114-
#[unstable(feature = "process_set_argv0", issue = "66510")]
114+
#[stable(feature = "process_set_argv0", since = "1.45.0")]
115115
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
116116
where
117117
S: AsRef<OsStr>;

src/libstd/sys/vxworks/ext/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub trait CommandExt {
111111
///
112112
/// Set the first process argument, `argv[0]`, to something other than the
113113
/// default executable path.
114-
#[unstable(feature = "process_set_argv0", issue = "66510")]
114+
#[stable(feature = "process_set_argv0", since = "1.45.0")]
115115
fn arg0<S>(&mut self, arg: S) -> &mut process::Command
116116
where
117117
S: AsRef<OsStr>;

src/rustllvm/PassWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
445445
const char *TripleStr, const char *CPU, const char *Feature,
446446
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
447447
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
448-
bool PositionIndependentExecutable, bool FunctionSections,
448+
bool FunctionSections,
449449
bool DataSections,
450450
bool TrapUnreachable,
451451
bool Singlethread,

src/rustllvm/RustWrapper.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(
720720

721721
extern "C" LLVMMetadataRef
722722
LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder,
723-
LLVMMetadataRef File,
724723
LLVMMetadataRef ParameterTypes) {
725724
return wrap(Builder->createSubroutineType(
726725
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
@@ -755,7 +754,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
755754

756755
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType(
757756
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
758-
uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding) {
757+
uint64_t SizeInBits, unsigned Encoding) {
759758
return wrap(Builder->createBasicType(StringRef(Name, NameLen), SizeInBits, Encoding));
760759
}
761760

@@ -964,9 +963,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
964963

965964
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
966965
LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope,
967-
const char *Name, size_t NameLen,
968-
LLVMMetadataRef Ty, LLVMMetadataRef File, unsigned LineNo,
969-
unsigned ColumnNo) {
966+
const char *Name, size_t NameLen, LLVMMetadataRef Ty) {
970967
return wrap(Builder->createTemplateTypeParameter(
971968
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), unwrapDI<DIType>(Ty)));
972969
}

src/test/ui/command/command-argv0-debug.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// ignore-cloudabi no processes
55
// ignore-emscripten no processes
66
// ignore-sgx no processes
7-
#![feature(process_set_argv0)]
8-
97
use std::os::unix::process::CommandExt;
108
use std::process::Command;
119

src/test/ui/command/command-argv0.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// ignore-cloudabi no processes
55
// ignore-emscripten no processes
66
// ignore-sgx no processes
7-
#![feature(process_set_argv0)]
8-
97
use std::env;
108
use std::os::unix::process::CommandExt;
119
use std::process::Command;
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Foo(u8);
2+
3+
#[derive(Clone)]
4+
struct FooHolster {
5+
the_foos: Vec<Foo>, //~ERROR Clone
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0277]: the trait bound `Foo: std::clone::Clone` is not satisfied
2+
--> $DIR/traits-issue-71136.rs:5:5
3+
|
4+
LL | the_foos: Vec<Foo>,
5+
| ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `std::clone::Clone`
6+
|
7+
= note: required because of the requirements on the impl of `std::clone::Clone` for `std::vec::Vec<Foo>`
8+
= note: required by `std::clone::Clone::clone`
9+
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)