@@ -17,6 +17,7 @@ use rustc_infer::infer::outlives::obligations::TypeOutlives;
17
17
use rustc_infer:: infer:: region_constraints:: GenericKind ;
18
18
use rustc_infer:: infer:: { self , RegionckMode } ;
19
19
use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
20
+ use rustc_infer:: traits:: TraitEngine ;
20
21
use rustc_middle:: hir:: nested_filter;
21
22
use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts , Subst } ;
22
23
use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
@@ -1796,7 +1797,7 @@ fn report_bivariance(
1796
1797
1797
1798
/// Feature gates RFC 2056 -- trivial bounds, checking for global bounds that
1798
1799
/// aren't true.
1799
- fn check_false_global_bounds ( fcx : & FnCtxt < ' _ , ' _ > , mut span : Span , id : hir:: HirId ) {
1800
+ fn check_false_global_bounds ( fcx : & FnCtxt < ' _ , ' _ > , span : Span , id : hir:: HirId ) {
1800
1801
let empty_env = ty:: ParamEnv :: empty ( ) ;
1801
1802
1802
1803
let def_id = fcx. tcx . hir ( ) . local_def_id ( id) ;
@@ -1807,33 +1808,64 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
1807
1808
1808
1809
for obligation in implied_obligations {
1809
1810
let pred = obligation. predicate ;
1811
+
1812
+ // only use the span of the predicate clause (#90869)
1813
+ let hir_node = fcx. tcx . hir ( ) . find ( id) ;
1814
+ let span = if let Some ( hir:: Generics { where_clause, .. } ) =
1815
+ hir_node. and_then ( |node| node. generics ( ) )
1816
+ {
1817
+ let obligation_span = obligation. cause . span ( fcx. tcx ) ;
1818
+ where_clause
1819
+ . predicates
1820
+ . iter ( )
1821
+ // There seems to be no better way to find out which predicate we are in
1822
+ . find ( |pred| pred. span ( ) . contains ( obligation_span) )
1823
+ . map ( |pred| pred. span ( ) )
1824
+ . unwrap_or ( obligation_span)
1825
+ } else {
1826
+ span
1827
+ } ;
1828
+
1810
1829
// Match the existing behavior.
1811
1830
if pred. is_global ( ) && !pred. has_late_bound_regions ( ) {
1812
1831
let pred = fcx. normalize_associated_types_in ( span, pred) ;
1813
- let hir_node = fcx. tcx . hir ( ) . find ( id) ;
1814
-
1815
- // only use the span of the predicate clause (#90869)
1816
-
1817
- if let Some ( hir:: Generics { where_clause, .. } ) =
1818
- hir_node. and_then ( |node| node. generics ( ) )
1819
- {
1820
- let obligation_span = obligation. cause . span ( fcx. tcx ) ;
1821
-
1822
- span = where_clause
1823
- . predicates
1824
- . iter ( )
1825
- // There seems to be no better way to find out which predicate we are in
1826
- . find ( |pred| pred. span ( ) . contains ( obligation_span) )
1827
- . map ( |pred| pred. span ( ) )
1828
- . unwrap_or ( obligation_span) ;
1829
- }
1830
1832
1831
1833
let obligation = traits:: Obligation :: new (
1832
1834
traits:: ObligationCause :: new ( span, id, traits:: TrivialBound ) ,
1833
1835
empty_env,
1834
1836
pred,
1835
1837
) ;
1836
1838
fcx. register_predicate ( obligation) ;
1839
+ } else {
1840
+ let infer:: InferOk { value : norm_pred, obligations } =
1841
+ fcx. normalize_associated_types_in_as_infer_ok ( span, pred) ;
1842
+ if norm_pred. is_global ( ) {
1843
+ fcx. probe ( |_| {
1844
+ let mut fulfillment_cx = traits:: FulfillmentContext :: new_in_snapshot ( ) ;
1845
+ for obligation in obligations {
1846
+ fulfillment_cx. register_predicate_obligation ( & fcx, obligation) ;
1847
+ }
1848
+ fulfillment_cx. register_predicate_obligation ( & fcx, traits:: Obligation :: new (
1849
+ traits:: ObligationCause :: new ( span, id, traits:: TrivialBound ) ,
1850
+ empty_env,
1851
+ norm_pred,
1852
+ ) ) ;
1853
+ if !fulfillment_cx. select_all_or_error ( & fcx) . is_empty ( ) {
1854
+ let mut diag = fcx
1855
+ . tcx
1856
+ . sess
1857
+ // NOTE: Error for the crater run
1858
+ . struct_span_warn ( span, "where-clause bound is impossible to satisfy" ) ;
1859
+ diag. note ( format ! ( "the bound `{}` was previously accepted, but it may become a hard error in a future release" , pred) ) ;
1860
+ if fcx. sess ( ) . opts . unstable_features . is_nightly_build ( ) {
1861
+ diag. help (
1862
+ "add `#![feature(trivial_bounds)]` to the crate attributes to allow it" ,
1863
+ ) ;
1864
+ }
1865
+ diag. emit ( ) ;
1866
+ }
1867
+ } )
1868
+ }
1837
1869
}
1838
1870
}
1839
1871
0 commit comments