]> git.lizzy.rs Git - rust.git/commitdiff
Bail out early if there already were errors
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 28 Jan 2022 16:42:29 +0000 (16:42 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 2 Feb 2022 15:40:12 +0000 (15:40 +0000)
compiler/rustc_trait_selection/src/opaque_types.rs
src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr
src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr

index d3a28c6d3aa35e8947f0014a6b8b5f2bda0bba5c..cd12430a2a249c5e0579a6c20b2fc2f67701c91a 100644 (file)
@@ -48,6 +48,10 @@ fn infer_opaque_definition_from_instantiation(
         instantiated_ty: Ty<'tcx>,
         span: Span,
     ) -> Ty<'tcx> {
+        if self.is_tainted_by_errors() {
+            return self.tcx.ty_error();
+        }
+
         let OpaqueTypeKey { def_id, substs } = opaque_type_key;
 
         // Use substs to build up a reverse map from regions to their
@@ -67,7 +71,6 @@ fn infer_opaque_definition_from_instantiation(
         // after producing an error for each of them.
         let definition_ty = instantiated_ty.fold_with(&mut ReverseMapper::new(
             self.tcx,
-            self.is_tainted_by_errors(),
             def_id,
             map,
             instantiated_ty,
@@ -82,10 +85,6 @@ fn infer_opaque_definition_from_instantiation(
 struct ReverseMapper<'tcx> {
     tcx: TyCtxt<'tcx>,
 
-    /// If errors have already been reported in this fn, we suppress
-    /// our own errors because they are sometimes derivative.
-    tainted_by_errors: bool,
-
     opaque_type_def_id: DefId,
     map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
     map_missing_regions_to_empty: bool,
@@ -100,7 +99,6 @@ struct ReverseMapper<'tcx> {
 impl<'tcx> ReverseMapper<'tcx> {
     fn new(
         tcx: TyCtxt<'tcx>,
-        tainted_by_errors: bool,
         opaque_type_def_id: DefId,
         map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
         hidden_ty: Ty<'tcx>,
@@ -108,7 +106,6 @@ fn new(
     ) -> Self {
         Self {
             tcx,
-            tainted_by_errors,
             opaque_type_def_id,
             map,
             map_missing_regions_to_empty: false,
@@ -167,9 +164,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
         match self.map.get(&r.into()).map(|k| k.unpack()) {
             Some(GenericArgKind::Lifetime(r1)) => r1,
             Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
-            None if self.map_missing_regions_to_empty || self.tainted_by_errors => {
-                self.tcx.lifetimes.re_root_empty
-            }
+            None if self.map_missing_regions_to_empty => self.tcx.lifetimes.re_root_empty,
             None if generics.parent.is_some() => {
                 if let Some(hidden_ty) = self.hidden_ty.take() {
                     unexpected_hidden_region_diagnostic(
index ef9756acee058bfa8a4648d580bfc9cbd7c89034..dc85db66d32ba4d9adad945b9a9c4ef848712567 100644 (file)
@@ -24,15 +24,6 @@ LL |     t
    |
    = help: consider adding an explicit lifetime bound `T: 'static`...
 
-error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/generic_type_does_not_live_long_enough.rs:10:24
-   |
-LL | type WrongGeneric<T> = impl 'static;
-   |                        ^^^^^^^^^^^^
-   |
-   = help: consider adding an explicit lifetime bound `T: 'static`...
-   = note: ...so that the type `T` will meet its required lifetime bounds
-
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0310`.
index 5fef79d0917d6df8a3612bef9882fdffab95e925..1538274d45cb22a5c3b9db37c3f9b5c06ac23a82 100644 (file)
@@ -10,29 +10,5 @@ error: higher-ranked subtype error
 LL |         |x| x
    |         ^^^^^
 
-error[E0308]: mismatched types
-  --> $DIR/issue-57611-trait-alias.rs:17:16
-   |
-LL |     type Bar = impl Baz<Self, Self>;
-   |                ^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
-   |
-   = note: expected type `for<'r> Fn<(&'r X,)>`
-              found type `Fn<(&'static X,)>`
-note: this closure does not fulfill the lifetime requirements
-  --> $DIR/issue-57611-trait-alias.rs:20:9
-   |
-LL |         |x| x
-   |         ^^^^^
-
-error: implementation of `FnOnce` is not general enough
-  --> $DIR/issue-57611-trait-alias.rs:17:16
-   |
-LL |     type Bar = impl Baz<Self, Self>;
-   |                ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
-   |
-   = note: closure with signature `fn(&'static X) -> &'static X` must implement `FnOnce<(&'0 X,)>`, for any lifetime `'0`...
-   = note: ...but it actually implements `FnOnce<(&'static X,)>`
-
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0308`.