Skip to content
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

Rollup of 10 pull requests #81068

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5ccef56
Explain why borrows can't be held across yield point in async blocks
sledgehammervampire Jan 2, 2021
12f1795
Fix location of error message explanation
sledgehammervampire Jan 2, 2021
2b9c8ff
Update issue-78938-async-block.rs
sledgehammervampire Jan 2, 2021
9e345a5
Revise async block error message
sledgehammervampire Jan 9, 2021
757bd23
Remove trailing whitespace
sledgehammervampire Jan 9, 2021
04b6036
Make `--color always` apply to logging too
jyn514 Jan 11, 2021
3ee3071
Update src/test/ui/async-await/issues/issue-78938-async-block.stderr
sledgehammervampire Jan 12, 2021
b2f5048
stabilize the poll_map feature
KodrAus Jan 13, 2021
c200036
Put all feature gate tests under `feature-gates/`
camelid Jan 13, 2021
7f41465
Move help link to error index
sledgehammervampire Jan 13, 2021
f5c4287
Bless test output
sledgehammervampire Jan 13, 2021
a9ead34
Fix whitespace
sledgehammervampire Jan 13, 2021
174135f
Fix error E0373 documentation
sledgehammervampire Jan 14, 2021
63deae5
Fix E0373 code example
sledgehammervampire Jan 14, 2021
5468d98
Simplify E0373 async code example
sledgehammervampire Jan 15, 2021
0660b8b
Introduce {Ref, RefMut}::try_map for optional projections
udoprog Oct 27, 2020
3e9c95b
Update compiler/rustc_mir/src/borrow_check/diagnostics/conflict_error…
sledgehammervampire Jan 15, 2021
e8757af
Use Result and rename to filter_map
udoprog Dec 17, 2020
e3274fd
Remove doctree::Import
CraftSpider Jan 14, 2021
2a0c9e2
Address nit
CraftSpider Jan 14, 2021
e42c1b9
Fix JSON test
CraftSpider Jan 15, 2021
31b17f5
Add warning to compare.py about error messages
CraftSpider Jan 15, 2021
32a20f4
Change rebuild heuristic in BinaryHeap::append
hanmertens Jan 15, 2021
c625b97
add tracking issue to cell_filter_map
KodrAus Jan 16, 2021
eef383f
doctest: Reset errors before dropping the parse session
osa1 Jan 15, 2021
0ef5557
Add a test
osa1 Jan 16, 2021
b681631
codegen_cranelift: Fix redundant semicolon warn
osa1 Jan 16, 2021
8797986
Add a regression test for #76281
JohnTitor Jan 11, 2021
d0f8553
Rollup merge of #77435 - hanmertens:binary_heap_append, r=scottmcm
JohnTitor Jan 16, 2021
0e5dcaf
Rollup merge of #78455 - udoprog:refcell-opt-map, r=KodrAus
JohnTitor Jan 16, 2021
0d901f2
Rollup merge of #80614 - 1000teslas:issue-78938-fix, r=tmandry
JohnTitor Jan 16, 2021
046da7a
Rollup merge of #80901 - jyn514:better-colors, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
e9a6063
Rollup merge of #80902 - JohnTitor:issue-76281, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
605557f
Rollup merge of #80968 - KodrAus:stabilize/poll_map, r=Mark-Simulacrum
JohnTitor Jan 16, 2021
32e9c33
Rollup merge of #80971 - camelid:feature-gate-testsuite-organization,…
JohnTitor Jan 16, 2021
58c1b90
Rollup merge of #81021 - CraftSpider:rustdoc-remove-import, r=jyn514
JohnTitor Jan 16, 2021
6a131cb
Rollup merge of #81040 - osa1:fix_80992, r=jyn514
JohnTitor Jan 16, 2021
c8bca90
Rollup merge of #81065 - osa1:cranelift_semicolon_warning, r=jyn514
JohnTitor Jan 16, 2021
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
}
ty => unreachable!("bswap {}", ty),
}
};
}
let res = CValue::by_val(swap(&mut fx.bcx, arg), fx.layout_of(T));
ret.write_cvalue(fx, res);
};
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0373.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ fn foo() -> Box<Fn(u32) -> u32> {

Now that the closure has its own copy of the data, there's no need to worry
about safety.

This error may also be encountered while using `async` blocks:

```compile_fail,E0373,edition2018
use std::future::Future;

async fn f() {
let v = vec![1, 2, 3i32];
spawn(async { //~ ERROR E0373
println!("{:?}", v)
});
}

fn spawn<F: Future + Send + 'static>(future: F) {
unimplemented!()
}
```

Similarly to closures, `async` blocks are not executed immediately and may
capture closed-over data by reference. For more information, see
https://rust-lang.github.io/async-book/03_async_await/01_chapter.html.
19 changes: 14 additions & 5 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,21 +1318,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MachineApplicable,
);

let msg = match category {
match category {
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
format!("{} is returned here", kind)
let msg = format!("{} is returned here", kind);
err.span_note(constraint_span, &msg);
}
ConstraintCategory::CallArgument => {
fr_name.highlight_region_name(&mut err);
format!("function requires argument type to outlive `{}`", fr_name)
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
err.note(
"async blocks are not executed immediately and must either take a \
reference or ownership of outside variables they use",
);
} else {
let msg = format!("function requires argument type to outlive `{}`", fr_name);
err.span_note(constraint_span, &msg);
}
}
_ => bug!(
"report_escaping_closure_capture called with unexpected constraint \
category: `{:?}`",
category
),
};
err.span_note(constraint_span, &msg);
}

err
}

