Skip to content

Commit 4606a4d

Browse files
committed
Auto merge of rust-lang#134201 - matthiaskrgr:rollup-22b721y, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#122003 (link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets) - rust-lang#133859 (Move some alloc tests to the alloctests crate) - rust-lang#134070 (Some asm! diagnostic adjustments and a papercut fix) - rust-lang#134144 (Properly consider APITs for never type fallback ascription fix) - rust-lang#134152 (Simplify `rustc_mir_dataflow::abs_domain`.) - rust-lang#134154 (suppress field expr with generics error message if it's a method) - rust-lang#134155 (Forbid `unsafe_op_in_unsafe_fn` for Hurd) - rust-lang#134173 (allow `symbol_intern_string_literal` lint in test modules) - rust-lang#134178 (Stabilize the Rust 2024 prelude) - rust-lang#134179 (Remove outdated consteval note from `<*mut T>::align_offset` docs.) - rust-lang#134187 (Remove `PErr`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 903d297 + 2ced8b3 commit 4606a4d

File tree

49 files changed

+475
-190
lines changed

Some content is hidden

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

49 files changed

+475
-190
lines changed

compiler/rustc_ast/src/util/comments/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
2+
13
use rustc_span::create_default_session_globals_then;
24

35
use super::*;

compiler/rustc_errors/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ mod styled_buffer;
9494
mod tests;
9595
pub mod translation;
9696

97-
pub type PErr<'a> = Diag<'a>;
98-
pub type PResult<'a, T> = Result<T, PErr<'a>>;
97+
pub type PResult<'a, T> = Result<T, Diag<'a>>;
9998

10099
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
101100

@@ -576,6 +575,10 @@ pub enum StashKey {
576575
UndeterminedMacroResolution,
577576
/// Used by `Parser::maybe_recover_trailing_expr`
578577
ExprInPat,
578+
/// If in the parser we detect a field expr with turbofish generic params it's possible that
579+
/// it's a method call without parens. If later on in `hir_typeck` we find out that this is
580+
/// the case we suppress this message and we give a better suggestion.
581+
GenericInFieldExpr,
579582
}
580583

