Skip to content

Commit

Permalink
Auto merge of rust-lang#130066 - compiler-errors:rollup-sq6l0va, r=co…
Browse files Browse the repository at this point in the history
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128871 (bypass linker configuration and cross target check for specific commands)
 - rust-lang#129468 ([testsuite][cleanup] Remove all usages of `dont_merge` hack to avoid function merging)
 - rust-lang#129614 (Adjust doc comment of Condvar::wait_while)
 - rust-lang#129840 (Implement suggestions for `elided_named_lifetimes`)
 - rust-lang#129891 (Do not request sanitizers for naked functions)
 - rust-lang#129899 (Add Suggestions for Misspelled Keywords)
 - rust-lang#129940 (s390x: Fix a regression related to backchain feature)
 - rust-lang#129987 (Don't store region in `CapturedPlace`)
 - rust-lang#130054 (Add missing quotation marks)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 7, 2024
2 parents 7468b69 + b09b7da commit 4ff16a9
Show file tree
Hide file tree
Showing 87 changed files with 945 additions and 237 deletions.
46 changes: 25 additions & 21 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,26 +411,31 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
// the string "false". Now it is disabled by absence of the attribute.
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
}
} else if llvm_util::get_version() >= (19, 0, 0) {
// For non-naked functions, set branch protection attributes on aarch64.
if let Some(BranchProtection { bti, pac_ret }) =
cx.sess().opts.unstable_opts.branch_protection
{
assert!(cx.sess().target.arch == "aarch64");
if bti {
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
}
if let Some(PacRet { leaf, key }) = pac_ret {
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address",
if leaf { "all" } else { "non-leaf" },
));
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address-key",
if key == PAuthKey::A { "a_key" } else { "b_key" },
));
} else {
// Do not set sanitizer attributes for naked functions.
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));

if llvm_util::get_version() >= (19, 0, 0) {
// For non-naked functions, set branch protection attributes on aarch64.
if let Some(BranchProtection { bti, pac_ret }) =
cx.sess().opts.unstable_opts.branch_protection
{
assert!(cx.sess().target.arch == "aarch64");
if bti {
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
}
if let Some(PacRet { leaf, key }) = pac_ret {
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address",
if leaf { "all" } else { "non-leaf" },
));
to_add.push(llvm::CreateAttrStringValue(
cx.llcx,
"sign-return-address-key",
if key == PAuthKey::A { "a_key" } else { "b_key" },
));
}
}
}
}
Expand Down Expand Up @@ -485,7 +490,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
if let Some(backchain) = backchain_attr(cx) {
to_add.push(backchain);
}
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
to_add.extend(patchable_function_entry_attrs(cx, codegen_fn_attrs.patchable_function_entry));

// Always annotate functions with the target-cpu they are compiled for.
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
None
}
})
.filter(|feature| {
RUSTC_SPECIAL_FEATURES.contains(feature) || features.contains(&Symbol::intern(feature))
})
.filter(|feature| features.contains(&Symbol::intern(feature)))
.map(|feature| Symbol::intern(feature))
.collect()
}
Expand Down
59 changes: 19 additions & 40 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirId;
use rustc_infer::infer::UpvarRegion;
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
use rustc_middle::mir::FakeReadCause;
use rustc_middle::traits::ObligationCauseCode;
Expand Down Expand Up @@ -425,7 +424,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
upvar_ty,
capture,
if needs_ref { Some(closure_env_region) } else { child_capture.region },
if needs_ref {
closure_env_region
} else {
self.tcx.lifetimes.re_erased
},
);
},
),
Expand Down Expand Up @@ -587,7 +590,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

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

apply_capture_kind_on_capture_ty(self.tcx, upvar_ty, capture, captured_place.region)
apply_capture_kind_on_capture_ty(
self.tcx,
upvar_ty,
capture,
self.tcx.lifetimes.re_erased,
)
})
.collect()
}
Expand Down Expand Up @@ -775,13 +783,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let Some(min_cap_list) = root_var_min_capture_list.get_mut(&var_hir_id) else {
let mutability = self.determine_capture_mutability(&typeck_results, &place);
let min_cap_list = vec![ty::CapturedPlace {
var_ident,
place,
info: capture_info,
mutability,
region: None,
}];
let min_cap_list =
vec![ty::CapturedPlace { var_ident, place, info: capture_info, mutability }];
root_var_min_capture_list.insert(var_hir_id, min_cap_list);
continue;
};
Expand Down Expand Up @@ -874,34 +877,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Only need to insert when we don't have an ancestor in the existing min capture list
if !ancestor_found {
let mutability = self.determine_capture_mutability(&typeck_results, &place);
let captured_place = ty::CapturedPlace {
var_ident,
place,
info: updated_capture_info,
mutability,
region: None,
};
let captured_place =
ty::CapturedPlace { var_ident, place, info: updated_capture_info, mutability };
min_cap_list.push(captured_place);
}
}