Expand Down
10 changes: 8 additions & 2 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,16 @@ impl<T: Ord> BinaryHeap<T> {
// and about 2 * (len1 + len2) comparisons in the worst case
// while `extend` takes O(len2 * log(len1)) operations
// and about 1 * len2 * log_2(len1) comparisons in the worst case,
// assuming len1 >= len2.
// assuming len1 >= len2. For larger heaps, the crossover point
// no longer follows this reasoning and was determined empirically.
#[inline]
fn better_to_rebuild(len1: usize, len2: usize) -> bool {
2 * (len1 + len2) < len2 * log2_fast(len1)
let tot_len = len1 + len2;
if tot_len <= 2048 {
2 * tot_len < len2 * log2_fast(len1)
} else {
2 * tot_len < len2 * 11
}
}

if better_to_rebuild(self.len(), other.len()) {
Expand Down
86 changes: 86 additions & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,40 @@ impl<'b, T: ?Sized> Ref<'b, T> {
Ref { value: f(orig.value), borrow: orig.borrow }
}

/// Makes a new `Ref` for an optional component of the borrowed data. The
/// original guard is returned as an `Err(..)` if the closure returns
/// `None`.
///
/// The `RefCell` is already immutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as
/// `Ref::filter_map(...)`. A method would interfere with methods of the same
/// name on the contents of a `RefCell` used through `Deref`.
///
/// # Examples
///
/// ```
/// #![feature(cell_filter_map)]
///
/// use std::cell::{RefCell, Ref};
///
/// let c = RefCell::new(vec![1, 2, 3]);
/// let b1: Ref<Vec<u32>> = c.borrow();
/// let b2: Result<Ref<u32>, _> = Ref::filter_map(b1, |v| v.get(1));
/// assert_eq!(*b2.unwrap(), 2);
/// ```
#[unstable(feature = "cell_filter_map", reason = "recently added", issue = "81061")]
#[inline]
pub fn filter_map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Result<Ref<'b, U>, Self>
where
F: FnOnce(&T) -> Option<&U>,
{
match f(orig.value) {
Some(value) => Ok(Ref { value, borrow: orig.borrow }),
None => Err(orig),
}
}

/// Splits a `Ref` into multiple `Ref`s for different components of the
/// borrowed data.
///
Expand Down Expand Up @@ -1372,6 +1406,58 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
RefMut { value: f(value), borrow }
}

/// Makes a new `RefMut` for an optional component of the borrowed data. The
/// original guard is returned as an `Err(..)` if the closure returns
/// `None`.
///
/// The `RefCell` is already mutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as
/// `RefMut::filter_map(...)`. A method would interfere with methods of the
/// same name on the contents of a `RefCell` used through `Deref`.
///
/// # Examples
///
/// ```
/// #![feature(cell_filter_map)]
///
/// use std::cell::{RefCell, RefMut};
///
/// let c = RefCell::new(vec![1, 2, 3]);
///
/// {
/// let b1: RefMut<Vec<u32>> = c.borrow_mut();
/// let mut b2: Result<RefMut<u32>, _> = RefMut::filter_map(b1, |v| v.get_mut(1));
///
/// if let Ok(mut b2) = b2 {
/// *b2 += 2;
/// }
/// }
///
/// assert_eq!(*c.borrow(), vec![1, 4, 3]);
/// ```
#[unstable(feature = "cell_filter_map", reason = "recently added", issue = "81061")]
#[inline]
pub fn filter_map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> Result<RefMut<'b, U>, Self>
where
F: FnOnce(&mut T) -> Option<&mut U>,
{
// FIXME(nll-rfc#40): fix borrow-check
let RefMut { value, borrow } = orig;
let value = value as *mut T;
// SAFETY: function holds onto an exclusive reference for the duration
// of its call through `orig`, and the pointer is only de-referenced
// inside of the function call never allowing the exclusive reference to
// escape.
match f(unsafe { &mut *value }) {
Some(value) => Ok(RefMut { value, borrow }),
None => {
// SAFETY: same as above.
Err(RefMut { value: unsafe { &mut *value }, borrow })
}
}
}

/// Splits a `RefMut` into multiple `RefMut`s for different components of the
/// borrowed data.
///
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/task/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<T, E> Poll<Result<T, E>> {

impl<T, E> Poll<Option<Result<T, E>>> {
/// Changes the success value of this `Poll` with the closure provided.
#[unstable(feature = "poll_map", issue = "63514")]
#[stable(feature = "poll_map", since = "1.51.0")]
pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
where
F: FnOnce(T) -> U,
Expand All @@ -98,7 +98,7 @@ impl<T, E> Poll<Option<Result<T, E>>> {
}

/// Changes the error value of this `Poll` with the closure provided.
#[unstable(feature = "poll_map", issue = "63514")]
#[stable(feature = "poll_map", since = "1.51.0")]
pub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
where
F: FnOnce(E) -> U,
Expand Down
10 changes: 10 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,22 @@ impl<'a> Builder<'a> {
cargo.env("REAL_LIBRARY_PATH", e);
}

// Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger`
// from out of tree it shouldn't matter, since x.py is only used for
// building in-tree.
let color_logs = ["RUSTDOC_LOG_COLOR", "RUSTC_LOG_COLOR", "RUST_LOG_COLOR"];
match self.build.config.color {
Color::Always => {
cargo.arg("--color=always");
for log in &color_logs {
cargo.env(log, "always");
}
}
Color::Never => {
cargo.arg("--color=never");
for log in &color_logs {
cargo.env(log, "never");
}
}
Color::Auto => {} // nothing to do
}
Expand Down
Loading