Skip to content

Type error causes cascading region error #30580

@arielb1

Description

@arielb1
Contributor

I have encountered this problem several times while compiling versions of rustc with errors, but this is the first self-contained example I have found.

STR

pub struct Foo { a: u32 }
pub struct Pass<'a, 'tcx: 'a>(&'a mut &'a (), &'a &'tcx ());

impl<'a, 'tcx> Pass<'a, 'tcx>
{
    pub fn tcx(&self) -> &'a &'tcx () { self.1 }
    fn lol(&mut self, b: &Foo)
    {
        b.c;
        self.tcx();
    }
}

fn main() {}

Expected Result

A single error as the field c does not exist

Actual Result

<anon>:9:9: 9:12 error: attempted access of field `c` on type `&Foo`, but no field with that name was found
<anon>:9         b.c;
                 ^~~
<anon>:10:14: 10:19 error: cannot infer an appropriate lifetime for lifetime parameter `'tcx` due to conflicting requirements [E0495]
<anon>:10         self.tcx();
                       ^~~~~
<anon>:7:5: 11:6 help: consider using an explicit lifetime parameter as shown: fn lol(&mut self, b: &Foo)
<anon>: 7     fn lol(&mut self, b: &Foo)
<anon>: 8     {
<anon>: 9         b.c;
<anon>:10         self.tcx();
<anon>:11     }
error: aborting due to 2 previous errors

Note the fat cascading region error. This reproduces on 1.5/1.6 and current nightly.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lifetimesArea: Lifetimes / regions
on Dec 27, 2015
arielb1

arielb1 commented on Dec 27, 2015

@arielb1
ContributorAuthor
added a commit that references this issue on Mar 13, 2016
511cb30
added a commit that references this issue on Mar 16, 2016
a5487e8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @arielb1

        Issue actions

          Type error causes cascading region error · Issue #30580 · rust-lang/rust