Skip to content

Rollup of 9 pull requests #139940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
068a332
cfi: Remove #[no_sanitize(cfi)] for extern weak functions
1c3t3a Apr 11, 2025
8887af7
Improve parse errors for lifetimes in type position
fmease Apr 14, 2025
6242335
Improve diagnostic for E0178 (bad `+` in type)
fmease Apr 15, 2025
ee53c26
Add `explicit_extern_abis` unstable feature
obeis Apr 8, 2025
c4d3563
Also remove the no_sanitize feature for std
1c3t3a Apr 15, 2025
b084603
rustc_target: RISC-V: feature addition batch 2
a4lg Apr 6, 2025
52392ec
rustc_target: Use "B" shorthand on the RISC-V Android target
a4lg Apr 6, 2025
bd9bd38
Allow disabling `--llvm-shared` in opt-dist
Kobzol Apr 16, 2025
6f386e7
Only delete the lld directory if it exists
Kobzol Apr 16, 2025
48e119e
stepping into impls for norm is unproductive
lcnr Apr 16, 2025
face471
replace some #[rustc_intrinsic] usage with use of the libcore declara…
RalfJung Apr 16, 2025
7ce21e4
Cleaned up base tests for `isize` and `usize` in `tests/ui/numbers-ar…
spencer3035 Apr 16, 2025
01cfa9a
Add hard error for `extern` without explicit ABI
obeis Apr 8, 2025
d17c04e
Add test for `extern` without explicit ABI
obeis Apr 8, 2025
bb3c981
Don't require rigid alias's trait to hold
compiler-errors Apr 16, 2025
bb3e156
Rollup merge of #135340 - obeis:explicit-extern-abis, r=traviscross,n…
matthiaskrgr Apr 16, 2025
ff55f2a
Rollup merge of #139440 - a4lg:riscv-feature-addition-batch-2, r=Amanieu
matthiaskrgr Apr 16, 2025
f14e632
Rollup merge of #139667 - 1c3t3a:remove-no-sanitize, r=m-ou-se
matthiaskrgr Apr 16, 2025
c594a88
Rollup merge of #139828 - compiler-errors:rigid-trait, r=lcnr
matthiaskrgr Apr 16, 2025
7ab385e
Rollup merge of #139854 - fmease:modern-diag-for-lt-in-ty, r=davidtwco
matthiaskrgr Apr 16, 2025
afb60d3
Rollup merge of #139889 - spencer3035:clean-ui-tests-3-of-n, r=jieyouxu
matthiaskrgr Apr 16, 2025
848ec58
Rollup merge of #139894 - Kobzol:opt-dist-fixes, r=lqd
matthiaskrgr Apr 16, 2025
9e0be6c
Rollup merge of #139900 - lcnr:normalizes-to-where-bounds-unproductiv…
matthiaskrgr Apr 16, 2025
f8f22ad
Rollup merge of #139915 - RalfJung:intrinsic-imports, r=compiler-errors
matthiaskrgr Apr 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
.suggestion = remove the {$remove_descr}
.label = `extern` block begins here

ast_passes_extern_without_abi = `extern` declarations without an explicit ABI are disallowed
.suggestion = specify an ABI
.help = prior to Rust 2024, a default ABI was inferred

ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
.suggestion = remove the attribute
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ impl<'a> AstValidator<'a> {
self.dcx().emit_err(errors::PatternFnPointer { span });
});
if let Extern::Implicit(extern_span) = bfty.ext {
self.maybe_lint_missing_abi(extern_span, ty.id);
self.handle_missing_abi(extern_span, ty.id);
}
}
TyKind::TraitObject(bounds, ..) => {
Expand Down Expand Up @@ -717,10 +717,12 @@ impl<'a> AstValidator<'a> {
}
}

fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
fn handle_missing_abi(&mut self, span: Span, id: NodeId) {
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
// call site which do not have a macro backtrace. See #61963.
if self
if span.edition().at_least_edition_future() && self.features.explicit_extern_abis() {
self.dcx().emit_err(errors::MissingAbi { span });
} else if self
.sess
.source_map()
.span_to_snippet(span)
Expand Down Expand Up @@ -996,7 +998,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

if abi.is_none() {
self.maybe_lint_missing_abi(*extern_span, item.id);
self.handle_missing_abi(*extern_span, item.id);
}
self.with_in_extern_mod(*safety, |this| {
visit::walk_item(this, item);
Expand Down Expand Up @@ -1370,7 +1372,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
},
) = fk
{
self.maybe_lint_missing_abi(*extern_span, id);
self.handle_missing_abi(*extern_span, id);
}

// Functions without bodies cannot have patterns.
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,12 @@ pub(crate) struct DuplicatePreciseCapturing {
#[label]
pub bound2: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_extern_without_abi)]
#[help]
pub(crate) struct MissingAbi {
#[primary_span]
#[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
pub span: Span,
}
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ declare_features! (
(incomplete, ergonomic_clones, "1.87.0", Some(132290)),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Disallows `extern` without an explicit ABI.
(unstable, explicit_extern_abis, "CURRENT_RUSTC_VERSION", Some(134986)),
/// Allows explicit tail calls via `become` expression.
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
/// Allows using `aapcs`, `efiapi`, `sysv64` and `win64` as calling conventions
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ lint_expectation = this lint expectation is unfulfilled
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
.suggestion = convert it to a `use`

lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
lint_extern_without_abi = `extern` declarations without an explicit ABI are deprecated
.label = ABI should be specified here
.suggestion = explicitly specify the {$default_abi} ABI

Expand Down
21 changes: 13 additions & 8 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,23 @@ where
// fixing it may cause inference breakage or introduce ambiguity.
GoalSource::Misc => PathKind::Unknown,
GoalSource::NormalizeGoal(path_kind) => path_kind,
GoalSource::ImplWhereBound => {
GoalSource::ImplWhereBound => match self.current_goal_kind {
// We currently only consider a cycle coinductive if it steps
// into a where-clause of a coinductive trait.
CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
// While normalizing via an impl does step into a where-clause of
// an impl, accessing the associated item immediately steps out of
// it again. This means cycles/recursive calls are not guarded
// by impls used for normalization.
//
// See tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.rs
// for how this can go wrong.
CurrentGoalKind::NormalizesTo => PathKind::Inductive,
// We probably want to make all traits coinductive in the future,
// so we treat cycles involving their where-clauses as ambiguous.
if let CurrentGoalKind::CoinductiveTrait = self.current_goal_kind {
PathKind::Coinductive
} else {
PathKind::Unknown
}
}
// so we treat cycles involving where-clauses of not-yet coinductive
// traits as ambiguous for now.
CurrentGoalKind::Misc => PathKind::Unknown,
},
// Relating types is always unproductive. If we were to map proof trees to
// corecursive functions as explained in #136824, relating types never
// introduces a constructor which could cause the recursion to be guarded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ where
goal,
goal.predicate.alias,
);
this.add_goal(GoalSource::AliasWellFormed, goal.with(cx, trait_ref));
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
})
})
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ parse_maybe_recover_from_bad_qpath_stage_2 =
.suggestion = types that don't start with an identifier need to be surrounded with angle brackets in qualified paths

parse_maybe_recover_from_bad_type_plus =
expected a path on the left-hand side of `+`, not `{$ty}`
expected a path on the left-hand side of `+`

parse_maybe_report_ambiguous_plus =
ambiguous `+` in a type
Expand Down Expand Up @@ -642,7 +642,9 @@ parse_mut_on_nested_ident_pattern = `mut` must be attached to each individual bi
.suggestion = add `mut` to each binding
parse_mut_on_non_ident_pattern = `mut` must be followed by a named binding
.suggestion = remove the `mut` prefix
parse_need_plus_after_trait_object_lifetime = lifetime in trait object type must be followed by `+`

parse_need_plus_after_trait_object_lifetime = lifetimes must be followed by `+` to form a trait object type
.suggestion = consider adding a trait bound after the potential lifetime bound

parse_nested_adt = `{$kw_str}` definition cannot be nested inside `{$keyword}`
.suggestion = consider creating a new `{$kw_str}` definition instead of nesting
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub(crate) struct AmbiguousPlus {
#[derive(Diagnostic)]
#[diag(parse_maybe_recover_from_bad_type_plus, code = E0178)]
pub(crate) struct BadTypePlus {
pub ty: String,
#[primary_span]
pub span: Span,
#[subdiagnostic]
Expand Down Expand Up @@ -2806,6 +2805,8 @@ pub(crate) struct ReturnTypesUseThinArrow {
pub(crate) struct NeedPlusAfterTraitObjectLifetime {
#[primary_span]
pub span: Span,
#[suggestion(code = " + /* Trait */", applicability = "has-placeholders")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,19 +1657,19 @@ impl<'a> Parser<'a> {

self.bump(); // `+`
let _bounds = self.parse_generic_bounds()?;
let sum_span = ty.span.to(self.prev_token.span);

let sub = match &ty.kind {
TyKind::Ref(_lifetime, mut_ty) => {
let lo = mut_ty.ty.span.shrink_to_lo();
let hi = self.prev_token.span.shrink_to_hi();
BadTypePlusSub::AddParen { suggestion: AddParen { lo, hi } }
}
TyKind::Ptr(..) | TyKind::BareFn(..) => BadTypePlusSub::ForgotParen { span: sum_span },
_ => BadTypePlusSub::ExpectPath { span: sum_span },
TyKind::Ptr(..) | TyKind::BareFn(..) => {
BadTypePlusSub::ForgotParen { span: ty.span.to(self.prev_token.span) }
}
_ => BadTypePlusSub::ExpectPath { span: ty.span },
};

self.dcx().emit_err(BadTypePlus { ty: pprust::ty_to_string(ty), span: sum_span, sub });
self.dcx().emit_err(BadTypePlus { span: ty.span, sub });

Ok(())
}
Expand Down
63 changes: 57 additions & 6 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_ast::{
Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty,
TyKind, UnsafeBinderTy,
};
use rustc_errors::{Applicability, PResult};
use rustc_errors::{Applicability, Diag, PResult};
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
use thin_vec::{ThinVec, thin_vec};

Expand Down Expand Up @@ -411,6 +411,9 @@ impl<'a> Parser<'a> {
TyKind::Path(None, path) if maybe_bounds => {
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true)
}
// For `('a) + …`, we know that `'a` in type position already lead to an error being
// emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
// other irrelevant consequential errors.
TyKind::TraitObject(bounds, TraitObjectSyntax::None)
if maybe_bounds && bounds.len() == 1 && !trailing_plus =>
{
Expand All @@ -425,12 +428,60 @@ impl<'a> Parser<'a> {
}

fn parse_bare_trait_object(&mut self, lo: Span, allow_plus: AllowPlus) -> PResult<'a, TyKind> {
let lt_no_plus = self.check_lifetime() && !self.look_ahead(1, |t| t.is_like_plus());
let bounds = self.parse_generic_bounds_common(allow_plus)?;
if lt_no_plus {
self.dcx().emit_err(NeedPlusAfterTraitObjectLifetime { span: lo });
// A lifetime only begins a bare trait object type if it is followed by `+`!
if self.token.is_lifetime() && !self.look_ahead(1, |t| t.is_like_plus()) {
// In Rust 2021 and beyond, we assume that the user didn't intend to write a bare trait
// object type with a leading lifetime bound since that seems very unlikely given the
// fact that `dyn`-less trait objects are *semantically* invalid.
if self.psess.edition.at_least_rust_2021() {
let lt = self.expect_lifetime();
let mut err = self.dcx().struct_span_err(lo, "expected type, found lifetime");
err.span_label(lo, "expected type");
return Ok(match self.maybe_recover_ref_ty_no_leading_ampersand(lt, lo, err) {
Ok(ref_ty) => ref_ty,
Err(err) => TyKind::Err(err.emit()),
});
}

self.dcx().emit_err(NeedPlusAfterTraitObjectLifetime {
span: lo,
suggestion: lo.shrink_to_hi(),
});
}
Ok(TyKind::TraitObject(
self.parse_generic_bounds_common(allow_plus)?,
TraitObjectSyntax::None,
))
}

fn maybe_recover_ref_ty_no_leading_ampersand<'cx>(
&mut self,
lt: Lifetime,
lo: Span,
mut err: Diag<'cx>,
) -> Result<TyKind, Diag<'cx>> {
if !self.may_recover() {
return Err(err);
}
let snapshot = self.create_snapshot_for_diagnostic();
let mutbl = self.parse_mutability();
match self.parse_ty_no_plus() {
Ok(ty) => {
err.span_suggestion_verbose(
lo.shrink_to_lo(),
"you might have meant to write a reference type here",
"&",
Applicability::MaybeIncorrect,
);
err.emit();
Ok(TyKind::Ref(Some(lt), MutTy { ty, mutbl }))
}
Err(diag) => {
diag.cancel();
self.restore_snapshot(snapshot);
Err(err)
}
}
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None))
}

fn parse_remaining_bounds_path(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ symbols! {
expf16,
expf32,
expf64,
explicit_extern_abis,
explicit_generic_args_with_impl_trait,
explicit_tail_calls,
export_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn target() -> Target {
options: TargetOptions {
code_model: Some(CodeModel::Medium),
cpu: "generic-rv64".into(),
features: "+m,+a,+f,+d,+c,+zicsr,+zifencei,+zba,+zbb,+zbs,+v".into(),
features: "+m,+a,+f,+d,+c,+b,+v,+zicsr,+zifencei".into(),
llvm_abiname: "lp64d".into(),
supported_sanitizers: SanitizerSet::ADDRESS,
max_atomic_width: Some(64),
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("a", Stable, &["zaamo", "zalrsc"]),
("c", Stable, &[]),
("b", Unstable(sym::riscv_target_feature), &["zba", "zbb", "zbs"]),
("c", Stable, &["zca"]),
("d", Unstable(sym::riscv_target_feature), &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]),
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
Expand Down Expand Up @@ -520,17 +521,25 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("zbkc", Stable, &[]),
("zbkx", Stable, &[]),
("zbs", Stable, &[]),
("zca", Unstable(sym::riscv_target_feature), &[]),
("zcb", Unstable(sym::riscv_target_feature), &["zca"]),
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zicboz", Unstable(sym::riscv_target_feature), &[]),
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zicond", Unstable(sym::riscv_target_feature), &[]),
("zicsr", Unstable(sym::riscv_target_feature), &[]),
("zifencei", Unstable(sym::riscv_target_feature), &[]),
("zihintntl", Unstable(sym::riscv_target_feature), &[]),
("zihintpause", Unstable(sym::riscv_target_feature), &[]),
("zihpm", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zimop", Unstable(sym::riscv_target_feature), &[]),
("zk", Stable, &["zkn", "zkr", "zkt"]),
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
("zknd", Stable, &[]),
Expand All @@ -541,6 +550,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("zksed", Stable, &[]),
("zksh", Stable, &[]),
("zkt", Stable, &[]),
("ztso", Unstable(sym::riscv_target_feature), &[]),
("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]),
("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@
#![feature(needs_panic_runtime)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(no_sanitize)]
#![feature(optimize_attribute)]
#![feature(prelude_import)]
#![feature(rustc_attrs)]
Expand Down
3 changes: 0 additions & 3 deletions library/std/src/sys/fd/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ impl FileDesc {
}

#[cfg(all(target_os = "android", target_pointer_width = "32"))]
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
weak!(
fn preadv64(
Expand Down
14 changes: 0 additions & 14 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,20 +1463,6 @@ impl File {
Ok(())
}

// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[cfg_attr(
any(
target_os = "android",
all(
target_os = "linux",
target_env = "gnu",
target_pointer_width = "32",
not(target_arch = "riscv32")
)
),
no_sanitize(cfi)
)]
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
#[cfg(not(any(
target_os = "redox",
Expand Down
3 changes: 0 additions & 3 deletions library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ impl Thread {
}

#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[no_sanitize(cfi)]
pub fn set_name(name: &CStr) {
weak!(
fn pthread_setname_np(
Expand Down
11 changes: 0 additions & 11 deletions library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,6 @@ impl Timespec {
}
}

// FIXME(#115199): Rust currently omits weak function definitions
// and its metadata from LLVM IR.
#[cfg_attr(
all(
target_os = "linux",
target_env = "gnu",
target_pointer_width = "32",
not(target_arch = "riscv32")
),
no_sanitize(cfi)
)]
pub fn now(clock: libc::clockid_t) -> Timespec {
use crate::mem::MaybeUninit;
use crate::sys::cvt;
Expand Down
Loading
Loading