Skip to content

Commit e1b6931

Browse files
committed
Auto merge of rust-lang#127125 - matthiaskrgr:rollup-6phy5dz, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#123237 (Various rustc_codegen_ssa cleanups) - rust-lang#126960 (Improve error message in tidy) - rust-lang#127002 (Implement `x perf` as a separate tool) - rust-lang#127050 (Make mtime of reproducible tarballs dependent on git commit) - rust-lang#127081 (Add a run-make test that LLD is not being used by default on the x64 beta/stable channel) - rust-lang#127106 (Improve unsafe extern blocks diagnostics) - rust-lang#127110 (Fix a error suggestion for E0121 when using placeholder _ as return types on function signature.) - rust-lang#127114 (fix: prefer `(*p).clone` to `p.clone` if the `p` is a raw pointer) - rust-lang#127118 (Show `used attribute`'s kind for user when find it isn't applied to a `static` variable.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1b7355 + fb181b2 commit e1b6931

Some content is hidden

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

58 files changed

+672
-274
lines changed

Cargo.lock

+7
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,13 @@ dependencies = [
34613461
"stable_mir",
34623462
]
34633463

3464+
[[package]]
3465+
name = "rustc-perf-wrapper"
3466+
version = "0.1.0"
3467+
dependencies = [
3468+
"clap",
3469+
]
3470+
34643471
[[package]]
34653472
name = "rustc-rayon"
34663473
version = "0.5.0"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ members = [
4444
"src/tools/rustdoc-gui-test",
4545
"src/tools/opt-dist",
4646
"src/tools/coverage-dump",
47+
"src/tools/rustc-perf-wrapper",
4748
]
4849

4950
exclude = [

compiler/rustc_ast_passes/src/ast_validation.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,18 @@ impl<'a> AstValidator<'a> {
469469
fn check_item_safety(&self, span: Span, safety: Safety) {
470470
match self.extern_mod_safety {
471471
Some(extern_safety) => {
472-
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
473-
&& (extern_safety == Safety::Default || !self.features.unsafe_extern_blocks)
474-
{
475-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
476-
item_span: span,
477-
block: self.current_extern_span().shrink_to_lo(),
478-
});
472+
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
473+
if extern_safety == Safety::Default {
474+
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
475+
item_span: span,
476+
block: Some(self.current_extern_span().shrink_to_lo()),
477+
});
478+
} else if !self.features.unsafe_extern_blocks {
479+
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
480+
item_span: span,
481+
block: None,
482+
});
483+
}
479484
}
480485
}
481486
None => {
@@ -1098,7 +1103,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10981103
}
10991104
}
11001105
} else if let &Safety::Unsafe(span) = safety {
1101-
this.dcx().emit_err(errors::UnsafeItem { span, kind: "extern block" });
1106+
let mut diag = this
1107+
.dcx()
1108+
.create_err(errors::UnsafeItem { span, kind: "extern block" });
1109+
rustc_session::parse::add_feature_diagnostics(
1110+
&mut diag,
1111+
self.session,
1112+
sym::unsafe_extern_blocks,
1113+
);
1114+
diag.emit();
11021115
}
11031116

