Skip to content

Rollup of 12 pull requests #137789

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 36 commits into from
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7061551
Add FileCheck annotations to mir-opt/issues
Shunpoco Dec 30, 2024
736ef0a
Don't error when adding a staticlib with bitcode files compiled by ne…
bjorn3 Feb 14, 2025
9147b6d
Add test
bjorn3 Feb 14, 2025
809858e
After introducing the warning in 1.83, now also warn in deps
tdittr Jan 20, 2025
e6d3987
Bless UI tests
tdittr Jan 20, 2025
3a3aede
Update some comparison tests now that they pass in LLVM20
scottmcm Feb 18, 2025
ab4ad6b
Change variadic-ffi-2 to use a platform independant ABI
tdittr Feb 18, 2025
ec45166
Tell llvm-ar to not create a symbol table
bjorn3 Feb 21, 2025
92eb445
tests: use minicore more
davidtwco Feb 24, 2025
7041eed
Prefer a two value enum over bool
oli-obk Feb 12, 2025
0ea02cd
Avoid having to handle an `Option` in the type system
oli-obk Feb 5, 2025
ff7c93f
Remove the `Option` part of range ends in the HIR
oli-obk Feb 5, 2025
73b7e5f
Hide the end of ranges in pretty printing if it's also the maximum of…
oli-obk Feb 5, 2025
9f190d7
Restore usage of io::Error
bjorn3 Feb 26, 2025
4fcebee
Fix Windows `Command` search path bug
ChrisDenton Feb 26, 2025
9a2362a
linker: Fix escaping style for response files on Windows
petrochenkov Feb 26, 2025
e28500d
Re-enable `--generate-link-to-defintion` for tools internal rustdoc
aDotInTheVoid Feb 26, 2025
d8a067b
remove most `simd_` intrinsic declaration in tests
folkertdev Feb 24, 2025
a837e99
simplify some imports with `simd::*`
folkertdev Feb 24, 2025
4e961dc
make `simd_insert` and `simd_extract` `const fn`s
folkertdev Feb 24, 2025
038f4e2
use the right feature in codegen tests
folkertdev Feb 24, 2025
660241d
Fix test directives that were accidentally ignored
yotamofek Feb 24, 2025
0881dba
Move "unused_exter_crate" test from rustdoc-ui to rustdoc
yotamofek Feb 27, 2025
b67b6c0
Fix sized constraint for unsafe binder
compiler-errors Feb 28, 2025
1afa069
Rollup merge of #134943 - Shunpoco:116971-mir-opt-issues, r=DianQK
jieyouxu Feb 28, 2025
671a420
Rollup merge of #135767 - tdittr:fn_ptr_calling_conventions-in-deps, …
jieyouxu Feb 28, 2025
996e86a
Rollup merge of #136922 - oli-obk:pattern-types-option-ends, r=BoxyUwU
jieyouxu Feb 28, 2025
02047d2
Rollup merge of #137017 - bjorn3:ignore_invalid_bitcode, r=oli-obk
jieyouxu Feb 28, 2025
6e2ccb2
Rollup merge of #137197 - scottmcm:cmp-20, r=ibraheemdev
jieyouxu Feb 28, 2025
08f194f
Rollup merge of #137540 - yotamofek:pr/more-deprecated-test-directive…
jieyouxu Feb 28, 2025
94fec13
Rollup merge of #137551 - folkertdev:import-simd-intrinsics, r=RalfJung
jieyouxu Feb 28, 2025
89080b2
Rollup merge of #137599 - davidtwco:use-minicore-more, r=jieyouxu
jieyouxu Feb 28, 2025
8447cf9
Rollup merge of #137673 - ChrisDenton:search-path-bug, r=dtolnay
jieyouxu Feb 28, 2025
c14e217
Rollup merge of #137676 - petrochenkov:winresp, r=Kobzol
jieyouxu Feb 28, 2025
3f9ee0f
Rollup merge of #137693 - aDotInTheVoid:gaming, r=onur-ozkan,Guillaum…
jieyouxu Feb 28, 2025
e5ca055
Rollup merge of #137770 - compiler-errors:unsafe-binder-sized-crit, r…
jieyouxu Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -136,6 +136,7 @@ struct LoweringContext<'a, 'hir> {

allow_try_trait: Arc<[Symbol]>,
allow_gen_future: Arc<[Symbol]>,
allow_pattern_type: Arc<[Symbol]>,
allow_async_iterator: Arc<[Symbol]>,
allow_for_await: Arc<[Symbol]>,
allow_async_fn_traits: Arc<[Symbol]>,
@@ -176,6 +177,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
allow_gen_future: if tcx.features().async_fn_track_caller() {
[sym::gen_future, sym::closure_track_caller].into()
} else {
@@ -1357,7 +1359,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
TyKind::Pat(ty, pat) => {
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat))
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat, ty.span))
}
TyKind::MacCall(_) => {
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
122 changes: 112 additions & 10 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ use std::sync::Arc;
use rustc_ast::ptr::P;
use rustc_ast::*;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{self as hir, LangItem};
use rustc_middle::span_bug;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{Ident, Span};
use rustc_span::{DesugaringKind, Ident, Span, kw};

use super::errors::{
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
@@ -430,22 +430,124 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
}

pub(crate) fn lower_ty_pat(&mut self, pattern: &TyPat) -> &'hir hir::TyPat<'hir> {
self.arena.alloc(self.lower_ty_pat_mut(pattern))
pub(crate) fn lower_ty_pat(
&mut self,
pattern: &TyPat,
base_type: Span,
) -> &'hir hir::TyPat<'hir> {
self.arena.alloc(self.lower_ty_pat_mut(pattern, base_type))
}

fn lower_ty_pat_mut(&mut self, pattern: &TyPat) -> hir::TyPat<'hir> {
fn lower_ty_pat_mut(&mut self, pattern: &TyPat, base_type: Span) -> hir::TyPat<'hir> {
// loop here to avoid recursion
let pat_hir_id = self.lower_node_id(pattern.id);
let node = match &pattern.kind {
TyPatKind::Range(e1, e2, Spanned { node: end, .. }) => hir::TyPatKind::Range(
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
e2.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
self.lower_range_end(end, e2.is_some()),
TyPatKind::Range(e1, e2, Spanned { node: end, span }) => hir::TyPatKind::Range(
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)).unwrap_or_else(|| {
self.lower_ty_pat_range_end(
hir::LangItem::RangeMin,
span.shrink_to_lo(),
base_type,
)
}),
e2.as_deref()
.map(|e| match end {
RangeEnd::Included(..) => self.lower_anon_const_to_const_arg(e),
RangeEnd::Excluded => self.lower_excluded_range_end(e),
})
.unwrap_or_else(|| {
self.lower_ty_pat_range_end(
hir::LangItem::RangeMax,
span.shrink_to_hi(),
base_type,
)
}),
),
TyPatKind::Err(guar) => hir::TyPatKind::Err(*guar),
};

hir::TyPat { hir_id: pat_hir_id, kind: node, span: self.lower_span(pattern.span) }
}

