Skip to content

Commit 4ff16a9

Browse files
committed
Auto merge of #130066 - compiler-errors:rollup-sq6l0va, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #128871 (bypass linker configuration and cross target check for specific commands) - #129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging) - #129614 (Adjust doc comment of Condvar::wait_while) - #129840 (Implement suggestions for `elided_named_lifetimes`) - #129891 (Do not request sanitizers for naked functions) - #129899 (Add Suggestions for Misspelled Keywords) - #129940 (s390x: Fix a regression related to backchain feature) - #129987 (Don't store region in `CapturedPlace`) - #130054 (Add missing quotation marks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7468b69 + b09b7da commit 4ff16a9

File tree

87 files changed

+945
-237
lines changed

Some content is hidden

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

87 files changed

+945
-237
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -411,26 +411,31 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
411411
// the string "false". Now it is disabled by absence of the attribute.
412412
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
413413
}
414-
} else if llvm_util::get_version() >= (19, 0, 0) {
415-
// For non-naked functions, set branch protection attributes on aarch64.
416-
if let Some(BranchProtection { bti, pac_ret }) =
417-
cx.sess().opts.unstable_opts.branch_protection
418-
{
419-
assert!(cx.sess().target.arch == "aarch64");
420-
if bti {
421-
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
422-
}
423-
if let Some(PacRet { leaf, key }) = pac_ret {
424-
to_add.push(llvm::CreateAttrStringValue(
425-
cx.llcx,
426-
"sign-return-address",
427-
if leaf { "all" } else { "non-leaf" },
428-
));
429-
to_add.push(llvm::CreateAttrStringValue(
430-
cx.llcx,
431-
"sign-return-address-key",
432-
if key == PAuthKey::A { "a_key" } else { "b_key" },
433-
));
414+
} else {
415+
// Do not set sanitizer attributes for naked functions.
416+
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
417+
418+
if llvm_util::get_version() >= (19, 0, 0) {
419+
// For non-naked functions, set branch protection attributes on aarch64.
420+
if let Some(BranchProtection { bti, pac_ret }) =
421+
cx.sess().opts.unstable_opts.branch_protection
422+
{
423+
assert!(cx.sess().target.arch == "aarch64");
424+
if bti {
425+
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
426+
}
427+
if let Some(PacRet { leaf, key }) = pac_ret {
428+
to_add.push(llvm::CreateAttrStringValue(
429+
cx.llcx,
430+
"sign-return-address",
431+
if leaf { "all" } else { "non-leaf" },
432+
));
433+
to_add.push(llvm::CreateAttrStringValue(
434+
cx.llcx,
435+
"sign-return-address-key",
436+
if key == PAuthKey::A { "a_key" } else { "b_key" },
437+
));
438+
}
434439
}
435440
}
436441
}
@@ -485,7 +490,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
485490
if let Some(backchain) = backchain_attr(cx) {
486491
to_add.push(backchain);
487492
}
488-
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
489493
to_add.extend(patchable_function_entry_attrs(cx, codegen_fn_attrs.patchable_function_entry));
490494

491495
// Always annotate functions with the target-cpu they are compiled for.

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
353353
None
354354
}
355355
})
356-
.filter(|feature| {
357-
RUSTC_SPECIAL_FEATURES.contains(feature) || features.contains(&Symbol::intern(feature))
358-
})
356+
.filter(|feature| features.contains(&Symbol::intern(feature)))
359357
.map(|feature| Symbol::intern(feature))
360358
.collect()
361359
}

compiler/rustc_hir_typeck/src/upvar.rs

+19-40
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use rustc_hir as hir;
3939
use rustc_hir::def_id::LocalDefId;
4040
use rustc_hir::intravisit::{self, Visitor};
4141
use rustc_hir::HirId;
42-
use rustc_infer::infer::UpvarRegion;
4342
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
4443
use rustc_middle::mir::FakeReadCause;
4544
use rustc_middle::traits::ObligationCauseCode;
@@ -425,7 +424,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
425424
self.tcx,
426425
upvar_ty,
427426
capture,
428-
if needs_ref { Some(closure_env_region) } else { child_capture.region },
427+
if needs_ref {
428+
closure_env_region
429+
} else {
430+
self.tcx.lifetimes.re_erased
431+
},
429432
);
430433
},
431434
),
@@ -587,7 +590,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
587590

