Skip to content

Commit c6c4abf

Browse files
committed
Auto merge of #119927 - matthiaskrgr:rollup-885ws57, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #119587 (Varargs support for system ABI) - #119891 (rename `reported_signature_mismatch` to reflect its use) - #119894 (Allow `~const` on associated type bounds again) - #119896 (Taint `_` placeholder types in trait impl method signatures) - #119898 (Remove unused `ErrorReporting` variant from overflow handling) - #119902 (fix typo in `fn()` docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1d8d7b1 + f53caa1 commit c6c4abf

33 files changed

+289
-104
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
232232
.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
233233
.trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds
234234
.impl = inherent impls cannot have `~const` trait bounds
235+
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
236+
.trait_impl_assoc_ty = associated types in non-const impls cannot have `~const` trait bounds
237+
.inherent_assoc_ty = inherent associated types cannot have `~const` trait bounds
235238
.object = trait objects cannot have `~const` trait bounds
236239
.item = this item cannot have `~const` trait bounds
237240

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,17 @@ enum SelfSemantic {
3737
}
3838

3939
/// What is the context that prevents using `~const`?
40+
// FIXME(effects): Consider getting rid of this in favor of `errors::TildeConstReason`, they're
41+
// almost identical. This gets rid of an abstraction layer which might be considered bad.
4042
enum DisallowTildeConstContext<'a> {
4143
TraitObject,
4244
Fn(FnKind<'a>),
4345
Trait(Span),
4446
TraitImpl(Span),
4547
Impl(Span),
48+
TraitAssocTy(Span),
49+
TraitImplAssocTy(Span),
50+
InherentAssocTy(Span),
4651
Item,
4752
}
4853

@@ -316,6 +321,7 @@ impl<'a> AstValidator<'a> {
316321
constness: Const::No,
317322
polarity: ImplPolarity::Positive,
318323
trait_ref,
324+
..
319325
} = parent
320326
{
321327
Some(trait_ref.path.span.shrink_to_lo())
@@ -1286,6 +1292,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12861292
// suggestion for moving such bounds to the assoc const fns if available.
12871293
errors::TildeConstReason::Impl { span }
12881294
}
1295+
&DisallowTildeConstContext::TraitAssocTy(span) => {
1296+
errors::TildeConstReason::TraitAssocTy { span }
1297+
}
1298+
&DisallowTildeConstContext::TraitImplAssocTy(span) => {
1299+
errors::TildeConstReason::TraitImplAssocTy { span }
1300+
}
1301+
&DisallowTildeConstContext::InherentAssocTy(span) => {
1302+
errors::TildeConstReason::InherentAssocTy { span }
1303+
}
12891304
DisallowTildeConstContext::TraitObject => {
12901305
errors::TildeConstReason::TraitObject
12911306
}
@@ -1483,13 +1498,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14831498
self.check_item_named(item.ident, "const");
14841499
}
14851500

1501+
let parent_is_const =
1502+
self.outer_trait_or_trait_impl.as_ref().and_then(TraitOrTraitImpl::constness).is_some();
1503+
14861504
match &item.kind {
14871505
AssocItemKind::Fn(box Fn { sig, generics, body, .. })
1488-
if self
1489-
.outer_trait_or_trait_impl
1490-
.as_ref()
1491-
.and_then(TraitOrTraitImpl::constness)
1492-
.is_some()
1506+
if parent_is_const
14931507
|| ctxt == AssocCtxt::Trait
14941508
|| matches!(sig.header.constness, Const::Yes(_)) =>
14951509
{
@@ -1505,6 +1519,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15051519
);
15061520
self.visit_fn(kind, item.span, item.id);
15071521
}
1522+
AssocItemKind::Type(_) => {
1523+
let disallowed = (!parent_is_const).then(|| match self.outer_trait_or_trait_impl {
1524+
Some(TraitOrTraitImpl::Trait { .. }) => {
1525+
DisallowTildeConstContext::TraitAssocTy(item.span)
1526+
}
1527+
Some(TraitOrTraitImpl::TraitImpl { .. }) => {
1528+
DisallowTildeConstContext::TraitImplAssocTy(item.span)
1529+
}
1530+
None => DisallowTildeConstContext::InherentAssocTy(item.span),
1531+
});
1532+
self.with_tilde_const(disallowed, |this| {
1533+
this.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt))
1534+
})
1535+
}
15081536
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt)),
15091537
}
15101538
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ pub struct ConstBoundTraitObject {
565565
pub span: Span,
566566
}
567567

568+
// FIXME(effects): Consider making the note/reason the message of the diagnostic.
569+
// FIXME(effects): Provide structured suggestions (e.g., add `const` / `#[const_trait]` here).
568570
#[derive(Diagnostic)]
569571
#[diag(ast_passes_tilde_const_disallowed)]
570572
pub struct TildeConstDisallowed {
@@ -598,6 +600,21 @@ pub enum TildeConstReason {
598600
#[primary_span]
599601
span: Span,
600602
},
603+
#[note(ast_passes_trait_assoc_ty)]
604+
TraitAssocTy {
605+
#[primary_span]
606+
span: Span,
607+
},
608+
#[note(ast_passes_trait_impl_assoc_ty)]
609+
TraitImplAssocTy {
610+
#[primary_span]
611+
span: Span,
612+
},
613+
#[note(ast_passes_inherent_assoc_ty)]
614+
InherentAssocTy {
615+
#[primary_span]
616+
span: Span,
617+
},
601618
#[note(ast_passes_object)]
602619
TraitObject,
603620
#[note(ast_passes_item)]

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26592659
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i))
26602660
{
26612661
infer_replacements.push((a.span, suggested_ty.to_string()));
2662-
return suggested_ty;
2662+
return Ty::new_error_with_message(
2663+
self.tcx(),
2664+
a.span,
2665+
suggested_ty.to_string(),
2666+
);
26632667
}
26642668
}
26652669

