Skip to content

Commit

Permalink
Add is_defaulted_unit helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Feb 3, 2017
1 parent 5dbaefb commit 085f046
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// Test whether this is a `()` which was produced by defaulting a
// diverging type variable with `!` disabled. If so, we may need
// to raise a warning.
if let ty::TyTuple(_, true) = obligation.predicate.skip_binder()
.self_ty().sty {

if obligation.predicate.skip_binder().self_ty().is_defaulted_unit() {
let mut raise_warning = true;
// Don't raise a warning if the trait is implemented for ! and only
// permits a trivial implementation for !. This stops us warning
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

// Test whether this is a `()` which was produced by defaulting a
// diverging type variable with feature(never_type) disabled.
pub fn is_defaulted_unit(&self) -> bool {
match self.sty {
TyTuple(_, true) => true,
_ => false,
}
}

/// Checks whether a type is visibly uninhabited from a particular module.
/// # Example
/// ```rust
Expand Down

0 comments on commit 085f046

Please sign in to comment.