From 9c7dbe82e736a657b298e41cd4640100218b37e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lanteri=20Thauvin?= Date: Thu, 31 Dec 2020 02:22:10 +0100 Subject: [PATCH 01/22] Notify when an `I-prioritize` issue is closed --- triagebot.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index c0cf50e516700..66cad406d4839 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -101,6 +101,8 @@ message_on_add = """\ - Needs `I-nominated`? """ message_on_remove = "Issue #{number}'s prioritization request has been removed." +message_on_close = "Issue #{number} has been closed while requested for prioritization." +message_on_reopen = "Issue #{number} has been reopened." [github-releases] format = "rustc" From 39ef8ea767f6dd953e63f8a0a4828dac37bed50c Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Thu, 22 Jul 2021 16:46:19 -0700 Subject: [PATCH 02/22] Refactor Markdown length-limited summary implementation This commit refactors the implementation of `markdown_summary_with_limit()`, separating the logic of determining when the limit has been reached from the actual rendering process. The main advantage of the new approach is that it guarantees that all HTML tags are closed, whereas the previous implementation could generate tags that were never closed. It also ensures that no empty tags are generated (e.g., ``). The new implementation consists of a general-purpose struct `HtmlWithLimit` that manages the length-limiting logic and a function `markdown_summary_with_limit()` that renders Markdown to HTML using the struct. --- src/librustdoc/html/length_limit.rs | 94 +++++++++++++++++++++++++++++ src/librustdoc/html/markdown.rs | 72 +++++++++------------- src/librustdoc/html/mod.rs | 1 + src/librustdoc/lib.rs | 1 + 4 files changed, 125 insertions(+), 43 deletions(-) create mode 100644 src/librustdoc/html/length_limit.rs diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs new file mode 100644 index 0000000000000..42b94b511181d --- /dev/null +++ b/src/librustdoc/html/length_limit.rs @@ -0,0 +1,94 @@ +//! See [`HtmlWithLimit`]. + +use std::fmt::Write; +use std::ops::ControlFlow; + +use crate::html::escape::Escape; + +/// A buffer that allows generating HTML with a length limit. +/// +/// This buffer ensures that: +/// +/// * all tags are closed, +/// * only the most recently opened tag is closed, +/// * no tags are left empty (e.g., ``) due to the length limit being reached, +/// * all text is escaped. +#[derive(Debug)] +pub(super) struct HtmlWithLimit { + buf: String, + len: usize, + limit: usize, + /// A list of tags that have been requested to be opened via [`Self::open_tag()`] + /// but have not actually been pushed to `buf` yet. This ensures that tags are not + /// left empty (e.g., ``) due to the length limit being reached. + queued_tags: Vec<&'static str>, + /// A list of all tags that have been opened but not yet closed. + unclosed_tags: Vec<&'static str>, +} + +impl HtmlWithLimit { + /// Create a new buffer, with a limit of `length_limit`. + pub(super) fn new(length_limit: usize) -> Self { + Self { + buf: String::new(), + len: 0, + limit: length_limit, + unclosed_tags: Vec::new(), + queued_tags: Vec::new(), + } + } + + /// Finish using the buffer and get the written output. + /// This function will close all unclosed tags for you. + pub(super) fn finish(mut self) -> String { + self.close_all_tags(); + self.buf + } + + /// Write some plain text to the buffer, escaping as needed. + /// + /// This function skips writing the text if the length limit was reached + /// and returns [`ControlFlow::Break`]. + pub(super) fn push(&mut self, text: &str) -> ControlFlow<(), ()> { + if self.len + text.len() > self.limit { + return ControlFlow::BREAK; + } + + self.flush_queue(); + write!(self.buf, "{}", Escape(text)).unwrap(); + self.len += text.len(); + + ControlFlow::CONTINUE + } + + /// Open an HTML tag. + pub(super) fn open_tag(&mut self, tag_name: &'static str) { + self.queued_tags.push(tag_name); + } + + /// Close the most recently opened HTML tag. + pub(super) fn close_tag(&mut self) { + let tag_name = self.unclosed_tags.pop().unwrap(); + self.buf.push_str("'); + } + + /// Write all queued tags and add them to the `unclosed_tags` list. + fn flush_queue(&mut self) { + for tag_name in self.queued_tags.drain(..) { + self.buf.push('<'); + self.buf.push_str(tag_name); + self.buf.push('>'); + + self.unclosed_tags.push(tag_name); + } + } + + /// Close all unclosed tags. + fn close_all_tags(&mut self) { + while !self.unclosed_tags.is_empty() { + self.close_tag(); + } + } +} diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 472323daf3017..5a569c690e548 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -23,12 +23,13 @@ use rustc_hir::HirId; use rustc_middle::ty::TyCtxt; use rustc_span::edition::Edition; use rustc_span::Span; + use std::borrow::Cow; use std::cell::RefCell; use std::collections::VecDeque; use std::default::Default; use std::fmt::Write; -use std::ops::Range; +use std::ops::{ControlFlow, Range}; use std::str; use crate::clean::RenderedLink; @@ -36,6 +37,7 @@ use crate::doctest; use crate::html::escape::Escape; use crate::html::format::Buffer; use crate::html::highlight; +use crate::html::length_limit::HtmlWithLimit; use crate::html::toc::TocBuilder; use pulldown_cmark::{ @@ -1081,15 +1083,6 @@ fn markdown_summary_with_limit( return (String::new(), false); } - let mut s = String::with_capacity(md.len() * 3 / 2); - let mut text_length = 0; - let mut stopped_early = false; - - fn push(s: &mut String, text_length: &mut usize, text: &str) { - write!(s, "{}", Escape(text)).unwrap(); - *text_length += text.len(); - } - let mut replacer = |broken_link: BrokenLink<'_>| { if let Some(link) = link_names.iter().find(|link| &*link.original_text == broken_link.reference) @@ -1101,56 +1094,49 @@ fn markdown_summary_with_limit( }; let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); - let p = LinkReplacer::new(p, link_names); + let mut p = LinkReplacer::new(p, link_names); - 'outer: for event in p { + // FIXME: capacity + let mut buf = HtmlWithLimit::new(length_limit); + let mut stopped_early = false; + p.try_for_each(|event| { match &event { Event::Text(text) => { - for word in text.split_inclusive(char::is_whitespace) { - if text_length + word.len() >= length_limit { - stopped_early = true; - break 'outer; - } - - push(&mut s, &mut text_length, word); + let r = + text.split_inclusive(char::is_whitespace).try_for_each(|word| buf.push(word)); + if r.is_break() { + stopped_early = true; } + return r; } Event::Code(code) => { - if text_length + code.len() >= length_limit { + buf.open_tag("code"); + let r = buf.push(code); + if r.is_break() { stopped_early = true; - break; + } else { + buf.close_tag(); } - - s.push_str(""); - push(&mut s, &mut text_length, code); - s.push_str(""); + return r; } Event::Start(tag) => match tag { - Tag::Emphasis => s.push_str(""), - Tag::Strong => s.push_str(""), - Tag::CodeBlock(..) => break, + Tag::Emphasis => buf.open_tag("em"), + Tag::Strong => buf.open_tag("strong"), + Tag::CodeBlock(..) => return ControlFlow::BREAK, _ => {} }, Event::End(tag) => match tag { - Tag::Emphasis => s.push_str(""), - Tag::Strong => s.push_str(""), - Tag::Paragraph => break, - Tag::Heading(..) => break, + Tag::Emphasis | Tag::Strong => buf.close_tag(), + Tag::Paragraph | Tag::Heading(..) => return ControlFlow::BREAK, _ => {} }, - Event::HardBreak | Event::SoftBreak => { - if text_length + 1 >= length_limit { - stopped_early = true; - break; - } - - push(&mut s, &mut text_length, " "); - } + Event::HardBreak | Event::SoftBreak => buf.push(" ")?, _ => {} - } - } + }; + ControlFlow::CONTINUE + }); - (s, stopped_early) + (buf.finish(), stopped_early) } /// Renders a shortened first paragraph of the given Markdown as a subset of Markdown, diff --git a/src/librustdoc/html/mod.rs b/src/librustdoc/html/mod.rs index 60ebdf5690d0d..109b0a356db5f 100644 --- a/src/librustdoc/html/mod.rs +++ b/src/librustdoc/html/mod.rs @@ -2,6 +2,7 @@ crate mod escape; crate mod format; crate mod highlight; crate mod layout; +mod length_limit; // used by the error-index generator, so it needs to be public pub mod markdown; crate mod render; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e02d92b11b844..ab94e0d568353 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -5,6 +5,7 @@ #![feature(rustc_private)] #![feature(array_methods)] #![feature(box_patterns)] +#![feature(control_flow_enum)] #![feature(in_band_lifetimes)] #![feature(nll)] #![feature(test)] From 09f0876dc63bb386bc07d182b1bf85afb61f7db6 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 12:39:17 -0700 Subject: [PATCH 03/22] Clarify wording in docs --- src/librustdoc/html/length_limit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 42b94b511181d..91e098979acf7 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -10,7 +10,7 @@ use crate::html::escape::Escape; /// This buffer ensures that: /// /// * all tags are closed, -/// * only the most recently opened tag is closed, +/// * tags are closed in the reverse order of when they were opened (i.e., the correct HTML order), /// * no tags are left empty (e.g., ``) due to the length limit being reached, /// * all text is escaped. #[derive(Debug)] From 74147b86c50ebdaa7d8420fcbf82fa647a6db394 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 16:58:29 -0700 Subject: [PATCH 04/22] Use the length limit as the initial capacity The length limit turns out to be a surprisingly good heuristic for initial allocation size. See here for more details [1]. [1]: https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 --- src/librustdoc/html/length_limit.rs | 12 +++++++++++- src/librustdoc/html/markdown.rs | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 91e098979acf7..cc4a7f37fe9aa 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -29,8 +29,18 @@ pub(super) struct HtmlWithLimit { impl HtmlWithLimit { /// Create a new buffer, with a limit of `length_limit`. pub(super) fn new(length_limit: usize) -> Self { + let buf = if length_limit > 1000 { + // If the length limit is really large, don't preallocate tons of memory. + String::new() + } else { + // The length limit is actually a good heuristic for initial allocation size. + // Measurements showed that using it as the initial capacity ended up using less memory + // than `String::new`. + // See https://github.com/rust-lang/rust/pull/88173#discussion_r692531631 for more. + String::with_capacity(length_limit) + }; Self { - buf: String::new(), + buf, len: 0, limit: length_limit, unclosed_tags: Vec::new(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5a569c690e548..b2ca134998188 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1096,7 +1096,6 @@ fn markdown_summary_with_limit( let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer)); let mut p = LinkReplacer::new(p, link_names); - // FIXME: capacity let mut buf = HtmlWithLimit::new(length_limit); let mut stopped_early = false; p.try_for_each(|event| { From d18936a731fa1d2bf49073bd0f059129ef1b0ef1 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 17:24:49 -0700 Subject: [PATCH 05/22] Use `write!` --- src/librustdoc/html/length_limit.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index cc4a7f37fe9aa..2b47033744fdd 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -79,17 +79,13 @@ impl HtmlWithLimit { /// Close the most recently opened HTML tag. pub(super) fn close_tag(&mut self) { let tag_name = self.unclosed_tags.pop().unwrap(); - self.buf.push_str("'); + write!(self.buf, "", tag_name).unwrap(); } /// Write all queued tags and add them to the `unclosed_tags` list. fn flush_queue(&mut self) { for tag_name in self.queued_tags.drain(..) { - self.buf.push('<'); - self.buf.push_str(tag_name); - self.buf.push('>'); + write!(self.buf, "<{}>", tag_name).unwrap(); self.unclosed_tags.push(tag_name); } From 4fcae2c89113e0767ee066a42f418261cebdc4bd Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 20:32:31 -0300 Subject: [PATCH 06/22] Add const and static TAIT tests --- .../static-const-types.rs | 16 +++++++++ .../static-const-types.stderr | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/static-const-types.rs create mode 100644 src/test/ui/type-alias-impl-trait/static-const-types.stderr diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.rs b/src/test/ui/type-alias-impl-trait/static-const-types.rs new file mode 100644 index 0000000000000..f630d27833503 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/static-const-types.rs @@ -0,0 +1,16 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME: This should compile, but it currently doesn't + +use std::fmt::Debug; + +type Foo = impl Debug; +//~^ ERROR: could not find defining uses + +static FOO1: Foo = 22_u32; +//~^ ERROR: mismatched types [E0308] +const FOO2: Foo = 22_u32; +//~^ ERROR: mismatched types [E0308] + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/static-const-types.stderr b/src/test/ui/type-alias-impl-trait/static-const-types.stderr new file mode 100644 index 0000000000000..72083d014fe3a --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/static-const-types.stderr @@ -0,0 +1,33 @@ +error[E0308]: mismatched types + --> $DIR/static-const-types.rs:11:20 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | static FOO1: Foo = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error[E0308]: mismatched types + --> $DIR/static-const-types.rs:13:19 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | const FOO2: Foo = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: could not find defining uses + --> $DIR/static-const-types.rs:8:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. From f8ca5764c36feab162893cd16b567d87edd4cf8e Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 18:14:25 -0700 Subject: [PATCH 07/22] Add tests for `HtmlWithLimit` --- src/librustdoc/html/length_limit.rs | 3 + src/librustdoc/html/length_limit/tests.rs | 117 ++++++++++++++++++++++ src/librustdoc/html/markdown/tests.rs | 2 + 3 files changed, 122 insertions(+) create mode 100644 src/librustdoc/html/length_limit/tests.rs diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 2b47033744fdd..ecf41f7afa7e3 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -98,3 +98,6 @@ impl HtmlWithLimit { } } } + +#[cfg(test)] +mod tests; diff --git a/src/librustdoc/html/length_limit/tests.rs b/src/librustdoc/html/length_limit/tests.rs new file mode 100644 index 0000000000000..5a006d44d58c5 --- /dev/null +++ b/src/librustdoc/html/length_limit/tests.rs @@ -0,0 +1,117 @@ +use super::*; + +#[test] +fn empty() { + assert_eq!(HtmlWithLimit::new(0).finish(), ""); + assert_eq!(HtmlWithLimit::new(60).finish(), ""); +} + +#[test] +fn basic() { + let mut buf = HtmlWithLimit::new(60); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn no_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.push("Hello"); + buf.push(" world!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn limit_0() { + let mut buf = HtmlWithLimit::new(0); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), ""); +} + +#[test] +fn exactly_limit() { + let mut buf = HtmlWithLimit::new(12); + buf.push("Hello "); + buf.open_tag("em"); + buf.push("world"); + buf.close_tag(); + buf.push("!"); + assert_eq!(buf.finish(), "Hello world!"); +} + +#[test] +fn multiple_nested_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("This is a "); + buf.open_tag("em"); + buf.push("paragraph"); + buf.open_tag("strong"); + buf.push("!"); + buf.close_tag(); + buf.close_tag(); + buf.close_tag(); + assert_eq!(buf.finish(), "

