From 873ed1977e3fcc013462064b5d35c9e8444df918 Mon Sep 17 00:00:00 2001 From: bohan Date: Sat, 23 Dec 2023 15:57:24 +0800 Subject: [PATCH 1/5] fallback `default` to `None` during ast-loweing for lifetime binder --- compiler/rustc_ast_lowering/messages.ftl | 2 ++ compiler/rustc_ast_lowering/src/errors.rs | 7 ++++++ compiler/rustc_ast_lowering/src/lib.rs | 25 +++++++++++++++++-- tests/ui/parser/issue-119042.rs | 7 ++++++ .../non_lifetime_binders/issue-118697.rs | 9 +++++++ .../non_lifetime_binders/issue-118697.stderr | 21 ++++++++++++++++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tests/ui/parser/issue-119042.rs create mode 100644 tests/ui/traits/non_lifetime_binders/issue-118697.rs create mode 100644 tests/ui/traits/non_lifetime_binders/issue-118697.stderr diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index 6bde4f2d8fa5a..5a1b1c799eb98 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -45,6 +45,8 @@ ast_lowering_closure_cannot_be_static = closures cannot be static ast_lowering_coroutine_too_many_parameters = too many parameters for a coroutine (expected 0 or 1 parameters) +ast_lowering_default_parameter_in_binder = default parameter is not allowed in this binder + ast_lowering_does_not_support_modifiers = the `{$class_name}` register class does not support template modifiers diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 11bb559719b9f..718a5b03cf27b 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -395,3 +395,10 @@ pub enum BadReturnTypeNotation { span: Span, }, } + +#[derive(Diagnostic)] +#[diag(ast_lowering_default_parameter_in_binder)] +pub(crate) struct UnexpectedDefaultParameterInBinder { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index e35d7d62cad48..3bec0a9e5711b 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -33,6 +33,7 @@ #![allow(internal_features)] #![feature(rustdoc_internals)] #![doc(rust_logo)] +#![feature(if_let_guard)] #![feature(box_patterns)] #![feature(let_chains)] #![recursion_limit = "256"] @@ -65,6 +66,7 @@ use rustc_session::parse::{add_feature_diagnostics, feature_err}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{DesugaringKind, Span, DUMMY_SP}; use smallvec::SmallVec; +use std::borrow::Cow; use std::collections::hash_map::Entry; use thin_vec::ThinVec; @@ -874,8 +876,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { binder: NodeId, generic_params: &[GenericParam], ) -> &'hir [hir::GenericParam<'hir>] { - let mut generic_params: Vec<_> = self - .lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder) + let mut generic_params: Vec<_> = generic_params + .iter() + .map(|param| { + let param = match param.kind { + GenericParamKind::Type { ref default } if let Some(ty) = default => { + // Default type is not permitted in non-lifetime binders. + // So we emit an error and default to `None` to prevent + // potential ice. + self.tcx.sess.emit_err(errors::UnexpectedDefaultParameterInBinder { + span: ty.span(), + }); + let param = GenericParam { + kind: GenericParamKind::Type { default: None }, + ..param.clone() + }; + Cow::Owned(param) + } + _ => Cow::Borrowed(param), + }; + self.lower_generic_param(param.as_ref(), hir::GenericParamSource::Binder) + }) .collect(); let extra_lifetimes = self.resolver.take_extra_lifetime_params(binder); debug!(?extra_lifetimes); diff --git a/tests/ui/parser/issue-119042.rs b/tests/ui/parser/issue-119042.rs new file mode 100644 index 0000000000000..a4fee169d1cbc --- /dev/null +++ b/tests/ui/parser/issue-119042.rs @@ -0,0 +1,7 @@ +// check-pass + +macro_rules! a { ($ty:ty) => {} } + +a! { for fn() } + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/issue-118697.rs b/tests/ui/traits/non_lifetime_binders/issue-118697.rs new file mode 100644 index 0000000000000..a282d0c5a40d9 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/issue-118697.rs @@ -0,0 +1,9 @@ +#![allow(incomplete_features)] +#![feature(non_lifetime_binders)] + +type T = dyn for Fn(()); +//~^ ERROR default parameter is not allowed in this binder +//~| ERROR cannot find type `A` in this scope +//~| ERROR late-bound type parameter not allowed on trait object types + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/issue-118697.stderr b/tests/ui/traits/non_lifetime_binders/issue-118697.stderr new file mode 100644 index 0000000000000..52ce568d69ddc --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/issue-118697.stderr @@ -0,0 +1,21 @@ +error[E0412]: cannot find type `A` in this scope + --> $DIR/issue-118697.rs:4:22 + | +LL | type T = dyn for Fn(()); + | ^ not found in this scope + +error: default parameter is not allowed in this binder + --> $DIR/issue-118697.rs:4:22 + | +LL | type T = dyn for Fn(()); + | ^^^^^^ + +error: late-bound type parameter not allowed on trait object types + --> $DIR/issue-118697.rs:4:18 + | +LL | type T = dyn for Fn(()); + | ^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0412`. From 3896f0bb9bc78a2b6d2cf0b3c45d4845d0be8c0b Mon Sep 17 00:00:00 2001 From: AlexBuz Date: Sun, 24 Dec 2023 19:28:03 -0600 Subject: [PATCH 2/5] Fix doc typo for read_exact_at --- library/std/src/os/unix/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index 0eb4e88cfad96..e995d5133f8a7 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -68,7 +68,7 @@ pub trait FileExt { io::default_read_vectored(|b| self.read_at(b, offset), bufs) } - /// Reads the exact number of byte required to fill `buf` from the given offset. + /// Reads the exact number of bytes required to fill `buf` from the given offset. /// /// The offset is relative to the start of the file and thus independent /// from the current cursor. From 0e88874292736719d156798015e3272e5ea6e7cd Mon Sep 17 00:00:00 2001 From: jyn Date: Mon, 25 Dec 2023 07:57:13 -0500 Subject: [PATCH 3/5] fix `./configure --set change-id` --- config.example.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 4cf7c1e81990c..dacc61a3e4c48 100644 --- a/config.example.toml +++ b/config.example.toml @@ -30,7 +30,7 @@ # # If `change-id` does not match the version that is currently running, # `x.py` will inform you about the changes made on bootstrap. -# change-id = +#change-id = # ============================================================================= # Tweaking how LLVM is compiled From 51dff45aa3d7eb33afcc2eca8dae604bdfb08e43 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Dec 2023 20:50:09 +0100 Subject: [PATCH 4/5] Update sysinfo version to 0.30.1 --- Cargo.lock | 2 +- src/bootstrap/Cargo.lock | 4 ++-- src/bootstrap/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d78e29de0e08..c615a8f84a3f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5205,7 +5205,7 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.2" +version = "0.29.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9557d0845b86eea8182f7b10dff120214fb6cd9fd937b6f4917714e546a38695" dependencies = [ diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index 63190fc318020..0debc6efa57b2 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -620,9 +620,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68492e7268037de59ae153d7efb79546cf94a18a9548235420d3d8d2436b4b1" +checksum = "01e979b637815805abbdeea72e4b6d9374dd0efce6524cc65c31e14911dbc671" dependencies = [ "cfg-if", "core-foundation-sys", diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 225eccca40f77..09c5cb2297448 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -59,7 +59,7 @@ walkdir = "2" xz2 = "0.1" # Dependencies needed by the build-metrics feature -sysinfo = { version = "0.30.0", optional = true } +sysinfo = { version = "0.30", optional = true } # Solaris doesn't support flock() and thus fd-lock is not option now [target.'cfg(not(target_os = "solaris"))'.dependencies] From c2dcfc762d0489511ce527307cdc2cfd8384b430 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 25 Dec 2023 22:45:38 +0100 Subject: [PATCH 5/5] Update sysinfo sub-dependency version to 0.29.11 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c615a8f84a3f9..a53e13983bc95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5205,9 +5205,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.29.10" +version = "0.29.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9557d0845b86eea8182f7b10dff120214fb6cd9fd937b6f4917714e546a38695" +checksum = "cd727fc423c2060f6c92d9534cef765c65a6ed3f428a03d7def74a8c4348e666" dependencies = [ "cfg-if", "core-foundation-sys",