提交 daa4dc99 编写于 作者: B bors

Auto merge of #88461 - GuillaumeGomez:rollup-khgu0eb, r=GuillaumeGomez

Rollup of 13 pull requests

Successful merges:

 - #80543 (Notify when an `I-prioritize` issue is closed or reopened)
 - #83251 (Suggestion for call on immutable binding of mutable type)
 - #85534 (add rustc-demangle assertion on mangled symbol)
 - #88173 (Refactor Markdown length-limited summary implementation)
 - #88349 (Add const and static TAIT tests)
 - #88357 (add unsized coercion test)
 - #88381 (Handle stack_t.ss_sp type change for DragonFlyBSD)
 - #88387 (Remove vestigial rustfix tests.)
 - #88396 (Bump vulnerable crates)
 - #88407 (Fix formatting in release notes from 52a98834)
 - #88411 (Remove `Session.if_let_suggestions`)
 - #88417 (RELEASES.md: fix broken link)
 - #88419 (Fix code blocks color in Ayu theme)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
......@@ -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",
]
......@@ -4968,9 +4968,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",
......
......@@ -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
-------
......@@ -116,9 +117,11 @@ 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
[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
......
......@@ -5,11 +5,14 @@
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};
use rustc_span::Span;
use rustc_span::{BytePos, Span};
use crate::borrow_check::diagnostics::BorrowedContentSource;
use crate::borrow_check::MirBorrowckCtxt;
......@@ -241,13 +244,74 @@ pub(crate) fn report_mutability_error(
.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",
);
}
}
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,
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
......
......@@ -215,7 +215,6 @@ pub(crate) fn smart_resolve_report_errors(
"let ".to_string(),
Applicability::MaybeIncorrect,
);
self.r.session.if_let_suggestions.borrow_mut().insert(*span);
}
_ => {}
}
......
......@@ -209,9 +209,6 @@ pub struct Session {
/// Set of enabled features for the current target.
pub target_features: FxHashSet<Symbol>,
/// `Span`s for `if` conditions that we have suggested turning into `if let`.
pub if_let_suggestions: Lock<FxHashSet<Span>>,
}
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);
......
......@@ -246,10 +246,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 {
......
......@@ -919,9 +919,10 @@ fn check_expr_assign(
);
}
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();
}
......
......@@ -161,24 +161,10 @@ unsafe fn get_stackp() -> *mut libc::c_void {
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();
......
//! 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,
/// * 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., `<em></em>`) 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., `<em></em>`) 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 {
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,
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.
///
/// **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);
}
/// Close the most recently opened HTML tag.
pub(super) fn close_tag(&mut self) {
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.
fn flush_queue(&mut self) {
for tag_name in self.queued_tags.drain(..) {
write!(self.buf, "<{}>", tag_name).unwrap();
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();
}
}
}
#[cfg(test)]
mod tests;
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 <em>world</em>!");
}
#[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 <em>world</em>!");
}
#[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(), "<p>This is a <em>paragraph<strong>!</strong></em></p>");
}
#[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(), "<p>This is a <em>paragraph<strong>!</strong></em></p>");
}
#[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(),
"<p>\
<strong>word#0</strong>\
<strong>word#1</strong>\
<strong>word#2</strong>\
</p>"
);
}
#[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 <p> before finishing
assert_eq!(buf.finish(), "<p>Hello</p>");
}
#[test]
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(), "<p>Hello</p>");
}
......@@ -23,12 +23,13 @@
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::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,48 @@ fn push(s: &mut String, text_length: &mut usize, text: &str) {
};
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 {
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("<code>");
push(&mut s, &mut text_length, code);
s.push_str("</code>");
return r;
}
Event::Start(tag) => match tag {
Tag::Emphasis => s.push_str("<em>"),
Tag::Strong => s.push_str("<strong>"),
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("</em>"),
Tag::Strong => s.push_str("</strong>"),
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,
......
......@@ -225,6 +225,7 @@ fn t(input: &str, expect: &str) {
assert_eq!(output, expect, "original: {}", input);
}
t("", "");
t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)");
t("*italic*", "<em>italic</em>");
t("**bold**", "<strong>bold</strong>");
......@@ -264,6 +265,7 @@ fn t(input: &str, expect: &str) {
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");
......
......@@ -2,6 +2,7 @@
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;
......
......@@ -40,7 +40,7 @@ h4 {
.code-header {
color: #e6e1cf;
}
pre > code {
.docblock pre > code, pre > code {
color: #e6e1cf;
}
span code {
......
......@@ -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)]
......
// The ayu theme has a different color for the "<code>" tags in the doc blocks. We need to
// check that the rule isn't applied on other "<code>" 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)
// The ayu theme has a different color for the "<code>" tags in the doc blocks. We need to
// check that the rule isn't applied on other "<code>" 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)
......@@ -25,6 +25,8 @@
/// ```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.
......
// Point at the captured immutable outer variable
fn foo(mut f: Box<FnMut()>) {
f();
}
fn main() {
let mut y = true;
foo(Box::new(move || y = false) as Box<_>);
}
// Point at the captured immutable outer variable
fn foo(mut f: Box<FnMut()>) {
f();
}
fn main() {
let y = true;
foo(Box::new(move || y = false) as Box<_>);
}
// compile-flags:--crate-type lib
// compile-flags:--crate-type lib
fn foo() {}
#[no_mangle] pub static RAH: usize = 5;
fn main() {}
#[no_mangle] pub const RAH: usize = 5;
fn main() {}
#![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));
}
#![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);
}
fn main() {
match &Some(3) {
&None => 1,
&Some(2) => { 3 }
_ => 2
};
}
fn main() {
match &Some(3) {
&None => 1
&Some(2) => { 3 }
_ => 2
};
}
fn main() {
println!("●●");
}
fn main() {
println!('●●');
}
......@@ -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
}
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);
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
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
|
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:8:12
--> $DIR/mut-borrow-of-mut-ref.rs:11:12
|
LL | g(&mut &mut b);
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^ 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
|
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
|
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
|
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
|
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 2 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0596`.
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
......
......@@ -2,10 +2,18 @@ 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
| help: try removing `&mut` here
| ^^^^^^^^^ 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
|
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
......
......@@ -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
......
......@@ -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
}
......@@ -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`.
#![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() {}
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`.
// 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<T: ?Sized>(Box<T>, 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);
}
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`.
......@@ -102,6 +102,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."
[notify-zulip."T-rustdoc"]
required_labels = ["I-nominated"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册