Skip to content

Commit 832db2f

Browse files
committed
Auto merge of rust-lang#114673 - matthiaskrgr:rollup-9kroqpp, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#110435 (rustdoc-json: Add test for field ordering.) - rust-lang#111891 (feat: `riscv-interrupt-{m,s}` calling conventions) - rust-lang#114377 (test_get_dbpath_for_term(): handle non-utf8 paths (fix FIXME)) - rust-lang#114469 (Detect method not found on arbitrary self type with different mutability) - rust-lang#114587 (Convert Const to Allocation in smir) - rust-lang#114670 (Don't use `type_of` to determine if item has intrinsic shim) Failed merges: - rust-lang#114599 (Add impl trait declarations to SMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 08d00b4 + a87dda3 commit 832db2f

File tree

55 files changed

+1173
-155
lines changed

Some content is hidden

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

55 files changed

+1173
-155
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+17
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,26 @@ pub struct InvalidAbi {
3131
pub abi: Symbol,
3232
pub command: String,
3333
#[subdiagnostic]
34+
pub explain: Option<InvalidAbiReason>,
35+
#[subdiagnostic]
3436
pub suggestion: Option<InvalidAbiSuggestion>,
3537
}
3638

39+
pub struct InvalidAbiReason(pub &'static str);
40+
41+
impl rustc_errors::AddToDiagnostic for InvalidAbiReason {
42+
fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F)
43+
where
44+
F: Fn(
45+
&mut rustc_errors::Diagnostic,
46+
rustc_errors::SubdiagnosticMessage,
47+
) -> rustc_errors::SubdiagnosticMessage,
48+
{
49+
#[allow(rustc::untranslatable_diagnostic)]
50+
diag.note(self.0);
51+
}
52+
}
53+
3754
#[derive(Subdiagnostic)]
3855
#[suggestion(
3956
ast_lowering_invalid_abi_suggestion,

compiler/rustc_ast_lowering/src/item.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::errors::{InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound};
1+
use super::errors::{InvalidAbi, InvalidAbiReason, InvalidAbiSuggestion, MisplacedRelaxTraitBound};
22
use super::ResolverAstLoweringExt;
33
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
44
use super::{FnDeclKind, LoweringContext, ParamMode};
@@ -1271,8 +1271,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
12711271
}
12721272

12731273
pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi {
1274-
abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|| {
1275-
self.error_on_invalid_abi(abi);
1274+
abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|err| {
1275+
self.error_on_invalid_abi(abi, err);
12761276
abi::Abi::Rust
12771277
})
12781278
}
@@ -1285,7 +1285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12851285
}
12861286
}
12871287

