Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9aac78a

Browse files
committed
Auto merge of rust-lang#119918 - matthiaskrgr:rollup-kjjh51l, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#119891 (rename `reported_signature_mismatch` to reflect its use) - rust-lang#119894 (Allow `~const` on associated type bounds again) - rust-lang#119896 (Taint `_` placeholder types in trait impl method signatures) - rust-lang#119898 (Remove unused `ErrorReporting` variant from overflow handling) - rust-lang#119902 (fix typo in `fn()` docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 284cb71 + 7144248 commit 9aac78a

25 files changed

+255
-91
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_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_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_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
}

0 commit comments

Comments
 (0)