Skip to content

Commit

Permalink
make type_flags(ReError) | HAS_ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Mar 19, 2024
1 parent 094a620 commit 64a5ca5
Show file tree
Hide file tree
Showing 46 changed files with 120 additions and 626 deletions.
4 changes: 0 additions & 4 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,6 @@ fn check_opaque_type_parameter_valid(
// Only check the parent generics, which will ignore any of the
// duplicated lifetime args that come from reifying late-bounds.
for (i, arg) in opaque_type_key.args.iter().take(parent_generics.count()).enumerate() {
if let Err(guar) = arg.error_reported() {
return Err(guar);
}

let arg_is_param = match arg.unpack() {
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
GenericArgKind::Lifetime(lt) if is_ty_alias => {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl<'tcx> Region<'tcx> {
}
ty::ReError(_) => {
flags = flags | TypeFlags::HAS_FREE_REGIONS;
flags = flags | TypeFlags::HAS_ERROR;
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bitflags! {
| TypeFlags::HAS_TY_INHERENT.bits()
| TypeFlags::HAS_CT_PROJECTION.bits();

/// Is an error type/const reachable?
/// Is an error type/lifetime/const reachable?
const HAS_ERROR = 1 << 15;

/// Does this have any region that "appears free" in the type?
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/async-await/in-trait/return-not-existing-pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ trait MyTrait<'a, 'b, T> {
impl<'a, 'b, T, U> MyTrait<T> for U {
//~^ ERROR: implicit elided lifetime not allowed here [E0726]
async fn foo(_: T) -> (&'a U, &'b T) {}
//~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186]
//~| ERROR: mismatched types [E0308]
//~^ ERROR: mismatched types [E0308]
}

fn main() {}
15 changes: 3 additions & 12 deletions tests/ui/async-await/in-trait/return-not-existing-pair.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ error[E0412]: cannot find type `ConnImpl` in this scope
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ^^^^^^^^ not found in this scope

error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
--> $DIR/return-not-existing-pair.rs:11:5
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ------------------------------------------------------------ `&self` used in trait
...
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl

error[E0308]: mismatched types
--> $DIR/return-not-existing-pair.rs:11:42
|
Expand All @@ -33,7 +24,7 @@ LL | async fn foo(_: T) -> (&'a U, &'b T) {}
= note: expected tuple `(&'a U, &'b T)`
found unit type `()`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0186, E0308, E0412, E0726.
For more information about an error, try `rustc --explain E0186`.
Some errors have detailed explanations: E0308, E0412, E0726.
For more information about an error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,5 @@ error: cannot capture late-bound lifetime in constant
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| -- lifetime defined here ^^

error: overly complex generic constant
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants
|
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error[E0391]: cycle detected when evaluating type-level constant
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `bug::{constant#0}`...
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires caching mir of `bug::{constant#0}` for CTFE...
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires elaborating drops for `bug::{constant#0}`...
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires borrow-checking `bug::{constant#0}`...
--> $DIR/late-bound-in-return-issue-77357.rs:9:46
|
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires normalizing `Binder { value: ConstEvaluatable(UnevaluatedConst { def: DefId(0:8 ~ late_bound_in_return_issue_77357[9394]::bug::{constant#0}), args: [T/#0] }: usize), bound_vars: [] }`...
= note: ...which again requires evaluating type-level constant, completing the cycle
= note: cycle used when normalizing `&dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]>`
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error: aborting due to 3 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0391`.
4 changes: 2 additions & 2 deletions tests/ui/error-codes/E0637.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//~^ ERROR: `'_` cannot be used here [E0637]
//~| ERROR: missing lifetime specifier
if str1.len() > str2.len() {
str1 //~ ERROR: lifetime may not live long enough
str1
} else {
str2 //~ ERROR: lifetime may not live long enough
str2
}
}

Expand Down
20 changes: 1 addition & 19 deletions tests/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ help: consider introducing a higher-ranked lifetime here
LL | T: for<'a> Into<&'a u32>,
| +++++++ ++

error: lifetime may not live long enough
--> $DIR/E0637.rs:5:9
|
LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
| - let's call the lifetime of this reference `'1`
...
LL | str1
| ^^^^ returning this value requires that `'1` must outlive `'static`

error: lifetime may not live long enough
--> $DIR/E0637.rs:7:9
|
LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
| - let's call the lifetime of this reference `'2`
...
LL | str2
| ^^^^ returning this value requires that `'2` must outlive `'static`

error: aborting due to 5 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.
2 changes: 1 addition & 1 deletion tests/ui/generic-associated-types/issue-80433.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ fn test_simpler<'a>(dst: &'a mut impl TestMut<Output = &'a mut f32>)

fn main() {
let mut t1: E<f32> = Default::default();
test_simpler(&mut t1); //~ ERROR does not live long enough
test_simpler(&mut t1);
}
17 changes: 2 additions & 15 deletions tests/ui/generic-associated-types/issue-80433.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,7 @@ LL | *dst.test_mut() = n.into();
| `dst` escapes the function body here
| argument requires that `'a` must outlive `'static`

error[E0597]: `t1` does not live long enough
--> $DIR/issue-80433.rs:32:18
|
LL | let mut t1: E<f32> = Default::default();
| ------ binding `t1` declared here
LL | test_simpler(&mut t1);
| -------------^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `t1` is borrowed for `'static`
LL | }
| - `t1` dropped here while still borrowed

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0107, E0499, E0521, E0597.
Some errors have detailed explanations: E0107, E0499, E0521.
For more information about an error, try `rustc --explain E0107`.
3 changes: 0 additions & 3 deletions tests/ui/impl-trait/impl-fn-hrtb-bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ use std::fmt::Debug;
fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|x| x
//~^ ERROR lifetime may not live long enough
}

fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|x| x
//~^ ERROR lifetime may not live long enough
}

fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|x| x
//~^ ERROR lifetime may not live long enough
}

fn d() -> impl Fn() -> (impl Debug + '_) {
Expand Down
39 changes: 6 additions & 33 deletions tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
--> $DIR/impl-fn-hrtb-bounds.rs:22:38
--> $DIR/impl-fn-hrtb-bounds.rs:19:38
|
LL | fn d() -> impl Fn() -> (impl Debug + '_) {
| ^^ expected named lifetime parameter
Expand All @@ -22,58 +22,31 @@ note: lifetime declared here
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
| ^

error: lifetime may not live long enough
--> $DIR/impl-fn-hrtb-bounds.rs:6:9
|
LL | |x| x
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is impl Debug + '2
| has type `&'1 u8`

error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
--> $DIR/impl-fn-hrtb-bounds.rs:10:52
--> $DIR/impl-fn-hrtb-bounds.rs:9:52
|
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-hrtb-bounds.rs:10:20
--> $DIR/impl-fn-hrtb-bounds.rs:9:20
|
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
| ^^

error: lifetime may not live long enough
--> $DIR/impl-fn-hrtb-bounds.rs:12:9
|
LL | |x| x
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is impl Debug + '2
| has type `&'1 u8`

error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
--> $DIR/impl-fn-hrtb-bounds.rs:16:52
--> $DIR/impl-fn-hrtb-bounds.rs:14:52
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| ^^
|
note: lifetime declared here
--> $DIR/impl-fn-hrtb-bounds.rs:16:20
--> $DIR/impl-fn-hrtb-bounds.rs:14:20
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| ^^

error: lifetime may not live long enough
--> $DIR/impl-fn-hrtb-bounds.rs:18:9
|
LL | |x| x
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is impl Debug + '2
| has type `&'1 u8`

error: aborting due to 7 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0106, E0657.
For more information about an error, try `rustc --explain E0106`.
1 change: 0 additions & 1 deletion tests/ui/impl-trait/impl-fn-parsing-ambiguities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn a() -> impl Fn(&u8) -> impl Debug + '_ {
//~^ ERROR ambiguous `+` in a type
//~| ERROR cannot capture higher-ranked lifetime from outer `impl Trait`
|x| x
//~^ ERROR lifetime may not live long enough
}

fn b() -> impl Fn() -> impl Debug + Send {
Expand Down
13 changes: 2 additions & 11 deletions tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
| ^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + '_)`

error: ambiguous `+` in a type
--> $DIR/impl-fn-parsing-ambiguities.rs:11:24
--> $DIR/impl-fn-parsing-ambiguities.rs:10:24
|
LL | fn b() -> impl Fn() -> impl Debug + Send {
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`
Expand All @@ -22,15 +22,6 @@ note: lifetime declared here
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
| ^

error: lifetime may not live long enough
--> $DIR/impl-fn-parsing-ambiguities.rs:7:9
|
LL | |x| x
| -- ^ returning this value requires that `'1` must outlive `'2`
| ||
| |return type of closure is impl Debug + '2
| has type `&'1 u8`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0657`.
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/nested-rpit-hrtb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}

fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
//~| ERROR implementation of `Bar` is not general enough

fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
//~| ERROR: the trait bound `for<'a> &'a (): Qux<'_>` is not satisfied

// This should resolve.
fn one_hrtb_mention_fn_trait_param<'b>() -> impl for<'a> Foo<'a, Assoc = impl Qux<'b>> {}
Expand Down
Loading

0 comments on commit 64a5ca5

Please sign in to comment.