1288-
fn error_on_invalid_abi(&self, abi: StrLit) {
1288+
fn error_on_invalid_abi(&self, abi: StrLit, err: abi::AbiUnsupported) {
12891289
let abi_names = abi::enabled_names(self.tcx.features(), abi.span)
12901290
.iter()
12911291
.map(|s| Symbol::intern(s))
@@ -1294,6 +1294,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
12941294
self.tcx.sess.emit_err(InvalidAbi {
12951295
abi: abi.symbol_unescaped,
12961296
span: abi.span,
1297+
explain: match err {
1298+
abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
1299+
_ => None,
1300+
},
12971301
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
12981302
span: abi.span,
12991303
suggestion: format!("\"{suggested_name}\""),

compiler/rustc_codegen_cranelift/src/abi/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
4848
default_call_conv
4949
}
5050

51-
Conv::X86Intr => sess.fatal("x86-interrupt call conv not yet implemented"),
51+
Conv::X86Intr | Conv::RiscvInterrupt { .. } => {
52+
sess.fatal(format!("interrupt call conv {c:?} not yet implemented"))
53+
}
5254

5355
Conv::ArmAapcs => sess.fatal("aapcs call conv not yet implemented"),
5456
Conv::CCmseNonSecureCall => {

compiler/rustc_codegen_llvm/src/abi.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,16 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
383383
}
384384

385385
fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value) {
386-
let mut func_attrs = SmallVec::<[_; 2]>::new();
386+
let mut func_attrs = SmallVec::<[_; 3]>::new();
387387
if self.ret.layout.abi.is_uninhabited() {
388388
func_attrs.push(llvm::AttributeKind::NoReturn.create_attr(cx.llcx));
389389
}
390390
if !self.can_unwind {
391391
func_attrs.push(llvm::AttributeKind::NoUnwind.create_attr(cx.llcx));
392392
}
393+
if let Conv::RiscvInterrupt { kind } = self.conv {
394+
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", kind.as_str()));
395+
}
393396
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs });
394397

395398
let mut i = 0;
@@ -565,7 +568,9 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
565568
impl From<Conv> for llvm::CallConv {
566569
fn from(conv: Conv) -> Self {
567570
match conv {
568-
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall => llvm::CCallConv,
571+
Conv::C | Conv::Rust | Conv::CCmseNonSecureCall | Conv::RiscvInterrupt { .. } => {
572+
llvm::CCallConv
573+
}
569574
Conv::RustCold => llvm::ColdCallConv,
570575
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
571576
Conv::AvrInterrupt => llvm::AvrInterrupt,

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ declare_features! (
313313
(active, abi_msp430_interrupt, "1.16.0", Some(38487), None),
314314
/// Allows `extern "ptx-*" fn()`.
315315
(active, abi_ptx, "1.15.0", Some(38788), None),
316+
/// Allows `extern "riscv-interrupt-m" fn()` and `extern "riscv-interrupt-s" fn()`.
317+
(active, abi_riscv_interrupt, "CURRENT_RUSTC_VERSION", Some(111889), None),
316318
/// Allows `extern "x86-interrupt" fn()`.
317319
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
318320
/// Allows additional const parameter types, such as `&'static str` or user defined types

compiler/rustc_hir_typeck/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::errors::{
1313
YieldExprOutsideOfGenerator,
1414
};
1515
use crate::fatally_break_rust;
16-
use crate::method::SelfSource;
16+
use crate::method::{MethodCallComponents, SelfSource};
1717
use crate::type_error_struct;
1818
use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectation};
1919
use crate::{
@@ -1281,7 +1281,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12811281
segment.ident,
12821282
SelfSource::MethodCall(rcvr),
12831283
error,
1284-
Some((rcvr, args)),
1284+
Some(MethodCallComponents { receiver: rcvr, args, full_expr: expr }),
12851285
expected,
12861286
false,
12871287
) {

compiler/rustc_hir_typeck/src/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod prelude2021;
77
pub mod probe;
88
mod suggest;
99

10-
pub use self::suggest::SelfSource;
10+
pub use self::suggest::{MethodCallComponents, SelfSource};
1111
pub use self::MethodError::*;
1212

1313
use crate::errors::OpMethodGenericParams;

compiler/rustc_hir_typeck/src/method/suggest.rs

+65-14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ use rustc_hir::intravisit::Visitor;
5050
use std::cmp::{self, Ordering};
5151
use std::iter;
5252

53+
/// After identifying that `full_expr` is a method call, we use this type to keep the expression's
54+
/// components readily available to us to point at the right place in diagnostics.
55+
#[derive(Debug, Clone, Copy)]
56+
pub struct MethodCallComponents<'tcx> {
57+
pub receiver: &'tcx hir::Expr<'tcx>,
58+
pub args: &'tcx [hir::Expr<'tcx>],
59+
pub full_expr: &'tcx hir::Expr<'tcx>,
60+
}
61+
5362
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5463
fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
5564
let tcx = self.tcx;
@@ -115,7 +124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
115124
item_name: Ident,
116125
source: SelfSource<'tcx>,
117126
error: MethodError<'tcx>,
118-
args: Option<(&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>])>,
127+
args: Option<MethodCallComponents<'tcx>>,
119128
expected: Expectation<'tcx>,
120129
trait_missing_method: bool,
121130
) -> Option<DiagnosticBuilder<'_, ErrorGuaranteed>> {
@@ -257,18 +266,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
257266
fn suggest_missing_writer(
258267
&self,
259268
rcvr_ty: Ty<'tcx>,
260-
args: (&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>]),
269+
args: MethodCallComponents<'tcx>,
261270
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
262271
let (ty_str, _ty_file) = self.tcx.short_ty_string(rcvr_ty);
263-
let mut err =
264-
struct_span_err!(self.tcx.sess, args.0.span, E0599, "cannot write into `{}`", ty_str);
272+
let mut err = struct_span_err!(
273+
self.tcx.sess,
274+
args.receiver.span,
275+
E0599,
276+
"cannot write into `{}`",
277+
ty_str
278+
);
265279
err.span_note(
266-
args.0.span,
280+
args.receiver.span,
267281
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method",
268282
);
269-
if let ExprKind::Lit(_) = args.0.kind {
283+
if let ExprKind::Lit(_) = args.receiver.kind {
270284
err.span_help(
271-
args.0.span.shrink_to_lo(),
285+
args.receiver.span.shrink_to_lo(),
272286
"a writer is needed before this format string",
273287
);
274288
};
@@ -282,7 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
282296
rcvr_ty: Ty<'tcx>,
283297
item_name: Ident,
284298
source: SelfSource<'tcx>,
285-
args: Option<(&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>])>,
299+
args: Option<MethodCallComponents<'tcx>>,
286300
sugg_span: Span,
287301
no_match_data: &mut NoMatchData<'tcx>,
288302
expected: Expectation<'tcx>,
@@ -953,6 +967,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
953967

954968
unsatisfied_bounds = true;
955969
}
970+
} else if let ty::Adt(def, targs) = rcvr_ty.kind() && let Some(args) = args {
971+
// This is useful for methods on arbitrary self types that might have a simple
972+
// mutability difference, like calling a method on `Pin<&mut Self>` that is on
973+
// `Pin<&Self>`.
974+
if targs.len() == 1 {
975+
let mut item_segment = hir::PathSegment::invalid();
976+
item_segment.ident = item_name;
977+
for t in [Ty::new_mut_ref, Ty::new_imm_ref, |_, _, t| t] {
978+
let new_args = tcx.mk_args_from_iter(
979+
targs
980+
.iter()
981+
.map(|arg| match arg.as_type() {
982+
Some(ty) => ty::GenericArg::from(
983+
t(tcx, tcx.lifetimes.re_erased, ty.peel_refs()),
984+
),
985+
_ => arg,
986+
})
987+
);
988+
let rcvr_ty = Ty::new_adt(tcx, *def, new_args);
989+
if let Ok(method) = self.lookup_method_for_diagnostic(
990+
rcvr_ty,
991+
&item_segment,
992+
span,
993+
args.full_expr,
994+
args.receiver,
995+
) {
996+
err.span_note(
997+
tcx.def_span(method.def_id),
998+
format!("{item_kind} is available for `{rcvr_ty}`"),
999+
);
1000+
}
1001+
}
1002+
}
9561003
}
9571004