This is a paragraph!

"); +} + +#[test] +fn forgot_to_close_tags() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("This is a "); + buf.open_tag("em"); + buf.push("paragraph"); + buf.open_tag("strong"); + buf.push("!"); + assert_eq!(buf.finish(), "

This is a paragraph!

"); +} + +#[test] +fn past_the_limit() { + let mut buf = HtmlWithLimit::new(20); + buf.open_tag("p"); + (0..10).try_for_each(|n| { + buf.open_tag("strong"); + buf.push("word#")?; + buf.push(&n.to_string())?; + buf.close_tag(); + ControlFlow::CONTINUE + }); + buf.close_tag(); + assert_eq!( + buf.finish(), + "

\ + word#0\ + word#1\ + word#2\ +

" + ); +} + +#[test] +fn quickly_past_the_limit() { + let mut buf = HtmlWithLimit::new(6); + buf.open_tag("p"); + buf.push("Hello"); + buf.push(" World"); + // intentionally not closing

before finishing + assert_eq!(buf.finish(), "

Hello

"); +} + +#[test] +#[should_panic = "called `Option::unwrap()` on a `None` value"] +fn close_too_many() { + let mut buf = HtmlWithLimit::new(60); + buf.open_tag("p"); + buf.push("Hello"); + buf.close_tag(); + buf.close_tag(); +} diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 1e4bdc2d15199..eca75ef013aae 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -225,6 +225,7 @@ fn test_short_markdown_summary() { assert_eq!(output, expect, "original: {}", input); } + t("", ""); t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)"); t("*italic*", "italic"); t("**bold**", "bold"); @@ -264,6 +265,7 @@ fn test_plain_text_summary() { assert_eq!(output, expect, "original: {}", input); } + t("", ""); t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)"); t("**bold**", "bold"); t("Multi-line\nsummary", "Multi-line summary"); From d932e62dd9a6137a831d0917aa80aefd7ff47018 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 13:49:51 -0700 Subject: [PATCH 08/22] Assert that `tag_name` is alphabetic --- src/librustdoc/html/length_limit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index ecf41f7afa7e3..28a207a84ba6d 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -72,7 +72,15 @@ impl HtmlWithLimit { } /// Open an HTML tag. + /// + /// **Note:** HTML attributes have not yet been implemented. + /// This function will panic if called with a non-alphabetic `tag_name`. pub(super) fn open_tag(&mut self, tag_name: &'static str) { + assert!( + tag_name.chars().all(|c| ('a'..='z').contains(&c)), + "tag_name contained non-alphabetic chars: {:?}", + tag_name + ); self.queued_tags.push(tag_name); } From 4478ecc352d6f3f12c1cb4b9dd5e7e06762286ee Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 20:09:17 -0700 Subject: [PATCH 09/22] Don't panic if `close_tag()` is called without tags to close This can happen when a tag is opened after the length limit is reached; the tag will not end up being added to `unclosed_tags` because the queue will never be flushed. So, now, if the `unclosed_tags` stack is empty, `close_tag()` does nothing. This change fixes a panic in the `limit_0` unit test. --- src/librustdoc/html/length_limit.rs | 12 ++++++++++-- src/librustdoc/html/length_limit/tests.rs | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/length_limit.rs b/src/librustdoc/html/length_limit.rs index 28a207a84ba6d..bbdc91c8d2ec8 100644 --- a/src/librustdoc/html/length_limit.rs +++ b/src/librustdoc/html/length_limit.rs @@ -86,8 +86,16 @@ impl HtmlWithLimit { /// Close the most recently opened HTML tag. pub(super) fn close_tag(&mut self) { - let tag_name = self.unclosed_tags.pop().unwrap(); - write!(self.buf, "", tag_name).unwrap(); + match self.unclosed_tags.pop() { + // Close the most recently opened tag. + Some(tag_name) => write!(self.buf, "", tag_name).unwrap(), + // There are valid cases where `close_tag()` is called without + // there being any tags to close. For example, this occurs when + // a tag is opened after the length limit is exceeded; + // `flush_queue()` will never be called, and thus, the tag will + // not end up being added to `unclosed_tags`. + None => {} + } } /// Write all queued tags and add them to the `unclosed_tags` list. diff --git a/src/librustdoc/html/length_limit/tests.rs b/src/librustdoc/html/length_limit/tests.rs index 5a006d44d58c5..2d02b8a16da67 100644 --- a/src/librustdoc/html/length_limit/tests.rs +++ b/src/librustdoc/html/length_limit/tests.rs @@ -107,11 +107,14 @@ fn quickly_past_the_limit() { } #[test] -#[should_panic = "called `Option::unwrap()` on a `None` value"] fn close_too_many() { let mut buf = HtmlWithLimit::new(60); buf.open_tag("p"); buf.push("Hello"); buf.close_tag(); + // This call does not panic because there are valid cases + // where `close_tag()` is called with no tags left to close. + // So `close_tag()` does nothing in this case. buf.close_tag(); + assert_eq!(buf.finish(), "