588591
debug!(?captured_place.place, ?upvar_ty, ?capture, ?captured_place.mutability);
589592

590-
apply_capture_kind_on_capture_ty(self.tcx, upvar_ty, capture, captured_place.region)
593+
apply_capture_kind_on_capture_ty(
594+
self.tcx,
595+
upvar_ty,
596+
capture,
597+
self.tcx.lifetimes.re_erased,
598+
)
591599
})
592600
.collect()
593601
}
@@ -775,13 +783,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
775783

776784
let Some(min_cap_list) = root_var_min_capture_list.get_mut(&var_hir_id) else {
777785
let mutability = self.determine_capture_mutability(&typeck_results, &place);
778-
let min_cap_list = vec![ty::CapturedPlace {
779-
var_ident,
780-
place,
781-
info: capture_info,
782-
mutability,
783-
region: None,
784-
}];
786+
let min_cap_list =
787+
vec![ty::CapturedPlace { var_ident, place, info: capture_info, mutability }];
785788
root_var_min_capture_list.insert(var_hir_id, min_cap_list);
786789
continue;
787790
};
@@ -874,34 +877,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
874877
// Only need to insert when we don't have an ancestor in the existing min capture list
875878
if !ancestor_found {
876879
let mutability = self.determine_capture_mutability(&typeck_results, &place);
877-
let captured_place = ty::CapturedPlace {
878-
var_ident,
879-
place,
880-
info: updated_capture_info,
881-
mutability,
882-
region: None,
883-
};
880+
let captured_place =
881+
ty::CapturedPlace { var_ident, place, info: updated_capture_info, mutability };
884882
min_cap_list.push(captured_place);
885883
}
886884
}
887885

888-
// For each capture that is determined to be captured by ref, add region info.
889-
for (_, captures) in &mut root_var_min_capture_list {
890-
for capture in captures {
891-
match capture.info.capture_kind {
892-
ty::UpvarCapture::ByRef(_) => {
893-
let PlaceBase::Upvar(upvar_id) = capture.place.base else {
894-
bug!("expected upvar")
895-
};
896-
let origin = UpvarRegion(upvar_id, closure_span);
897-
let upvar_region = self.next_region_var(origin);
898-
capture.region = Some(upvar_region);
899-
}
900-
_ => (),
901-
}
902-
}
903-
}
904-
905886
debug!(
906887
"For closure={:?}, min_captures before sorting={:?}",
907888
closure_def_id, root_var_min_capture_list
@@ -1195,7 +1176,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11951176
self.tcx,
11961177
ty,
11971178
max_capture_info.capture_kind,
1198-
Some(self.tcx.lifetimes.re_erased),
1179+
self.tcx.lifetimes.re_erased,
11991180
)
12001181
}
12011182
};
@@ -1217,7 +1198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12171198
self.tcx,
12181199
capture.place.ty(),
12191200
capture.info.capture_kind,
1220-
Some(self.tcx.lifetimes.re_erased),
1201+
self.tcx.lifetimes.re_erased,
12211202
);
12221203

12231204
// Checks if a capture implements any of the auto traits
@@ -1935,13 +1916,11 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
19351916
tcx: TyCtxt<'tcx>,
19361917
ty: Ty<'tcx>,
19371918
capture_kind: UpvarCapture,
1938-
region: Option<ty::Region<'tcx>>,
1919+
region: ty::Region<'tcx>,
19391920
) -> Ty<'tcx> {
19401921
match capture_kind {
19411922
ty::UpvarCapture::ByValue => ty,
1942-
ty::UpvarCapture::ByRef(kind) => {
1943-
Ty::new_ref(tcx, region.unwrap(), ty, kind.to_mutbl_lossy())
1944-
}
1923+
ty::UpvarCapture::ByRef(kind) => Ty::new_ref(tcx, region, ty, kind.to_mutbl_lossy()),
19451924
}
19461925
}
19471926

compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ lint_duplicate_matcher_binding = duplicate matcher binding
255255
lint_elided_named_lifetime = elided lifetime has a name
256256
.label_elided = this elided lifetime gets resolved as `{$name}`
257257
.label_named = lifetime `{$name}` declared here
258+
.suggestion = consider specifying it explicitly
258259
259260
lint_enum_intrinsics_mem_discriminant =
260261
the return value of `mem::discriminant` is unspecified when called with a non-enum type

compiler/rustc_lint/src/context/diagnostics.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use rustc_errors::{
88
elided_lifetime_in_path_suggestion, Applicability, Diag, DiagArgValue, LintDiagnostic,
99
};
1010
use rustc_middle::middle::stability;
11-
use rustc_session::lint::BuiltinLintDiag;
11+
use rustc_session::lint::{BuiltinLintDiag, ElidedLifetimeResolution};
1212
use rustc_session::Session;
1313
use rustc_span::symbol::kw;
1414
use rustc_span::BytePos;
1515
use tracing::debug;
1616

17-
use crate::lints;
17+
use crate::lints::{self, ElidedNamedLifetime};
1818

1919
mod check_cfg;
2020

@@ -442,15 +442,14 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
442442
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
443443
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
444444
}
445-
BuiltinLintDiag::ElidedIsStatic { elided } => {
446-
lints::ElidedNamedLifetime { elided, name: kw::StaticLifetime, named_declaration: None }
447-
.decorate_lint(diag)
448-
}
449-
BuiltinLintDiag::ElidedIsParam { elided, param: (param_name, param_span) } => {
450-
lints::ElidedNamedLifetime {
451-
elided,
452-
name: param_name,
453-
named_declaration: Some(param_span),
445+
BuiltinLintDiag::ElidedNamedLifetimes { elided: (span, kind), resolution } => {
446+
match resolution {
447+
ElidedLifetimeResolution::Static => {
448+
ElidedNamedLifetime { span, kind, name: kw::StaticLifetime, declaration: None }
449+
}
450+
ElidedLifetimeResolution::Param(name, declaration) => {
451+
ElidedNamedLifetime { span, kind, name, declaration: Some(declaration) }
452+
}
454453
}
455454
.decorate_lint(diag)
456455
}

compiler/rustc_lint/src/lints.rs

+49-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::{
99
};
1010
use rustc_hir::def::Namespace;
1111
use rustc_hir::def_id::DefId;
12-
use rustc_hir::{self as hir};
12+
use rustc_hir::{self as hir, MissingLifetimeKind};
1313
use rustc_macros::{LintDiagnostic, Subdiagnostic};
1414
use rustc_middle::ty::inhabitedness::InhabitedPredicate;
1515
use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
@@ -2623,14 +2623,56 @@ pub(crate) struct ElidedLifetimesInPaths {
26232623
pub subdiag: ElidedLifetimeInPathSubdiag,
26242624
}
26252625

2626-
#[derive(LintDiagnostic)]
2627-
#[diag(lint_elided_named_lifetime)]
26282626
pub(crate) struct ElidedNamedLifetime {
2629-
#[label(lint_label_elided)]
2630-
pub elided: Span,
2627+
pub span: Span,
2628+
pub kind: MissingLifetimeKind,
26312629
pub name: Symbol,
2632-
#[label(lint_label_named)]
2633-
pub named_declaration: Option<Span>,
2630+
pub declaration: Option<Span>,
2631+
}
2632+
2633+
impl<G: EmissionGuarantee> LintDiagnostic<'_, G> for ElidedNamedLifetime {
2634+
fn decorate_lint(self, diag: &mut rustc_errors::Diag<'_, G>) {
2635+
let Self { span, kind, name, declaration } = self;
2636+
diag.primary_message(fluent::lint_elided_named_lifetime);
2637+
diag.arg("name", name);
2638+
diag.span_label(span, fluent::lint_label_elided);
2639+
if let Some(declaration) = declaration {
2640+
diag.span_label(declaration, fluent::lint_label_named);
2641+
}
2642+
// FIXME(GrigorenkoPV): this `if` and `return` should be removed,
2643+
// but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
2644+
// https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
2645+
// HACK: `'static` suggestions will never sonflict, emit only those for now.
2646+
if name != rustc_span::symbol::kw::StaticLifetime {
2647+
return;
2648+
}
2649+
match kind {
2650+
MissingLifetimeKind::Underscore => diag.span_suggestion_verbose(
2651+
span,
2652+
fluent::lint_suggestion,
2653+
format!("{name}"),
2654+
Applicability::MachineApplicable,
2655+
),
2656+
MissingLifetimeKind::Ampersand => diag.span_suggestion_verbose(
2657+
span.shrink_to_hi(),
2658+
fluent::lint_suggestion,
2659+
format!("{name} "),
2660+
Applicability::MachineApplicable,
2661+
),
2662+
MissingLifetimeKind::Comma => diag.span_suggestion_verbose(
2663+
span.shrink_to_hi(),
2664+
fluent::lint_suggestion,
2665+
format!("{name}, "),
2666+
Applicability::MachineApplicable,
2667+
),
2668+
MissingLifetimeKind::Brackets => diag.span_suggestion_verbose(
2669+
span.shrink_to_hi(),
2670+
fluent::lint_suggestion,
2671+
format!("<{name}>"),
2672+
Applicability::MachineApplicable,
2673+
),
2674+
};
2675+
}
26342676
}
26352677

26362678
#[derive(LintDiagnostic)]

compiler/rustc_lint_defs/src/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{
1010
};
1111
use rustc_error_messages::{DiagMessage, MultiSpan};
1212
use rustc_hir::def::Namespace;
13-
use rustc_hir::{HashStableContext, HirId};
13+
use rustc_hir::{HashStableContext, HirId, MissingLifetimeKind};
1414
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1515
use rustc_span::edition::Edition;
1616
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
@@ -556,6 +556,12 @@ pub enum DeprecatedSinceKind {
556556
InVersion(String),
557557
}
558558

559+
#[derive(Debug)]
560+
pub enum ElidedLifetimeResolution {
561+
Static,
562+
Param(Symbol, Span),
563+
}
564+
559565
// This could be a closure, but then implementing derive trait
560566
// becomes hacky (and it gets allocated).
561567
#[derive(Debug)]
@@ -568,12 +574,9 @@ pub enum BuiltinLintDiag {
568574
},
569575
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
570576
ElidedLifetimesInPaths(usize, Span, bool, Span),
571-
ElidedIsStatic {
572-
elided: Span,
573-
},
574-
ElidedIsParam {
575-
elided: Span,
576-
param: (Symbol, Span),
577+
ElidedNamedLifetimes {
578+
elided: (Span, MissingLifetimeKind),
579+
resolution: ElidedLifetimeResolution,
577580
},
578581
UnknownCrateTypes {
579582
span: Span,

compiler/rustc_middle/src/ty/closure.rs

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub struct CapturedPlace<'tcx> {
8888

8989
/// Represents if `place` can be mutated or not.
9090
pub mutability: hir::Mutability,
91-
92-
/// Region of the resulting reference if the upvar is captured by ref.
93-
pub region: Option<ty::Region<'tcx>>,
9491
}
9592

9693
impl<'tcx> CapturedPlace<'tcx> {

compiler/rustc_parse/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ parse_invalid_char_in_escape_msg = invalid character in {$is_hex ->
381381
*[false] unicode
382382
} escape
383383
384+
384385
parse_invalid_comparison_operator = invalid comparison operator `{$invalid}`
385386
.use_instead = `{$invalid}` is not a valid comparison operator, use `{$correct}`
386387
.spaceship_operator_invalid = `<=>` is not a valid comparison operator, use `std::cmp::Ordering`
@@ -581,6 +582,11 @@ parse_missing_trait_in_trait_impl = missing trait in a trait impl
581582
.suggestion_add_trait = add a trait here
582583
.suggestion_remove_for = for an inherent impl, drop this `for`
583584
585+
parse_misspelled_kw = {$is_incorrect_case ->
586+
[true] write keyword `{$similar_kw}` in lowercase
587+
*[false] there is a keyword `{$similar_kw}` with a similar name
588+
}
589+
584590
parse_modifier_lifetime = `{$modifier}` may only modify trait bounds, not lifetime bounds
585591
.suggestion = remove the `{$modifier}`
586592

0 commit comments

Comments
 (0)