/// Lowers the range end of an exclusive range (`2..5`) to an inclusive range 2..=(5 - 1).
/// This way the type system doesn't have to handle the distinction between inclusive/exclusive ranges.
fn lower_excluded_range_end(&mut self, e: &AnonConst) -> &'hir hir::ConstArg<'hir> {
let span = self.lower_span(e.value.span);
let unstable_span = self.mark_span_with_reason(
DesugaringKind::PatTyRange,
span,
Some(Arc::clone(&self.allow_pattern_type)),
);
let anon_const = self.with_new_scopes(span, |this| {
let def_id = this.local_def_id(e.id);
let hir_id = this.lower_node_id(e.id);
let body = this.lower_body(|this| {
// Need to use a custom function as we can't just subtract `1` from a `char`.
let kind = hir::ExprKind::Path(this.make_lang_item_qpath(
hir::LangItem::RangeSub,
unstable_span,
None,
));
let fn_def = this.arena.alloc(hir::Expr { hir_id: this.next_id(), kind, span });
let args = this.arena.alloc([this.lower_expr_mut(&e.value)]);
(
&[],
hir::Expr {
hir_id: this.next_id(),
kind: hir::ExprKind::Call(fn_def, args),
span,
},
)
});
hir::AnonConst { def_id, hir_id, body, span }
});
self.arena.alloc(hir::ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(self.arena.alloc(anon_const)),
})
}

