]> git.lizzy.rs Git - rust.git/commitdiff
use relevant span when unifying `ConstVarValue`s
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Wed, 23 Sep 2020 09:00:44 +0000 (11:00 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Wed, 23 Sep 2020 09:00:44 +0000 (11:00 +0200)
compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
compiler/rustc_middle/src/infer/unify_key.rs

index b7debba68b58eb226f7016012519c2a7e1bccc1a..b00adec822e510a0c37e251304d537aa9a5c6801 100644 (file)
@@ -309,7 +309,8 @@ pub fn extract_type_name(
                         );
                     }
 
-                    Some(origin.span).filter(|s| !s.is_dummy())
+                    debug_assert!(!origin.span.is_dummy());
+                    Some(origin.span)
                 } else {
                     bug!("unexpect const: {:?}", ct);
                 };
index 499f92b4041161b8bba9fd1d5ecf827e98403365..4d884dde393876d5680f00b84269b1b5bc6dfebb 100644 (file)
@@ -6,7 +6,7 @@
 };
 use rustc_span::def_id::DefId;
 use rustc_span::symbol::Symbol;
-use rustc_span::{Span, DUMMY_SP};
+use rustc_span::Span;
 
 use std::cmp;
 use std::marker::PhantomData;
@@ -176,17 +176,17 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
     type Error = (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>);
 
     fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
-        let val = match (value1.val, value2.val) {
+        let (val, span) = match (value1.val, value2.val) {
             (ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
                 bug!("equating two const variables, both of which have known values")
             }
 
             // If one side is known, prefer that one.
             (ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => {
-                Ok(value1.val)
+                (value1.val, value1.origin.span)
             }
             (ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => {
-                Ok(value2.val)
+                (value2.val, value2.origin.span)
             }
 
             // If both sides are *unknown*, it hardly matters, does it?
@@ -200,14 +200,14 @@ fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
                 // universe is the minimum of the two universes, because that is
                 // the one which contains the fewest names in scope.
                 let universe = cmp::min(universe1, universe2);
-                Ok(ConstVariableValue::Unknown { universe })
+                (ConstVariableValue::Unknown { universe }, value1.origin.span)
             }
-        }?;
+        };
 
         Ok(ConstVarValue {
             origin: ConstVariableOrigin {
                 kind: ConstVariableOriginKind::ConstInference,
-                span: DUMMY_SP,
+                span: span,
             },
             val,
         })