From 1b5ac399082253288772dc1dabaa9d5458c927a9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 4 Apr 2023 00:28:05 +0000 Subject: [PATCH 1/8] dyn* is a valid const --- .../src/transform/check_consts/check.rs | 2 +- tests/ui/dyn-star/const-and-static.rs | 10 ++++++++++ tests/ui/dyn-star/const-and-static.stderr | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/ui/dyn-star/const-and-static.rs create mode 100644 tests/ui/dyn-star/const-and-static.stderr diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index d6110a050f2dc..20c0852fe33a9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -553,7 +553,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } Rvalue::Cast(CastKind::DynStar, _, _) => { - unimplemented!() + // `dyn*` coercion is implemented for CTFE. } Rvalue::Cast(_, _, _) => {} diff --git a/tests/ui/dyn-star/const-and-static.rs b/tests/ui/dyn-star/const-and-static.rs new file mode 100644 index 0000000000000..551b072abfab8 --- /dev/null +++ b/tests/ui/dyn-star/const-and-static.rs @@ -0,0 +1,10 @@ +// check-pass + +#![feature(dyn_star)] +//~^ WARN the feature `dyn_star` is incomplete + +const C: dyn* Send + Sync = &(); + +static S: dyn* Send + Sync = &(); + +fn main() {} diff --git a/tests/ui/dyn-star/const-and-static.stderr b/tests/ui/dyn-star/const-and-static.stderr new file mode 100644 index 0000000000000..df8f42fb0f573 --- /dev/null +++ b/tests/ui/dyn-star/const-and-static.stderr @@ -0,0 +1,11 @@ +warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/const-and-static.rs:3:12 + | +LL | #![feature(dyn_star)] + | ^^^^^^^^ + | + = note: see issue #102425 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + From 69e3f7a30dc4858d951473d8e4c2540a063e5350 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Tue, 4 Apr 2023 02:40:31 +0100 Subject: [PATCH 2/8] Disable `has_thread_local` on OpenHarmony OpenHarmony uses emulated TLS, which doesn't link properly when using thread-local variables across crate boundaries with `-C prefer-dynamic`. This PR makes thread_local! use pthreads directly instead. --- compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs | 1 + compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs index 0a5e654cf0d03..bf1b089f657b4 100644 --- a/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/aarch64_unknown_linux_ohos.rs @@ -18,6 +18,7 @@ pub fn target() -> Target { features: "+reserve-x18".into(), mcount: "\u{1}_mcount".into(), force_emulated_tls: true, + has_thread_local: false, supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs index a64f3a4f0493e..16da245336773 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_ohos.rs @@ -21,6 +21,7 @@ pub fn target() -> Target { crt_static_default: false, mcount: "\u{1}mcount".into(), force_emulated_tls: true, + has_thread_local: false, ..super::linux_musl_base::opts() }, } From 8b21f9ee22fa96a656bfcbf6f0a57120304d56a8 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Tue, 4 Apr 2023 15:31:37 +0800 Subject: [PATCH 3/8] write threads info into log only when debugging --- compiler/rustc_log/src/lib.rs | 2 +- src/librustdoc/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index 22924efa94842..21f6a404a0153 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -83,7 +83,7 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> { .with_verbose_exit(verbose_entry_exit) .with_verbose_entry(verbose_entry_exit) .with_indent_amount(2); - #[cfg(parallel_compiler)] + #[cfg(all(parallel_compiler, debug_assertions))] let layer = layer.with_thread_ids(true).with_thread_names(true); let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4c4dbc9864fd9..79f53ee57cc9d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -203,7 +203,7 @@ fn init_logging() { .with_verbose_exit(true) .with_verbose_entry(true) .with_indent_amount(2); - #[cfg(parallel_compiler)] + #[cfg(all(parallel_compiler, debug_assertions))] let layer = layer.with_thread_ids(true).with_thread_names(true); use tracing_subscriber::layer::SubscriberExt; From ebde2ab363ea4cfff4fbb58ef821f3bcebc351a5 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 3 Apr 2023 21:30:13 +0100 Subject: [PATCH 4/8] Deny `use`ing tool paths --- compiler/rustc_resolve/messages.ftl | 4 ++++ compiler/rustc_resolve/src/errors.rs | 9 +++++++++ compiler/rustc_resolve/src/ident.rs | 18 +++++++----------- tests/ui/resolve/tool-import.rs | 8 ++++++++ tests/ui/resolve/tool-import.stderr | 9 +++++++++ 5 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 tests/ui/resolve/tool-import.rs create mode 100644 tests/ui/resolve/tool-import.stderr diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index 817bb83ed786a..2199ceee53261 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -207,5 +207,9 @@ resolve_expected_found = resolve_indeterminate = cannot determine resolution for the visibility +resolve_tool_module_imported = + cannot use a tool module through an import + .note = the tool module imported here + resolve_module_only = visibility must resolve to a module diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 867363f4246af..07aaaa1eb7f60 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -469,6 +469,15 @@ pub(crate) struct ExpectedFound { #[diag(resolve_indeterminate, code = "E0578")] pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span); +#[derive(Diagnostic)] +#[diag(resolve_tool_module_imported)] +pub(crate) struct ToolModuleImported { + #[primary_span] + pub(crate) span: Span, + #[note] + pub(crate) import: Span, +} + #[derive(Diagnostic)] #[diag(resolve_module_only)] pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 06206efb9abd5..2467e604a15b9 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -17,7 +17,7 @@ use crate::late::{ ConstantHasGenerics, ConstantItemKind, HasGenericParams, PathSource, Rib, RibKind, }; use crate::macros::{sub_namespace_match, MacroRulesScope}; -use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize}; +use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize}; use crate::{Import, ImportKind, LexicalScopeBinding, Module, ModuleKind, ModuleOrUniformRoot}; use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError, Res}; use crate::{ResolutionError, Resolver, Scope, ScopeSet, Segment, ToNameBinding, Weak}; @@ -1357,7 +1357,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } }; - let is_last = i == path.len() - 1; + let is_last = i + 1 == path.len(); let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS }; let name = ident.name; @@ -1494,16 +1494,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { if let Some(next_module) = binding.module() { module = Some(ModuleOrUniformRoot::Module(next_module)); record_segment_res(self, res); - } else if res == Res::ToolMod && i + 1 != path.len() { + } else if res == Res::ToolMod && !is_last && opt_ns.is_some() { if binding.is_import() { - self.tcx - .sess - .struct_span_err( - ident.span, - "cannot use a tool module through an import", - ) - .span_note(binding.span, "the tool module imported here") - .emit(); + self.tcx.sess.emit_err(errors::ToolModuleImported { + span: ident.span, + import: binding.span, + }); } let res = Res::NonMacroAttr(NonMacroAttrKind::Tool); return PathResult::NonModule(PartialRes::new(res)); diff --git a/tests/ui/resolve/tool-import.rs b/tests/ui/resolve/tool-import.rs new file mode 100644 index 0000000000000..971993332f540 --- /dev/null +++ b/tests/ui/resolve/tool-import.rs @@ -0,0 +1,8 @@ +// edition: 2018 + +use clippy::time::Instant; +//~^ `clippy` is a tool module + +fn main() { + Instant::now(); +} diff --git a/tests/ui/resolve/tool-import.stderr b/tests/ui/resolve/tool-import.stderr new file mode 100644 index 0000000000000..d3bdfc93d4923 --- /dev/null +++ b/tests/ui/resolve/tool-import.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: `clippy` is a tool module, not a module + --> $DIR/tool-import.rs:3:5 + | +LL | use clippy::time::Instant; + | ^^^^^^ `clippy` is a tool module, not a module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0433`. From 2df3f490dd71e50fd074ade846397f4ac9cbb6f7 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 5 Apr 2023 21:20:07 +0900 Subject: [PATCH 5/8] Add regression test for #80409 Signed-off-by: Yuki Okushi --- tests/ui/inference/issue-80409.rs | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/ui/inference/issue-80409.rs diff --git a/tests/ui/inference/issue-80409.rs b/tests/ui/inference/issue-80409.rs new file mode 100644 index 0000000000000..80cad6dfc46e4 --- /dev/null +++ b/tests/ui/inference/issue-80409.rs @@ -0,0 +1,36 @@ +// check-pass + +#![allow(unreachable_code, unused)] + +use std::marker::PhantomData; + +struct FsmBuilder { + _fsm: PhantomData, +} + +impl FsmBuilder { + fn state(&mut self) -> FsmStateBuilder { + todo!() + } +} + +struct FsmStateBuilder { + _state: PhantomData, +} + +impl FsmStateBuilder { + fn on_entry)>(&self, _action: TAction) {} +} + +trait Fsm { + type Context; +} + +struct StateContext<'a, TFsm: Fsm> { + context: &'a mut TFsm::Context, +} + +fn main() { + let mut builder: FsmBuilder = todo!(); + builder.state().on_entry(|_| {}); +} From b8e90766b596df4cad9ed0256eed5ba445c7e4ae Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 5 Apr 2023 21:32:13 +0900 Subject: [PATCH 6/8] Add regression test for #86351 Signed-off-by: Yuki Okushi --- tests/ui/const_prop/issue-86351.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/ui/const_prop/issue-86351.rs diff --git a/tests/ui/const_prop/issue-86351.rs b/tests/ui/const_prop/issue-86351.rs new file mode 100644 index 0000000000000..b5f1e7f7449a2 --- /dev/null +++ b/tests/ui/const_prop/issue-86351.rs @@ -0,0 +1,22 @@ +// compile-flags: --crate-type=lib -Zmir-opt-level=2 +// build-pass +// ^-- Must be build-pass, because check-pass will not run const prop. + +pub trait TestTrait { + type MyType; + fn func() -> Option + where + Self: Sized; +} + +impl dyn TestTrait +where + Self: Sized, +{ + pub fn other_func() -> Option { + match Self::func() { + Some(me) => Some(me), + None => None, + } + } +} From 906bdd3bdb5423794971786d3b0783206645b340 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 Apr 2023 17:13:00 +0200 Subject: [PATCH 7/8] Improve display of logo on very small screens --- src/librustdoc/html/static/css/rustdoc.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 726394d8348e7..e86eaa65b75b8 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -6,6 +6,10 @@ 3. Copy the filenames with updated suffixes from the directory. */ +:root { + --nav-sub-mobile-padding: 8px; +} + /* See FiraSans-LICENSE.txt for the Fira Sans license. */ @font-face { font-family: 'Fira Sans'; @@ -1726,7 +1730,7 @@ in main.js .source nav.sub { margin: 0; - padding: 8px; + padding: var(--nav-sub-mobile-padding); } } @@ -1783,6 +1787,7 @@ in main.js .sub-logo-container > img { height: 35px; width: 35px; + margin-bottom: var(--nav-sub-mobile-padding); } } From 8f5404d0d79f7cef9445b531aae5394fe3b22f29 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 5 Apr 2023 17:13:12 +0200 Subject: [PATCH 8/8] Update GUI tests for logo display on very small screens --- tests/rustdoc-gui/huge-logo.goml | 4 +++- tests/rustdoc-gui/source-code-page.goml | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/rustdoc-gui/huge-logo.goml b/tests/rustdoc-gui/huge-logo.goml index 01f06771c15a5..69459bd3e23b5 100644 --- a/tests/rustdoc-gui/huge-logo.goml +++ b/tests/rustdoc-gui/huge-logo.goml @@ -18,4 +18,6 @@ size: (1280, 1024) assert-property: (".sub-logo-container", {"offsetWidth": "60", "offsetHeight": 60}) size: (400, 600) -assert-property: (".sub-logo-container", {"offsetWidth": "35", "offsetHeight": 35}) +// 43 because 35px + 8px of margin +assert-css: (".sub-logo-container > img", {"margin-bottom": "8px"}) +assert-property: (".sub-logo-container", {"offsetWidth": "35", "offsetHeight": 43}) diff --git a/tests/rustdoc-gui/source-code-page.goml b/tests/rustdoc-gui/source-code-page.goml index 7c35119e6959d..ea6ff12328ca7 100644 --- a/tests/rustdoc-gui/source-code-page.goml +++ b/tests/rustdoc-gui/source-code-page.goml @@ -216,3 +216,8 @@ call-function: ("check-sidebar-dir-entry", { "x": 0, "y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6, }) + +// Now we check that the logo has a bottom margin so it's not stuck to the search input. +assert-css: (".sub-logo-container > img", {"margin-bottom": "8px"}) +store-property: (logo_height, ".sub-logo-container", "clientHeight") +assert-position: (".search-form", {"y": |logo_height| + 8})