Skip to content

Rollup of 7 pull requests #87058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let Some(desc) = access_place_desc {
item_msg = format!("`{}`", desc);
reason = match error_access {
AccessKind::Mutate => format!(" which is behind {}", pointer_type),
AccessKind::Mutate => format!(", which is behind {}", pointer_type),
AccessKind::MutableBorrow => {
format!(", as it is behind {}", pointer_type)
}
Expand Down Expand Up @@ -897,16 +897,32 @@ fn suggest_ampmut<'tcx>(
) -> (Span, String) {
if let Some(assignment_rhs_span) = opt_assignment_rhs_span {
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) {
let is_mutbl = |ty: &str| -> bool {
if ty.starts_with("mut") {
let rest = &ty[3..];
match rest.chars().next() {
// e.g. `&mut x`
Some(c) if c.is_whitespace() => true,
// e.g. `&mut(x)`
Some('(') => true,
// e.g. `&mutablevar`
_ => false,
}
} else {
false
}
};
if let (true, Some(ws_pos)) =
(src.starts_with("&'"), src.find(|c: char| -> bool { c.is_whitespace() }))
{
let lt_name = &src[1..ws_pos];
let ty = &src[ws_pos..];
if !ty.trim_start().starts_with("mut") {
let ty = src[ws_pos..].trim_start();
if !is_mutbl(ty) {
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty));
}
} else if let Some(stripped) = src.strip_prefix('&') {
if !stripped.trim_start().starts_with("mut") {
let stripped = stripped.trim_start();
if !is_mutbl(stripped) {
return (assignment_rhs_span, format!("&mut {}", stripped));
}
}
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,17 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
fcx.write_method_call(self.call_expr.hir_id, method_callee);
}
None => {
span_bug!(
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
// lang items are not defined (issue #86238).
let mut err = fcx.inh.tcx.sess.struct_span_err(
self.call_expr.span,
"failed to find an overloaded call trait for closure call"
"failed to find an overloaded call trait for closure call",
);
err.help(
"make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
and have associated `call`/`call_mut`/`call_once` functions",
);
err.emit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl bool {
/// assert_eq!(false.then_some(0), None);
/// assert_eq!(true.then_some(0), Some(0));
/// ```
#[unstable(feature = "bool_to_option", issue = "64260")]
#[unstable(feature = "bool_to_option", issue = "80967")]
#[inline]
pub fn then_some<T>(self, t: T) -> Option<T> {
if self { Some(t) } else { None }
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub(crate) fn update_llvm_submodule(build: &Build) {
t!(std::fs::read_dir(dir)).next().is_none()
}

if !build.config.submodules {
return;
}

// NOTE: The check for the empty directory is here because when running x.py
// the first time, the llvm submodule won't be checked out. Check it out
// now so we can build it.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% The Rust Reference has moved

We've split up the reference into chapters. Please find it at its new
home [here](reference/index.html).
home [here](https://doc.rust-lang.org/stable/reference/introduction.html).
23 changes: 8 additions & 15 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,6 @@ window.initSearch = function(rawSearchIndex) {
};
}

function getObjectNameFromId(id) {
if (typeof id === "number") {
return searchIndex[id].name;
}
return id;
}

function checkGenerics(obj, val) {
// The names match, but we need to be sure that all generics kinda
// match as well.
Expand All @@ -306,10 +299,10 @@ window.initSearch = function(rawSearchIndex) {
var elems = Object.create(null);
var elength = obj[GENERICS_DATA].length;
for (var x = 0; x < elength; ++x) {
if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0;
if (!elems[obj[GENERICS_DATA][x]]) {
elems[obj[GENERICS_DATA][x]] = 0;
}
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
elems[obj[GENERICS_DATA][x]] += 1;
}
var total = 0;
var done = 0;
Expand All @@ -318,7 +311,7 @@ window.initSearch = function(rawSearchIndex) {
var vlength = val.generics.length;
for (x = 0; x < vlength; ++x) {
var lev = MAX_LEV_DISTANCE + 1;
var firstGeneric = getObjectNameFromId(val.generics[x]);
var firstGeneric = val.generics[x];
var match = null;
if (elems[firstGeneric]) {
match = firstGeneric;
Expand Down Expand Up @@ -361,16 +354,16 @@ window.initSearch = function(rawSearchIndex) {
var elems = Object.create(null);
len = obj[GENERICS_DATA].length;
for (x = 0; x < len; ++x) {
if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) {
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0;
if (!elems[obj[GENERICS_DATA][x]]) {
elems[obj[GENERICS_DATA][x]] = 0;
}
elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1;
elems[obj[GENERICS_DATA][x]] += 1;
}

var allFound = true;
len = val.generics.length;
for (x = 0; x < len; ++x) {
firstGeneric = getObjectNameFromId(val.generics[x]);
firstGeneric = val.generics[x];
if (elems[firstGeneric]) {
elems[firstGeneric] -= 1;
} else {
Expand Down
40 changes: 21 additions & 19 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ fn opts() -> Vec<RustcOptGroup> {
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;
vec![
stable("h", |o| o.optflag("h", "help", "show this help message")),
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
stable("h", |o| o.optflagmulti("h", "help", "show this help message")),
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")),
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")),
stable("r", |o| {
o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
}),
Expand Down Expand Up @@ -309,14 +309,14 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
stable("plugins", |o| o.optmulti("", "plugins", "removed", "PLUGINS")),
stable("no-default", |o| o.optflag("", "no-defaults", "don't run the default passes")),
stable("no-default", |o| o.optflagmulti("", "no-defaults", "don't run the default passes")),
stable("document-private-items", |o| {
o.optflag("", "document-private-items", "document private items")
o.optflagmulti("", "document-private-items", "document private items")
}),
unstable("document-hidden-items", |o| {
o.optflag("", "document-hidden-items", "document items that have doc(hidden)")
o.optflagmulti("", "document-hidden-items", "document items that have doc(hidden)")
}),
stable("test", |o| o.optflag("", "test", "run code examples as tests")),
stable("test", |o| o.optflagmulti("", "test", "run code examples as tests")),
stable("test-args", |o| {
o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS")
}),
Expand Down Expand Up @@ -386,7 +386,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL")
}),
stable("markdown-no-toc", |o| {
o.optflag("", "markdown-no-toc", "don't include table of contents")
o.optflagmulti("", "markdown-no-toc", "don't include table of contents")
}),
stable("e", |o| {
o.optopt(
Expand All @@ -412,13 +412,13 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("display-warnings", |o| {
o.optflag("", "display-warnings", "to print code warnings when testing doc")
o.optflagmulti("", "display-warnings", "to print code warnings when testing doc")
}),
stable("crate-version", |o| {
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
}),
unstable("sort-modules-by-appearance", |o| {
o.optflag(
o.optflagmulti(
"",
"sort-modules-by-appearance",
"sort modules by where they appear in the program, rather than alphabetically",
Expand Down Expand Up @@ -495,7 +495,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
}),
unstable("disable-minification", |o| {
o.optflag("", "disable-minification", "Disable minification applied on JS files")
o.optflagmulti("", "disable-minification", "Disable minification applied on JS files")
}),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")),
Expand Down Expand Up @@ -523,7 +523,7 @@ fn opts() -> Vec<RustcOptGroup> {
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
}),
unstable("enable-index-page", |o| {
o.optflag("", "enable-index-page", "To enable generation of the index page")
o.optflagmulti("", "enable-index-page", "To enable generation of the index page")
}),
unstable("static-root-path", |o| {
o.optopt(
Expand All @@ -535,7 +535,7 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("disable-per-crate-search", |o| {
o.optflag(
o.optflagmulti(
"",
"disable-per-crate-search",
"disables generating the crate selector on the search box",
Expand All @@ -550,14 +550,14 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("show-coverage", |o| {
o.optflag(
o.optflagmulti(
"",
"show-coverage",
"calculate percentage of public items with documentation",
)
}),
unstable("enable-per-target-ignores", |o| {
o.optflag(
o.optflagmulti(
"",
"enable-per-target-ignores",
"parse ignore-foo for ignoring doctests on a per-target basis",
Expand All @@ -582,9 +582,9 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("test-builder", |o| {
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH")
}),
unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")),
unstable("generate-redirect-map", |o| {
o.optflag(
o.optflagmulti(
"",
"generate-redirect-map",
"Generate JSON file at the top level instead of generating HTML redirection files",
Expand All @@ -598,9 +598,11 @@ fn opts() -> Vec<RustcOptGroup> {
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
)
}),
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
unstable("no-run", |o| {
o.optflagmulti("", "no-run", "Compile doctests without running them")
}),
unstable("show-type-layout", |o| {
o.optflag("", "show-type-layout", "Include the memory layout of types in the docs")
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
}),
]
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/rustdoc/duplicate-flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// compile-flags: --document-private-items --document-private-items

// @has duplicate_flags/struct.Private.html
struct Private;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5
|
LL | fn a(s: &S) {
| -- help: consider changing this to be a mutable reference: `&mut S<'_>`
LL | *s.pointer += 1;
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written

error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
|
LL | fn c(s: & &mut S) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0594]: cannot assign to `**t1` which is behind a `&` reference
error[E0594]: cannot assign to `**t1`, which is behind a `&` reference
--> $DIR/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs:9:5
|
LL | let t1 = t0;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-issue-14498.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0594]: cannot assign to `***p` which is behind a `&` reference
error[E0594]: cannot assign to `***p`, which is behind a `&` reference
--> $DIR/borrowck-issue-14498.rs:16:5
|
LL | let p = &y;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0594]: cannot assign to `*item` which is behind a `&` reference
error[E0594]: cannot assign to `*item`, which is behind a `&` reference
--> $DIR/issue-69789-iterator-mut-suggestion.rs:7:9
|
LL | for item in &mut std::iter::empty::<&'static ()>() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/issue-83309-ice-immut-in-for-loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
for v in Query.iter_mut() {
//~^ NOTE this iterator yields `&` references
*v -= 1;
//~^ ERROR cannot assign to `*v` which is behind a `&` reference
//~^ ERROR cannot assign to `*v`, which is behind a `&` reference
//~| NOTE `v` is a `&` reference, so the data it refers to cannot be written
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0594]: cannot assign to `*v` which is behind a `&` reference
error[E0594]: cannot assign to `*v`, which is behind a `&` reference
--> $DIR/issue-83309-ice-immut-in-for-loop.rs:11:9
|
LL | for v in Query.iter_mut() {
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/borrowck/issue-85765.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ fn main() {
rofl.push(Vec::new());
//~^ ERROR cannot borrow `*rofl` as mutable, as it is behind a `&` reference
//~| NOTE `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable

let mut mutvar = 42;
let r = &mutvar;
//~^ HELP consider changing this to be a mutable reference
*r = 0;
//~^ ERROR cannot assign to `*r`, which is behind a `&` reference
//~| NOTE `r` is a `&` reference, so the data it refers to cannot be written
}
14 changes: 12 additions & 2 deletions src/test/ui/borrowck/issue-85765.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ LL |
LL | rofl.push(Vec::new());
| ^^^^ `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable

error: aborting due to previous error
error[E0594]: cannot assign to `*r`, which is behind a `&` reference
--> $DIR/issue-85765.rs:12:5
|
LL | let r = &mutvar;
| ------- help: consider changing this to be a mutable reference: `&mut mutvar`
LL |
LL | *r = 0;
| ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
8 changes: 4 additions & 4 deletions src/test/ui/borrowck/mutability-errors.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0594]: cannot assign to `*x` which is behind a `&` reference
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
--> $DIR/mutability-errors.rs:9:5
|
LL | fn named_ref(x: &(i32,)) {
| ------- help: consider changing this to be a mutable reference: `&mut (i32,)`
LL | *x = (1,);
| ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written

error[E0594]: cannot assign to `x.0` which is behind a `&` reference
error[E0594]: cannot assign to `x.0`, which is behind a `&` reference
--> $DIR/mutability-errors.rs:10:5
|
LL | fn named_ref(x: &(i32,)) {
Expand Down Expand Up @@ -57,15 +57,15 @@ error[E0596]: cannot borrow data in a `&` reference as mutable
LL | &mut f().0;
| ^^^^^^^^^^ cannot borrow as mutable

error[E0594]: cannot assign to `*x` which is behind a `*const` pointer
error[E0594]: cannot assign to `*x`, which is behind a `*const` pointer
--> $DIR/mutability-errors.rs:23:5
|
LL | unsafe fn named_ptr(x: *const (i32,)) {
| ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)`
LL | *x = (1,);
| ^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written

error[E0594]: cannot assign to `x.0` which is behind a `*const` pointer
error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer
--> $DIR/mutability-errors.rs:24:5
|
LL | unsafe fn named_ptr(x: *const (i32,)) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-39544.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ pub fn with_tuple() {
let mut y = 0;
let x = (&y,);
*x.0 = 1;
//~^ ERROR cannot assign to `*x.0` which is behind a `&` reference
//~^ ERROR cannot assign to `*x.0`, which is behind a `&` reference
}
Loading