581584
fn default_track_diagnostic<R>(diag: DiagInner, f: &mut dyn FnMut(DiagInner) -> R) -> R {

compiler/rustc_hir/src/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
2+
13
use rustc_data_structures::stable_hasher::Hash64;
24
use rustc_span::def_id::{DefPathHash, StableCrateId};
35
use rustc_span::edition::Edition;

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+74-44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::assert_matches::debug_assert_matches;
33
use rustc_abi::FieldIdx;
44
use rustc_ast::InlineAsmTemplatePiece;
55
use rustc_data_structures::fx::FxIndexSet;
6+
use rustc_hir::def_id::DefId;
67
use rustc_hir::{self as hir, LangItem};
78
use rustc_middle::bug;
89
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
@@ -21,6 +22,12 @@ pub struct InlineAsmCtxt<'a, 'tcx> {
2122
get_operand_ty: Box<dyn Fn(&'tcx hir::Expr<'tcx>) -> Ty<'tcx> + 'a>,
2223
}
2324

25+
enum NonAsmTypeReason<'tcx> {
26+
UnevaluatedSIMDArrayLength(DefId, ty::Const<'tcx>),
27+
Invalid(Ty<'tcx>),
28+
InvalidElement(DefId, Ty<'tcx>),
29+
}
30+
2431
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
2532
pub fn new_global_asm(tcx: TyCtxt<'tcx>) -> Self {
2633
InlineAsmCtxt {
@@ -56,7 +63,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
5663
false
5764
}
5865

59-
fn get_asm_ty(&self, ty: Ty<'tcx>) -> Option<InlineAsmType> {
66+
fn get_asm_ty(&self, ty: Ty<'tcx>) -> Result<InlineAsmType, NonAsmTypeReason<'tcx>> {
6067
let asm_ty_isize = match self.tcx.sess.target.pointer_width {
6168
16 => InlineAsmType::I16,
6269
32 => InlineAsmType::I32,
@@ -65,64 +72,62 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
6572
};
6673

6774
match *ty.kind() {
68-
ty::Int(IntTy::I8) | ty::Uint(UintTy::U8) => Some(InlineAsmType::I8),
69-
ty::Int(IntTy::I16) | ty::Uint(UintTy::U16) => Some(InlineAsmType::I16),
70-
ty::Int(IntTy::I32) | ty::Uint(UintTy::U32) => Some(InlineAsmType::I32),
71-
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => Some(InlineAsmType::I64),
72-
ty::Int(IntTy::I128) | ty::Uint(UintTy::U128) => Some(InlineAsmType::I128),
73-
ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => Some(asm_ty_isize),
74-
ty::Float(FloatTy::F16) => Some(InlineAsmType::F16),
75-
ty::Float(FloatTy::F32) => Some(InlineAsmType::F32),
76-
ty::Float(FloatTy::F64) => Some(InlineAsmType::F64),
77-
ty::Float(FloatTy::F128) => Some(InlineAsmType::F128),
78-
ty::FnPtr(..) => Some(asm_ty_isize),
79-
ty::RawPtr(ty, _) if self.is_thin_ptr_ty(ty) => Some(asm_ty_isize),
75+
ty::Int(IntTy::I8) | ty::Uint(UintTy::U8) => Ok(InlineAsmType::I8),
76+
ty::Int(IntTy::I16) | ty::Uint(UintTy::U16) => Ok(InlineAsmType::I16),
77+
ty::Int(IntTy::I32) | ty::Uint(UintTy::U32) => Ok(InlineAsmType::I32),
78+
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => Ok(InlineAsmType::I64),
79+
ty::Int(IntTy::I128) | ty::Uint(UintTy::U128) => Ok(InlineAsmType::I128),
80+
ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => Ok(asm_ty_isize),
81+
ty::Float(FloatTy::F16) => Ok(InlineAsmType::F16),
82+
ty::Float(FloatTy::F32) => Ok(InlineAsmType::F32),
83+
ty::Float(FloatTy::F64) => Ok(InlineAsmType::F64),
84+
ty::Float(FloatTy::F128) => Ok(InlineAsmType::F128),
85+
ty::FnPtr(..) => Ok(asm_ty_isize),
86+
ty::RawPtr(ty, _) if self.is_thin_ptr_ty(ty) => Ok(asm_ty_isize),
8087
ty::Adt(adt, args) if adt.repr().simd() => {
8188
let fields = &adt.non_enum_variant().fields;
82-
let elem_ty = fields[FieldIdx::ZERO].ty(self.tcx, args);
89+
let field = &fields[FieldIdx::ZERO];
90+
let elem_ty = field.ty(self.tcx, args);
8391

8492
let (size, ty) = match elem_ty.kind() {
8593
ty::Array(ty, len) => {
94+
let len = self.tcx.normalize_erasing_regions(self.typing_env, *len);
8695
if let Some(len) = len.try_to_target_usize(self.tcx) {
8796
(len, *ty)
8897
} else {
89-
return None;
98+
return Err(NonAsmTypeReason::UnevaluatedSIMDArrayLength(
99+
field.did, len,
100+
));
90101
}
91102
}
92103
_ => (fields.len() as u64, elem_ty),
93104
};
94105

95106
match ty.kind() {
96-
ty::Int(IntTy::I8) | ty::Uint(UintTy::U8) => Some(InlineAsmType::VecI8(size)),
97-
ty::Int(IntTy::I16) | ty::Uint(UintTy::U16) => {
98-
Some(InlineAsmType::VecI16(size))
99-
}
100-
ty::Int(IntTy::I32) | ty::Uint(UintTy::U32) => {
101-
Some(InlineAsmType::VecI32(size))
102-
}
103-
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => {
104-
Some(InlineAsmType::VecI64(size))
105-
}
107+
ty::Int(IntTy::I8) | ty::Uint(UintTy::U8) => Ok(InlineAsmType::VecI8(size)),
108+
ty::Int(IntTy::I16) | ty::Uint(UintTy::U16) => Ok(InlineAsmType::VecI16(size)),
109+
ty::Int(IntTy::I32) | ty::Uint(UintTy::U32) => Ok(InlineAsmType::VecI32(size)),
110+
ty::Int(IntTy::I64) | ty::Uint(UintTy::U64) => Ok(InlineAsmType::VecI64(size)),
106111
ty::Int(IntTy::I128) | ty::Uint(UintTy::U128) => {
107-
Some(InlineAsmType::VecI128(size))
112+
Ok(InlineAsmType::VecI128(size))
108113
}
109114
ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize) => {
110-
Some(match self.tcx.sess.target.pointer_width {
115+
Ok(match self.tcx.sess.target.pointer_width {
111116
16 => InlineAsmType::VecI16(size),
112117
32 => InlineAsmType::VecI32(size),
113118
64 => InlineAsmType::VecI64(size),
114119
width => bug!("unsupported pointer width: {width}"),
115120
})
116121
}
117-
ty::Float(FloatTy::F16) => Some(InlineAsmType::VecF16(size)),
118-
ty::Float(FloatTy::F32) => Some(InlineAsmType::VecF32(size)),
119-
ty::Float(FloatTy::F64) => Some(InlineAsmType::VecF64(size)),
120-
ty::Float(FloatTy::F128) => Some(InlineAsmType::VecF128(size)),
121-
_ => None,
122+
ty::Float(FloatTy::F16) => Ok(InlineAsmType::VecF16(size)),
123+
ty::Float(FloatTy::F32) => Ok(InlineAsmType::VecF32(size)),
124+
ty::Float(FloatTy::F64) => Ok(InlineAsmType::VecF64(size)),
125+
ty::Float(FloatTy::F128) => Ok(InlineAsmType::VecF128(size)),
126+
_ => Err(NonAsmTypeReason::InvalidElement(field.did, ty)),
122127
}
123128
}
124129
ty::Infer(_) => bug!("unexpected infer ty in asm operand"),
125-
_ => None,
130+
_ => Err(NonAsmTypeReason::Invalid(ty)),
126131
}
127132
}
128133

@@ -163,17 +168,42 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
163168
}
164169
_ => self.get_asm_ty(ty),
165170
};
166-
let Some(asm_ty) = asm_ty else {
167-
let msg = format!("cannot use value of type `{ty}` for inline assembly");
168-
self.tcx
169-
.dcx()
170-
.struct_span_err(expr.span, msg)
171-
.with_note(
172-
"only integers, floats, SIMD vectors, pointers and function pointers \
173-
can be used as arguments for inline assembly",
174-
)
175-
.emit();
176-
return None;
171+
let asm_ty = match asm_ty {
172+
Ok(asm_ty) => asm_ty,
173+
Err(reason) => {
174+
match reason {
175+
NonAsmTypeReason::UnevaluatedSIMDArrayLength(did, len) => {
176+
let msg = format!("cannot evaluate SIMD vector length `{len}`");
177+
self.tcx
178+
.dcx()
179+
.struct_span_err(self.tcx.def_span(did), msg)
180+
.with_span_note(
181+
expr.span,
182+
"SIMD vector length needs to be known statically for use in `asm!`",
183+
)
184+
.emit();
185+
}
186+
NonAsmTypeReason::Invalid(ty) => {
187+
let msg = format!("cannot use value of type `{ty}` for inline assembly");
188+
self.tcx.dcx().struct_span_err(expr.span, msg).with_note(
189+
"only integers, floats, SIMD vectors, pointers and function pointers \
190+
can be used as arguments for inline assembly",
191+
).emit();
192+
}
193+
NonAsmTypeReason::InvalidElement(did, ty) => {
194+
let msg = format!(
195+
"cannot use SIMD vector with element type `{ty}` for inline assembly"
196+
);
197+
self.tcx.dcx()
198+
.struct_span_err(self.tcx.def_span(did), msg).with_span_note(
199+
expr.span,
200+
"only integers, floats, SIMD vectors, pointers and function pointers \
201+
can be used as arguments for inline assembly",
202+
).emit();
203+
}
204+
}
205+
return None;
206+
}
177207
};
178208

179209
// Check that the type implements Copy. The only case where this can

compiler/rustc_hir_typeck/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30763076
err.help("methods are immutable and cannot be assigned to");
30773077
}
30783078

3079-
err.emit()
3079+
// See `StashKey::GenericInFieldExpr` for more info
3080+
self.dcx().try_steal_replace_and_emit_err(field.span, StashKey::GenericInFieldExpr, err)
30803081
}
30813082

30823083
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {

compiler/rustc_hir_typeck/src/fallback.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -613,19 +613,16 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
613613
if arg_segment.args.is_none()
614614
&& let Some(all_args) = self.fcx.typeck_results.borrow().node_args_opt(id)
615615
&& let generics = self.fcx.tcx.generics_of(def_id)
616-
&& let args = &all_args[generics.parent_count..]
616+
&& let args = all_args[generics.parent_count..].iter().zip(&generics.own_params)
617617
// We can't turbofish consts :(
618-
&& args.iter().all(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_) | ty::GenericArgKind::Lifetime(_)))
618+
&& args.clone().all(|(_, param)| matches!(param.kind, ty::GenericParamDefKind::Type { .. } | ty::GenericParamDefKind::Lifetime))
619619
{
620-
let n_tys = args
621-
.iter()
622-
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
623-
.count();
624-
for (idx, arg) in args
625-
.iter()
626-
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
627-
.enumerate()
628-
{
620+
// We filter out APITs, which are not turbofished.
621+
let non_apit_type_args = args.filter(|(_, param)| {
622+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: false, .. })
623+
});
624+
let n_tys = non_apit_type_args.clone().count();
625+
for (idx, (arg, _)) in non_apit_type_args.enumerate() {
629626
if let Some(ty) = arg.as_type()
630627
&& let Some(vid) = self.fcx.root_vid(ty)
631628
&& self.reachable_vids.contains(&vid)

compiler/rustc_lint/src/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
2+
13
use rustc_span::{Symbol, create_default_session_globals_then};
24

35
use crate::levels::parse_lint_and_tool_name;

compiler/rustc_mir_dataflow/src/move_paths/abs_domain.rs

+9-35
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,34 @@
44
//! field-deref on a local variable, `x.field`, has the same meaning
55
//! in both domains). Indexed projections are the exception: `a[x]`
66
//! needs to be treated as mapping to the same move path as `a[y]` as
7-
//! well as `a[13]`, etc.
7+
//! well as `a[13]`, etc. So we map these `x`/`y` values to `()`.
88
//!
99
//! (In theory, the analysis could be extended to work with sets of
1010
//! paths, so that `a[0]` and `a[13]` could be kept distinct, while
1111
//! `a[x]` would still overlap them both. But that is not this
1212
//! representation does today.)
1313
14-
use rustc_middle::mir::{Local, Operand, PlaceElem, ProjectionElem};
15-
use rustc_middle::ty::Ty;
16-
17-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
18-
pub(crate) struct AbstractOperand;
19-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
20-
pub(crate) struct AbstractType;
21-
pub(crate) type AbstractElem = ProjectionElem<AbstractOperand, AbstractType>;
14+
use rustc_middle::mir::{PlaceElem, ProjectionElem, ProjectionKind};
2215

2316
pub(crate) trait Lift {
24-
type Abstract;
25-
fn lift(&self) -> Self::Abstract;
26-
}
27-
impl<'tcx> Lift for Operand<'tcx> {
28-
type Abstract = AbstractOperand;
29-
fn lift(&self) -> Self::Abstract {
30-
AbstractOperand
31-
}
32-
}
33-
impl Lift for Local {
34-
type Abstract = AbstractOperand;
35-
fn lift(&self) -> Self::Abstract {
36-
AbstractOperand
37-
}
38-
}
39-
impl<'tcx> Lift for Ty<'tcx> {
40-
type Abstract = AbstractType;
41-
fn lift(&self) -> Self::Abstract {
42-
AbstractType
43-
}
17+
fn lift(&self) -> ProjectionKind;
4418
}
19+
4520
impl<'tcx> Lift for PlaceElem<'tcx> {
46-
type Abstract = AbstractElem;
47-
fn lift(&self) -> Self::Abstract {
21+
fn lift(&self) -> ProjectionKind {
4822
match *self {
4923
ProjectionElem::Deref => ProjectionElem::Deref,
50-
ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty.lift()),
51-
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty.lift()),
52-
ProjectionElem::Index(ref i) => ProjectionElem::Index(i.lift()),
24+
ProjectionElem::Field(f, _ty) => ProjectionElem::Field(f, ()),
25+
ProjectionElem::OpaqueCast(_ty) => ProjectionElem::OpaqueCast(()),
26+
ProjectionElem::Index(_i) => ProjectionElem::Index(()),
5327
ProjectionElem::Subslice { from, to, from_end } => {
5428
ProjectionElem::Subslice { from, to, from_end }
5529
}
5630
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
5731
ProjectionElem::ConstantIndex { offset, min_length, from_end }
5832
}
5933
ProjectionElem::Downcast(a, u) => ProjectionElem::Downcast(a, u),
60-
ProjectionElem::Subtype(ty) => ProjectionElem::Subtype(ty.lift()),
34+
ProjectionElem::Subtype(_ty) => ProjectionElem::Subtype(()),
6135
}
6236
}
6337
}

compiler/rustc_mir_dataflow/src/move_paths/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::{Ty, TyCtxt};
88
use rustc_span::Span;
99
use smallvec::SmallVec;
1010

11-
use self::abs_domain::{AbstractElem, Lift};
11+
use self::abs_domain::Lift;
1212
use crate::un_derefer::UnDerefer;
1313

1414
mod abs_domain;
@@ -300,7 +300,7 @@ pub struct MovePathLookup<'tcx> {
300300
/// subsequent search so that it is solely relative to that
301301
/// base-place). For the remaining lookup, we map the projection
302302
/// elem to the associated MovePathIndex.
303-
projections: FxHashMap<(MovePathIndex, AbstractElem), MovePathIndex>,
303+
projections: FxHashMap<(MovePathIndex, ProjectionKind), MovePathIndex>,
304304

305305
un_derefer: UnDerefer<'tcx>,
306306
}

compiler/rustc_parse/src/lexer/tokentrees.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::token::{self, Delimiter, Token};
22
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
33
use rustc_ast_pretty::pprust::token_to_string;
4-
use rustc_errors::{Applicability, PErr};
4+
use rustc_errors::{Applicability, Diag};
55
use rustc_span::symbol::kw;
66

77
use super::diagnostics::{report_suspicious_mismatch_block, same_indentation_level};
@@ -14,7 +14,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
1414
pub(super) fn lex_token_trees(
1515
&mut self,
1616
is_delimited: bool,
17-
) -> (Spacing, TokenStream, Result<(), Vec<PErr<'psess>>>) {
17+
) -> (Spacing, TokenStream, Result<(), Vec<Diag<'psess>>>) {
1818
// Move past the opening delimiter.
1919
let open_spacing = self.bump_minimal();
2020

@@ -56,7 +56,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
5656
}
5757
}
5858