@@ -2677,7 +2681,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26772681
self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None)
26782682
{
26792683
infer_replacements.push((output.span, suggested_ty.to_string()));
2680-
suggested_ty
2684+
Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string())
26812685
} else {
26822686
visitor.visit_ty(output);
26832687
self.ast_ty_to_ty(output)

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ use rustc_hir::def::DefKind;
116116
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
117117

118118
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
119-
const CONVENTIONS_UNSTABLE: &str = "`C`, `cdecl`, `aapcs`, `win64`, `sysv64` or `efiapi`";
119+
const CONVENTIONS_UNSTABLE: &str =
120+
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
120121
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
121122
const UNSTABLE_EXPLAIN: &str =
122123
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";

compiler/rustc_infer/src/infer/at.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> InferCtxt<'tcx> {
8484
selection_cache: self.selection_cache.clone(),
8585
evaluation_cache: self.evaluation_cache.clone(),
8686
reported_trait_errors: self.reported_trait_errors.clone(),
87-
reported_closure_mismatch: self.reported_closure_mismatch.clone(),
87+
reported_signature_mismatch: self.reported_signature_mismatch.clone(),
8888
tainted_by_errors: self.tainted_by_errors.clone(),
8989
err_count_on_creation: self.err_count_on_creation,
9090
universe: self.universe.clone(),

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub struct InferCtxt<'tcx> {
278278
/// avoid reporting the same error twice.
279279
pub reported_trait_errors: RefCell<FxIndexMap<Span, Vec<ty::Predicate<'tcx>>>>,
280280

281-
pub reported_closure_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>,
281+
pub reported_signature_mismatch: RefCell<FxHashSet<(Span, Option<Span>)>>,
282282

283283
/// When an error occurs, we want to avoid reporting "derived"
284284
/// errors that are due to this original failure. Normally, we
@@ -702,7 +702,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
702702
selection_cache: Default::default(),
703703
evaluation_cache: Default::default(),
704704
reported_trait_errors: Default::default(),
705-
reported_closure_mismatch: Default::default(),
705+
reported_signature_mismatch: Default::default(),
706706
tainted_by_errors: Cell::new(None),
707707
err_count_on_creation: tcx.dcx().err_count(),
708708
universe: Cell::new(ty::UniverseIndex::ROOT),

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,23 @@ impl<'tcx> Collector<'tcx> {
520520
) -> DllImport {
521521
let span = self.tcx.def_span(item);
522522

523+
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
523524
let calling_convention = if self.tcx.sess.target.arch == "x86" {
524525
match abi {
525526
Abi::C { .. } | Abi::Cdecl { .. } => DllCallingConvention::C,
526-
Abi::Stdcall { .. } | Abi::System { .. } => {
527-
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
527+
Abi::Stdcall { .. } => DllCallingConvention::Stdcall(self.i686_arg_list_size(item)),
528+
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
529+
// `__stdcall` only applies on x86 and on non-variadic functions:
530+
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
531+
Abi::System { .. } => {
532+
let c_variadic =
533+
self.tcx.type_of(item).instantiate_identity().fn_sig(self.tcx).c_variadic();
534+
535+
if c_variadic {
536+
DllCallingConvention::C
537+
} else {
538+
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
539+
}
528540
}
529541
Abi::Fastcall { .. } => {
530542
DllCallingConvention::Fastcall(self.i686_arg_list_size(item))

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,6 @@ pub enum SelectionError<'tcx> {
611611
NotConstEvaluatable(NotConstEvaluatable),
612612
/// Exceeded the recursion depth during type projection.
613613
Overflow(OverflowError),
614-
/// Signaling that an error has already been emitted, to avoid
615-
/// multiple errors being shown.
616-
ErrorReporting,
617614
/// Computing an opaque type's hidden type caused an error (e.g. a cycle error).
618615
/// We can thus not know whether the hidden type implements an auto trait, so
619616
/// we should not presume anything about it.

compiler/rustc_middle/src/traits/select.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ impl EvaluationResult {
302302
pub enum OverflowError {
303303
Error(ErrorGuaranteed),
304304
Canonical,
305-
ErrorReporting,
306305
}
307306

308307
impl From<ErrorGuaranteed> for OverflowError {
@@ -318,7 +317,6 @@ impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
318317
match overflow_error {
319318
OverflowError::Error(e) => SelectionError::Overflow(OverflowError::Error(e)),
320319
OverflowError::Canonical => SelectionError::Overflow(OverflowError::Canonical),
321-
OverflowError::ErrorReporting => SelectionError::ErrorReporting,
322320
}
323321
}
324322
}

0 commit comments

Comments
 (0)