9581005
let label_span_not_found = |err: &mut Diagnostic| {
@@ -1111,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11111158
span,
11121159
rcvr_ty,
11131160
item_name,
1114-
args.map(|(_, args)| args.len() + 1),
1161+
args.map(|MethodCallComponents { args, .. }| args.len() + 1),
11151162
source,
11161163
no_match_data.out_of_scope_traits.clone(),
11171164
&unsatisfied_predicates,
@@ -1192,7 +1239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921239
&self,
11931240
rcvr_ty: Ty<'tcx>,
11941241
item_name: Ident,
1195-
args: Option<(&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>])>,
1242+
args: Option<MethodCallComponents<'tcx>>,
11961243
span: Span,
11971244
err: &mut Diagnostic,
11981245
sources: &mut Vec<CandidateSource>,
@@ -1343,7 +1390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13431390
rcvr_ty: Ty<'tcx>,
13441391
source: SelfSource<'tcx>,
13451392
item_name: Ident,
1346-
args: Option<(&hir::Expr<'tcx>, &[hir::Expr<'tcx>])>,
1393+
args: Option<MethodCallComponents<'tcx>>,
13471394
sugg_span: Span,
13481395
) {
13491396
let mut has_unsuggestable_args = false;
@@ -1415,7 +1462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14151462
None
14161463
};
14171464
let mut applicability = Applicability::MachineApplicable;
1418-
let args = if let Some((receiver, args)) = args {
1465+
let args = if let Some(MethodCallComponents { receiver, args, .. }) = args {
14191466
// The first arg is the same kind as the receiver
14201467
let explicit_args = if first_arg.is_some() {
14211468
std::iter::once(receiver).chain(args.iter()).collect::<Vec<_>>()
@@ -2995,7 +3042,7 @@ pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
29953042

29963043
fn print_disambiguation_help<'tcx>(
29973044
item_name: Ident,
2998-
args: Option<(&'tcx hir::Expr<'tcx>, &'tcx [hir::Expr<'tcx>])>,
3045+
args: Option<MethodCallComponents<'tcx>>,
29993046
err: &mut Diagnostic,
30003047
trait_name: String,
30013048
rcvr_ty: Ty<'_>,
@@ -3007,7 +3054,11 @@ fn print_disambiguation_help<'tcx>(
30073054
fn_has_self_parameter: bool,
30083055
) {
30093056
let mut applicability = Applicability::MachineApplicable;
3010-
let (span, sugg) = if let (ty::AssocKind::Fn, Some((receiver, args))) = (kind, args) {
3057+
let (span, sugg) = if let (
3058+
ty::AssocKind::Fn,
3059+
Some(MethodCallComponents { receiver, args, .. }),
3060+
) = (kind, args)
3061+
{
30113062
let args = format!(
30123063
"({}{})",
30133064
rcvr_ty.ref_mutability().map_or("", |mutbl| mutbl.ref_prefix_str()),

compiler/rustc_middle/src/mir/interpret/allocation.rs

+3
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
329329

330330
/// Try to create an Allocation of `size` bytes, panics if there is not enough memory
331331
/// available to the compiler to do so.
332+
///
333+
/// Example use case: To obtain an Allocation filled with specific data,
334+
/// first call this function and then call write_scalar to fill in the right data.
332335
pub fn uninit(size: Size, align: Align) -> Self {
333336
match Self::uninit_inner(size, align, || {
334337
panic!("Allocation::uninit called with panic_on_fail had allocation failure");

compiler/rustc_middle/src/ty/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
12391239
| EfiApi
12401240
| AvrInterrupt
12411241
| AvrNonBlockingInterrupt
1242+
| RiscvInterruptM
1243+
| RiscvInterruptS
12421244
| CCmseNonSecureCall
12431245
| Wasm
12441246
| PlatformIntrinsic

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn abi_can_unwind(abi: Abi) -> bool {
3030
| EfiApi
3131
| AvrInterrupt
3232
| AvrNonBlockingInterrupt
33+
| RiscvInterruptM
34+
| RiscvInterruptS
3335
| CCmseNonSecureCall
3436
| Wasm
3537
| RustIntrinsic

compiler/rustc_smir/src/rustc_internal/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ impl<'tcx> Tables<'tcx> {
112112
stable_mir::ty::TraitDef(self.create_def_id(did))
113113
}
114114

115+
pub fn const_def(&mut self, did: DefId) -> stable_mir::ty::ConstDef {
116+
stable_mir::ty::ConstDef(self.create_def_id(did))
117+
}
118+
115119
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
116120
// FIXME: this becomes inefficient when we have too many ids
117121
for (i, &d) in self.def_ids.iter().enumerate() {

0 commit comments

Comments
 (0)