59-
fn eof_err(&mut self) -> PErr<'psess> {
59+
fn eof_err(&mut self) -> Diag<'psess> {
6060
let msg = "this file contains an unclosed delimiter";
6161
let mut err = self.dcx().struct_span_err(self.token.span, msg);
6262

@@ -98,7 +98,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
9898
fn lex_token_tree_open_delim(
9999
&mut self,
100100
open_delim: Delimiter,
101-
) -> Result<TokenTree, Vec<PErr<'psess>>> {
101+
) -> Result<TokenTree, Vec<Diag<'psess>>> {
102102
// The span for beginning of the delimited section.
103103
let pre_span = self.token.span;
104104

@@ -250,8 +250,8 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
250250
fn unclosed_delim_err(
251251
&mut self,
252252
tts: TokenStream,
253-
mut errs: Vec<PErr<'psess>>,
254-
) -> Vec<PErr<'psess>> {
253+
mut errs: Vec<Diag<'psess>>,
254+
) -> Vec<Diag<'psess>> {
255255
// If there are unclosed delims, see if there are diff markers and if so, point them
256256
// out instead of complaining about the unclosed delims.
257257
let mut parser = Parser::new(self.psess, tts, None);
@@ -308,7 +308,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
308308
errs
309309
}
310310

311-
fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'psess> {
311+
fn close_delim_err(&mut self, delim: Delimiter) -> Diag<'psess> {
312312
// An unexpected closing delimiter (i.e., there is no matching opening delimiter).
313313
let token_str = token_to_string(&self.token);
314314
let msg = format!("unexpected closing delimiter: `{token_str}`");

0 commit comments

Comments
 (0)