11041117
if abi.is_none() {

compiler/rustc_ast_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub struct InvalidSafetyOnExtern {
222222
#[primary_span]
223223
pub item_span: Span,
224224
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
225-
pub block: Span,
225+
pub block: Option<Span>,
226226
}
227227

228228
#[derive(Diagnostic)]

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -1288,14 +1288,16 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
12881288
return false;
12891289
}
12901290
// Try to find predicates on *generic params* that would allow copying `ty`
1291-
let suggestion =
1291+
let mut suggestion =
12921292
if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
12931293
format!(": {symbol}.clone()")
12941294
} else {
12951295
".clone()".to_owned()
12961296
};
12971297
let mut sugg = Vec::with_capacity(2);
12981298
let mut inner_expr = expr;
1299+
let mut is_raw_ptr = false;
1300+
let typeck_result = self.infcx.tcx.typeck(self.mir_def_id());
12991301
// Remove uses of `&` and `*` when suggesting `.clone()`.
13001302
while let hir::ExprKind::AddrOf(.., inner) | hir::ExprKind::Unary(hir::UnOp::Deref, inner) =
13011303
&inner_expr.kind
@@ -1306,14 +1308,32 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
13061308
return false;
13071309
}
13081310
inner_expr = inner;
1311+
if let Some(inner_type) = typeck_result.node_type_opt(inner.hir_id) {
1312+
if matches!(inner_type.kind(), ty::RawPtr(..)) {
1313+
is_raw_ptr = true;
1314+
break;
1315+
}
1316+
}
13091317
}
1310-
if inner_expr.span.lo() != expr.span.lo() {
1318+
// Cloning the raw pointer doesn't make sense in some cases and would cause a type mismatch error. (see #126863)
1319+
if inner_expr.span.lo() != expr.span.lo() && !is_raw_ptr {
1320+
// Remove "(*" or "(&"
13111321
sugg.push((expr.span.with_hi(inner_expr.span.lo()), String::new()));
13121322
}
1323+
// Check whether `expr` is surrounded by parentheses or not.
13131324
let span = if inner_expr.span.hi() != expr.span.hi() {
13141325
// Account for `(*x)` to suggest `x.clone()`.
1315-
expr.span.with_lo(inner_expr.span.hi())
1326+
if is_raw_ptr {
1327+
expr.span.shrink_to_hi()
1328+
} else {
1329+
// Remove the close parenthesis ")"
1330+
expr.span.with_lo(inner_expr.span.hi())
1331+
}
13161332
} else {
1333+
if is_raw_ptr {
1334+
sugg.push((expr.span.shrink_to_lo(), "(".to_string()));
1335+
suggestion = ").clone()".to_string();
1336+
}
13171337
expr.span.shrink_to_hi()
13181338
};
13191339
sugg.push((span, suggestion));

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,27 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
639639
fn add_borrow_suggestions(&self, err: &mut Diag<'_>, span: Span) {
640640
match self.infcx.tcx.sess.source_map().span_to_snippet(span) {
641641
Ok(snippet) if snippet.starts_with('*') => {
642-
err.span_suggestion_verbose(
643-
span.with_hi(span.lo() + BytePos(1)),
644-
"consider removing the dereference here",
645-
String::new(),
646-
Applicability::MaybeIncorrect,
647-
);
642+
let sp = span.with_lo(span.lo() + BytePos(1));
643+
let inner = self.find_expr(sp);
644+
let mut is_raw_ptr = false;
645+
if let Some(inner) = inner {
646+
let typck_result = self.infcx.tcx.typeck(self.mir_def_id());
647+
if let Some(inner_type) = typck_result.node_type_opt(inner.hir_id) {
648+
if matches!(inner_type.kind(), ty::RawPtr(..)) {
649+
is_raw_ptr = true;
650+
}
651+
}
652+
}
653+
// If the `inner` is a raw pointer, do not suggest removing the "*", see #126863
654+
// FIXME: need to check whether the assigned object can be a raw pointer, see `tests/ui/borrowck/issue-20801.rs`.
655+
if !is_raw_ptr {
656+
err.span_suggestion_verbose(
657+
span.with_hi(span.lo() + BytePos(1)),
658+
"consider removing the dereference here",
659+
String::new(),
660+
Applicability::MaybeIncorrect,
661+
);
662+
}
648663
}
649664
_ => {
650665
err.span_suggestion_verbose(

compiler/rustc_codegen_gcc/src/common.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2828
global
2929
// TODO(antoyo): set linkage.
3030
}
31+
32+
pub fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
33+
if value.get_type() == self.bool_type.make_pointer() {
34+
if let Some(pointee) = typ.get_pointee() {
35+
if pointee.dyncast_vector().is_some() {
36+
panic!()
37+
}
38+
}
39+
}
40+
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
41+
// SIMD builtins require a constant value.
42+
self.bitcast_if_needed(value, typ)
43+
}
3144
}
3245

3346
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
@@ -239,19 +252,6 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
239252
const_alloc_to_gcc(self, alloc)
240253
}
241254

242-
fn const_bitcast(&self, value: RValue<'gcc>, typ: Type<'gcc>) -> RValue<'gcc> {
243-
if value.get_type() == self.bool_type.make_pointer() {
244-
if let Some(pointee) = typ.get_pointee() {
245-
if pointee.dyncast_vector().is_some() {
246-
panic!()
247-
}
248-
}
249-
}
250-
// NOTE: since bitcast makes a value non-constant, don't bitcast if not necessary as some
251-
// SIMD builtins require a constant value.
252-
self.bitcast_if_needed(value, typ)
253-
}
254-
255255
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
256256
self.context
257257
.new_array_access(None, base_addr, self.const_usize(offset.bytes()))

compiler/rustc_codegen_gcc/src/context.rs

-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::callee::get_fn;
2727
use crate::common::SignType;
2828

2929
pub struct CodegenCx<'gcc, 'tcx> {
30-
pub check_overflow: bool,
3130
pub codegen_unit: &'tcx CodegenUnit<'tcx>,
3231
pub context: &'gcc Context<'gcc>,
3332

@@ -134,8 +133,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
134133
tcx: TyCtxt<'tcx>,
135134
supports_128bit_integers: bool,
136135
) -> Self {
137-
let check_overflow = tcx.sess.overflow_checks();
138-
139136
let create_type = |ctype, rust_type| {
140137
let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
141138
let align = layout.align.abi.bytes();
@@ -271,7 +268,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
271268
}
272269

273270
let mut cx = Self {
274-
check_overflow,
275271
codegen_unit,
276272
context,
277273
current_func: RefCell::new(None),
@@ -511,10 +507,6 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
511507
&self.tcx.sess
512508
}
513509

514-
fn check_overflow(&self) -> bool {
515-
self.check_overflow
516-
}
517-
518510
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
519511
self.codegen_unit
520512
}

