Skip to content

Rollup of 10 pull requests #141606

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7238669
intrinsics: reduce references to LLVM and update notes on where the i…
RalfJung May 24, 2025
ff33414
ScalarInt: support conversion with signed int types and cmp::Ordering
RalfJung May 24, 2025
77e295c
Improve `ambiguous_wide_pointer_comparisons` lint compare diagnostics
Urgau May 25, 2025
1a29427
Remove out-of-date `noop_*` names.
nnethercote May 19, 2025
b71a127
dist: make sure llvm-project submodule is present
onur-ozkan May 26, 2025
0ea12c3
cfg_version: pull out dedicated syntax test from feature gate test
jieyouxu May 25, 2025
5e31cd3
Support opaque_types_defined_by for SyntheticCoroutineBody
compiler-errors May 26, 2025
1d35ac9
Add missing edition directives for async-await tests
Veykril May 26, 2025
c27aff3
Add test
BoxyUwU May 26, 2025
0497f31
rustc book: fix erratic sentence by making it more simple
tshepang May 26, 2025
19802e8
Remove an unnecessary use of `Box::into_inner`.
nnethercote May 26, 2025
5079039
Rollup merge of #141536 - Urgau:ambi_wide_ptr-cmp-diag, r=fee1-dead
jieyouxu May 26, 2025
7b7097c
Rollup merge of #141552 - jieyouxu:cfg-version-tests, r=est31
jieyouxu May 26, 2025
3d7518f
Rollup merge of #141563 - nnethercote:rm-noop, r=petrochenkov
jieyouxu May 26, 2025
1f817bc
Rollup merge of #141568 - onur-ozkan:141393-fix, r=Kobzol
jieyouxu May 26, 2025
ea4e427
Rollup merge of #141582 - RalfJung:cleanup, r=bjorn3
jieyouxu May 26, 2025
02fbf61
Rollup merge of #141584 - compiler-errors:typing-env-synthetic-body, …
jieyouxu May 26, 2025
460598e
Rollup merge of #141587 - ferrocene:lw-yurotqzwvwlw, r=jieyouxu
jieyouxu May 26, 2025
dc3ccc5
Rollup merge of #141594 - BoxyUwU:another_gai_test, r=jieyouxu
jieyouxu May 26, 2025
e175c5e
Rollup merge of #141596 - tshepang:patch-2, r=Urgau
jieyouxu May 26, 2025
76bafd3
Rollup merge of #141599 - nnethercote:rm-Box-into_inner, r=fmease,che…
jieyouxu May 26, 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
29 changes: 4 additions & 25 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ pub trait MutVisitor: Sized {
// fn flat_map_t(&mut self, t: T) -> SmallVec<[T; 1]>; // rare
// fn filter_map_t(&mut self, t: T) -> Option<T>; // rarest
//
// Any additions to this trait should happen in form of a call to a public
// `noop_*` function that only calls out to the visitor again, not other
// `noop_*` functions. This is a necessary API workaround to the problem of
// not being able to call out to the super default method in an overridden
// default method.
//
// When writing these methods, it is better to use destructuring like this:
//
// fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
Expand Down Expand Up @@ -191,7 +185,7 @@ pub trait MutVisitor: Sized {
}

fn filter_map_expr(&mut self, e: P<Expr>) -> Option<P<Expr>> {
noop_filter_map_expr(self, e)
walk_filter_map_expr(self, e)
}

fn visit_generic_arg(&mut self, arg: &mut GenericArg) {
Expand Down Expand Up @@ -393,14 +387,11 @@ super::common_visitor_and_walkers!((mut) MutVisitor);
/// Use a map-style function (`FnOnce(T) -> T`) to overwrite a `&mut T`. Useful
/// when using a `flat_map_*` or `filter_map_*` method within a `visit_`
/// method.
//
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
pub fn visit_clobber<T: DummyAstNode>(t: &mut T, f: impl FnOnce(T) -> T) {
let old_t = std::mem::replace(t, T::dummy());
*t = f(old_t);
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[inline]
fn visit_vec<T, F>(elems: &mut Vec<T>, mut visit_elem: F)
where
Expand All @@ -411,7 +402,6 @@ where
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[inline]
fn visit_thin_vec<T, F>(elems: &mut ThinVec<T>, mut visit_elem: F)
where
Expand All @@ -422,7 +412,6 @@ where
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[inline]
fn visit_opt<T, F>(opt: &mut Option<T>, mut visit_elem: F)
where
Expand All @@ -433,30 +422,25 @@ where
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_attrs<T: MutVisitor>(vis: &mut T, attrs: &mut AttrVec) {
for attr in attrs.iter_mut() {
vis.visit_attribute(attr);
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[allow(unused)]
fn visit_exprs<T: MutVisitor>(vis: &mut T, exprs: &mut Vec<P<Expr>>) {
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_thin_exprs<T: MutVisitor>(vis: &mut T, exprs: &mut ThinVec<P<Expr>>) {
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_bounds<T: MutVisitor>(vis: &mut T, bounds: &mut GenericBounds, ctxt: BoundKind) {
visit_vec(bounds, |bound| vis.visit_param_bound(bound, ctxt));
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
match args {
AttrArgs::Empty => {}
Expand All @@ -468,7 +452,6 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_delim_args<T: MutVisitor>(vis: &mut T, args: &mut DelimArgs) {
let DelimArgs { dspan, delim: _, tokens: _ } = args;
let DelimSpan { open, close } = dspan;
Expand Down Expand Up @@ -771,15 +754,13 @@ pub fn walk_flat_map_param<T: MutVisitor>(vis: &mut T, mut param: Param) -> Smal
smallvec![param]
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_defaultness<T: MutVisitor>(vis: &mut T, defaultness: &mut Defaultness) {
match defaultness {
Defaultness::Default(span) => vis.visit_span(span),
Defaultness::Final => {}
}
}

// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
fn visit_polarity<T: MutVisitor>(vis: &mut T, polarity: &mut ImplPolarity) {
match polarity {
ImplPolarity::Positive => {}
Expand Down Expand Up @@ -1716,11 +1697,9 @@ pub fn walk_expr<T: MutVisitor>(vis: &mut T, Expr { kind, id, span, attrs, token
vis.visit_span(span);
}

pub fn noop_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
Some({
vis.visit_expr(&mut e);
e
})
pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
vis.visit_expr(&mut e);
Some(e)
}

pub fn walk_flat_map_stmt<T: MutVisitor>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
let ty = tcx.ty_ordering_enum(None);
let layout =
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)).unwrap();
Self::from_scalar(Scalar::from_i8(c as i8), layout)
Self::from_scalar(Scalar::Int(c.into()), layout)
}

pub fn from_pair(a: Self, b: Self, cx: &(impl HasTypingEnv<'tcx> + HasTyCtxt<'tcx>)) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
));
self.note("consider using `--verbose` to print the full type name to the console");
}
Box::into_inner(self.diag.take().unwrap())
*self.diag.take().unwrap()
}

/// This method allows us to access the path of the file where "long types" are written to.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(associated_type_defaults)]
#![feature(box_into_inner)]
#![feature(box_patterns)]
#![feature(default_field_values)]
#![feature(error_reporter)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/placeholders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl MutVisitor for PlaceholderExpander {
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
match expr.kind {
ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(),
_ => noop_filter_map_expr(self, expr),
_ => walk_filter_map_expr(self, expr),
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ lint_ambiguous_negative_literals = `-` has lower precedence than method calls, w
lint_ambiguous_wide_pointer_comparisons = ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
.addr_metadata_suggestion = use explicit `std::ptr::eq` method to compare metadata and addresses
.addr_suggestion = use `std::ptr::addr_eq` or untyped pointers to only compare their addresses
.cast_suggestion = use untyped pointers to only compare their addresses
.expect_suggestion = or expect the lint to compare the pointers metadata and addresses

lint_associated_const_elided_lifetime = {$elided ->
[true] `&` without an explicit lifetime name cannot be used here
Expand Down
110 changes: 68 additions & 42 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,13 +1782,20 @@ pub(crate) enum InvalidNanComparisonsSuggestion {
#[derive(LintDiagnostic)]
pub(crate) enum AmbiguousWidePointerComparisons<'a> {
#[diag(lint_ambiguous_wide_pointer_comparisons)]
Spanful {
SpanfulEq {
#[subdiagnostic]
addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion<'a>,
#[subdiagnostic]
addr_metadata_suggestion: Option<AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a>>,
},
#[diag(lint_ambiguous_wide_pointer_comparisons)]
SpanfulCmp {
#[subdiagnostic]
cast_suggestion: AmbiguousWidePointerComparisonsCastSuggestion<'a>,
#[subdiagnostic]
expect_suggestion: AmbiguousWidePointerComparisonsExpectSuggestion<'a>,
},
#[diag(lint_ambiguous_wide_pointer_comparisons)]
#[help(lint_addr_metadata_suggestion)]
#[help(lint_addr_suggestion)]
Spanless,
Expand Down Expand Up @@ -1816,48 +1823,67 @@ pub(crate) struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
}

#[derive(Subdiagnostic)]
pub(crate) enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
#[multipart_suggestion(
lint_addr_suggestion,
style = "verbose",
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
AddrEq {
ne: &'a str,
deref_left: &'a str,
deref_right: &'a str,
l_modifiers: &'a str,
r_modifiers: &'a str,
#[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
left: Span,
#[suggestion_part(code = "{l_modifiers}, {deref_right}")]
middle: Span,
#[suggestion_part(code = "{r_modifiers})")]
right: Span,
},
#[multipart_suggestion(
lint_addr_suggestion,
style = "verbose",
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
#[multipart_suggestion(
lint_addr_suggestion,
style = "verbose",
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
pub(crate) struct AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
pub(crate) ne: &'a str,
pub(crate) deref_left: &'a str,
pub(crate) deref_right: &'a str,
pub(crate) l_modifiers: &'a str,
pub(crate) r_modifiers: &'a str,
#[suggestion_part(code = "{ne}std::ptr::addr_eq({deref_left}")]
pub(crate) left: Span,
#[suggestion_part(code = "{l_modifiers}, {deref_right}")]
pub(crate) middle: Span,
#[suggestion_part(code = "{r_modifiers})")]
pub(crate) right: Span,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(
lint_cast_suggestion,
style = "verbose",
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
pub(crate) struct AmbiguousWidePointerComparisonsCastSuggestion<'a> {
pub(crate) deref_left: &'a str,
pub(crate) deref_right: &'a str,
pub(crate) paren_left: &'a str,
pub(crate) paren_right: &'a str,
pub(crate) l_modifiers: &'a str,
pub(crate) r_modifiers: &'a str,
#[suggestion_part(code = "({deref_left}")]
pub(crate) left_before: Option<Span>,
#[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
pub(crate) left_after: Span,
#[suggestion_part(code = "({deref_right}")]
pub(crate) right_before: Option<Span>,
#[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
pub(crate) right_after: Span,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(
lint_expect_suggestion,
style = "verbose",
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
pub(crate) struct AmbiguousWidePointerComparisonsExpectSuggestion<'a> {
pub(crate) paren_left: &'a str,
pub(crate) paren_right: &'a str,
// FIXME(#127436): Adjust once resolved
#[suggestion_part(
code = r#"{{ #[expect(ambiguous_wide_pointer_comparisons, reason = "...")] {paren_left}"#
)]
Cast {
deref_left: &'a str,
deref_right: &'a str,
paren_left: &'a str,
paren_right: &'a str,
l_modifiers: &'a str,
r_modifiers: &'a str,
#[suggestion_part(code = "({deref_left}")]
left_before: Option<Span>,
#[suggestion_part(code = "{l_modifiers}{paren_left}.cast::<()>()")]
left_after: Span,
#[suggestion_part(code = "({deref_right}")]
right_before: Option<Span>,
#[suggestion_part(code = "{r_modifiers}{paren_right}.cast::<()>()")]
right_after: Span,
},
pub(crate) before: Span,
#[suggestion_part(code = "{paren_right} }}")]
pub(crate) after: Span,
}

#[derive(LintDiagnostic)]
Expand Down
52 changes: 31 additions & 21 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ mod improper_ctypes;

use crate::lints::{
AmbiguousWidePointerComparisons, AmbiguousWidePointerComparisonsAddrMetadataSuggestion,
AmbiguousWidePointerComparisonsAddrSuggestion, AtomicOrderingFence, AtomicOrderingLoad,
AmbiguousWidePointerComparisonsAddrSuggestion, AmbiguousWidePointerComparisonsCastSuggestion,
AmbiguousWidePointerComparisonsExpectSuggestion, AtomicOrderingFence, AtomicOrderingLoad,
AtomicOrderingStore, ImproperCTypes, InvalidAtomicOrderingDiag, InvalidNanComparisons,
InvalidNanComparisonsSuggestion, UnpredictableFunctionPointerComparisons,
UnpredictableFunctionPointerComparisonsSuggestion, UnusedComparisons, UsesPowerAlignment,
Expand Down Expand Up @@ -362,6 +363,7 @@ fn lint_wide_pointer<'tcx>(
let ne = if cmpop == ComparisonOp::BinOp(hir::BinOpKind::Ne) { "!" } else { "" };
let is_eq_ne = matches!(cmpop, ComparisonOp::BinOp(hir::BinOpKind::Eq | hir::BinOpKind::Ne));
let is_dyn_comparison = l_inner_ty_is_dyn && r_inner_ty_is_dyn;
let via_method_call = matches!(&e.kind, ExprKind::MethodCall(..) | ExprKind::Call(..));

let left = e.span.shrink_to_lo().until(l_span.shrink_to_lo());
let middle = l_span.shrink_to_hi().until(r_span.shrink_to_lo());
Expand All @@ -376,21 +378,21 @@ fn lint_wide_pointer<'tcx>(
cx.emit_span_lint(
AMBIGUOUS_WIDE_POINTER_COMPARISONS,
e.span,
AmbiguousWidePointerComparisons::Spanful {
addr_metadata_suggestion: (is_eq_ne && !is_dyn_comparison).then(|| {
AmbiguousWidePointerComparisonsAddrMetadataSuggestion {
ne,
deref_left,
deref_right,
l_modifiers,
r_modifiers,
left,
middle,
right,
}
}),
addr_suggestion: if is_eq_ne {
AmbiguousWidePointerComparisonsAddrSuggestion::AddrEq {
if is_eq_ne {
AmbiguousWidePointerComparisons::SpanfulEq {
addr_metadata_suggestion: (!is_dyn_comparison).then(|| {
AmbiguousWidePointerComparisonsAddrMetadataSuggestion {
ne,
deref_left,
deref_right,
l_modifiers,
r_modifiers,
left,
middle,
right,
}
}),
addr_suggestion: AmbiguousWidePointerComparisonsAddrSuggestion {
ne,
deref_left,
deref_right,
Expand All @@ -399,9 +401,11 @@ fn lint_wide_pointer<'tcx>(
left,
middle,
right,
}
} else {
AmbiguousWidePointerComparisonsAddrSuggestion::Cast {
},
}
} else {
AmbiguousWidePointerComparisons::SpanfulCmp {
cast_suggestion: AmbiguousWidePointerComparisonsCastSuggestion {
deref_left,
deref_right,
l_modifiers,
Expand All @@ -412,8 +416,14 @@ fn lint_wide_pointer<'tcx>(
left_after: l_span.shrink_to_hi(),
right_before: (r_ty_refs != 0).then_some(r_span.shrink_to_lo()),
right_after: r_span.shrink_to_hi(),
}
},
},
expect_suggestion: AmbiguousWidePointerComparisonsExpectSuggestion {
paren_left: if via_method_call { "" } else { "(" },
paren_right: if via_method_call { "" } else { ")" },
before: e.span.shrink_to_lo(),
after: e.span.shrink_to_hi(),
},
}
},
);
}
Expand Down
Loading
Loading