Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #125331

Merged
merged 26 commits into from
May 20, 2024
Merged

Rollup of 7 pull requests #125331

merged 26 commits into from
May 20, 2024

Commits on May 9, 2024

  1. Configuration menu
    Copy the full SHA
    c54301f View commit details
    Browse the repository at this point in the history
  2. fix: Check whether next_node is else-less if in get_return_block

    Fix rust-lang#124819, where a if-less block causes a wrong output. It is
    caused by get_return_block in get_fn_decl. In get_return_block,
    when a else-less if expression is the tail expression, the check
    for next_node will keep iterating. So it is necessary to make a
    early return in the check.
    cardigan1008 committed May 9, 2024
    Configuration menu
    Copy the full SHA
    62318b3 View commit details
    Browse the repository at this point in the history

Commits on May 14, 2024

  1. Configuration menu
    Copy the full SHA
    1a3a54c View commit details
    Browse the repository at this point in the history
  2. coverage: Memoize newly-created counter expressions

    This currently has no effect, but is expected to be useful when expanding
    support for branch coverage and MC/DC coverage.
    Zalathar committed May 14, 2024
    Configuration menu
    Copy the full SHA
    a68bb5e View commit details
    Browse the repository at this point in the history
  3. coverage: Simplify counter expressions using simple algebra

    Some of these cases currently don't occur in practice, but are included for
    completeness, and to avoid having to add them later as branch coverage and
    MC/DC coverage start building more complex expressions.
    Zalathar committed May 14, 2024
    Configuration menu
    Copy the full SHA
    d01df6f View commit details
    Browse the repository at this point in the history
  4. create a feature gate

    jdonszelmann committed May 14, 2024
    Configuration menu
    Copy the full SHA
    42119ff View commit details
    Browse the repository at this point in the history

Commits on May 16, 2024

  1. feat: add unit test

    cardigan1008 committed May 16, 2024
    Configuration menu
    Copy the full SHA
    c811acb View commit details
    Browse the repository at this point in the history