/// When a range has no end specified (`1..` or `1..=`) or no start specified (`..5` or `..=5`),
/// we instead use a constant of the MAX/MIN of the type.
/// This way the type system does not have to handle the lack of a start/end.
fn lower_ty_pat_range_end(
&mut self,
lang_item: LangItem,
span: Span,
base_type: Span,
) -> &'hir hir::ConstArg<'hir> {
let parent_def_id = self.current_hir_id_owner.def_id;
let node_id = self.next_node_id();

// Add a definition for the in-band const def.
// We're generating a range end that didn't exist in the AST,
// so the def collector didn't create the def ahead of time. That's why we have to do
// it here.
let def_id = self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
let hir_id = self.lower_node_id(node_id);

let unstable_span = self.mark_span_with_reason(
DesugaringKind::PatTyRange,
self.lower_span(span),
Some(Arc::clone(&self.allow_pattern_type)),
);
let span = self.lower_span(base_type);

let path_expr = hir::Expr {
hir_id: self.next_id(),
kind: hir::ExprKind::Path(self.make_lang_item_qpath(lang_item, unstable_span, None)),
span,
};

let ct = self.with_new_scopes(span, |this| {
self.arena.alloc(hir::AnonConst {
def_id,
hir_id,
body: this.lower_body(|_this| (&[], path_expr)),
span,
})
});
let hir_id = self.next_id();
self.arena.alloc(hir::ConstArg { kind: hir::ConstArgKind::Anon(ct), hir_id })
}
}
25 changes: 22 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
@@ -132,14 +132,33 @@ fn get_llvm_object_symbols(
if err.is_null() {
return Ok(true);
} else {
return Err(unsafe { *Box::from_raw(err as *mut io::Error) });
let error = unsafe { *Box::from_raw(err as *mut io::Error) };
// These are the magic constants for LLVM bitcode files:
// https://github.com/llvm/llvm-project/blob/7eadc1960d199676f04add402bb0aa6f65b7b234/llvm/lib/BinaryFormat/Magic.cpp#L90-L97
if buf.starts_with(&[0xDE, 0xCE, 0x17, 0x0B]) || buf.starts_with(&[b'B', b'C', 0xC0, 0xDE])
{
// For LLVM bitcode, failure to read the symbols is not fatal. The bitcode may have been
// produced by a newer LLVM version that the one linked to rustc. This is fine provided
// that the linker does use said newer LLVM version. We skip writing the symbols for the
// bitcode to the symbol table of the archive. Traditional linkers don't like this, but
// newer linkers like lld, mold and wild ignore the symbol table anyway, so if they link
// against a new enough LLVM it will work out in the end.
// LLVM's archive writer also has this same behavior of only warning about invalid
// bitcode since https://github.com/llvm/llvm-project/pull/96848

// We don't have access to the DiagCtxt here to produce a nice warning in the correct format.
eprintln!("warning: Failed to read symbol table from LLVM bitcode: {}", error);
return Ok(true);
} else {
return Err(error);
}
}

unsafe extern "C" fn callback(state: *mut c_void, symbol_name: *const c_char) -> *mut c_void {
let f = unsafe { &mut *(state as *mut &mut dyn FnMut(&[u8]) -> io::Result<()>) };
match f(unsafe { CStr::from_ptr(symbol_name) }.to_bytes()) {
Ok(()) => std::ptr::null_mut(),
Err(err) => Box::into_raw(Box::new(err)) as *mut c_void,
Err(err) => Box::into_raw(Box::new(err) as Box<io::Error>) as *mut c_void,
}
}

@@ -148,7 +167,7 @@ fn get_llvm_object_symbols(
Box::into_raw(Box::new(io::Error::new(
io::ErrorKind::Other,
format!("LLVM error: {}", error.to_string_lossy()),
))) as *mut c_void
)) as Box<io::Error>) as *mut c_void
}
}

8 changes: 6 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
@@ -1726,8 +1726,12 @@ fn exec_linker(
args.push_str(
&Escape {
arg: arg.to_str().unwrap(),
// LLD also uses MSVC-like parsing for @-files by default when running on windows hosts
is_like_msvc: sess.target.is_like_msvc || (cfg!(windows) && flavor.uses_lld()),
// Windows-style escaping for @-files is used by
// - all linkers targeting MSVC-like targets, including LLD
// - all LLD flavors running on Windows hosts
// С/С++ compilers use Posix-style escaping (except clang-cl, which we do not use).
is_like_msvc: sess.target.is_like_msvc
|| (cfg!(windows) && flavor.uses_lld() && !flavor.uses_cc()),
}
.to_string(),
);
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1600,7 +1600,7 @@ pub struct PatField<'hir> {
pub span: Span,
}

