Skip to content

Spans for errors in try operator expressions are not great #42234

Closed

Description

@nrc

E.g.,

error: the type of this value must be known in this context
   --> src/librustc_save_analysis/sig.rs:281:39
    |
281 |             let generics: Signature = generics.make(offset + text.len(), id, scx)?;
    |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

the expression with unknown type is the variable use generics, but the error highlight covers the entire sub-expression of expr?. I assume this is due to us doing something sub-optimal with the spans here in the HIR lowering.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-HIRArea: The high-level intermediate representation (HIR)
    on May 26, 2017
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jun 7, 2017
  3. aturon commented on Jun 7, 2017

    @aturon
    Contributor

    @nrc is worried that similar issues are arising with other desugarings, i.e. that this might be an across-the-board regression. Worth investigating.

  4. nikomatsakis commented on Jun 8, 2017

    @nikomatsakis
    Contributor

    Standalone example:

    fn foo() -> Result<(), ()> {
        let x = None;
        Ok(x.unwrap().make()?)
    }
    
    fn main() { }

    gives

    rustc 1.17.0 (56124baa9 2017-04-24)
    error: the type of this value must be known in this context
     --> <anon>:3:8
      |
    3 |     Ok(x.unwrap().make()?)
      |        ^^^^^^^^^^^^^^^^^
    
    error: aborting due to previous error
    
  5. nikomatsakis commented on Jun 8, 2017

    @nikomatsakis
    Contributor

    triage: P-medium

    Doesn't seem like a "stop everything" sort of problem, but would be good to figure it out. However, it does not appear to be a regression: e.g., the above test case behaves the same in 1.16.0 as well.

  6. added a commit that references this issue on Feb 6, 2018
    b55e07e
  7. added a commit that references this issue on Feb 7, 2018
    732c830
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-HIRArea: The high-level intermediate representation (HIR)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions