Skip to content

Fix keyword_idents_2024 missing lifetimes in various positions #133989

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,9 @@ impl EarlyLintPass for KeywordIdents {
self.check_ident_token(cx, UnderMacro(false), *ident, "");
}
}
fn check_lifetime(&mut self, cx: &EarlyContext<'_>, lt: &ast::Lifetime) {
self.check_ident_token(cx, UnderMacro(false), lt.ident.without_first_quote(), "'");
}
}

declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMENTS]);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>

fn visit_lifetime(&mut self, lt: &'a ast::Lifetime, _: ast_visit::LifetimeCtxt) {
self.check_id(lt.id);
lint_callback!(self, check_lifetime, lt);
}

fn visit_path(&mut self, p: &'a ast::Path, id: ast::NodeId) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ macro_rules! early_lint_methods {
$macro!($args, [
fn check_param(a: &rustc_ast::Param);
fn check_ident(a: &rustc_span::symbol::Ident);
fn check_lifetime(a: &rustc_ast::Lifetime);
fn check_crate(a: &rustc_ast::Crate);
fn check_crate_post(a: &rustc_ast::Crate);
fn check_item(a: &rustc_ast::Item);
Expand Down
49 changes: 47 additions & 2 deletions tests/ui/rust-2024/gen-kw.e2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,56 @@ LL | () => { mod test { fn gen() {} } }
error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:25:9
|
LL | fn test<'gen>() {}
LL | fn test<'gen>(_: &'gen i32) {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: aborting due to 4 previous errors
error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:25:19
|
LL | fn test<'gen>(_: &'gen i32) {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:33:10
|
LL | struct S<'gen>(&'gen i32);
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:33:17
|
LL | struct S<'gen>(&'gen i32);
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:42:6
|
LL | impl<'gen> Tr for S<'gen> {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:42:21
|
LL | impl<'gen> Tr for S<'gen> {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: aborting due to 9 previous errors

49 changes: 47 additions & 2 deletions tests/ui/rust-2024/gen-kw.e2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,56 @@ LL | () => { mod test { fn gen() {} } }
error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:25:9
|
LL | fn test<'gen>() {}
LL | fn test<'gen>(_: &'gen i32) {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: aborting due to 4 previous errors
error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:25:19
|
LL | fn test<'gen>(_: &'gen i32) {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:33:10
|
LL | struct S<'gen>(&'gen i32);
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:33:17
|
LL | struct S<'gen>(&'gen i32);
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:42:6
|
LL | impl<'gen> Tr for S<'gen> {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: `gen` is a keyword in the 2024 edition
--> $DIR/gen-kw.rs:42:21
|
LL | impl<'gen> Tr for S<'gen> {}
| ^^^^ help: you can use a raw identifier to stay compatible: `'r#gen`
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>

error: aborting due to 9 previous errors

22 changes: 21 additions & 1 deletion tests/ui/rust-2024/gen-kw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,29 @@ macro_rules! t {
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
}

fn test<'gen>() {}
fn test<'gen>(_: &'gen i32) {}
//~^ ERROR `gen` is a keyword in the 2024 edition
//~| ERROR `gen` is a keyword in the 2024 edition
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
Comment on lines +25 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: I know this gets eventually deduplicated, but the duplicate error messages are interesting


struct S<'gen>(&'gen i32);
//~^ ERROR `gen` is a keyword in the 2024 edition
//~| ERROR `gen` is a keyword in the 2024 edition
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!

trait Tr {}
impl<'gen> Tr for S<'gen> {}
//~^ ERROR `gen` is a keyword in the 2024 edition
//~| ERROR `gen` is a keyword in the 2024 edition
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2015]~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!
//[e2018]~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2024!

t!();
Loading