Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6c4abf

Browse files
committedJan 13, 2024
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
}

‎compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
840840
"sparc" => sparc::compute_abi_info(cx, self),
841841
"sparc64" => sparc64::compute_abi_info(cx, self),
842842
"nvptx64" => {
843-
if cx.target_spec().adjust_abi(abi) == spec::abi::Abi::PtxKernel {
843+
if cx.target_spec().adjust_abi(abi, self.c_variadic) == spec::abi::Abi::PtxKernel {
844844
nvptx64::compute_ptx_kernel_abi_info(cx, self)
845845
} else {
846846
nvptx64::compute_abi_info(self)
@@ -849,7 +849,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
849849
"hexagon" => hexagon::compute_abi_info(self),
850850
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
851851
"wasm32" | "wasm64" => {
852-
if cx.target_spec().adjust_abi(abi) == spec::abi::Abi::Wasm {
852+
if cx.target_spec().adjust_abi(abi, self.c_variadic) == spec::abi::Abi::Wasm {
853853
wasm::compute_wasm_abi_info(self)
854854
} else {
855855
wasm::compute_c_abi_info(cx, self)

‎compiler/rustc_target/src/spec/abi/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,16 @@ impl Abi {
7070
// * C and Cdecl obviously support varargs.
7171
// * C can be based on Aapcs, SysV64 or Win64, so they must support varargs.
7272
// * EfiApi is based on Win64 or C, so it also supports it.
73+
// * System falls back to C for functions with varargs.
7374
//
7475
// * Stdcall does not, because it would be impossible for the callee to clean
7576
// up the arguments. (callee doesn't know how many arguments are there)
7677
// * Same for Fastcall, Vectorcall and Thiscall.
77-
// * System can become Stdcall, so is also a no-no.
7878
// * Other calling conventions are related to hardware or the compiler itself.
7979
match self {
8080
Self::C { .. }
8181
| Self::Cdecl { .. }
82+
| Self::System { .. }
8283
| Self::Aapcs { .. }
8384
| Self::Win64 { .. }
8485
| Self::SysV64 { .. }

‎compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,10 +2401,14 @@ impl DerefMut for Target {
24012401

24022402
impl Target {
24032403
/// Given a function ABI, turn it into the correct ABI for this target.
2404-
pub fn adjust_abi(&self, abi: Abi) -> Abi {
2404+
pub fn adjust_abi(&self, abi: Abi, c_variadic: bool) -> Abi {
24052405
match abi {
24062406
Abi::C { .. } => self.default_adjusted_cabi.unwrap_or(abi),
2407-
Abi::System { unwind } if self.is_like_windows && self.arch == "x86" => {
2407+
2408+
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
2409+
// `__stdcall` only applies on x86 and on non-variadic functions:
2410+
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
2411+
Abi::System { unwind } if self.is_like_windows && self.arch == "x86" && !c_variadic => {
24082412
Abi::Stdcall { unwind }
24092413
}
24102414
Abi::System { unwind } => Abi::C { unwind },

‎compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
947947
Overflow(_) => {
948948
bug!("overflow should be handled before the `report_selection_error` path");
949949
}
950-
SelectionError::ErrorReporting => {
951-
bug!("ErrorReporting Overflow should not reach `report_selection_err` call")
952-
}
953950
};
954951

955952
self.note_obligation_cause(&mut err, &obligation);
@@ -3459,14 +3456,12 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
34593456
let found_node = found_did.and_then(|did| self.tcx.hir().get_if_local(did));
34603457
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
34613458

3462-
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
3459+
if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) {
34633460
// We check closures twice, with obligations flowing in different directions,
34643461
// but we want to complain about them only once.
34653462
return None;
34663463
}
34673464

3468-
self.reported_closure_mismatch.borrow_mut().insert((span, found_span));
3469-
34703465
let mut not_tupled = false;
34713466

34723467
let found = match found_trait_ref.skip_binder().args.type_at(1).kind() {

‎compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
116116
r,
117117
)
118118
}
119-
OverflowError::ErrorReporting => EvaluationResult::EvaluatedToErr,
120119
OverflowError::Error(_) => EvaluationResult::EvaluatedToErr,
121120
})
122121
}
123-
Err(OverflowError::ErrorReporting) => EvaluationResult::EvaluatedToErr,
124122
Err(OverflowError::Error(_)) => EvaluationResult::EvaluatedToErr,
125123
}
126124
}

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use super::util;
1414
use super::util::closure_trait_ref_and_return_type;
1515
use super::wf;
1616
use super::{
17-
ErrorReporting, ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation,
18-
ObligationCause, ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation,
19-
Selection, SelectionError, SelectionResult, TraitQueryMode,
17+
ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation, ObligationCause,
18+
ObligationCauseCode, Overflow, PolyTraitObligation, PredicateObligation, Selection,
19+
SelectionError, SelectionResult, TraitQueryMode,
2020
};
2121

2222
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
@@ -496,7 +496,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
496496
}
497497
Ok(_) => Ok(None),
498498
Err(OverflowError::Canonical) => Err(Overflow(OverflowError::Canonical)),
499-
Err(OverflowError::ErrorReporting) => Err(ErrorReporting),
500499
Err(OverflowError::Error(e)) => Err(Overflow(OverflowError::Error(e))),
501500
})
502501
.flat_map(Result::transpose)
@@ -1233,7 +1232,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12331232
Ok(Some(c)) => self.evaluate_candidate(stack, &c),
12341233
Ok(None) => Ok(EvaluatedToAmbig),
12351234
Err(Overflow(OverflowError::Canonical)) => Err(OverflowError::Canonical),
1236-
Err(ErrorReporting) => Err(OverflowError::ErrorReporting),
12371235
Err(..) => Ok(EvaluatedToErr),
12381236
}
12391237
}

‎compiler/rustc_ty_utils/src/abi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ fn fn_sig_for_fn_abi<'tcx>(
228228
}
229229

