@@ -1958,6 +1958,37 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1958
1958
if predicate. references_error ( ) {
1959
1959
return ;
1960
1960
}
1961
+
1962
+ // This is kind of a hack: it frequently happens that some earlier
1963
+ // error prevents types from being fully inferred, and then we get
1964
+ // a bunch of uninteresting errors saying something like "<generic
1965
+ // #0> doesn't implement Sized". It may even be true that we
1966
+ // could just skip over all checks where the self-ty is an
1967
+ // inference variable, but I was afraid that there might be an
1968
+ // inference variable created, registered as an obligation, and
1969
+ // then never forced by writeback, and hence by skipping here we'd
1970
+ // be ignoring the fact that we don't KNOW the type works
1971
+ // out. Though even that would probably be harmless, given that
1972
+ // we're only talking about builtin traits, which are known to be
1973
+ // inhabited. We used to check for `self.tcx.sess.has_errors()` to
1974
+ // avoid inundating the user with unnecessary errors, but we now
1975
+ // check upstream for type errors and don't add the obligations to
1976
+ // begin with in those cases.
1977
+ if self . tcx . lang_items ( ) . sized_trait ( ) == Some ( trait_ref. def_id ( ) ) {
1978
+ if !self . is_tainted_by_errors ( ) {
1979
+ self . emit_inference_failure_err (
1980
+ body_id,
1981
+ span,
1982
+ trait_ref. self_ty ( ) . skip_binder ( ) . into ( ) ,
1983
+ vec ! [ ] ,
1984
+ ErrorCode :: E0282 ,
1985
+ false ,
1986
+ )
1987
+ . emit ( ) ;
1988
+ }
1989
+ return ;
1990
+ }
1991
+
1961
1992
// Typically, this ambiguity should only happen if
1962
1993
// there are unresolved type inference variables
1963
1994
// (otherwise it would suggest a coherence
@@ -1997,37 +2028,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1997
2028
)
1998
2029
} ;
1999
2030
2000
- // This is kind of a hack: it frequently happens that some earlier
2001
- // error prevents types from being fully inferred, and then we get
2002
- // a bunch of uninteresting errors saying something like "<generic
2003
- // #0> doesn't implement Sized". It may even be true that we
2004
- // could just skip over all checks where the self-ty is an
2005
- // inference variable, but I was afraid that there might be an
2006
- // inference variable created, registered as an obligation, and
2007
- // then never forced by writeback, and hence by skipping here we'd
2008
- // be ignoring the fact that we don't KNOW the type works
2009
- // out. Though even that would probably be harmless, given that
2010
- // we're only talking about builtin traits, which are known to be
2011
- // inhabited. We used to check for `self.tcx.sess.has_errors()` to
2012
- // avoid inundating the user with unnecessary errors, but we now
2013
- // check upstream for type errors and don't add the obligations to
2014
- // begin with in those cases.
2015
- if self . tcx . lang_items ( ) . sized_trait ( ) == Some ( trait_ref. def_id ( ) ) {
2016
- if !self . is_tainted_by_errors ( ) {
2017
- self . emit_inference_failure_err (
2018
- body_id,
2019
- span,
2020
- trait_ref. self_ty ( ) . skip_binder ( ) . into ( ) ,
2021
- vec ! [ ] ,
2022
- ErrorCode :: E0282 ,
2023
- false ,
2024
- )
2025
- . emit ( ) ;
2026
- }
2027
- err. cancel ( ) ;
2028
- return ;
2029
- }
2030
-
2031
2031
let obligation = Obligation :: new (
2032
2032
obligation. cause . clone ( ) ,
2033
2033
obligation. param_env ,
0 commit comments