-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Extend E0623 for fn items #44516
Merged
Merged
Extend E0623 for fn items #44516
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f50c33
Adding E0623 for structs
gaurikholkar ed11812
extend E0623 for fns
gaurikholkar b2d869d
add logs
gaurikholkar 54af570
correct depth initialisation
gaurikholkar a128051
fixes
gaurikholkar 93529b4
add ui test for fn items, tidy fixes
gaurikholkar 6e3cdce
Adding changes for trait objects
gaurikholkar e71eef1
fix ui tests
gaurikholkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
fn foo(x: fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
// Debruijn 1 1 1 1 | ||
// Anon-Index 0 1 0 1 | ||
// ------ | ||
// debruijn indices are shifted by 1 in here | ||
y.push(z); // index will be zero or one | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |
hir_map: &self.tcx.hir, | ||
bound_region: *br, | ||
found_type: None, | ||
depth: 1, | ||
}; | ||
nested_visitor.visit_ty(arg); | ||
nested_visitor.found_type | ||
|
@@ -195,6 +196,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { | |
// The type where the anonymous lifetime appears | ||
// for e.g. Vec<`&u8`> and <`&u8`> | ||
found_type: Option<&'gcx hir::Ty>, | ||
depth: u32, | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { | ||
|
@@ -204,6 +206,21 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { | |
|
||
fn visit_ty(&mut self, arg: &'gcx hir::Ty) { | ||
match arg.node { | ||
hir::TyBareFn(_) => { | ||
self.depth += 1; | ||
intravisit::walk_ty(self, arg); | ||
self.depth -= 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No such field [00:06:31] error[E0609]: no field `depth` on type `&mut infer::error_reporting::different_lifetimes::FindNestedTypeVisitor<'a, 'gcx, 'tcx>`
[00:06:31] --> /checkout/src/librustc/infer/error_reporting/different_lifetimes.rs:208:22
[00:06:31] |
[00:06:31] 208 | self.depth += 1;
[00:06:31] | ^^^^^
[00:06:31]
[00:06:31] error[E0609]: no field `depth` on type `&mut infer::error_reporting::different_lifetimes::FindNestedTypeVisitor<'a, 'gcx, 'tcx>`
[00:06:31] --> /checkout/src/librustc/infer/error_reporting/different_lifetimes.rs:210:22
[00:06:31] |
[00:06:31] 210 | self.depth -= 1;
[00:06:31] | ^^^^^
[00:06:31]
[00:06:41] error: aborting due to 2 previous errors
[00:06:41]
[00:06:41] error: Could not compile `rustc`. |
||
return; | ||
} | ||
|
||
hir::TyTraitObject(ref bounds, _) => { | ||
for bound in bounds { | ||
self.depth += 1; | ||
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None); | ||
self.depth -= 1; | ||
} | ||
} | ||
|
||
hir::TyRptr(ref lifetime, _) => { | ||
// the lifetime of the TyRptr | ||
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id); | ||
|
@@ -217,7 +234,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { | |
debruijn_index.depth, | ||
anon_index, | ||
br_index); | ||
if debruijn_index.depth == 1 && anon_index == br_index { | ||
if debruijn_index.depth == self.depth && anon_index == br_index { | ||
self.found_type = Some(arg); | ||
return; // we can stop visiting now | ||
} | ||
|
@@ -246,7 +263,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> { | |
debug!("self.infcx.tcx.hir.local_def_id(id)={:?}", | ||
self.infcx.tcx.hir.local_def_id(id)); | ||
debug!("def_id={:?}", def_id); | ||
if debruijn_index.depth == 1 && | ||
if debruijn_index.depth == self.depth && | ||
self.infcx.tcx.hir.local_def_id(id) == def_id { | ||
self.found_type = Some(arg); | ||
return; // we can stop visiting now | ||
|
18 changes: 18 additions & 0 deletions
18
src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-4.rs:12:13 | ||
| | ||
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) { | ||
| --- --- these references are declared with different lifetimes... | ||
12 | z.push((x,y)); | ||
| ^ ...but data flows into `z` here | ||
|
||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-4.rs:12:15 | ||
| | ||
11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) { | ||
| --- --- these references are declared with different lifetimes... | ||
12 | z.push((x,y)); | ||
| ^ ...but data flows into `z` here | ||
|
||
error: aborting due to 2 previous errors | ||
|
19 changes: 19 additions & 0 deletions
19
src/test/ui/lifetime-errors/ex3-both-anon-regions-both-are-structs-4.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
struct Ref<'a, 'b> { | ||
a: &'a u32, | ||
b: &'b u32, | ||
} | ||
|
||
fn foo(mut x: Ref) { | ||
x.a = x.b; | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/lifetime-errors/ex3-both-anon-regions-both-are-structs-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-both-are-structs-4.rs:16:11 | ||
| | ||
15 | fn foo(mut x: Ref) { | ||
| --- | ||
| | | ||
| this type was declared with multiple lifetimes... | ||
16 | x.a = x.b; | ||
| ^^^ ...but data with one lifetime flows into the other here | ||
|
||
error: aborting due to previous error | ||
|
17 changes: 17 additions & 0 deletions
17
src/test/ui/lifetime-errors/ex3-both-anon-regions-one-is-struct-4.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
struct Ref<'a, 'b> { a: &'a u32, b: &'b u32 } | ||
|
||
fn foo(mut y: Ref, x: &u32) { | ||
y.b = x; | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-one-is-struct-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-one-is-struct-4.rs:14:11 | ||
| | ||
13 | fn foo(mut y: Ref, x: &u32) { | ||
| --- ---- these two types are declared with different lifetimes... | ||
14 | y.b = x; | ||
| ^ ...but data from `x` flows into `y` here | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-fn-items.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
y.push(z); | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-fn-items.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-using-fn-items.rs:11:10 | ||
| | ||
10 | fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) { | ||
| --- --- these two types are declared with different lifetimes... | ||
11 | y.push(z); | ||
| ^ ...but data from `z` flows into `y` here | ||
|
||
error: aborting due to previous error | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-trait-objects.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
fn foo(x:Box<Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) { | ||
y.push(z); | ||
} | ||
|
||
fn main() { } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetime-errors/ex3-both-anon-regions-using-trait-objects.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/ex3-both-anon-regions-using-trait-objects.rs:11:10 | ||
| | ||
10 | fn foo(x:Box<Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) { | ||
| --- --- these two types are declared with different lifetimes... | ||
11 | y.push(z); | ||
| ^ ...but data from `z` flows into `y` here | ||
|
||
error: aborting due to previous error | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you accidentially left this file in the root dir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah. I'm open a PR for that or I have an ongoing PR, I'll make sure to delete that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #44549. Thanks!