230230
#[inline]
231-
fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv {
231+
fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi, c_variadic: bool) -> Conv {
232232
use rustc_target::spec::abi::Abi::*;
233-
match tcx.sess.target.adjust_abi(abi) {
233+
match tcx.sess.target.adjust_abi(abi, c_variadic) {
234234
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::Rust,
235235

236236
// This is intentionally not using `Conv::Cold`, as that has to preserve
@@ -488,7 +488,7 @@ fn fn_abi_new_uncached<'tcx>(
488488
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
489489
let sig = cx.tcx.normalize_erasing_late_bound_regions(cx.param_env, sig);
490490

491-
let conv = conv_from_spec_abi(cx.tcx(), sig.abi);
491+
let conv = conv_from_spec_abi(cx.tcx(), sig.abi, sig.c_variadic);
492492

493493
let mut inputs = sig.inputs();
494494
let extra_args = if sig.abi == RustCall {

‎library/core/src/primitive_docs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,9 +1605,9 @@ mod prim_ref {}
16051605
/// type in the function pointer to the type at the function declaration, and the return value is
16061606
/// [`transmute`d][mem::transmute] from the type in the declaration to the type in the
16071607
/// pointer. All the usual caveats and concerns around transmutation apply; for instance, if the
1608-
/// function expects a `NonNullI32` and the function pointer uses the ABI-compatible type
1609-
/// `Option<NonNullI32>`, and the value used for the argument is `None`, then this call is Undefined
1610-
/// Behavior since transmuting `None::<NonNullI32>` to `NonNullI32` violates the non-null
1608+
/// function expects a `NonZeroI32` and the function pointer uses the ABI-compatible type
1609+
/// `Option<NonZeroI32>`, and the value used for the argument is `None`, then this call is Undefined
1610+
/// Behavior since transmuting `None::<NonZeroI32>` to `NonZeroI32` violates the non-zero
16111611
/// requirement.
16121612
///
16131613
/// #### Requirements concerning target features

‎src/librustdoc/clean/blanket_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
8181
match infcx.evaluate_obligation(&obligation) {
8282
Ok(eval_result) if eval_result.may_apply() => {}
8383
Err(traits::OverflowError::Canonical) => {}
84-
Err(traits::OverflowError::ErrorReporting) => {}
8584
_ => continue 'blanket_impls,
8685
}
8786
}

‎tests/ui/c-variadic/variadic-ffi-2.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
fn baz(f: extern "stdcall" fn(usize, ...)) {
55
//~^ ERROR: C-variadic function must have a compatible calling convention,
6-
// like C, cdecl, aapcs, win64, sysv64 or efiapi
6+
// like C, cdecl, system, aapcs, win64, sysv64 or efiapi
77
f(22, 44);
88
}
99

10+
fn system(f: extern "system" fn(usize, ...)) {
11+
f(22, 44);
12+
}
1013
fn aapcs(f: extern "aapcs" fn(usize, ...)) {
1114
f(22, 44);
1215
}

‎tests/ui/c-variadic/variadic-ffi-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `aapcs`, `win64`, `sysv64` or `efiapi`
1+
error[E0045]: C-variadic function must have a compatible calling convention, like `C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`
22
--> $DIR/variadic-ffi-2.rs:4:11
33
|
44
LL | fn baz(f: extern "stdcall" fn(usize, ...)) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `T: Trait` is not satisfied
2+
--> $DIR/assoc-type-const-bound-usage-0.rs:21:6
3+
|
4+
LL | <T as /* FIXME: ~const */ Trait>::Assoc::func()
5+
| ^ the trait `Trait` is not implemented for `T`
6+
|
7+
help: consider further restricting this bound
8+
|
9+
LL | const fn qualified<T: ~const Trait + Trait>() -> i32 {
10+
| +++++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// FIXME(effects): Collapse the revisions into one once we support `<Ty as ~const Trait>::Proj`.
2+
// revisions: unqualified qualified
3+
//[unqualified] check-pass
4+
//[qualified] known-bug: unknown
5+
6+
#![feature(const_trait_impl, effects)]
7+
8+
#[const_trait]
9+
trait Trait {
10+
type Assoc: ~const Trait;
11+
fn func() -> i32;
12+
}
13+
14+
#[cfg(unqualified)]
15+
const fn unqualified<T: ~const Trait>() -> i32 {
16+
T::Assoc::func()
17+
}
18+
19+
#[cfg(qualified)]
20+
const fn qualified<T: ~const Trait>() -> i32 {
21+
<T as /* FIXME: ~const */ Trait>::Assoc::func()
22+
}
23+
24+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `T: Trait` is not satisfied
2+
--> $DIR/assoc-type-const-bound-usage-1.rs:23:43
3+
|
4+
LL | fn qualified<T: const Trait>() -> Type<{ <T as /* FIXME: const */ Trait>::Assoc::func() }> {
5+
| ^ the trait `Trait` is not implemented for `T`
6+
|
7+
help: consider further restricting this bound
8+
|
9+
LL | fn qualified<T: const Trait + Trait>() -> Type<{ <T as /* FIXME: const */ Trait>::Assoc::func() }> {
10+
| +++++++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// FIXME(effects): Collapse the revisions into one once we support `<Ty as const Trait>::Proj`.
2+
// revisions: unqualified qualified
3+
//[unqualified] check-pass
4+
//[qualified] known-bug: unknown
5+
6+
#![feature(const_trait_impl, effects, generic_const_exprs)]
7+
#![allow(incomplete_features)]
8+
9+
#[const_trait]
10+
trait Trait {
11+
type Assoc: ~const Trait;
12+
fn func() -> i32;
13+
}
14+
15+
struct Type<const N: i32>;
16+
17+
#[cfg(unqualified)]
18+
fn unqualified<T: const Trait>() -> Type<{ T::Assoc::func() }> {
19+
Type
20+
}
21+
22+
#[cfg(qualified)]
23+
fn qualified<T: const Trait>() -> Type<{ <T as /* FIXME: const */ Trait>::Assoc::func() }> {
24+
Type
25+
}
26+
27+
fn main() {}

‎tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
// known-bug: #110395
1+
// FIXME(effects): Replace `Add` with `std::ops::Add` once the latter a `#[const_trait]` again.
2+
#![feature(const_trait_impl, effects)]
23

3-
#![feature(const_trait_impl)]
4+
#[const_trait]
5+
trait Add<Rhs = Self> {
6+
type Output;
7+
8+
fn add(self, other: Rhs) -> Self::Output;
9+
}
10+
11+
impl const Add for i32 {
12+
type Output = Self;
13+
14+
fn add(self, other: Self) -> Self::Output {
15+
self + other
16+
}
17+
}
418

519
struct NonConstAdd(i32);
620

7-
impl std::ops::Add for NonConstAdd {
21+
impl Add for NonConstAdd {
822
type Output = Self;
923

1024
fn add(self, rhs: Self) -> Self {
11-
NonConstAdd(self.0 + rhs.0)
25+
NonConstAdd(self.0.add(rhs.0))
1226
}
1327
}
1428

1529
#[const_trait]
1630
trait Foo {
17-
type Bar: ~const std::ops::Add;
31+
type Bar: ~const Add;
1832
}
1933

2034
impl const Foo for NonConstAdd {
21-
type Bar = NonConstAdd;
35+
type Bar = NonConstAdd; //~ ERROR the trait bound `NonConstAdd: ~const Add` is not satisfied
2236
}
2337

2438
#[const_trait]
2539
trait Baz {
26-
type Qux: std::ops::Add;
40+
type Qux: Add;
2741
}
2842

2943
impl const Baz for NonConstAdd {
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error: `~const` is not allowed here
2-
--> $DIR/assoc-type.rs:17:15
1+
error[E0277]: the trait bound `NonConstAdd: ~const Add` is not satisfied
2+
--> $DIR/assoc-type.rs:35:16
33
|
4-
LL | type Bar: ~const std::ops::Add;
5-
| ^^^^^^
4+
LL | type Bar = NonConstAdd;
5+
| ^^^^^^^^^^^ the trait `~const Add` is not implemented for `NonConstAdd`
66
|
7-
= note: this item cannot have `~const` trait bounds
8-
9-
error: `~const` can only be applied to `#[const_trait]` traits
10-
--> $DIR/assoc-type.rs:17:22
7+
= help: the trait `Add` is implemented for `NonConstAdd`
8+
note: required by a bound in `Foo::Bar`
9+
--> $DIR/assoc-type.rs:31:15
1110
|
12-
LL | type Bar: ~const std::ops::Add;
13-
| ^^^^^^^^^^^^^
11+
LL | type Bar: ~const Add;
12+
| ^^^^^^^^^^ required by this bound in `Foo::Bar`
1413

15-
error: aborting due to 2 previous errors
14+
error: aborting due to 1 previous error
1615

16+
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ error: `~const` is not allowed here
7272
LL | type Type<T: ~const Trait>: ~const Trait;
7373
| ^^^^^^
7474
|
75-
= note: this item cannot have `~const` trait bounds
75+
note: associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
76+
--> $DIR/tilde-const-invalid-places.rs:25:5
77+
|
78+
LL | type Type<T: ~const Trait>: ~const Trait;
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7680

7781
error: `~const` is not allowed here
7882
--> $DIR/tilde-const-invalid-places.rs:25:33
7983
|
8084
LL | type Type<T: ~const Trait>: ~const Trait;
8185
| ^^^^^^
8286
|
83-
= note: this item cannot have `~const` trait bounds
87+
note: associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
88+
--> $DIR/tilde-const-invalid-places.rs:25:5
89+
|
90+
LL | type Type<T: ~const Trait>: ~const Trait;
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8492

8593
error: `~const` is not allowed here
8694
--> $DIR/tilde-const-invalid-places.rs:28:30
@@ -108,7 +116,11 @@ error: `~const` is not allowed here
108116
LL | type Type<T: ~const Trait> = ();
109117
| ^^^^^^
110118
|
111-
= note: this item cannot have `~const` trait bounds
119+
note: associated types in non-const impls cannot have `~const` trait bounds
120+
--> $DIR/tilde-const-invalid-places.rs:34:5
121+
|
122+
LL | type Type<T: ~const Trait> = ();
123+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112124

113125
error: `~const` is not allowed here
114126
--> $DIR/tilde-const-invalid-places.rs:36:30
@@ -136,7 +148,11 @@ error: `~const` is not allowed here
136148
LL | type Type<T: ~const Trait> = ();
137149
| ^^^^^^
138150
|
139-
= note: this item cannot have `~const` trait bounds
151+
note: inherent associated types cannot have `~const` trait bounds
152+
--> $DIR/tilde-const-invalid-places.rs:44:5
153+
|
154+
LL | type Type<T: ~const Trait> = ();
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140156

141157
error: `~const` is not allowed here
142158
--> $DIR/tilde-const-invalid-places.rs:46:30
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
#![feature(const_trait_impl, effects)]
3+
4+
#[const_trait]
5+
trait Trait {
6+
// FIXME(effects): `~const` bounds in trait associated types (excluding associated type bounds)
7+
// don't look super useful. Should we forbid them again?
8+
type Assoc<T: ~const Bound>;
9+
}
10+
11+
impl const Trait for () {
12+
type Assoc<T: ~const Bound> = T;
13+
}
14+
15+
#[const_trait]
16+
trait Bound {}
17+
18+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Deserialize {
2+
fn deserialize(&self);
3+
}
4+
5+
struct ArchivedVec<T>(T);
6+
7+
impl<T> Deserialize for ArchivedVec<T> {
8+
fn deserialize(s: _) {}
9+
//~^ ERROR: `_` is not allowed within types on item signatures
10+
//~| ERROR: has a `&self` declaration in the trait, but not in the impl
11+
}
12+
13+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2+
--> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:23
3+
|
4+
LL | fn deserialize(s: _) {}
5+
| ^ not allowed in type signatures
6+
|
7+
help: try replacing `_` with the type in the corresponding trait method signature
8+
|
9+
LL | fn deserialize(s: &ArchivedVec<T>) {}
10+
| ~~~~~~~~~~~~~~~
11+
12+
error[E0186]: method `deserialize` has a `&self` declaration in the trait, but not in the impl
13+
--> $DIR/method-argument-mismatch-variance-ice-119867.rs:8:5
14+
|
15+
LL | fn deserialize(&self);
16+
| ---------------------- `&self` used in trait
17+
...
18+
LL | fn deserialize(s: _) {}
19+
| ^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0121, E0186.
24+
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)
Please sign in to comment.