-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix split index calculation in check_type_alias_where_clause_location
#138037
Open
stuuupidcat
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
stuuupidcat:fix/where-cfg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−6
Open
Changes from all commits
Commits
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
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
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
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
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
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
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,30 @@ | ||
#![feature(lazy_type_alias)] | ||
//~^ WARNING: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features] | ||
|
||
trait TraitA {} | ||
trait TraitB {} | ||
|
||
fn this(_x: &()) {} | ||
|
||
fn needs_copy<T>() { | ||
type F<T> | ||
where | ||
//~^ ERROR: where clauses are not allowed before the type for type aliases | ||
#[cfg(a)] | ||
//~^ ERROR: attributes in `where` clause are unstable | ||
//~| WARNING: unexpected `cfg` condition name: `a` | ||
T: TraitA, | ||
#[cfg(b)] | ||
//~^ ERROR: attributes in `where` clause are unstable | ||
//~| WARNING: unexpected `cfg` condition name: `b` | ||
T: TraitB, | ||
():, | ||
():, | ||
= T; | ||
let x: () = (); | ||
this(&x); | ||
} | ||
|
||
fn main() { | ||
needs_copy::<()>(); | ||
} |
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,70 @@ | ||
error: where clauses are not allowed before the type for type aliases | ||
--> $DIR/cfg-attr-issue-138010-1.rs:11:5 | ||
| | ||
LL | / where | ||
LL | | | ||
LL | | #[cfg(a)] | ||
... | | ||
LL | | ():, | ||
LL | | ():, | ||
| |____________^ | ||
| | ||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information | ||
help: move it to the end of the type declaration | ||
| | ||
LL ~ | ||
LL ~ = T where ():, ():; | ||
| | ||
|
||
error[E0658]: attributes in `where` clause are unstable | ||
--> $DIR/cfg-attr-issue-138010-1.rs:13:9 | ||
| | ||
LL | #[cfg(a)] | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #115590 <https://github.com/rust-lang/rust/issues/115590> for more information | ||
= help: add `#![feature(where_clause_attrs)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: attributes in `where` clause are unstable | ||
--> $DIR/cfg-attr-issue-138010-1.rs:17:9 | ||
| | ||
LL | #[cfg(b)] | ||
| ^^^^^^^^^ | ||
| | ||
= note: see issue #115590 <https://github.com/rust-lang/rust/issues/115590> for more information | ||
= help: add `#![feature(where_clause_attrs)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/cfg-attr-issue-138010-1.rs:1:12 | ||
| | ||
LL | #![feature(lazy_type_alias)] | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: unexpected `cfg` condition name: `a` | ||
--> $DIR/cfg-attr-issue-138010-1.rs:13:15 | ||
| | ||
LL | #[cfg(a)] | ||
| ^ help: found config with similar value: `target_feature = "a"` | ||
| | ||
= help: expected names are: `FALSE` and `test` and 31 more | ||
= help: to expect this configuration use `--check-cfg=cfg(a)` | ||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration | ||
= note: `#[warn(unexpected_cfgs)]` on by default | ||
|
||
warning: unexpected `cfg` condition name: `b` | ||
--> $DIR/cfg-attr-issue-138010-1.rs:17:15 | ||
| | ||
LL | #[cfg(b)] | ||
| ^ | ||
| | ||
= help: to expect this configuration use `--check-cfg=cfg(b)` | ||
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration | ||
|
||
error: aborting due to 3 previous errors; 3 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,33 @@ | ||
#![feature(where_clause_attrs, cfg_boolean_literals, lazy_type_alias)] | ||
#![expect(incomplete_features)] | ||
|
||
struct Foo; | ||
trait Trait {} | ||
|
||
impl Trait for Foo {} | ||
|
||
type MixedWhereBounds1 | ||
where //~ ERROR: where clauses are not allowed before the type for type aliases | ||
#[cfg(true)] | ||
Foo: Trait, | ||
= Foo | ||
where | ||
(): Sized; | ||
|
||
type MixedWhereBounds2 | ||
where //~ ERROR: where clauses are not allowed before the type for type aliases | ||
#[cfg(false)] | ||
Foo: Trait, | ||
= Foo | ||
where | ||
(): Sized; | ||
|
||
type MixedWhereBounds3 | ||
where | ||
//~^ ERROR: where clauses are not allowed before the type for type aliases | ||
Foo: Trait, | ||
= Foo | ||
where | ||
(): Sized; | ||
|
||
fn main() {} |
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,39 @@ | ||
error: where clauses are not allowed before the type for type aliases | ||
--> $DIR/cfg-attr-issue-138010-2.rs:10:1 | ||
| | ||
LL | / where | ||
LL | | #[cfg(true)] | ||
LL | | Foo: Trait, | ||
| |_______________^ help: remove this `where` | ||
| | ||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information | ||
|
||
error: where clauses are not allowed before the type for type aliases | ||
--> $DIR/cfg-attr-issue-138010-2.rs:18:1 | ||
| | ||
LL | / where | ||
LL | | #[cfg(false)] | ||
LL | | Foo: Trait, | ||
| |_______________^ help: remove this `where` | ||
| | ||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information | ||
|
||
error: where clauses are not allowed before the type for type aliases | ||
--> $DIR/cfg-attr-issue-138010-2.rs:26:1 | ||
| | ||
LL | / where | ||
LL | | | ||
LL | | Foo: Trait, | ||
| |_______________^ | ||
| | ||
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information | ||
help: move it to the end of the type declaration | ||
| | ||
LL + | ||
LL | = Foo | ||
LL | where | ||
LL ~ (): Sized, Foo: Trait; | ||
| | ||
|
||
error: aborting due to 3 previous errors | ||
|
Oops, something went wrong.
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.
Filtering things which have attributes applied to them isn't really correct because it's not necessarily the case that all
cfg
d where clauses will be removed during macro expansion, e.g.Here we have a where clause before the
=
that has an attribute applied to it, yet the where clause will still be present after macro expansion.If you run the compiler on this example with your changes, and then remove the
cfg
, you'll get different diagnostics output even though post-expansion it'll be the same set of where clauses. That's caused by thisbefore_with_attr_count
being1
and then when we split the where clauses into before/after you wind up splitting at0
so both clauses end up in the "after" bucket.Can you add both version as a test (with/without
cfg(true)
)?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.
I'm not really sure what the correct way to implement this is 🤔
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.
Thank you for your detailed explanation, I will add a few tests first.