From 1caec6fa1d09739f70b1f54766141cf204696503 Mon Sep 17 00:00:00 2001 From: Ethan Brierley Date: Fri, 23 Dec 2022 00:13:47 +0000 Subject: [PATCH 1/9] fix: misleading add `dyn` to derive macro suggestion --- .../rustc_hir_analysis/src/astconv/mod.rs | 8 ++++- tests/ui/traits/issue-106072.rs | 5 ++++ tests/ui/traits/issue-106072.stderr | 30 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/ui/traits/issue-106072.rs create mode 100644 tests/ui/traits/issue-106072.stderr diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 3521911b055..398dd18f512 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -3307,7 +3307,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let label = "add `dyn` keyword before this trait"; let mut diag = rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg); - diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable); + if self_ty.span.can_be_used_for_suggestions() { + diag.multipart_suggestion_verbose( + label, + sugg, + Applicability::MachineApplicable, + ); + } // check if the impl trait that we are considering is a impl of a local trait self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag); diag.emit(); diff --git a/tests/ui/traits/issue-106072.rs b/tests/ui/traits/issue-106072.rs new file mode 100644 index 00000000000..7064a39d21e --- /dev/null +++ b/tests/ui/traits/issue-106072.rs @@ -0,0 +1,5 @@ +#[derive(Clone)] //~ trait objects must include the `dyn` keyword + //~| trait objects must include the `dyn` keyword +struct Foo; +trait Foo {} //~ the name `Foo` is defined multiple times +fn main() {} diff --git a/tests/ui/traits/issue-106072.stderr b/tests/ui/traits/issue-106072.stderr new file mode 100644 index 00000000000..f9b7b814663 --- /dev/null +++ b/tests/ui/traits/issue-106072.stderr @@ -0,0 +1,30 @@ +error[E0428]: the name `Foo` is defined multiple times + --> $DIR/issue-106072.rs:4:1 + | +LL | struct Foo; + | ----------- previous definition of the type `Foo` here +LL | trait Foo {} + | ^^^^^^^^^ `Foo` redefined here + | + = note: `Foo` must be defined only once in the type namespace of this module + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/issue-106072.rs:1:10 + | +LL | #[derive(Clone)] + | ^^^^^ + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/issue-106072.rs:1:10 + | +LL | #[derive(Clone)] + | ^^^^^ + | + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0428, E0782. +For more information about an error, try `rustc --explain E0428`. From da3623abab0bb548b539a8a61ba5b813f5395db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vennberg?= Date: Sat, 14 Jan 2023 17:34:59 +0100 Subject: [PATCH 2/9] Removed various double spaces in compiler source comments. --- compiler/rustc_abi/src/lib.rs | 2 +- compiler/rustc_borrowck/src/places_conflict.rs | 2 +- compiler/rustc_hir_typeck/src/expr_use_visitor.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 2 +- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_trait_selection/src/traits/mod.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 4582d3c6bad..b48654d1ac3 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1100,7 +1100,7 @@ pub enum FieldsShape { /// named `inverse_memory_index`. /// // FIXME(eddyb) build a better abstraction for permutations, if possible. - // FIXME(camlorn) also consider small vector optimization here. + // FIXME(camlorn) also consider small vector optimization here. memory_index: Vec, }, } diff --git a/compiler/rustc_borrowck/src/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs index 89ac0dfa4d6..918fb2d6923 100644 --- a/compiler/rustc_borrowck/src/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -209,7 +209,7 @@ fn place_components_conflict<'tcx>( match (elem, &base_ty.kind(), access) { (_, _, Shallow(Some(ArtificialField::ArrayLength))) | (_, _, Shallow(Some(ArtificialField::ShallowBorrow))) => { - // The array length is like additional fields on the + // The array length is like additional fields on the // type; it does not overlap any existing data there. // Furthermore, if cannot actually be a prefix of any // borrowed place (at least in MIR as it is currently.) diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 7774ffc9b97..c8cda0dc90c 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -417,7 +417,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // Named constants have to be equated with the value // being matched, so that's a read of the value being matched. // - // FIXME: We don't actually reads for ZSTs. + // FIXME: We don't actually reads for ZSTs. needs_to_be_read = true; } _ => { diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index dd827777df9..3a3080b2c96 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -232,7 +232,7 @@ pub type PickResult<'tcx> = Result, MethodError<'tcx>>; pub enum Mode { // An expression of the form `receiver.method_name(...)`. // Autoderefs are performed on `receiver`, lookup is done based on the - // `self` argument of the method, and static methods aren't considered. + // `self` argument of the method, and static methods aren't considered. MethodCall, // An expression of the form `Type::item` or `::item`. // No autoderefs are performed, lookup is done based on the type each diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 1ccfc59f7a9..55576b4e0d1 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2091,7 +2091,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec< .map(|s| { // Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]", // where KIND is one of "dylib", "framework", "static", "link-arg" and - // where MODIFIERS are a comma separated list of supported modifiers + // where MODIFIERS are a comma separated list of supported modifiers // (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed // with either + or - to indicate whether it is enabled or disabled. // The last value specified for a given modifier wins. diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 37b40a2f75a..e5fbf981bed 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -308,7 +308,7 @@ pub fn normalize_param_env_or_error<'tcx>( // the `TypeOutlives` predicates first inside the unnormalized parameter environment, and // then we normalize the `TypeOutlives` bounds inside the normalized parameter environment. // - // This works fairly well because trait matching does not actually care about param-env + // This works fairly well because trait matching does not actually care about param-env // TypeOutlives predicates - these are normally used by regionck. let outlives_predicates: Vec<_> = predicates .drain_filter(|predicate| { From 0e65003c9e0ea97d7fcfbdb01cca181558b5fa15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vennberg?= Date: Sat, 14 Jan 2023 18:23:40 +0100 Subject: [PATCH 3/9] Fix some missed double spaces. --- compiler/rustc_borrowck/src/region_infer/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/typeck_results.rs | 2 +- compiler/rustc_parse/src/parser/pat.rs | 2 +- compiler/rustc_target/src/asm/mod.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 767f9fe39c6..c6e42336ef8 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -235,7 +235,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { /// # Parameters /// /// - `def_id`, the `impl Trait` type - /// - `substs`, the substs used to instantiate this opaque type + /// - `substs`, the substs used to instantiate this opaque type /// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of /// `opaque_defn.concrete_ty` #[instrument(level = "debug", skip(self))] diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 028a03c0b2b..b910bd888c0 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -193,7 +193,7 @@ pub struct TypeckResults<'tcx> { pub generator_interior_types: ty::Binder<'tcx, Vec>>, /// We sometimes treat byte string literals (which are of type `&[u8; N]`) - /// as `&[u8]`, depending on the pattern in which they are used. + /// as `&[u8]`, depending on the pattern in which they are used. /// This hashset records all instances where we behave /// like this to allow `const_to_pat` to reliably handle this situation. pub treat_byte_string_as_slice: ItemLocalSet, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 0b057f2f577..e73a17ced7d 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -469,7 +469,7 @@ impl<'a> Parser<'a> { /// Try to recover the more general form `intersect ::= $pat_lhs @ $pat_rhs`. /// /// Allowed binding patterns generated by `binding ::= ref? mut? $ident @ $pat_rhs` - /// should already have been parsed by now at this point, + /// should already have been parsed by now at this point, /// if the next token is `@` then we can try to parse the more general form. /// /// Consult `parse_pat_ident` for the `binding` grammar. diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 7f01f33d39c..70cd883be09 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -462,7 +462,7 @@ impl InlineAsmRegClass { } /// Returns a suggested template modifier to use for this type and an - /// example of a register named formatted with it. + /// example of a register named formatted with it. /// /// Such suggestions are useful if a type smaller than the full register /// size is used and a modifier can be used to point to the subregister of From de34489a019b8e5319c09504ca158022df188d49 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 14 Jan 2023 18:30:33 +0100 Subject: [PATCH 4/9] Add explanation for GUI test --- tests/rustdoc-gui/scrape-examples-button-focus.goml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/rustdoc-gui/scrape-examples-button-focus.goml b/tests/rustdoc-gui/scrape-examples-button-focus.goml index 10651a3f669..1b5c3a0d202 100644 --- a/tests/rustdoc-gui/scrape-examples-button-focus.goml +++ b/tests/rustdoc-gui/scrape-examples-button-focus.goml @@ -1,3 +1,5 @@ +// This test ensures that the scraped examples buttons are working as expecting +// when 'Enter' key is pressed when they're focused. goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html" // The next/prev buttons vertically scroll the code viewport between examples From 287c65838cd08904c740b6b412a0ea194d16002c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 14 Jan 2023 09:35:42 -0800 Subject: [PATCH 5/9] Fix the stability attributes for `std::os::fd`. As @bjorn3 pointed out [here], I used the wrong stability attribute in #98368 when making `std::os::fd` public. I set it to Rust 1.63, which was when io-safety was stabilized, but it should be Rust 1.66, which was when `std::os::fd` was stabilized. [here]: https://github.com/rust-lang/rust/pull/98368#discussion_r1063721420 --- library/std/src/os/fd/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/os/fd/mod.rs b/library/std/src/os/fd/mod.rs index c6aa7c77dbc..35de4860fe2 100644 --- a/library/std/src/os/fd/mod.rs +++ b/library/std/src/os/fd/mod.rs @@ -3,7 +3,7 @@ //! This module is supported on Unix platforms and WASI, which both use a //! similar file descriptor system for referencing OS resources. -#![stable(feature = "io_safety", since = "1.63.0")] +#![stable(feature = "os_fd", since = "1.66.0")] #![deny(unsafe_op_in_unsafe_fn)] // `RawFd`, `AsRawFd`, etc. @@ -19,7 +19,7 @@ mod net; mod tests; // Export the types and traits for the public API. -#[unstable(feature = "os_fd", issue = "98699")] +#[stable(feature = "os_fd", since = "1.66.0")] pub use owned::*; -#[unstable(feature = "os_fd", issue = "98699")] +#[stable(feature = "os_fd", since = "1.66.0")] pub use raw::*; From aa51a0f19ae571497a18d2f75e409a3944d4b736 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 15 Jan 2023 05:47:24 +0900 Subject: [PATCH 6/9] Add regression test for #92157 Signed-off-by: Yuki Okushi --- tests/ui/borrowck/issue-92157.rs | 40 ++++++++++++++++++++++++++++ tests/ui/borrowck/issue-92157.stderr | 11 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/ui/borrowck/issue-92157.rs create mode 100644 tests/ui/borrowck/issue-92157.stderr diff --git a/tests/ui/borrowck/issue-92157.rs b/tests/ui/borrowck/issue-92157.rs new file mode 100644 index 00000000000..6ee2320a603 --- /dev/null +++ b/tests/ui/borrowck/issue-92157.rs @@ -0,0 +1,40 @@ +#![feature(no_core)] +#![feature(lang_items)] + +#![no_core] + +#[cfg(target_os = "linux")] +#[link(name = "c")] +extern {} + +#[lang = "start"] +fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize { + //~^ ERROR: incorrect number of parameters for the `start` lang item + 40+2 +} + +#[lang = "sized"] +pub trait Sized {} +#[lang = "copy"] +pub trait Copy {} + +#[lang = "drop_in_place"] +#[allow(unconditional_recursion)] +pub unsafe fn drop_in_place(to_drop: *mut T) { + drop_in_place(to_drop) +} + +#[lang = "add"] +trait Add { + type Output; + fn add(self, other: RHS) -> Self::Output; +} + +impl Add for isize { + type Output = isize; + fn add(self, other: isize) -> isize { + self + other + } +} + +fn main() {} diff --git a/tests/ui/borrowck/issue-92157.stderr b/tests/ui/borrowck/issue-92157.stderr new file mode 100644 index 00000000000..a4010d73d05 --- /dev/null +++ b/tests/ui/borrowck/issue-92157.stderr @@ -0,0 +1,11 @@ +error: incorrect number of parameters for the `start` lang item + --> $DIR/issue-92157.rs:11:1 + | +LL | fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the `start` lang item should have four parameters, but found 3 + = note: the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize` + +error: aborting due to previous error + From cf5be0c3ac9ee3f6fb95a75d3ce8c75b6e771728 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 15 Jan 2023 05:52:22 +0900 Subject: [PATCH 7/9] Add regression test for #42114 Signed-off-by: Yuki Okushi --- .../higher-rank-trait-bounds/issue-42114.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/ui/higher-rank-trait-bounds/issue-42114.rs diff --git a/tests/ui/higher-rank-trait-bounds/issue-42114.rs b/tests/ui/higher-rank-trait-bounds/issue-42114.rs new file mode 100644 index 00000000000..01515fdc9d2 --- /dev/null +++ b/tests/ui/higher-rank-trait-bounds/issue-42114.rs @@ -0,0 +1,20 @@ +// check-pass + +fn lifetime<'a>() +where + &'a (): 'a, +{ + /* do nothing */ +} + +fn doesnt_work() +where + for<'a> &'a (): 'a, +{ + /* do nothing */ +} + +fn main() { + lifetime(); + doesnt_work(); +} From 208b781bdaca4343a8538f01abd6083e925046e6 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Sat, 14 Jan 2023 22:09:14 +0100 Subject: [PATCH 8/9] doc: fix typo --- library/core/src/num/int_macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 21518a3f551..b3cbe862a78 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1625,7 +1625,7 @@ macro_rules! int_impl { /// overflow. /// /// Performs "ternary subtraction" by subtracting both an integer - /// operandand a borrow-in bit from `self`, and returns a tuple of the + /// operand and a borrow-in bit from `self`, and returns a tuple of the /// difference along with a boolean indicating whether an arithmetic /// overflow would occur. On overflow, the wrapped value is returned. /// From 130d02b62e65c5f2a434eaec63c4249e9d508487 Mon Sep 17 00:00:00 2001 From: Nick Lamb Date: Sat, 14 Jan 2023 14:51:17 +0000 Subject: [PATCH 9/9] Improve E0308: suggest user meant to use byte literal, w/ tests and fix suggested by Nilstrieb Co-authored-by: nils <48135649+Nilstrieb@users.noreply.github.com> --- .../src/infer/error_reporting/mod.rs | 16 +++++++ .../suggestions/type-mismatch-byte-literal.rs | 18 ++++++++ .../type-mismatch-byte-literal.stderr | 42 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/ui/suggestions/type-mismatch-byte-literal.rs create mode 100644 tests/ui/suggestions/type-mismatch-byte-literal.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 533a3c768eb..abd99fc74da 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -1923,6 +1923,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (ty::Tuple(fields), _) => { self.emit_tuple_wrap_err(&mut err, span, found, fields) } + // If a byte was expected and the found expression is a char literal + // containing a single ASCII character, perhaps the user meant to write `b'c'` to + // specify a byte literal + (ty::Uint(ty::UintTy::U8), ty::Char) => { + if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) + && let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')) + && code.chars().next().map_or(false, |c| c.is_ascii()) + { + err.span_suggestion( + span, + "if you meant to write a byte literal, prefix with `b`", + format!("b'{}'", escape_literal(code)), + Applicability::MachineApplicable, + ); + } + } // If a character was expected and the found expression is a string literal // containing a single character, perhaps the user meant to write `'c'` to // specify a character literal (issue #92479) diff --git a/tests/ui/suggestions/type-mismatch-byte-literal.rs b/tests/ui/suggestions/type-mismatch-byte-literal.rs new file mode 100644 index 00000000000..34199f8c37c --- /dev/null +++ b/tests/ui/suggestions/type-mismatch-byte-literal.rs @@ -0,0 +1,18 @@ +// Tests that a suggestion is issued for type mismatch errors when a +// u8 is expected and a char literal which is ASCII is supplied. + +fn foo(_t: u8) {} + +fn main() { + let _x: u8 = 'X'; + //~^ ERROR: mismatched types [E0308] + //~| HELP: if you meant to write a byte literal, prefix with `b` + + foo('#'); + //~^ ERROR: mismatched types [E0308] + //~| HELP: if you meant to write a byte literal, prefix with `b` + + // Do not issue the suggestion if the char literal isn't ASCII + let _t: u8 = '€'; + //~^ ERROR: mismatched types [E0308] +} diff --git a/tests/ui/suggestions/type-mismatch-byte-literal.stderr b/tests/ui/suggestions/type-mismatch-byte-literal.stderr new file mode 100644 index 00000000000..c9c2e7498d0 --- /dev/null +++ b/tests/ui/suggestions/type-mismatch-byte-literal.stderr @@ -0,0 +1,42 @@ +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:7:18 + | +LL | let _x: u8 = 'X'; + | -- ^^^ expected `u8`, found `char` + | | + | expected due to this + | +help: if you meant to write a byte literal, prefix with `b` + | +LL | let _x: u8 = b'X'; + | ~~~~ + +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:11:9 + | +LL | foo('#'); + | --- ^^^ expected `u8`, found `char` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/type-mismatch-byte-literal.rs:4:4 + | +LL | fn foo(_t: u8) {} + | ^^^ ------ +help: if you meant to write a byte literal, prefix with `b` + | +LL | foo(b'#'); + | ~~~~ + +error[E0308]: mismatched types + --> $DIR/type-mismatch-byte-literal.rs:16:18 + | +LL | let _t: u8 = '€'; + | -- ^^^ expected `u8`, found `char` + | | + | expected due to this + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`.