// For each capture that is determined to be captured by ref, add region info.
for (_, captures) in &mut root_var_min_capture_list {
for capture in captures {
match capture.info.capture_kind {
ty::UpvarCapture::ByRef(_) => {
let PlaceBase::Upvar(upvar_id) = capture.place.base else {
bug!("expected upvar")
};
let origin = UpvarRegion(upvar_id, closure_span);
let upvar_region = self.next_region_var(origin);
capture.region = Some(upvar_region);
}
_ => (),
}
}
}

debug!(
"For closure={:?}, min_captures before sorting={:?}",
closure_def_id, root_var_min_capture_list
Expand Down Expand Up @@ -1195,7 +1176,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
ty,
max_capture_info.capture_kind,
Some(self.tcx.lifetimes.re_erased),
self.tcx.lifetimes.re_erased,
)
}
};
Expand All @@ -1217,7 +1198,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
capture.place.ty(),
capture.info.capture_kind,
Some(self.tcx.lifetimes.re_erased),
self.tcx.lifetimes.re_erased,
);

// Checks if a capture implements any of the auto traits
Expand Down Expand Up @@ -1935,13 +1916,11 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
capture_kind: UpvarCapture,
region: Option<ty::Region<'tcx>>,
region: ty::Region<'tcx>,
) -> Ty<'tcx> {
match capture_kind {
ty::UpvarCapture::ByValue => ty,
ty::UpvarCapture::ByRef(kind) => {
Ty::new_ref(tcx, region.unwrap(), ty, kind.to_mutbl_lossy())
}
ty::UpvarCapture::ByRef(kind) => Ty::new_ref(tcx, region, ty, kind.to_mutbl_lossy()),
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ lint_duplicate_matcher_binding = duplicate matcher binding
lint_elided_named_lifetime = elided lifetime has a name
.label_elided = this elided lifetime gets resolved as `{$name}`
.label_named = lifetime `{$name}` declared here
.suggestion = consider specifying it explicitly
lint_enum_intrinsics_mem_discriminant =
the return value of `mem::discriminant` is unspecified when called with a non-enum type
Expand Down
21 changes: 10 additions & 11 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use rustc_errors::{
elided_lifetime_in_path_suggestion, Applicability, Diag, DiagArgValue, LintDiagnostic,
};
use rustc_middle::middle::stability;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::{BuiltinLintDiag, ElidedLifetimeResolution};
use rustc_session::Session;
use rustc_span::symbol::kw;
use rustc_span::BytePos;
use tracing::debug;

use crate::lints;
use crate::lints::{self, ElidedNamedLifetime};

mod check_cfg;

Expand Down Expand Up @@ -442,15 +442,14 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
}
BuiltinLintDiag::ElidedIsStatic { elided } => {
lints::ElidedNamedLifetime { elided, name: kw::StaticLifetime, named_declaration: None }
.decorate_lint(diag)
}
BuiltinLintDiag::ElidedIsParam { elided, param: (param_name, param_span) } => {
lints::ElidedNamedLifetime {
elided,
name: param_name,
named_declaration: Some(param_span),
BuiltinLintDiag::ElidedNamedLifetimes { elided: (span, kind), resolution } => {
match resolution {
ElidedLifetimeResolution::Static => {
ElidedNamedLifetime { span, kind, name: kw::StaticLifetime, declaration: None }
}
ElidedLifetimeResolution::Param(name, declaration) => {
ElidedNamedLifetime { span, kind, name, declaration: Some(declaration) }
}
}
.decorate_lint(diag)
}
Expand Down
56 changes: 49 additions & 7 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_errors::{
};
use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir};
use rustc_hir::{self as hir, MissingLifetimeKind};
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::inhabitedness::InhabitedPredicate;
use rustc_middle::ty::{Clause, PolyExistentialTraitRef, Ty, TyCtxt};
Expand Down Expand Up @@ -2623,14 +2623,56 @@ pub(crate) struct ElidedLifetimesInPaths {
pub subdiag: ElidedLifetimeInPathSubdiag,
}

#[derive(LintDiagnostic)]
#[diag(lint_elided_named_lifetime)]
pub(crate) struct ElidedNamedLifetime {
#[label(lint_label_elided)]
pub elided: Span,
pub span: Span,
pub kind: MissingLifetimeKind,
pub name: Symbol,
#[label(lint_label_named)]
pub named_declaration: Option<Span>,
pub declaration: Option<Span>,
}

impl<G: EmissionGuarantee> LintDiagnostic<'_, G> for ElidedNamedLifetime {
fn decorate_lint(self, diag: &mut rustc_errors::Diag<'_, G>) {
let Self { span, kind, name, declaration } = self;
diag.primary_message(fluent::lint_elided_named_lifetime);
diag.arg("name", name);
diag.span_label(span, fluent::lint_label_elided);
if let Some(declaration) = declaration {
diag.span_label(declaration, fluent::lint_label_named);
}
// FIXME(GrigorenkoPV): this `if` and `return` should be removed,
// but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
// https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
// HACK: `'static` suggestions will never sonflict, emit only those for now.
if name != rustc_span::symbol::kw::StaticLifetime {
return;
}
match kind {
MissingLifetimeKind::Underscore => diag.span_suggestion_verbose(
span,
fluent::lint_suggestion,
format!("{name}"),
Applicability::MachineApplicable,
),
MissingLifetimeKind::Ampersand => diag.span_suggestion_verbose(
span.shrink_to_hi(),
fluent::lint_suggestion,
format!("{name} "),
Applicability::MachineApplicable,
),
MissingLifetimeKind::Comma => diag.span_suggestion_verbose(
span.shrink_to_hi(),
fluent::lint_suggestion,
format!("{name}, "),
Applicability::MachineApplicable,
),
MissingLifetimeKind::Brackets => diag.span_suggestion_verbose(
span.shrink_to_hi(),
fluent::lint_suggestion,
format!("<{name}>"),
Applicability::MachineApplicable,
),
};
}
}