Commits on May 17, 2024

  1. Suggest setting lifetime in borrowck error involving types with elide…

    …d lifetimes
    
    ```
    error: lifetime may not live long enough
      --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5
       |
    LL | fn foo(mut x: Ref, y: Ref) {
       |        -----       - has type `Ref<'_, '1>`
       |        |
       |        has type `Ref<'_, '2>`
    LL |     x.b = y.b;
       |     ^^^^^^^^^ assignment requires that `'1` must outlive `'2`
       |
    help: consider introducing a named lifetime parameter
       |
    LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) {
       |       ++++           ++++++++        ++++++++
    ```
    
    As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following
    
    ```
    help: consider introducing a named lifetime parameter
       |
    LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) {
       |       ++++           ++++++++        ++++++++
    ```
    
    but I believe this to still be an improvement over the status quo.
    
    CC rust-lang#40990.
    estebank committed May 17, 2024
    Configuration menu
    Copy the full SHA
    9f730e9 View commit details
    Browse the repository at this point in the history
  2. Always constrain the return type in lifetime suggestion

    ```
    error: lifetime may not live long enough
     --> f205.rs:8:16
      |
    7 |     fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> {
      |                                   -      --------- has type `Option<Reference<'1>>`
      |                                   |
      |                                   let's call the lifetime of this reference `'2`
    8 |         return reference;
      |                ^^^^^^^^^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
      |
    help: consider introducing a named lifetime parameter
      |
    7 |     fn resolve_symbolic_reference<'a>(&'a self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> {
      |                                  ++++  ++                                  ++++                      ++++
    ```
    
    The correct suggestion would be
    
    ```
    help: consider introducing a named lifetime parameter
      |
    7 |     fn resolve_symbolic_reference<'a>(&self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> {
      |                                  ++++                                   ++++                      ++++
    ```
    
    but we are not doing the analysis to detect that yet. If we constrain `&'a self`, then the return type with a borrow will implicitly take its lifetime from `'a`, it is better to make it explicit in the suggestion, in case that `&self` *doesn't* need to be `'a`, but the return does.
    estebank committed May 17, 2024
    Configuration menu
    Copy the full SHA
    120049f View commit details
    Browse the repository at this point in the history
  3. Account for owning item lifetimes in suggestion and annotate tests as…

    … `run-rustfix`
    
    ```
    error: lifetime may not live long enough
      --> $DIR/lt-ref-self.rs:12:9
       |
    LL |     fn ref_self(&self, f: &u32) -> &u32 {
       |                 -         - let's call the lifetime of this reference `'1`
       |                 |
       |                 let's call the lifetime of this reference `'2`
    LL |         f
       |         ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
       |
    help: consider introducing a named lifetime parameter and update trait if needed
       |
    LL |     fn ref_self<'b>(&'b self, f: &'b u32) -> &'b u32 {
       |                ++++  ++           ++          ++
    ```
    estebank committed May 17, 2024
    Configuration menu
    Copy the full SHA
    d1d585d View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ee5a157 View commit details
    Browse the repository at this point in the history
  5. Tweak suggested lifetimes to modify return type instead of &self re…

    …ceiver
    
    Do not suggest constraining the `&self` param, but rather the return type.
    If that is wrong (because it is not sufficient), a follow up error will tell the
    user to fix it. This way we lower the chances of *over* constraining, but still
    get the cake of "correctly" contrained in two steps.
    
    This is a correct suggestion:
    
    ```
    error: lifetime may not live long enough
      --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:9:9
       |
    LL |     fn foo<'a>(&self, x: &i32) -> &i32 {
       |                -         - let's call the lifetime of this reference `'1`
       |                |
       |                let's call the lifetime of this reference `'2`
    LL |         x
       |         ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
       |
    help: consider introducing a named lifetime parameter and update trait if needed
       |
    LL |     fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
       |                           ++          ++
    ```
    
    While this is incomplete because it should suggestino `&'a self`
    
    ```
    error: lifetime may not live long enough
      --> $DIR/ex3-both-anon-regions-self-is-anon.rs:7:19
       |
    LL |     fn foo<'a>(&self, x: &Foo) -> &Foo {
       |                -         - let's call the lifetime of this reference `'1`
       |                |
       |                let's call the lifetime of this reference `'2`
    LL |         if true { x } else { self }
       |                   ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
       |
    help: consider introducing a named lifetime parameter and update trait if needed
       |
    LL |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
       |                           ++          ++
    ```
    
    but the follow up error is
    
    ```
    error: lifetime may not live long enough
     --> tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:7:30
      |
    6 |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
      |            --  - let's call the lifetime of this reference `'1`
      |            |
      |            lifetime `'a` defined here
    7 |         if true { x } else { self }
      |                              ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
      |
    help: consider introducing a named lifetime parameter and update trait if needed
      |
    6 |     fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo {
      |                 ++
    ```
    estebank committed May 17, 2024
    Configuration menu
    Copy the full SHA
    1775e7b View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    cf5702e View commit details
    Browse the repository at this point in the history

Commits on May 18, 2024

  1. Configuration menu
    Copy the full SHA
    95c0e5c View commit details
    Browse the repository at this point in the history
  2. Fix clippy

    scottmcm committed May 18, 2024
    Configuration menu
    Copy the full SHA
    d83c65e View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. Configuration menu
    Copy the full SHA
    1d9757c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7b0fd3b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a4efe6f View commit details
    Browse the repository at this point in the history
  4. address nit

    pnkfelix authored May 20, 2024
    Configuration menu
    Copy the full SHA
    a2e0f10 View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#124682 - estebank:issue-40990, r=pnkfelix

    Suggest setting lifetime in borrowck error involving types with elided lifetimes
    
    ```
    error: lifetime may not live long enough
      --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5
       |
    LL | fn foo(mut x: Ref, y: Ref) {
       |        -----       - has type `Ref<'_, '1>`
       |        |
       |        has type `Ref<'_, '2>`
    LL |     x.b = y.b;
       |     ^^^^^^^^^ assignment requires that `'1` must outlive `'2`
       |
    help: consider introducing a named lifetime parameter
       |
    LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) {
       |       ++++           ++++++++        ++++++++
    ```
    
    As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following
    
    ```
    help: consider introducing a named lifetime parameter
       |
    LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) {
       |       ++++           ++++++++        ++++++++
    ```
    
    but I believe this to still be an improvement over the status quo.
    
    Fix rust-lang#40990.
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    29c603c View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#124917 - cardigan1008:issue-124819, r=pnkfelix

    Check whether the next_node is else-less if in get_return_block
    
    Fix rust-lang#124819
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    ba1bb80 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#125106 - Zalathar:expressions, r=davidtwco

    coverage: Memoize and simplify counter expressions
    
    When creating coverage counter expressions as part of coverage instrumentation, we often end up creating obviously-redundant expressions like `c1 + (c0 - c1)`, which is equivalent to just `c0`.
    
    To avoid doing so, this PR checks when we would create an expression matching one of 5 patterns, and uses the simplified form instead:
    - `(a - b) + b` → `a`.
    - `(a + b) - b` → `a`.
    - `(a + b) - a` → `b`.
    - `a + (b - a)` → `b`.
    - `a - (a - b)` → `b`.
    
    Of all the different ways to combine 3 operands and 2 operators, these are the patterns that allow simplification.
    
    (Some of those patterns currently don't occur in practice, but are included anyway for completeness, to avoid having to add them later as branch coverage and MC/DC coverage support expands.)
    
    ---
    
    This PR also adds memoization for newly-created (or newly-simplified) counter expressions, to avoid creating duplicates.
    
    This currently makes no difference to the final mappings, but is expected to be useful for MC/DC coverage of match expressions, as proposed by rust-lang#124278 (comment).
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    e0d9228 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    9987e90 View commit details
    Browse the repository at this point in the history
  9. Rollup merge of rust-lang#125305 - jwong101:120493-codegen-test, r=th…

    …e8472
    
    add some codegen tests for issue 120493
    
    I forgot to add these in rust-lang#123878.
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    83cceea View commit details
    Browse the repository at this point in the history
  10. Rollup merge of rust-lang#125314 - jdonszelmann:global-registration-f…

    …eature-gate, r=pnkfelix
    
     Add an experimental feature gate for global registration
    
    See rust-lang#125119 for the tracking issue.
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    a79737c View commit details
    Browse the repository at this point in the history
  11. Rollup merge of rust-lang#125318 - GuillaumeGomez:migrate-rustdoc-exa…

    …mples-whitespaces, r=jieyouxu
    
    Migrate `run-make/rustdoc-scrape-examples-whitespace` to `rmake.rs`
    
    Part of rust-lang#121876.
    
    r? `@jieyouxu`
    matthiaskrgr authored May 20, 2024
    Configuration menu
    Copy the full SHA
    1640225 View commit details
    Browse the repository at this point in the history