Skip to content

Commit 336e89b

Browse files
committed
Auto merge of #127665 - workingjubilee:rollup-g90yr21, r=workingjubilee
Rollup of 11 pull requests Successful merges: - #126502 (Ignore allocation bytes in some mir-opt tests) - #126922 (add lint for inline asm labels that look like binary) - #127209 (Added the `xop` target-feature and the `xop_target_feature` feature gate) - #127310 (Fix import suggestion ice) - #127338 (Migrate `extra-filename-with-temp-outputs` and `issue-85019-moved-src-dir` `run-make` tests to rmake) - #127381 (Migrate `issue-83045`, `rustc-macro-dep-files` and `env-dep-info` `run-make` tests to rmake) - #127535 (Fire unsafe_code lint on unsafe extern blocks) - #127619 (Suggest using precise capturing for hidden type that captures region) - #127631 (Remove `fully_normalize`) - #127632 (Implement `precise_capturing` support for rustdoc) - #127660 (Rename the internal `const_strlen` to just `strlen`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c6727fc + 8f8734c commit 336e89b

File tree

140 files changed

+1288
-690
lines changed

Some content is hidden

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

140 files changed

+1288
-690
lines changed

compiler/rustc_codegen_ssa/src/target_features.rs

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub fn from_target_feature(
8181
Some(sym::lahfsahf_target_feature) => rust_features.lahfsahf_target_feature,
8282
Some(sym::prfchw_target_feature) => rust_features.prfchw_target_feature,
8383
Some(sym::x86_amx_intrinsics) => rust_features.x86_amx_intrinsics,
84+
Some(sym::xop_target_feature) => rust_features.xop_target_feature,
8485
Some(name) => bug!("unknown target feature gate {}", name),
8586
None => true,
8687
};

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ declare_features! (
642642
(unstable, used_with_arg, "1.60.0", Some(93798)),
643643
/// Allows use of x86 `AMX` target-feature attributes and intrinsics
644644
(unstable, x86_amx_intrinsics, "CURRENT_RUSTC_VERSION", Some(126622)),
645+
/// Allows use of the `xop` target-feature
646+
(unstable, xop_target_feature, "CURRENT_RUSTC_VERSION", Some(127208)),
645647
/// Allows `do yeet` expressions
646648
(unstable, yeet_expr, "1.62.0", Some(96373)),
647649
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!

compiler/rustc_hir/src/hir.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,13 @@ impl PreciseCapturingArg<'_> {
27082708
PreciseCapturingArg::Param(param) => param.hir_id,
27092709
}
27102710
}
2711+
2712+
pub fn name(self) -> Symbol {
2713+
match self {
2714+
PreciseCapturingArg::Lifetime(lt) => lt.ident.name,
2715+
PreciseCapturingArg::Param(param) => param.ident.name,
2716+
}
2717+
}
27112718
}
27122719

27132720
/// We need to have a [`Node`] for the [`HirId`] that we attach the type/const param

compiler/rustc_infer/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ infer_opaque_hidden_type =
221221
222222
infer_outlives_bound = lifetime of the source pointer does not outlive lifetime bound of the object type
223223
infer_outlives_content = lifetime of reference outlives lifetime of borrowed content...
224+
225+
infer_precise_capturing_existing = add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it
226+
infer_precise_capturing_new = add a `use<...>` bound to explicitly capture `{$new_lifetime}`
227+
224228
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
225229
infer_prlf_defined_without_sub = the lifetime defined here...
226230
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com./rust-lang/rust/issues/100013> for more information)

compiler/rustc_infer/src/errors/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -1581,3 +1581,32 @@ pub enum ObligationCauseFailureCode {
15811581
subdiags: Vec<TypeErrorAdditionalDiags>,
15821582
},
15831583
}
1584+
1585+
#[derive(Subdiagnostic)]
1586+
pub enum AddPreciseCapturing {
1587+
#[suggestion(
1588+
infer_precise_capturing_new,
1589+
style = "verbose",
1590+
code = " + use<{concatenated_bounds}>",
1591+
applicability = "machine-applicable"
1592+
)]
1593+
New {
1594+
#[primary_span]
1595+
span: Span,
1596+
new_lifetime: Symbol,
1597+
concatenated_bounds: String,
1598+
},
1599+
#[suggestion(
1600+
infer_precise_capturing_existing,
1601+
style = "verbose",
1602+
code = "{pre}{new_lifetime}{post}",
1603+
applicability = "machine-applicable"
1604+
)]
1605+
Existing {
1606+
#[primary_span]
1607+
span: Span,
1608+
new_lifetime: Symbol,
1609+
pre: &'static str,
1610+
post: &'static str,
1611+
},
1612+
}

compiler/rustc_infer/src/infer/error_reporting/region.rs

+109-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::iter;
22

3+
use rustc_data_structures::fx::FxIndexSet;
34
use rustc_errors::{
45
struct_span_code_err, Applicability, Diag, Subdiagnostic, E0309, E0310, E0311, E0495,
56
};
@@ -12,7 +13,7 @@ use rustc_middle::traits::ObligationCauseCode;
1213
use rustc_middle::ty::error::TypeError;
1314
use rustc_middle::ty::{self, IsSuggestable, Region, Ty, TyCtxt, TypeVisitableExt as _};
1415
use rustc_span::symbol::kw;
15-
use rustc_span::{ErrorGuaranteed, Span};
16+
use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol};
1617
use rustc_type_ir::Upcast as _;
1718

1819
use super::nice_region_error::find_anon_type;
@@ -1201,17 +1202,21 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
12011202
"",
12021203
);
12031204
if let Some(reg_info) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
1204-
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
1205-
nice_region_error::suggest_new_region_bound(
1206-
tcx,
1207-
&mut err,
1208-
fn_returns,
1209-
hidden_region.to_string(),
1210-
None,
1211-
format!("captures `{hidden_region}`"),
1212-
None,
1213-
Some(reg_info.def_id),
1214-
)
1205+
if infcx.tcx.features().precise_capturing {
1206+
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
1207+
} else {
1208+
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
1209+
nice_region_error::suggest_new_region_bound(
1210+
tcx,
1211+
&mut err,
1212+
fn_returns,
1213+
hidden_region.to_string(),
1214+
None,
1215+
format!("captures `{hidden_region}`"),
1216+
None,
1217+
Some(reg_info.def_id),
1218+
)
1219+
}
12151220
}
12161221
}
12171222
ty::RePlaceholder(_) => {
@@ -1257,3 +1262,95 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
12571262

12581263
err
12591264
}
1265+
1266+
fn suggest_precise_capturing<'tcx>(
1267+
tcx: TyCtxt<'tcx>,
1268+
opaque_def_id: LocalDefId,
1269+
captured_lifetime: ty::Region<'tcx>,
1270+
diag: &mut Diag<'_>,
1271+
) {
1272+
let hir::OpaqueTy { bounds, .. } =
1273+
tcx.hir_node_by_def_id(opaque_def_id).expect_item().expect_opaque_ty();
1274+
1275+
let new_lifetime = Symbol::intern(&captured_lifetime.to_string());
1276+
1277+
if let Some((args, span)) = bounds.iter().find_map(|bound| match bound {
1278+
hir::GenericBound::Use(args, span) => Some((args, span)),
1279+
_ => None,
1280+
}) {
1281+
let last_lifetime_span = args.iter().rev().find_map(|arg| match arg {
1282+
hir::PreciseCapturingArg::Lifetime(lt) => Some(lt.ident.span),
1283+
_ => None,
1284+
});
1285+
1286+
let first_param_span = args.iter().find_map(|arg| match arg {
1287+
hir::PreciseCapturingArg::Param(p) => Some(p.ident.span),
1288+
_ => None,
1289+
});
1290+
1291+
let (span, pre, post) = if let Some(last_lifetime_span) = last_lifetime_span {
1292+
(last_lifetime_span.shrink_to_hi(), ", ", "")
1293+
} else if let Some(first_param_span) = first_param_span {
1294+
(first_param_span.shrink_to_lo(), "", ", ")
1295+
} else {
1296+
// If we have no args, then have `use<>` and need to fall back to using
1297+
// span math. This sucks, but should be reliable due to the construction
1298+
// of the `use<>` span.
1299+
(span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(), "", "")
1300+
};
1301+
1302+
diag.subdiagnostic(errors::AddPreciseCapturing::Existing { span, new_lifetime, pre, post });
1303+
} else {
1304+
let mut captured_lifetimes = FxIndexSet::default();
1305+
let mut captured_non_lifetimes = FxIndexSet::default();
1306+
1307+
let variances = tcx.variances_of(opaque_def_id);
1308+
let mut generics = tcx.generics_of(opaque_def_id);
1309+
loop {
1310+
for param in &generics.own_params {
1311+
if variances[param.index as usize] == ty::Bivariant {
1312+
continue;
1313+
}
1314+
1315+
match param.kind {
1316+
ty::GenericParamDefKind::Lifetime => {
1317+
captured_lifetimes.insert(param.name);
1318+
}
1319+
ty::GenericParamDefKind::Type { synthetic: true, .. } => {
1320+
// FIXME: We can't provide a good suggestion for
1321+
// `use<...>` if we have an APIT. Bail for now.
1322+
return;
1323+
}
1324+
ty::GenericParamDefKind::Type { .. }
1325+
| ty::GenericParamDefKind::Const { .. } => {
1326+
captured_non_lifetimes.insert(param.name);
1327+
}
1328+
}
1329+
}
1330+
1331+
if let Some(parent) = generics.parent {
1332+
generics = tcx.generics_of(parent);
1333+
} else {
1334+
break;
1335+
}
1336+
}
1337+
1338+
if !captured_lifetimes.insert(new_lifetime) {
1339+
// Uh, strange. This lifetime appears to already be captured...
1340+
return;
1341+
}
1342+
1343+
let concatenated_bounds = captured_lifetimes
1344+
.into_iter()
1345+
.chain(captured_non_lifetimes)
1346+
.map(|sym| sym.to_string())
1347+
.collect::<Vec<_>>()
1348+
.join(", ");
1349+
1350+
diag.subdiagnostic(errors::AddPreciseCapturing::New {
1351+
span: tcx.def_span(opaque_def_id).shrink_to_hi(),
1352+
new_lifetime,
1353+
concatenated_bounds,
1354+
});
1355+
}
1356+
}

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ fn test_unstable_options_tracking_hash() {
691691
untracked!(dump_mir, Some(String::from("abc")));
692692
untracked!(dump_mir_dataflow, true);
693693
untracked!(dump_mir_dir, String::from("abc"));
694+
untracked!(dump_mir_exclude_alloc_bytes, true);
694695
untracked!(dump_mir_exclude_pass_number, true);
695696
untracked!(dump_mir_graphviz, true);
696697
untracked!(dump_mono_stats, SwitchWithOptPath::Enabled(Some("mono-items-dir/".into())));

compiler/rustc_lint/messages.ftl

+15-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ lint_builtin_allow_internal_unsafe =
5252
lint_builtin_anonymous_params = anonymous parameters are deprecated and will be removed in the next edition
5353
.suggestion = try naming the parameter or explicitly ignoring it
5454
55-
lint_builtin_asm_labels = avoid using named labels in inline assembly
56-
.help = only local labels of the form `<number>:` should be used in inline asm
57-
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
58-
5955
lint_builtin_clashing_extern_diff_name = `{$this}` redeclares `{$orig}` with a different signature
6056
.previous_decl_label = `{$orig}` previously declared here
6157
.mismatch_label = this signature doesn't match the previous declaration
@@ -163,6 +159,8 @@ lint_builtin_unreachable_pub = unreachable `pub` {$what}
163159
164160
lint_builtin_unsafe_block = usage of an `unsafe` block
165161
162+
lint_builtin_unsafe_extern_block = usage of an `unsafe extern` block
163+
166164
lint_builtin_unsafe_impl = implementation of an `unsafe` trait
167165
168166
lint_builtin_unsafe_trait = declaration of an `unsafe` trait
@@ -403,6 +401,19 @@ lint_incomplete_include =
403401
404402
lint_inner_macro_attribute_unstable = inner macro attributes are unstable
405403
404+
lint_invalid_asm_label_binary = avoid using labels containing only the digits `0` and `1` in inline assembly
405+
.label = use a different label that doesn't start with `0` or `1`
406+
.note = an LLVM bug makes these labels ambiguous with a binary literal number
407+
.note = see <https://bugs.llvm.org/show_bug.cgi?id=36144> for more information
408+
409+
lint_invalid_asm_label_format_arg = avoid using named labels in inline assembly
410+
.help = only local labels of the form `<number>:` should be used in inline asm
411+
.note1 = format arguments may expand to a non-numeric value
412+
.note2 = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
413+
lint_invalid_asm_label_named = avoid using named labels in inline assembly
414+
.help = only local labels of the form `<number>:` should be used in inline asm
415+
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
416+
lint_invalid_asm_label_no_span = the label may be declared in the expansion of a macro
406417
lint_invalid_crate_type_value = invalid `crate_type` value
407418
.suggestion = did you mean
408419

0 commit comments

Comments
 (0)