Hello

"); } From bee13d18af34ce6056a0b76fb7652cafda52cb69 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 26 Aug 2021 12:57:42 +0200 Subject: [PATCH 10/22] add unsized coercion test --- .../unsized/param-mentioned-by-different-field.rs | 10 ++++++++++ .../param-mentioned-by-different-field.stderr | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/ui/unsized/param-mentioned-by-different-field.rs create mode 100644 src/test/ui/unsized/param-mentioned-by-different-field.stderr diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.rs b/src/test/ui/unsized/param-mentioned-by-different-field.rs new file mode 100644 index 0000000000000..cda94b306d333 --- /dev/null +++ b/src/test/ui/unsized/param-mentioned-by-different-field.rs @@ -0,0 +1,10 @@ +// We must not allow this with our current setup as `T` +// is mentioned both in the tail of `Foo` and by another +// field. +struct Foo(Box, T); + +fn main() { + let x: Foo<[u8; 1]> = Foo(Box::new([2]), [3]); + let y: &Foo<[u8]> = &x; //~ ERROR mismatched types + assert_eq!(y.0.len(), 1); +} diff --git a/src/test/ui/unsized/param-mentioned-by-different-field.stderr b/src/test/ui/unsized/param-mentioned-by-different-field.stderr new file mode 100644 index 0000000000000..d18fa6456f3ee --- /dev/null +++ b/src/test/ui/unsized/param-mentioned-by-different-field.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/param-mentioned-by-different-field.rs:8:25 + | +LL | let y: &Foo<[u8]> = &x; + | ---------- ^^ expected slice `[u8]`, found array `[u8; 1]` + | | + | expected due to this + | + = note: expected reference `&Foo<[u8]>` + found reference `&Foo<[u8; 1]>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From e6637284cca42cb497b6b767776136ede71c7119 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 27 Aug 2021 04:52:51 -0700 Subject: [PATCH 11/22] Remove vestigial rustfix tests. --- .../rustfix/closure-immutable-outer-variable.fixed | 10 ---------- src/test/rustfix/closure-immutable-outer-variable.rs | 10 ---------- src/test/rustfix/empty-no-fixes.fixed | 1 - src/test/rustfix/empty-no-fixes.rs | 1 - src/test/rustfix/empty-no-fixes.rs.fixed | 2 -- src/test/rustfix/issue-45562.fixed | 3 --- src/test/rustfix/issue-45562.rs | 3 --- ...d-extern-crate-rename-suggestion-formatting.fixed | 2 -- ...-bad-extern-crate-rename-suggestion-formatting.rs | 2 -- ...ue-46756-consider-borrowing-cast-or-binexpr.fixed | 12 ------------ ...issue-46756-consider-borrowing-cast-or-binexpr.rs | 12 ------------ src/test/rustfix/main-no-fixes.fixed | 1 - src/test/rustfix/main-no-fixes.rs | 1 - src/test/rustfix/main-no-fixes.rs.fixed | 1 - src/test/rustfix/missing-comma-in-match.fixed | 7 ------- src/test/rustfix/missing-comma-in-match.rs | 7 ------- src/test/rustfix/str-as-char.fixed | 3 --- src/test/rustfix/str-as-char.rs | 3 --- src/test/rustfix/tuple-float-index.fixed | 3 --- src/test/rustfix/tuple-float-index.rs | 3 --- 20 files changed, 87 deletions(-) delete mode 100644 src/test/rustfix/closure-immutable-outer-variable.fixed delete mode 100644 src/test/rustfix/closure-immutable-outer-variable.rs delete mode 100644 src/test/rustfix/empty-no-fixes.fixed delete mode 100644 src/test/rustfix/empty-no-fixes.rs delete mode 100644 src/test/rustfix/empty-no-fixes.rs.fixed delete mode 100644 src/test/rustfix/issue-45562.fixed delete mode 100644 src/test/rustfix/issue-45562.rs delete mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed delete mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs delete mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed delete mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs delete mode 100644 src/test/rustfix/main-no-fixes.fixed delete mode 100644 src/test/rustfix/main-no-fixes.rs delete mode 100644 src/test/rustfix/main-no-fixes.rs.fixed delete mode 100644 src/test/rustfix/missing-comma-in-match.fixed delete mode 100644 src/test/rustfix/missing-comma-in-match.rs delete mode 100644 src/test/rustfix/str-as-char.fixed delete mode 100644 src/test/rustfix/str-as-char.rs delete mode 100644 src/test/rustfix/tuple-float-index.fixed delete mode 100644 src/test/rustfix/tuple-float-index.rs diff --git a/src/test/rustfix/closure-immutable-outer-variable.fixed b/src/test/rustfix/closure-immutable-outer-variable.fixed deleted file mode 100644 index 05bbc13d714fa..0000000000000 --- a/src/test/rustfix/closure-immutable-outer-variable.fixed +++ /dev/null @@ -1,10 +0,0 @@ -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let mut y = true; - foo(Box::new(move || y = false) as Box<_>); -} diff --git a/src/test/rustfix/closure-immutable-outer-variable.rs b/src/test/rustfix/closure-immutable-outer-variable.rs deleted file mode 100644 index 6ed1bc12cb521..0000000000000 --- a/src/test/rustfix/closure-immutable-outer-variable.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Point at the captured immutable outer variable - -fn foo(mut f: Box) { - f(); -} - -fn main() { - let y = true; - foo(Box::new(move || y = false) as Box<_>); -} diff --git a/src/test/rustfix/empty-no-fixes.fixed b/src/test/rustfix/empty-no-fixes.fixed deleted file mode 100644 index 3724a00ce7ce0..0000000000000 --- a/src/test/rustfix/empty-no-fixes.fixed +++ /dev/null @@ -1 +0,0 @@ -// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs b/src/test/rustfix/empty-no-fixes.rs deleted file mode 100644 index 3724a00ce7ce0..0000000000000 --- a/src/test/rustfix/empty-no-fixes.rs +++ /dev/null @@ -1 +0,0 @@ -// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs.fixed b/src/test/rustfix/empty-no-fixes.rs.fixed deleted file mode 100644 index e30d3ae0965ae..0000000000000 --- a/src/test/rustfix/empty-no-fixes.rs.fixed +++ /dev/null @@ -1,2 +0,0 @@ -// compile-flags:--crate-type lib -fn foo() {} diff --git a/src/test/rustfix/issue-45562.fixed b/src/test/rustfix/issue-45562.fixed deleted file mode 100644 index 955b2cbf899ba..0000000000000 --- a/src/test/rustfix/issue-45562.fixed +++ /dev/null @@ -1,3 +0,0 @@ -#[no_mangle] pub static RAH: usize = 5; - -fn main() {} diff --git a/src/test/rustfix/issue-45562.rs b/src/test/rustfix/issue-45562.rs deleted file mode 100644 index a1ac07044e2c2..0000000000000 --- a/src/test/rustfix/issue-45562.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[no_mangle] pub const RAH: usize = 5; - -fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed deleted file mode 100644 index b4ae4dc1ab2f8..0000000000000 --- a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed +++ /dev/null @@ -1,2 +0,0 @@ -extern crate std as other_std; -fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs deleted file mode 100644 index a202b6c389a8c..0000000000000 --- a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs +++ /dev/null @@ -1,2 +0,0 @@ -extern crate std; -fn main() {} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed deleted file mode 100644 index bedc8e15ace6e..0000000000000 --- a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(&(behold as usize)); - light_flows_our_war_of_mocking_words(&(with_tears + 4)); -} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs deleted file mode 100644 index 9c7ae9657c003..0000000000000 --- a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(unused)] - -fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { - and_yet + 1 -} - -fn main() { - let behold: isize = 2; - let with_tears: usize = 3; - light_flows_our_war_of_mocking_words(behold as usize); - light_flows_our_war_of_mocking_words(with_tears + 4); -} diff --git a/src/test/rustfix/main-no-fixes.fixed b/src/test/rustfix/main-no-fixes.fixed deleted file mode 100644 index f328e4d9d04c3..0000000000000 --- a/src/test/rustfix/main-no-fixes.fixed +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs b/src/test/rustfix/main-no-fixes.rs deleted file mode 100644 index f328e4d9d04c3..0000000000000 --- a/src/test/rustfix/main-no-fixes.rs +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs.fixed b/src/test/rustfix/main-no-fixes.rs.fixed deleted file mode 100644 index f328e4d9d04c3..0000000000000 --- a/src/test/rustfix/main-no-fixes.rs.fixed +++ /dev/null @@ -1 +0,0 @@ -fn main() {} diff --git a/src/test/rustfix/missing-comma-in-match.fixed b/src/test/rustfix/missing-comma-in-match.fixed deleted file mode 100644 index d4696ab9547a6..0000000000000 --- a/src/test/rustfix/missing-comma-in-match.fixed +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - match &Some(3) { - &None => 1, - &Some(2) => { 3 } - _ => 2 - }; -} diff --git a/src/test/rustfix/missing-comma-in-match.rs b/src/test/rustfix/missing-comma-in-match.rs deleted file mode 100644 index fed796cffe6f9..0000000000000 --- a/src/test/rustfix/missing-comma-in-match.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - match &Some(3) { - &None => 1 - &Some(2) => { 3 } - _ => 2 - }; -} diff --git a/src/test/rustfix/str-as-char.fixed b/src/test/rustfix/str-as-char.fixed deleted file mode 100644 index 900fee94653c1..0000000000000 --- a/src/test/rustfix/str-as-char.fixed +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("●●"); -} diff --git a/src/test/rustfix/str-as-char.rs b/src/test/rustfix/str-as-char.rs deleted file mode 100644 index b446551fefa29..0000000000000 --- a/src/test/rustfix/str-as-char.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!('●●'); -} diff --git a/src/test/rustfix/tuple-float-index.fixed b/src/test/rustfix/tuple-float-index.fixed deleted file mode 100644 index 358a27d387820..0000000000000 --- a/src/test/rustfix/tuple-float-index.fixed +++ /dev/null @@ -1,3 +0,0 @@ -fn main () { - ((1, (2, 3)).1).1; -} diff --git a/src/test/rustfix/tuple-float-index.rs b/src/test/rustfix/tuple-float-index.rs deleted file mode 100644 index 72612252a8098..0000000000000 --- a/src/test/rustfix/tuple-float-index.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main () { - (1, (2, 3)).1.1; -} From 5eb960c8d9b33caade6fc637b8258f5a25572461 Mon Sep 17 00:00:00 2001 From: csmoe Date: Fri, 21 May 2021 10:11:40 +0800 Subject: [PATCH 12/22] add rustc-demangle assertion on mangled symbol --- compiler/rustc_symbol_mangling/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 7fb24ad1ed8e3..bea6cc12ad85b 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -250,10 +250,18 @@ fn compute_symbol_name( tcx.symbol_mangling_version(mangling_version_crate) }; - match mangling_version { + let symbol = match mangling_version { SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate), SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate), - } + }; + + debug_assert!( + rustc_demangle::try_demangle(&symbol).is_ok(), + "compute_symbol_name: `{}` cannot be demangled", + symbol + ); + + symbol } fn is_generic(substs: SubstsRef<'_>) -> bool { From 92e30f608b3ec9498a08b6bcc42da16a5d3329e8 Mon Sep 17 00:00:00 2001 From: klensy Date: Fri, 27 Aug 2021 17:38:53 +0300 Subject: [PATCH 13/22] crossbeam-deque v0.7.3 -> v0.7.4: https://rustsec.org/advisories/RUSTSEC-2021-0093 https://github.com/crossbeam-rs/crossbeam/pull/728/files openssl-src v111.15.0+1.1.1k -> v111.16.0+1.1.1l: https://rustsec.org/advisories/RUSTSEC-2021-0097 https://rustsec.org/advisories/RUSTSEC-2021-0098 https://www.openssl.org/news/vulnerabilities-1.1.1.html tar v0.4.35 -> v0.4.37: https://rustsec.org/advisories/RUSTSEC-2021-0080 updated to 0.4.37 as there breaking change in 0.4.36: https://github.com/alexcrichton/tar-rs/pull/260 --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cef4f11da801d..c861e020f5918 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -765,9 +765,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" dependencies = [ "crossbeam-epoch", "crossbeam-utils 0.7.2", @@ -2368,9 +2368,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" -version = "111.15.0+1.1.1k" +version = "111.16.0+1.1.1l" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a5f6ae2ac04393b217ea9f700cd04fa9bf3d93fae2872069f3d15d908af70a" +checksum = "7ab2173f69416cf3ec12debb5823d244127d23a9b127d5a5189aa97c5fa2859f" dependencies = [ "cc", ] @@ -4967,9 +4967,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d779dc6aeff029314570f666ec83f19df7280bb36ef338442cfa8c604021b80" +checksum = "d6f5515d3add52e0bbdcad7b83c388bb36ba7b754dda3b5f5bc2d38640cdba5c" dependencies = [ "filetime", "libc", From 7a46ff5981bc6f27a1a325f564adf7cff161a8ec Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 27 Aug 2021 14:03:04 -0700 Subject: [PATCH 14/22] Fix formatting in release notes from 52a988344bce118347d6a6567e67e20b7e99dc25 --- RELEASES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index dd299ca936ace..a6c1b0f50ce70 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -70,7 +70,8 @@ Cargo - [The package definition in `cargo metadata` now includes the `"default_run"` field from the manifest.][cargo/9550] - [Added `cargo d` as an alias for `cargo doc`.][cargo/9680] -- [Added `{lib}` as formatting option for `cargo tree` to print the "lib_name" of packages.][cargo/9663] +- [Added `{lib}` as formatting option for `cargo tree` to print the `"lib_name"` + of packages.][cargo/9663] Rustdoc ------- @@ -119,6 +120,7 @@ Compatibility Notes [cargo/9675]: https://github.com/rust-lang/cargo/pull/9675 [cargo/9550]: https://github.com/rust-lang/cargo/pull/9550 [cargo/9680]: https://github.com/rust-lang/cargo/pull/9680 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [`array::map`]: https://doc.rust-lang.org/stable/std/primitive.array.html#method.map [`Bound::cloned`]: https://doc.rust-lang.org/stable/std/ops/enum.Bound.html#method.cloned [`Drain::as_str`]: https://doc.rust-lang.org/stable/std/string/struct.Drain.html#method.as_str From 0d1d9788e5a98268472f6c8538f4c0d18c4986c6 Mon Sep 17 00:00:00 2001 From: Ryan Zoeller Date: Thu, 26 Aug 2021 23:37:36 -0500 Subject: [PATCH 15/22] Handle stack_t.ss_sp type change for DragonFlyBSD stack_t.ss_sp is now c_void on DragonFlyBSD, so the specialization is no longer needed. Changed in https://github.com/rust-lang/libc/commit/02922ef7504906589d02c2e4d97d1172fa247cc3. --- library/std/src/sys/unix/stack_overflow.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs index 81f47a779d33b..e8747e39bcbf4 100644 --- a/library/std/src/sys/unix/stack_overflow.rs +++ b/library/std/src/sys/unix/stack_overflow.rs @@ -161,24 +161,10 @@ mod imp { stackp.add(page_size()) } - #[cfg(any( - target_os = "linux", - target_os = "macos", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_os = "illumos" - ))] unsafe fn get_stack() -> libc::stack_t { libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ } } - #[cfg(target_os = "dragonfly")] - unsafe fn get_stack() -> libc::stack_t { - libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ } - } - pub unsafe fn make_handler() -> Handler { if !NEED_ALTSTACK.load(Ordering::Relaxed) { return Handler::null(); From 672d370764862272735466346e9291dbf3163aeb Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 27 Aug 2021 18:28:22 -0500 Subject: [PATCH 16/22] Remove `Session.if_let_suggestions` We can instead if either the LHS or RHS types contain `TyKind::Error`. In addition to covering the case where we would have previously updated `if_let_suggestions`, this might also prevent redundant errors in other cases as well. --- compiler/rustc_resolve/src/late/diagnostics.rs | 1 - compiler/rustc_session/src/session.rs | 4 ---- compiler/rustc_typeck/src/check/expr.rs | 7 ++++--- src/test/ui/suggestions/if-let-typo.rs | 1 + src/test/ui/suggestions/if-let-typo.stderr | 13 ++++++++++++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 9d923599db761..b3601ecf1d3ac 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -215,7 +215,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { "let ".to_string(), Applicability::MaybeIncorrect, ); - self.r.session.if_let_suggestions.borrow_mut().insert(*span); } _ => {} } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 20e94e32be61f..18b9339558797 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -209,9 +209,6 @@ pub struct Session { /// Set of enabled features for the current target. pub target_features: FxHashSet, - - /// `Span`s for `if` conditions that we have suggested turning into `if let`. - pub if_let_suggestions: Lock>, } pub struct PerfStats { @@ -1328,7 +1325,6 @@ pub fn build_session( miri_unleashed_features: Lock::new(Default::default()), asm_arch, target_features: FxHashSet::default(), - if_let_suggestions: Default::default(), }; validate_commandline_args_with_session_available(&sess); diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index ab927b7944223..51c646e500ca3 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -919,9 +919,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - if self.sess().if_let_suggestions.borrow().get(&expr.span).is_some() { - // We already emitted an `if let` suggestion due to an identifier not found. - err.delay_as_bug(); + // If the assignment expression itself is ill-formed, don't + // bother emitting another error + if lhs_ty.references_error() || rhs_ty.references_error() { + err.delay_as_bug() } else { err.emit(); } diff --git a/src/test/ui/suggestions/if-let-typo.rs b/src/test/ui/suggestions/if-let-typo.rs index 688b6e8265826..b9714b67e5888 100644 --- a/src/test/ui/suggestions/if-let-typo.rs +++ b/src/test/ui/suggestions/if-let-typo.rs @@ -10,4 +10,5 @@ fn main() { if Some(3) = foo {} //~ ERROR mismatched types //~^ ERROR destructuring assignments are unstable //~^^ ERROR invalid left-hand side of assignment + if x = 5 {} //~ ERROR cannot find value `x` in this scope } diff --git a/src/test/ui/suggestions/if-let-typo.stderr b/src/test/ui/suggestions/if-let-typo.stderr index 1e23ede7adc87..7f71cb485815f 100644 --- a/src/test/ui/suggestions/if-let-typo.stderr +++ b/src/test/ui/suggestions/if-let-typo.stderr @@ -9,6 +9,17 @@ help: you might have meant to use pattern matching LL | if let Some(x) = foo {} | +++ +error[E0425]: cannot find value `x` in this scope + --> $DIR/if-let-typo.rs:13:8 + | +LL | if x = 5 {} + | ^ not found in this scope + | +help: you might have meant to use pattern matching + | +LL | if let x = 5 {} + | +++ + error[E0658]: destructuring assignments are unstable --> $DIR/if-let-typo.rs:4:16 | @@ -79,7 +90,7 @@ error[E0308]: mismatched types LL | if Some(3) = foo {} | ^^^^^^^^^^^^^ expected `bool`, found `()` -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0070, E0308, E0425, E0658. For more information about an error, try `rustc --explain E0070`. From 2de6c14b25b63e30b37aa6124ac0c6beea131ed7 Mon Sep 17 00:00:00 2001 From: Cheng XU Date: Fri, 27 Aug 2021 23:21:50 -0700 Subject: [PATCH 17/22] RELEASES.md: fix broken link --- RELEASES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASES.md b/RELEASES.md index dd299ca936ace..5b8193c7e9e85 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -116,6 +116,7 @@ Compatibility Notes [79965]: https://github.com/rust-lang/rust/pull/79965 [87370]: https://github.com/rust-lang/rust/pull/87370 [87298]: https://github.com/rust-lang/rust/pull/87298 +[cargo/9663]: https://github.com/rust-lang/cargo/pull/9663 [cargo/9675]: https://github.com/rust-lang/cargo/pull/9675 [cargo/9550]: https://github.com/rust-lang/cargo/pull/9550 [cargo/9680]: https://github.com/rust-lang/cargo/pull/9680 From 1c3aedd23ab89b03bae389ec501845d03da63015 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 28 Aug 2021 11:43:21 +0200 Subject: [PATCH 18/22] Fix code blocks color in ayu theme --- src/librustdoc/html/static/css/themes/ayu.css | 2 +- src/test/rustdoc-gui/src/test_docs/lib.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index dab6d655c6a87..f9ddef4120bbe 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -40,7 +40,7 @@ h4 { .code-header { color: #e6e1cf; } -pre > code { +.docblock pre > code, pre > code { color: #e6e1cf; } span code { diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index bed72ccb9f929..af4f28047fc0d 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -25,6 +25,8 @@ use std::fmt; /// ```ignore (it's a test) /// Let's say I'm just some text will ya? /// ``` +/// +/// An inlined `code`! pub fn foo() {} /// Just a normal struct. From 261ee26ac53c5fc034587d2a3710142991da8249 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 28 Aug 2021 11:43:55 +0200 Subject: [PATCH 19/22] Add test for code blocks color --- src/test/rustdoc-gui/ayu-code-tag-colors.goml | 13 -------- src/test/rustdoc-gui/code-color.goml | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) delete mode 100644 src/test/rustdoc-gui/ayu-code-tag-colors.goml create mode 100644 src/test/rustdoc-gui/code-color.goml diff --git a/src/test/rustdoc-gui/ayu-code-tag-colors.goml b/src/test/rustdoc-gui/ayu-code-tag-colors.goml deleted file mode 100644 index 50af36fa3d641..0000000000000 --- a/src/test/rustdoc-gui/ayu-code-tag-colors.goml +++ /dev/null @@ -1,13 +0,0 @@ -// The ayu theme has a different color for the "" tags in the doc blocks. We need to -// check that the rule isn't applied on other "" elements. -goto: file://|DOC_PATH|/test_docs/enum.AnEnum.html -// We need to show the text, otherwise the colors aren't "computed" by the web browser. -show-text: true -// We set the theme to ayu. -local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"} -// We reload to get the text appearing and the theme applied. -reload: - -assert-css: (".docblock code", {"color": "rgb(255, 180, 84)"}, ALL) -// It includes variants and the "titles" as well (for example: "impl RefUnwindSafe for AnEnum"). -assert-css: ("div:not(.docblock) > code", {"color": "rgb(197, 197, 197)"}, ALL) diff --git a/src/test/rustdoc-gui/code-color.goml b/src/test/rustdoc-gui/code-color.goml new file mode 100644 index 0000000000000..2f95bfb6b177f --- /dev/null +++ b/src/test/rustdoc-gui/code-color.goml @@ -0,0 +1,30 @@ +// The ayu theme has a different color for the "" tags in the doc blocks. We need to +// check that the rule isn't applied on other "" elements. +// +// While we're at it, we also check it for the other themes. +goto: file://|DOC_PATH|/test_docs/fn.foo.html +// If the text isn't displayed, the browser doesn't compute color style correctly... +show-text: true +// Set the theme to dark. +local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(221, 221, 221)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(221, 221, 221)"}, ALL) + +// Set the theme to ayu. +local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(230, 225, 207)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(255, 180, 84)"}, ALL) + +// Set the theme to light. +local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} +// We reload the page so the local storage settings are being used. +reload: + +assert-css: (".docblock pre > code", {"color": "rgb(0, 0, 0)"}, ALL) +assert-css: (".docblock > p > code", {"color": "rgb(0, 0, 0)"}, ALL) From e4368de7b1a70ca2c9f140570fdbbe974c737bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 17 Mar 2021 18:45:49 -0700 Subject: [PATCH 20/22] Suggestion for call on immutable binding of mutable type When calling a method requiring a mutable self borrow on an inmutable to a mutable borrow of the type, suggest making the binding mutable. Fix #83241. --- .../diagnostics/mutability_errors.rs | 60 +++++++++++++++-- src/test/ui/borrowck/mut-borrow-of-mut-ref.rs | 28 +++++++- .../ui/borrowck/mut-borrow-of-mut-ref.stderr | 64 ++++++++++++++++--- src/test/ui/did_you_mean/issue-31424.stderr | 28 ++++++-- src/test/ui/did_you_mean/issue-34126.stderr | 14 +++- src/test/ui/nll/issue-51191.stderr | 28 ++++++-- 6 files changed, 188 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index 7be3f5414879e..f8a1b05f063c6 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -5,7 +5,10 @@ use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{ hir::place::PlaceBase, - mir::{self, ClearCrossCrate, Local, LocalDecl, LocalInfo, LocalKind, Location}, + mir::{ + self, BindingForm, ClearCrossCrate, ImplicitSelfKind, Local, LocalDecl, LocalInfo, + LocalKind, Location, + }, }; use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::{kw, Symbol}; @@ -241,13 +244,56 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { .map(|l| mut_borrow_of_mutable_ref(l, self.local_names[local])) .unwrap_or(false) => { + let decl = &self.body.local_decls[local]; err.span_label(span, format!("cannot {ACT}", ACT = act)); - err.span_suggestion( - span, - "try removing `&mut` here", - String::new(), - Applicability::MaybeIncorrect, - ); + if let Some(mir::Statement { + source_info, + kind: + mir::StatementKind::Assign(box ( + _, + mir::Rvalue::Ref( + _, + mir::BorrowKind::Mut { allow_two_phase_borrow: false }, + _, + ), + )), + .. + }) = &self.body[location.block].statements.get(location.statement_index) + { + match decl.local_info { + Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( + mir::VarBindingForm { + binding_mode: ty::BindingMode::BindByValue(Mutability::Not), + opt_ty_info: Some(sp), + opt_match_place: _, + pat_span: _, + }, + )))) => { + err.span_note(sp, "the binding is already a mutable borrow"); + } + _ => { + err.span_note( + decl.source_info.span, + "the binding is already a mutable borrow", + ); + } + } + err.span_help(source_info.span, "try removing `&mut` here"); + } else if decl.mutability == Mutability::Not + && !matches!( + decl.local_info, + Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf( + ImplicitSelfKind::MutRef + )))) + ) + { + err.span_suggestion_verbose( + decl.source_info.span.shrink_to_lo(), + "consider making the binding mutable", + "mut ".to_string(), + Applicability::MachineApplicable, + ); + } } // We want to suggest users use `let mut` for local (user diff --git a/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs b/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs index 3f092846dd4c0..7cdb16b282d54 100644 --- a/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs +++ b/src/test/ui/borrowck/mut-borrow-of-mut-ref.rs @@ -2,12 +2,36 @@ #![crate_type = "rlib"] pub fn f(b: &mut i32) { - g(&mut b); + //~^ NOTE the binding is already a mutable borrow + //~| NOTE the binding is already a mutable borrow + h(&mut b); //~^ ERROR cannot borrow + //~| NOTE cannot borrow as mutable //~| HELP try removing `&mut` here g(&mut &mut b); //~^ ERROR cannot borrow + //~| NOTE cannot borrow as mutable //~| HELP try removing `&mut` here } -pub fn g(_: &mut i32) {} +pub fn g(b: &mut i32) { //~ NOTE the binding is already a mutable borrow + h(&mut &mut b); + //~^ ERROR cannot borrow + //~| NOTE cannot borrow as mutable + //~| HELP try removing `&mut` here +} + +pub fn h(_: &mut i32) {} + +trait Foo { + fn bar(&mut self); +} + +impl Foo for &mut String { + fn bar(&mut self) {} +} + +pub fn baz(f: &mut String) { //~ HELP consider making the binding mutable + f.bar(); //~ ERROR cannot borrow `f` as mutable, as it is not declared as mutable + //~^ NOTE cannot borrow as mutable +} diff --git a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr index cb7355b233596..3ed54179b98db 100644 --- a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr +++ b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr @@ -1,21 +1,65 @@ error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable - --> $DIR/mut-borrow-of-mut-ref.rs:5:7 + --> $DIR/mut-borrow-of-mut-ref.rs:7:7 | -LL | g(&mut b); +LL | h(&mut b); + | ^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/mut-borrow-of-mut-ref.rs:4:13 + | +LL | pub fn f(b: &mut i32) { + | ^^^^^^^^ +help: try removing `&mut` here + --> $DIR/mut-borrow-of-mut-ref.rs:7:7 + | +LL | h(&mut b); | ^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable - --> $DIR/mut-borrow-of-mut-ref.rs:8:12 + --> $DIR/mut-borrow-of-mut-ref.rs:11:12 | LL | g(&mut &mut b); + | ^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/mut-borrow-of-mut-ref.rs:4:13 + | +LL | pub fn f(b: &mut i32) { + | ^^^^^^^^ +help: try removing `&mut` here + --> $DIR/mut-borrow-of-mut-ref.rs:11:12 + | +LL | g(&mut &mut b); + | ^^^^^^ + +error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable + --> $DIR/mut-borrow-of-mut-ref.rs:18:12 + | +LL | h(&mut &mut b); + | ^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/mut-borrow-of-mut-ref.rs:17:13 + | +LL | pub fn g(b: &mut i32) { + | ^^^^^^^^ +help: try removing `&mut` here + --> $DIR/mut-borrow-of-mut-ref.rs:18:12 + | +LL | h(&mut &mut b); | ^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here -error: aborting due to 2 previous errors +error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable + --> $DIR/mut-borrow-of-mut-ref.rs:35:5 + | +LL | f.bar(); + | ^ cannot borrow as mutable + | +help: consider making the binding mutable + | +LL | pub fn baz(mut f: &mut String) { + | ^^^ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0596`. diff --git a/src/test/ui/did_you_mean/issue-31424.stderr b/src/test/ui/did_you_mean/issue-31424.stderr index 838e81043db7b..88617381236d7 100644 --- a/src/test/ui/did_you_mean/issue-31424.stderr +++ b/src/test/ui/did_you_mean/issue-31424.stderr @@ -1,11 +1,19 @@ error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-31424.rs:7:9 | +LL | (&mut self).bar(); + | ^^^^^^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/issue-31424.rs:6:12 + | +LL | fn foo(&mut self) { + | ^^^^^^^^^ +help: try removing `&mut` here + --> $DIR/issue-31424.rs:7:9 + | LL | (&mut self).bar(); | ^^^^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here warning: function cannot return without recursing --> $DIR/issue-31424.rs:13:5 @@ -22,11 +30,19 @@ LL | (&mut self).bar(); error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-31424.rs:16:9 | +LL | (&mut self).bar(); + | ^^^^^^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/issue-31424.rs:13:18 + | +LL | fn bar(self: &mut Self) { + | ^^^^^^^^^ +help: try removing `&mut` here + --> $DIR/issue-31424.rs:16:9 + | LL | (&mut self).bar(); | ^^^^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here error: aborting due to 2 previous errors; 1 warning emitted diff --git a/src/test/ui/did_you_mean/issue-34126.stderr b/src/test/ui/did_you_mean/issue-34126.stderr index 669684fb3ddd7..a8c031686c081 100644 --- a/src/test/ui/did_you_mean/issue-34126.stderr +++ b/src/test/ui/did_you_mean/issue-34126.stderr @@ -1,11 +1,19 @@ error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-34126.rs:6:18 | +LL | self.run(&mut self); + | ^^^^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/issue-34126.rs:5:14 + | +LL | fn start(&mut self) { + | ^^^^^^^^^ +help: try removing `&mut` here + --> $DIR/issue-34126.rs:6:18 + | LL | self.run(&mut self); | ^^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable --> $DIR/issue-34126.rs:6:18 diff --git a/src/test/ui/nll/issue-51191.stderr b/src/test/ui/nll/issue-51191.stderr index 450993425e26b..18696f57c44ae 100644 --- a/src/test/ui/nll/issue-51191.stderr +++ b/src/test/ui/nll/issue-51191.stderr @@ -13,11 +13,19 @@ LL | (&mut self).bar(); error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-51191.rs:7:9 | +LL | (&mut self).bar(); + | ^^^^^^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/issue-51191.rs:4:18 + | +LL | fn bar(self: &mut Self) { + | ^^^^^^^^^ +help: try removing `&mut` here + --> $DIR/issue-51191.rs:7:9 + | LL | (&mut self).bar(); | ^^^^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-51191.rs:13:9 @@ -42,11 +50,19 @@ LL | (&mut self).bar(); error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable --> $DIR/issue-51191.rs:28:9 | +LL | (&mut self).bar(); + | ^^^^^^^^^^^ cannot borrow as mutable + | +note: the binding is already a mutable borrow + --> $DIR/issue-51191.rs:27:16 + | +LL | fn mtblref(&mut self) { + | ^^^^^^^^^ +help: try removing `&mut` here + --> $DIR/issue-51191.rs:28:9 + | LL | (&mut self).bar(); | ^^^^^^^^^^^ - | | - | cannot borrow as mutable - | help: try removing `&mut` here error: aborting due to 5 previous errors; 1 warning emitted From a6af6d6506e0420f2a62ce519db029c97f8cdd0b Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Mon, 9 Aug 2021 11:05:50 +0000 Subject: [PATCH 21/22] Provide structured suggestion for removal of `&mut` --- .../diagnostics/mutability_errors.rs | 22 +++++++++++++++++-- .../ui/borrowck/mut-borrow-of-mut-ref.stderr | 15 +++++-------- src/test/ui/did_you_mean/issue-34126.stderr | 5 ++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index f8a1b05f063c6..4e079ed865ac3 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -12,7 +12,7 @@ use rustc_middle::{ }; use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::{kw, Symbol}; -use rustc_span::Span; +use rustc_span::{BytePos, Span}; use crate::borrow_check::diagnostics::BorrowedContentSource; use crate::borrow_check::MirBorrowckCtxt; @@ -278,7 +278,25 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); } } - err.span_help(source_info.span, "try removing `&mut` here"); + if let Ok(snippet) = + self.infcx.tcx.sess.source_map().span_to_snippet(source_info.span) + { + if snippet.starts_with("&mut ") { + // We don't have access to the HIR to get accurate spans, but we can + // give a best effort structured suggestion. + err.span_suggestion_verbose( + source_info.span.with_hi(source_info.span.lo() + BytePos(5)), + "try removing `&mut` here", + String::new(), + Applicability::MachineApplicable, + ); + } else { + // This can occur with things like `(&mut self).foo()`. + err.span_help(source_info.span, "try removing `&mut` here"); + } + } else { + err.span_help(source_info.span, "try removing `&mut` here"); + } } else if decl.mutability == Mutability::Not && !matches!( decl.local_info, diff --git a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr index 3ed54179b98db..aa7771a736cfe 100644 --- a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr +++ b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr @@ -10,10 +10,9 @@ note: the binding is already a mutable borrow LL | pub fn f(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here - --> $DIR/mut-borrow-of-mut-ref.rs:7:7 | -LL | h(&mut b); - | ^^^^^^ +LL | h(b); + | -- error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:11:12 @@ -27,10 +26,9 @@ note: the binding is already a mutable borrow LL | pub fn f(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here - --> $DIR/mut-borrow-of-mut-ref.rs:11:12 | -LL | g(&mut &mut b); - | ^^^^^^ +LL | g(&mut b); + | -- error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:18:12 @@ -44,10 +42,9 @@ note: the binding is already a mutable borrow LL | pub fn g(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here - --> $DIR/mut-borrow-of-mut-ref.rs:18:12 | -LL | h(&mut &mut b); - | ^^^^^^ +LL | h(&mut b); + | -- error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:35:5 diff --git a/src/test/ui/did_you_mean/issue-34126.stderr b/src/test/ui/did_you_mean/issue-34126.stderr index a8c031686c081..86bc27106a9c1 100644 --- a/src/test/ui/did_you_mean/issue-34126.stderr +++ b/src/test/ui/did_you_mean/issue-34126.stderr @@ -10,10 +10,9 @@ note: the binding is already a mutable borrow LL | fn start(&mut self) { | ^^^^^^^^^ help: try removing `&mut` here - --> $DIR/issue-34126.rs:6:18 | -LL | self.run(&mut self); - | ^^^^^^^^^ +LL | self.run(self); + | -- error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable --> $DIR/issue-34126.rs:6:18 From 5b6f4b94c5679c9cce70d42cb4cbdbd55da2e0f7 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Sun, 29 Aug 2021 08:48:36 +0000 Subject: [PATCH 22/22] rebase: fix test output --- .../ui/borrowck/mut-borrow-of-mut-ref.stderr | 17 ++++++++++------- src/test/ui/did_you_mean/issue-34126.stderr | 5 +++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr index aa7771a736cfe..e4c51bb77c9ed 100644 --- a/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr +++ b/src/test/ui/borrowck/mut-borrow-of-mut-ref.stderr @@ -11,8 +11,9 @@ LL | pub fn f(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here | -LL | h(b); - | -- +LL - h(&mut b); +LL + h(b); + | error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:11:12 @@ -27,8 +28,9 @@ LL | pub fn f(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here | -LL | g(&mut b); - | -- +LL - g(&mut &mut b); +LL + g(&mut b); + | error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:18:12 @@ -43,8 +45,9 @@ LL | pub fn g(b: &mut i32) { | ^^^^^^^^ help: try removing `&mut` here | -LL | h(&mut b); - | -- +LL - h(&mut &mut b); +LL + h(&mut b); + | error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable --> $DIR/mut-borrow-of-mut-ref.rs:35:5 @@ -55,7 +58,7 @@ LL | f.bar(); help: consider making the binding mutable | LL | pub fn baz(mut f: &mut String) { - | ^^^ + | +++ error: aborting due to 4 previous errors diff --git a/src/test/ui/did_you_mean/issue-34126.stderr b/src/test/ui/did_you_mean/issue-34126.stderr index 86bc27106a9c1..666172197ce9b 100644 --- a/src/test/ui/did_you_mean/issue-34126.stderr +++ b/src/test/ui/did_you_mean/issue-34126.stderr @@ -11,8 +11,9 @@ LL | fn start(&mut self) { | ^^^^^^^^^ help: try removing `&mut` here | -LL | self.run(self); - | -- +LL - self.run(&mut self); +LL + self.run(self); + | error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable --> $DIR/issue-34126.rs:6:18