10000 Rollup of 6 pull requests by Dylan-DPC · Pull Request #98347 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 6 pull requests #98347

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c7b6e1d
lub: don't bail out due to empty binders
lcnr Jun 8, 2022
0667b00
update tests + add future compat test
lcnr Jun 8, 2022
3f12fa7
Add support for macro in "jump to def" feature
GuillaumeGomez Nov 26, 2021
dda980d
Rename ContextInfo into HrefContext
GuillaumeGomez Jun 18, 2022
810254b
Improve code readability and documentation
GuillaumeGomez Jun 18, 2022
f4db07e
Add test for macro support in "jump to def" feature
GuillaumeGomez Nov 26, 2021
987c731
Integrate `generate_macro_def_id_path` into `href_with_root_path`
GuillaumeGomez Jun 20, 2022
eb6141e
Support setting file accessed/modified timestamps
joshtriplett Jun 19, 2022
585767d
Add alias `File::set_modified` as shorthand
joshtriplett Jun 20, 2022
beb2f36
Fix panic by checking if `CStore` has the crate data we want before a…
GuillaumeGomez Jun 20, 2022
e900a35
Give name if anonymous region appears in impl signature
compiler-errors Jun 21, 2022
31476e7
Add a full regression test for #73727
JohnTitor Jun 21, 2022
5ed1495
This comment is out dated and misleading
spastorino Jun 21, 2022
d502e83
Rollup merge of #91264 - GuillaumeGomez:macro-jump-to-def, r=jsha
Dylan-DPC Jun 21, 2022
a6de3f6
Rollup merge of #97867 - lcnr:lub-binder, r=oli-obk
Dylan-DPC Jun 21, 2022
b5a2a80
Rollup merge of #98184 - compiler-errors:elided-lifetime-in-impl-nll,…
Dylan-DPC Jun 21, 2022
223d7f8
Rollup merge of #98246 - joshtriplett:times, r=m-ou-se
Dylan-DPC Jun 21, 2022
2b1ce20
Rollup merge of #98334 - JohnTitor:issue-73727, r=compiler-errors
Dylan-DPC Jun 21, 2022
9bf095d
Rollup merge of #98344 - spastorino:remove-misleading-comment, r=oli-obk
Dylan-DPC Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lub: don't bail out due to empty binders
  • Loading branch information
lcnr committed Jun 8, 2022
commit c7b6e1de661419a67a59ad59fba70a451c27cbb6
20 changes: 14 additions & 6 deletions compiler/rustc_infer/src/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,20 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
T: Relate<'tcx>,
{
debug!("binders(a={:?}, b={:?})", a, b);

// When higher-ranked types are involved, computing the LUB is
// very challenging, switch to invariance. This is obviously
// overly conservative but works ok in practice.
self.relate_with_variance(ty::Variance::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
Ok(a)
if a.skip_binder().has_escaping_bound_vars() || b.skip_binder().has_escaping_bound_vars() {
// When higher-ranked types are involved, computing the GLB is
// very challenging, switch to invariance. This is obviously
// overly conservative but works ok in practice.
self.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
a,
b,
)?;
Ok(a)
} else {
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))
}
}
}

Expand Down
20 changes: 14 additions & 6 deletions compiler/rustc_infer/src/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,20 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
T: Relate<'tcx>,
{
debug!("binders(a={:?}, b={:?})", a, b);

// When higher-ranked types are involved, computing the LUB is
// very challenging, switch to invariance. This is obviously
// overly conservative but works ok in practice.
self.relate_with_variance(ty::Variance::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
Ok(a)
if a.skip_binder().has_escaping_bound_vars() || b.skip_binder().has_escaping_bound_vars() {
// When higher-ranked types are involved, computing the LUB is
// very challenging, switch to invariance. This is obviously
// overly conservative but works ok in practice.
self.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
a,
b,
)?;
Ok(a)
} else {
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))
}
}
}

Expand Down
61 changes: 61 additions & 0 deletions src/test/ui/lub-glb/empty-binders-err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
fn lt<'a: 'a>() -> &'a () {
&()
}

fn lt_in_fn<'a: 'a>() -> fn(&'a ()) {
|_| ()
}

struct Contra<'a>(fn(&'a ()));
fn lt_in_contra<'a: 'a>() -> Contra<'a> {
Contra(|_| ())
}

