From bb04e7e2a2bd0f1a8e0034f6f93bb00673b4c210 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 14 Oct 2022 19:57:01 +0100 Subject: [PATCH 1/8] rustdoc-json: Document and Test that args can be patterns. --- src/rustdoc-json-types/lib.rs | 4 ++++ src/test/rustdoc-json/fns/pattern_arg.rs | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 src/test/rustdoc-json/fns/pattern_arg.rs diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 7379b04ad1677..dbbdeecd99d3e 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -618,6 +618,10 @@ pub struct FunctionPointer { #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct FnDecl { + /// List of argument names and their type. + /// + /// Note that not all names will be valid identifiers, as some of + /// them may be patterns. pub inputs: Vec<(String, Type)>, pub output: Option, pub c_variadic: bool, diff --git a/src/test/rustdoc-json/fns/pattern_arg.rs b/src/test/rustdoc-json/fns/pattern_arg.rs new file mode 100644 index 0000000000000..32b7da0fae4e2 --- /dev/null +++ b/src/test/rustdoc-json/fns/pattern_arg.rs @@ -0,0 +1,7 @@ +// @is "$.index[*][?(@.name=='fst')].inner.decl.inputs[0][0]" '"(x, _)"' +pub fn fst((x, _): (X, Y)) -> X { + x +} + +// @is "$.index[*][?(@.name=='drop_int')].inner.decl.inputs[0][0]" '"_"' +pub fn drop_int(_: i32) {} From db760f67908d977639fee048de9344504d0a5d86 Mon Sep 17 00:00:00 2001 From: Pratush Rai Date: Fri, 25 Nov 2022 10:52:22 +0530 Subject: [PATCH 2/8] bootstrap --- src/bootstrap/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f4fa556b97450..108de217d7bfa 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -647,9 +647,11 @@ impl Build { if !update(true).status().map_or(false, |status| status.success()) { self.run(&mut update(false)); } - + // + self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path)); - self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(absolute_path)); + self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(&absolute_path)); + self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path)) } /// If any submodule has been initialized already, sync it unconditionally. From 8d148988caf8a42f38cccd88a75a02c1c4968ad4 Mon Sep 17 00:00:00 2001 From: Pratush Rai Date: Sun, 27 Nov 2022 10:05:19 +0530 Subject: [PATCH 3/8] suggested changes --- src/bootstrap/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 108de217d7bfa..5411647c065b7 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -647,11 +647,11 @@ impl Build { if !update(true).status().map_or(false, |status| status.success()) { self.run(&mut update(false)); } - // + self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path)); self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(&absolute_path)); - self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path)) + self.run(Command::new("git").args(&["stash", "pop"]).current_dir(absolute_path)); } /// If any submodule has been initialized already, sync it unconditionally. From d74240791768624eeb4efe728a2d4ec84c2a7e65 Mon Sep 17 00:00:00 2001 From: Pratush Rai Date: Sun, 27 Nov 2022 22:23:16 +0530 Subject: [PATCH 4/8] suggested changes --- src/bootstrap/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5411647c065b7..a3d1893afbb65 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -647,7 +647,6 @@ impl Build { if !update(true).status().map_or(false, |status| status.success()) { self.run(&mut update(false)); } - self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path)); self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(&absolute_path)); From 3980945ab1cd0815ba6bcd19143943b3a39c0593 Mon Sep 17 00:00:00 2001 From: yukang Date: Tue, 29 Nov 2022 12:38:39 +0800 Subject: [PATCH 5/8] fix #104884, Avoid Invalid code suggested when encountering unsatisfied trait bounds in derive macro code --- compiler/rustc_middle/src/ty/diagnostics.rs | 6 +++ .../ui/proc-macro/auxiliary/issue-104884.rs | 23 +++++++++ .../issue-104884-trait-impl-sugg-err.rs | 20 ++++++++ .../issue-104884-trait-impl-sugg-err.stderr | 48 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/test/ui/proc-macro/auxiliary/issue-104884.rs create mode 100644 src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.rs create mode 100644 src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.stderr diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 69f50df62350f..160ee73ec65ee 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -355,6 +355,12 @@ pub fn suggest_constraining_type_params<'a>( )); } + // FIXME: remove the suggestions that are from derive, as the span is not correct + suggestions = suggestions + .into_iter() + .filter(|(span, _, _)| !span.in_derive_expansion()) + .collect::>(); + if suggestions.len() == 1 { let (span, suggestion, msg) = suggestions.pop().unwrap(); diff --git a/src/test/ui/proc-macro/auxiliary/issue-104884.rs b/src/test/ui/proc-macro/auxiliary/issue-104884.rs new file mode 100644 index 0000000000000..0de59d005731d --- /dev/null +++ b/src/test/ui/proc-macro/auxiliary/issue-104884.rs @@ -0,0 +1,23 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro_derive(AddImpl)] + +pub fn derive(input: TokenStream) -> TokenStream { + "use std::cmp::Ordering; + + impl Ord for PriorityQueue { + fn cmp(&self, other: &Self) -> Ordering { + self.0.cmp(&self.height) + } + } + " + .parse() + .unwrap() +} diff --git a/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.rs b/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.rs new file mode 100644 index 0000000000000..a0d619c456644 --- /dev/null +++ b/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.rs @@ -0,0 +1,20 @@ +// aux-build:issue-104884.rs + +use std::collections::BinaryHeap; + +#[macro_use] +extern crate issue_104884; + +#[derive(PartialEq, Eq, PartialOrd, Ord)] +struct PriorityQueueEntry { + value: T, +} + +#[derive(PartialOrd, AddImpl)] +//~^ ERROR can't compare `PriorityQueue` with `PriorityQueue` +//~| ERROR the trait bound `PriorityQueue: Eq` is not satisfied +//~| ERROR can't compare `T` with `T` + +struct PriorityQueue(BinaryHeap>); + +fn main() {} diff --git a/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.stderr b/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.stderr new file mode 100644 index 0000000000000..ac49e04e3c0a9 --- /dev/null +++ b/src/test/ui/proc-macro/issue-104884-trait-impl-sugg-err.stderr @@ -0,0 +1,48 @@ +error[E0277]: can't compare `PriorityQueue` with `PriorityQueue` + --> $DIR/issue-104884-trait-impl-sugg-err.rs:13:10 + | +LL | #[derive(PartialOrd, AddImpl)] + | ^^^^^^^^^^ no implementation for `PriorityQueue == PriorityQueue` + | + = help: the trait `PartialEq` is not implemented for `PriorityQueue` +note: required by a bound in `PartialOrd` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub trait PartialOrd: PartialEq { + | ^^^^^^^^^^^^^^ required by this bound in `PartialOrd` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `PriorityQueue: Eq` is not satisfied + --> $DIR/issue-104884-trait-impl-sugg-err.rs:13:22 + | +LL | #[derive(PartialOrd, AddImpl)] + | ^^^^^^^ the trait `Eq` is not implemented for `PriorityQueue` + | +note: required by a bound in `Ord` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub trait Ord: Eq + PartialOrd { + | ^^ required by this bound in `Ord` + = note: this error originates in the derive macro `AddImpl` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `T` with `T` + --> $DIR/issue-104884-trait-impl-sugg-err.rs:13:22 + | +LL | #[derive(PartialOrd, AddImpl)] + | ^^^^^^^ no implementation for `T < T` and `T > T` + | +note: required for `PriorityQueue` to implement `PartialOrd` + --> $DIR/issue-104884-trait-impl-sugg-err.rs:13:10 + | +LL | #[derive(PartialOrd, AddImpl)] + | ^^^^^^^^^^ +note: required by a bound in `Ord` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | +LL | pub trait Ord: Eq + PartialOrd { + | ^^^^^^^^^^^^^^^^ required by this bound in `Ord` + = note: this error originates in the derive macro `AddImpl` which comes from the expansion of the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. From 43f5d2b91071b4fe8c475fa1adc003b8005452f4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 29 Nov 2022 11:37:32 -0700 Subject: [PATCH 6/8] rustdoc: add comment to confusing CSS `main { min-width: 0 }` This CSS was added in cad0fce2053d52b7ba04c458f4c124c8b5c6141e, but the reason why it was necessary was unclear. This comment makes it clear. --- src/librustdoc/html/static/css/rustdoc.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index cf5592da43205..5c9468392425a 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -314,7 +314,7 @@ main { position: relative; flex-grow: 1; padding: 10px 15px 40px 45px; - min-width: 0; + min-width: 0; /* avoid growing beyond the size limit */ } .source main { From 42ff718d0fbc6f3c9a3386e65a16ab6c4ae89480 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Wed, 30 Nov 2022 07:46:01 +0100 Subject: [PATCH 7/8] Add a regression test for #104322 --- src/test/ui/traits/issue-104322.rs | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/test/ui/traits/issue-104322.rs diff --git a/src/test/ui/traits/issue-104322.rs b/src/test/ui/traits/issue-104322.rs new file mode 100644 index 0000000000000..dcc27f1f03ae1 --- /dev/null +++ b/src/test/ui/traits/issue-104322.rs @@ -0,0 +1,80 @@ +// build-pass +// +// Tests that overflows do not occur in certain situations +// related to generic diesel code + +use mini_diesel::*; + +pub trait HandleDelete {} + +pub fn handle_delete() +where + R: HasTable, + R::Table: HandleDelete + 'static, +{ +} + +impl HandleDelete for T +where + T: Table + HasTable + 'static, + K: 'static, + &'static K: Identifiable
, + T::PrimaryKey: EqAll<<&'static K as Identifiable>::Id>, + T::Query: FilterDsl<::Id>>::Output>, + Filter::Id>>::Output>: + IntoUpdateTarget
, +{ +} + +mod mini_diesel { + pub trait HasTable { + type Table: Table; + } + + pub trait Identifiable: HasTable { + type Id; + } + + pub trait EqAll { + type Output; + } + + pub trait IntoUpdateTarget: HasTable { + type WhereClause; + } + + pub trait Query { + type SqlType; + } + + pub trait AsQuery { + type Query: Query; + } + impl AsQuery for T { + type Query = Self; + } + + pub trait FilterDsl { + type Output; + } + + impl FilterDsl for T + where + T: Table, + T::Query: FilterDsl, + { + type Output = Filter; + } + + pub trait QuerySource { + type FromClause; + } + + pub trait Table: QuerySource + AsQuery + Sized { + type PrimaryKey; + } + + pub type Filter = >::Output; +} + +fn main() {} From 3a61ab61169984c3efbf5c4c3e3765591f83db72 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 30 Nov 2022 07:51:18 -0700 Subject: [PATCH 8/8] rustdoc: clean up sidebar link CSS Group `text-overflow: ellipses` along with `white-space: nowrap`. It makes no sense to try to apply it to links with `overflow-wrap: anywhere`, because it can't actually make ellipses when that's turned on. Simplify the selector for the 25rem left padding on sidebar links, to match up with the style for the container left padding that makes room for it. --- src/librustdoc/html/static/css/rustdoc.css | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index de882e66f43de..a8c75a6f0639d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -480,15 +480,11 @@ ul.block, .block li { list-style: none; } -.block a, -.sidebar h2 a, -.sidebar h3 a { +.sidebar-elems a, +.sidebar > h2 a { display: block; - padding: 0.25rem; + padding: 0.25rem; /* 4px */ margin-left: -0.25rem; - - text-overflow: ellipsis; - overflow: hidden; } .sidebar h2 { @@ -522,6 +518,8 @@ ul.block, .block li { .sidebar-elems .block li a { white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; } .mobile-topbar {