#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic, Hash, Eq, Encodable, Decodable)]
pub enum RangeEnd {
Included,
Excluded,
@@ -1668,7 +1668,7 @@ pub enum PatExprKind<'hir> {
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub enum TyPatKind<'hir> {
/// A range pattern (e.g., `1..=2` or `1..2`).
Range(Option<&'hir ConstArg<'hir>>, Option<&'hir ConstArg<'hir>>, RangeEnd),
Range(&'hir ConstArg<'hir>, &'hir ConstArg<'hir>),

/// A placeholder for a pattern that wasn't well formed in some way.
Err(ErrorGuaranteed),
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
@@ -708,9 +708,9 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) -> V::Res
pub fn walk_ty_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v TyPat<'v>) -> V::Result {
try_visit!(visitor.visit_id(pattern.hir_id));
match pattern.kind {
TyPatKind::Range(lower_bound, upper_bound, _) => {
visit_opt!(visitor, visit_const_arg_unambig, lower_bound);
visit_opt!(visitor, visit_const_arg_unambig, upper_bound);
TyPatKind::Range(lower_bound, upper_bound) => {
try_visit!(visitor.visit_const_arg_unambig(lower_bound));
try_visit!(visitor.visit_const_arg_unambig(upper_bound));
}
TyPatKind::Err(_) => (),
}
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
@@ -418,6 +418,9 @@ language_item_table! {
Range, sym::Range, range_struct, Target::Struct, GenericRequirement::None;
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct, GenericRequirement::None;
RangeTo, sym::RangeTo, range_to_struct, Target::Struct, GenericRequirement::None;
RangeMax, sym::RangeMax, range_max, Target::AssocConst, GenericRequirement::Exact(0);
RangeMin, sym::RangeMin, range_min, Target::AssocConst, GenericRequirement::Exact(0);
RangeSub, sym::RangeSub, range_sub, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::Exact(0);

// `new_range` types that are `Copy + IntoIterator`
RangeFromCopy, sym::RangeFromCopy, range_from_copy_struct, Target::Struct, GenericRequirement::None;
3 changes: 0 additions & 3 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
@@ -244,9 +244,6 @@ hir_analysis_inherent_ty_outside_relevant = cannot define inherent `impl` for a
.help = consider moving this inherent impl into the crate defining the type if possible
.span_help = alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items

hir_analysis_invalid_base_type = `{$ty}` is not a valid base type for range patterns
.note = range patterns only support integers

hir_analysis_invalid_generic_receiver_ty = invalid generic `self` parameter type: `{$receiver_ty}`
.note = type of `self` must not be a method generic parameter type

2 changes: 0 additions & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ use rustc_middle::ty::Ty;
use rustc_span::{Ident, Span, Symbol};

use crate::fluent_generated as fluent;
mod pattern_types;
pub(crate) use pattern_types::*;
pub(crate) mod wrong_number_of_generic_args;

mod precise_captures;
14 changes: 0 additions & 14 deletions compiler/rustc_hir_analysis/src/errors/pattern_types.rs

This file was deleted.

40 changes: 18 additions & 22 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
@@ -53,9 +53,7 @@ use rustc_type_ir::Upcast;
use tracing::{debug, instrument};

use crate::check::check_abi_fn_ptr;
use crate::errors::{
AmbiguousLifetimeBound, BadReturnTypeNotation, InvalidBaseType, NoVariantNamed,
};
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation, NoVariantNamed};
use crate::hir_ty_lowering::errors::{GenericsArgsErrExtend, prohibit_assoc_item_constraint};
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
use crate::middle::resolve_bound_vars as rbv;
@@ -2452,28 +2450,26 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let ty_span = ty.span;
let ty = self.lower_ty(ty);
let pat_ty = match pat.kind {
hir::TyPatKind::Range(start, end, include_end) => {
let ty = match ty.kind() {
ty::Int(_) | ty::Uint(_) | ty::Char => ty,
_ => Ty::new_error(
tcx,
self.dcx().emit_err(InvalidBaseType {
ty,
pat: "range",
hir::TyPatKind::Range(start, end) => {
let (ty, start, end) = match ty.kind() {
// Keep this list of types in sync with the list of types that
// the `RangePattern` trait is implemented for.
ty::Int(_) | ty::Uint(_) | ty::Char => {
let start = self.lower_const_arg(start, FeedConstTy::No);
let end = self.lower_const_arg(end, FeedConstTy::No);
(ty, start, end)
}
_ => {
let guar = self.dcx().span_delayed_bug(
ty_span,
pat_span: pat.span,
}),
),
};
let start = start.map(|expr| self.lower_const_arg(expr, FeedConstTy::No));
let end = end.map(|expr| self.lower_const_arg(expr, FeedConstTy::No));

let include_end = match include_end {
hir::RangeEnd::Included => true,
hir::RangeEnd::Excluded => false,
"invalid base type for range pattern",
);
let errc = ty::Const::new_error(tcx, guar);
(Ty::new_error(tcx, guar), errc, errc)
}
};

let pat = tcx.mk_pat(ty::PatternKind::Range { start, end, include_end });
let pat = tcx.mk_pat(ty::PatternKind::Range { start, end });
Ty::new_pat(tcx, ty, pat)
}
hir::TyPatKind::Err(e) => Ty::new_error(tcx, e),
10 changes: 3 additions & 7 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
@@ -252,13 +252,9 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {

ty::Pat(typ, pat) => {
match *pat {
ty::PatternKind::Range { start, end, include_end: _ } => {
if let Some(start) = start {
self.add_constraints_from_const(current, start, variance);
}
if let Some(end) = end {
self.add_constraints_from_const(current, end, variance);
}
ty::PatternKind::Range { start, end } => {
self.add_constraints_from_const(current, start, variance);
self.add_constraints_from_const(current, end, variance);
}
}
self.add_constraints_from_ty(current, typ, variance);
Loading