fn covariance<'a, 'b, 'upper, 'lower>(v: bool)
where
'upper: 'a,
'upper: 'b,
'a: 'lower,
'b: 'lower,

{
let _: &'upper () = match v {
//~^ ERROR lifetime may not live long enough
//~| ERROR lifetime may not live long enough
true => lt::<'a>(),
false => lt::<'b>(),
};
}

fn contra_fn<'a, 'b, 'upper, 'lower>(v: bool)
where
'upper: 'a,
'upper: 'b,
'a: 'lower,
'b: 'lower,

{

let _: fn(&'lower ()) = match v {
//~^ ERROR lifetime may not live long enough
true => lt_in_fn::<'a>(),
false => lt_in_fn::<'b>(),
};
}

fn contra_struct<'a, 'b, 'upper, 'lower>(v: bool)
where
'upper: 'a,
'upper: 'b,
'a: 'lower,
'b: 'lower,

{
let _: Contra<'lower> = match v {
//~^ ERROR lifetime may not live long enough
true => lt_in_contra::<'a>(),
false => lt_in_contra::<'b>(),
};
}

fn main() {}
59 changes: 59 additions & 0 deletions src/test/ui/lub-glb/empty-binders-err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
error: lifetime may not live long enough
--> $DIR/empty-binders-err.rs:22:12
|
LL | fn covariance<'a, 'b, 'upper, 'lower>(v: bool)
| -- ------ lifetime `'upper` defined here
| |
| lifetime `'a` defined here
...
LL | let _: &'upper () = match v {
| ^^^^^^^^^^ type annotation requires that `'a` must outlive `'upper`
|
= help: consider adding the following bound: `'a: 'upper`

error: lifetime may not live long enough
--> $DIR/empty-binders-err.rs:22:12
|
LL | fn covariance<'a, 'b, 'upper, 'lower>(v: bool)
| -- ------ lifetime `'upper` defined here
| |
| lifetime `'b` defined here
...
LL | let _: &'upper () = match v {
| ^^^^^^^^^^ type annotation requires that `'b` must outlive `'upper`
|
= help: consider adding the following bound: `'b: 'upper`

help: the following changes may resolve your lifetime errors
|
= help: add bound `'a: 'upper`
= help: add bound `'b: 'upper`

error: lifetime may not live long enough
--> $DIR/empty-binders-err.rs:39:12
|
LL | fn contra_fn<'a, 'b, 'upper, 'lower>(v: bool)
| -- ------ lifetime `'lower` defined here
| |
| lifetime `'a` defined here
...
LL | let _: fn(&'lower ()) = match v {
| ^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a`
|
= help: consider adding the following bound: `'lower: 'a`

error: lifetime may not live long enough
--> $DIR/empty-binders-err.rs:54:12
|
LL | fn contra_struct<'a, 'b, 'upper, 'lower>(v: bool)
| -- ------ lifetime `'lower` defined here
| |
| lifetime `'a` defined here
...
LL | let _: Contra<'lower> = match v {
| ^^^^^^^^^^^^^^ type annotation requires that `'lower` must outlive `'a`
|
= help: consider adding the following bound: `'lower: 'a`

error: aborting due to 4 previous errors

45 changes: 45 additions & 0 deletions src/test/ui/lub-glb/empty-binders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// check-pass
//
// Check that computing the lub works even for empty binders.
fn lt<'a: 'a>() -> &'a () {
&()
}

fn lt_in_fn<'a: 'a>() -> fn(&'a ()) {
|_| ()
}

struct Contra<'a>(fn(&'a ()));
fn lt_in_contra<'a: 'a>() -> Contra<'a> {
Contra(|_| ())
}

fn ok<'a, 'b, 'upper, 'lower>(v: bool)
where
'upper: 'a,
'upper: 'b,
'a: 'lower,
'b: 'lower,

{
let _: &'lower () = match v {
true => lt::<'a>(),
false => lt::<'b>(),
};

// This errored in the past because LUB and GLB always
// bailed out when encountering binders, even if they were
// empty.
let _: fn(&'upper ()) = match v {
true => lt_in_fn::<'a>(),
false => lt_in_fn::<'b>(),
};

// This was already accepted, as relate didn't encounter any binders.
let _: Contra<'upper> = match v {
true => lt_in_contra::<'a>(),
false => lt_in_contra::<'b>(),
};
}

fn main() {}
0