#[derive(LintDiagnostic)]
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{
};
use rustc_error_messages::{DiagMessage, MultiSpan};
use rustc_hir::def::Namespace;
use rustc_hir::{HashStableContext, HirId};
use rustc_hir::{HashStableContext, HirId, MissingLifetimeKind};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::edition::Edition;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
Expand Down Expand Up @@ -556,6 +556,12 @@ pub enum DeprecatedSinceKind {
InVersion(String),
}

#[derive(Debug)]
pub enum ElidedLifetimeResolution {
Static,
Param(Symbol, Span),
}

// This could be a closure, but then implementing derive trait
// becomes hacky (and it gets allocated).
#[derive(Debug)]
Expand All @@ -568,12 +574,9 @@ pub enum BuiltinLintDiag {
},
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
ElidedLifetimesInPaths(usize, Span, bool, Span),
ElidedIsStatic {
elided: Span,
},
ElidedIsParam {
elided: Span,
param: (Symbol, Span),
ElidedNamedLifetimes {
elided: (Span, MissingLifetimeKind),
resolution: ElidedLifetimeResolution,
},
UnknownCrateTypes {
span: Span,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ pub struct CapturedPlace<'tcx> {

/// Represents if `place` can be mutated or not.
pub mutability: hir::Mutability,

/// Region of the resulting reference if the upvar is captured by ref.
pub region: Option<ty::Region<'tcx>>,
}

impl<'tcx> CapturedPlace<'tcx> {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ parse_invalid_char_in_escape_msg = invalid character in {$is_hex ->
*[false] unicode
} escape
parse_invalid_comparison_operator = invalid comparison operator `{$invalid}`
.use_instead = `{$invalid}` is not a valid comparison operator, use `{$correct}`
.spaceship_operator_invalid = `<=>` is not a valid comparison operator, use `std::cmp::Ordering`
Expand Down Expand Up @@ -581,6 +582,11 @@ parse_missing_trait_in_trait_impl = missing trait in a trait impl
.suggestion_add_trait = add a trait here
.suggestion_remove_for = for an inherent impl, drop this `for`
parse_misspelled_kw = {$is_incorrect_case ->
[true] write keyword `{$similar_kw}` in lowercase
*[false] there is a keyword `{$similar_kw}` with a similar name
}
parse_modifier_lifetime = `{$modifier}` may only modify trait bounds, not lifetime bounds
.suggestion = remove the `{$modifier}`
Expand Down
Loading

0 comments on commit 4ff16a9

Please sign in to comment.