Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use super::util;
use super::util::{closure_trait_ref_and_return_type, predicate_for_trait_def};
use super::wf;
use super::{
ErrorReporting, ImplDerivedObligation, ImplDerivedObligationCause, Normalized, Obligation,
ObligationCause, ObligationCauseCode, Overflow, PredicateObligation, Selection, SelectionError,
SelectionResult, TraitObligation, TraitQueryMode,
DerivedObligation, ErrorReporting, ImplDerivedObligation, ImplDerivedObligationCause,
Normalized, Obligation, ObligationCause, ObligationCauseCode, Overflow, PredicateObligation,
Selection, SelectionError, SelectionResult, TraitObligation, TraitQueryMode,
};

use crate::infer::{InferCtxt, InferOk, TypeFreshener};
Expand Down Expand Up @@ -2657,14 +2657,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let predicates = predicates.instantiate_own(tcx, substs);
let mut obligations = Vec::with_capacity(predicates.len());
for (index, (predicate, span)) in predicates.into_iter().enumerate() {
let cause = cause.clone().derived_cause(parent_trait_pred, |derived| {
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
derived,
impl_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
});
let cause = if tcx.is_trait_alias(def_id) {
cause.clone().derived_cause(parent_trait_pred, DerivedObligation)
} else {
cause.clone().derived_cause(parent_trait_pred, |derived| {
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
derived,
impl_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
})
};
let predicate = normalize_with_depth_to(
self,
param_env,
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/traits/alias/issue-108072-unmet-trait-alias-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Regression test for #108072: do not ICE upon unmet trait alias constraint

#![feature(trait_alias)]

trait IteratorAlias = Iterator;

fn f(_: impl IteratorAlias) {}

fn main() {
f(()) //~ `()` is not an iterator
}
18 changes: 18 additions & 0 deletions tests/ui/traits/alias/issue-108072-unmet-trait-alias-bound.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: `()` is not an iterator
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:10:7
|
LL | f(())
| - ^^ `()` is not an iterator
| |
| required by a bound introduced by this call
|
= help: the trait `Iterator` is not implemented for `()`
note: required by a bound in `f`
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:7:14
|
LL | fn f(_: impl IteratorAlias) {}
| ^^^^^^^^^^^^^ required by this bound in `f`

error: aborting due to previous error

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