compiler/rustc_codegen_gcc/src/type_.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,34 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
8989
ty::FloatTy::F128 => self.type_f128(),
9090
}
9191
}
92-
}
9392

94-
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
95-
fn type_i1(&self) -> Type<'gcc> {
93+
pub fn type_i1(&self) -> Type<'gcc> {
9694
self.bool_type
9795
}
9896

97+
pub fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
98+
let types = fields.to_vec();
99+
if let Some(typ) = self.struct_types.borrow().get(fields) {
100+
return *typ;
101+
}
102+
let fields: Vec<_> = fields
103+
.iter()
104+
.enumerate()
105+
.map(|(index, field)| {
106+
self.context.new_field(None, *field, format!("field{}_TODO", index))
107+
})
108+
.collect();
109+
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
110+
if packed {
111+
#[cfg(feature = "master")]
112+
typ.set_packed();
113+
}
114+
self.struct_types.borrow_mut().insert(types, typ);
115+
typ
116+
}
117+
}
118+
119+
impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
99120
fn type_i8(&self) -> Type<'gcc> {
100121
self.i8_type
101122
}
@@ -131,7 +152,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
131152
fn type_f64(&self) -> Type<'gcc> {
132153
self.double_type
133154
}
134-
155+
135156
fn type_f128(&self) -> Type<'gcc> {
136157
unimplemented!("f16_f128")
137158
}
@@ -140,27 +161,6 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
140161
self.context.new_function_pointer_type(None, return_type, params, false)
141162
}
142163

143-
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
144-
let types = fields.to_vec();
145-
if let Some(typ) = self.struct_types.borrow().get(fields) {
146-
return *typ;
147-
}
148-
let fields: Vec<_> = fields
149-
.iter()
150-
.enumerate()
151-
.map(|(index, field)| {
152-
self.context.new_field(None, *field, format!("field{}_TODO", index))
153-
})
154-
.collect();
155-
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
156-
if packed {
157-
#[cfg(feature = "master")]
158-
typ.set_packed();
159-
}
160-
self.struct_types.borrow_mut().insert(types, typ);
161-
typ
162-
}
163-
164164
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
165165
if self.is_int_type_or_bool(typ) {
166166
TypeKind::Integer

compiler/rustc_codegen_llvm/src/common.rs

-4
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,6 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
329329
const_alloc_to_llvm(self, alloc, /*static*/ false)
330330
}
331331

332-
fn const_bitcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
333-
self.const_bitcast(val, ty)
334-
}
335-
336332
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
337333
unsafe {
338334
llvm::LLVMConstInBoundsGEP2(

compiler/rustc_codegen_llvm/src/context.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::back::write::to_llvm_code_model;
33
use crate::callee::get_fn;
44
use crate::coverageinfo;
55
use crate::debuginfo;
6+
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
67
use crate::llvm;
78
use crate::llvm_util;
89
use crate::type_::Type;
@@ -43,7 +44,6 @@ use std::str;
4344
/// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
4445
pub struct CodegenCx<'ll, 'tcx> {
4546
pub tcx: TyCtxt<'tcx>,
46-
pub check_overflow: bool,
4747
pub use_dll_storage_attrs: bool,
4848
pub tls_model: llvm::ThreadLocalMode,
4949

@@ -441,8 +441,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
441441
// start) and then strongly recommending static linkage on Windows!
442442
let use_dll_storage_attrs = tcx.sess.target.is_like_windows;
443443

444-
let check_overflow = tcx.sess.overflow_checks();
445-
446444
let tls_model = to_llvm_tls_model(tcx.sess.tls_model());
447445

448446
let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
@@ -466,7 +464,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
466464

467465
CodegenCx {
468466
tcx,
469-
check_overflow,
470467
use_dll_storage_attrs,
471468
tls_model,
472469
llmod,
@@ -522,6 +519,15 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
522519
&self.vtables
523520
}
524521

522+
fn apply_vcall_visibility_metadata(
523+
&self,
524+
ty: Ty<'tcx>,
525+
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
526+
vtable: &'ll Value,
527+
) {
528+
apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable);
529+
}
530+
525531
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
526532
get_fn(self, instance)
527533
}
@@ -596,10 +602,6 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
596602
self.tcx.sess
597603
}
598604

599-
fn check_overflow(&self) -> bool {
600-
self.check_overflow
601-
}
602-
603605
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
604606
self.codegen_unit
605607
}

0 commit comments

Comments
 (0)