From c7d9d89e9b160ff629ffe5725fd52dc4cbdcff44 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 1 Apr 2020 00:41:40 +0200 Subject: [PATCH 1/7] Hide `task_context` when lowering body --- src/librustc_ast_lowering/item.rs | 2 + src/test/ui/async-await/issue-70594.rs | 12 ++++++ src/test/ui/async-await/issue-70594.stderr | 44 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 src/test/ui/async-await/issue-70594.rs create mode 100644 src/test/ui/async-await/issue-70594.stderr diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs index b319ee76c819f..6005b607026fb 100644 --- a/src/librustc_ast_lowering/item.rs +++ b/src/librustc_ast_lowering/item.rs @@ -972,8 +972,10 @@ impl<'hir> LoweringContext<'_, 'hir> { f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>), ) -> hir::BodyId { let prev_gen_kind = self.generator_kind.take(); + let task_context = self.task_context.take(); let (parameters, result) = f(self); let body_id = self.record_body(parameters, result); + self.task_context = task_context; self.generator_kind = prev_gen_kind; body_id } diff --git a/src/test/ui/async-await/issue-70594.rs b/src/test/ui/async-await/issue-70594.rs new file mode 100644 index 0000000000000..e78231a68512d --- /dev/null +++ b/src/test/ui/async-await/issue-70594.rs @@ -0,0 +1,12 @@ +// edition:2018 + +async fn fun() { + [1; ().await]; + //~^ error: `await` is only allowed inside `async` functions and blocks + //~| error: `.await` is not allowed in a `const` + //~| error: `loop` is not allowed in a `const` + //~| error: `.await` is not allowed in a `const` + //~| error: the trait bound `(): std::future::Future` is not satisfied +} + +fn main() {} diff --git a/src/test/ui/async-await/issue-70594.stderr b/src/test/ui/async-await/issue-70594.stderr new file mode 100644 index 0000000000000..d2fa7e58f6a9b --- /dev/null +++ b/src/test/ui/async-await/issue-70594.stderr @@ -0,0 +1,44 @@ +error[E0728]: `await` is only allowed inside `async` functions and blocks + --> $DIR/issue-70594.rs:4:9 + | +LL | async fn fun() { + | --- this is not `async` +LL | [1; ().await]; + | ^^^^^^^^ only allowed inside `async` functions and blocks + +error[E0744]: `.await` is not allowed in a `const` + --> $DIR/issue-70594.rs:4:9 + | +LL | [1; ().await]; + | ^^^^^^^^ + +error[E0658]: `loop` is not allowed in a `const` + --> $DIR/issue-70594.rs:4:9 + | +LL | [1; ().await]; + | ^^^^^^^^ + | + = note: see issue #52000 for more information + = help: add `#![feature(const_loop)]` to the crate attributes to enable + +error[E0744]: `.await` is not allowed in a `const` + --> $DIR/issue-70594.rs:4:9 + | +LL | [1; ().await]; + | ^^^^^^^^ + +error[E0277]: the trait bound `(): std::future::Future` is not satisfied + --> $DIR/issue-70594.rs:4:9 + | +LL | [1; ().await]; + | ^^^^^^^^ the trait `std::future::Future` is not implemented for `()` + | + ::: $SRC_DIR/libcore/future/mod.rs:LL:COL + | +LL | F: Future, + | ------ required by this bound in `std::future::poll_with_context` + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0277, E0658, E0728, E0744. +For more information about an error, try `rustc --explain E0277`. From 6f3ff27ecc3e0f28d24b0696e037e5e9374c2a30 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 2 Apr 2020 11:03:47 -0700 Subject: [PATCH 2/7] Remove unused graphviz visualization This was used by the old framework that was removed in #69644. --- src/librustc_mir/dataflow/graphviz.rs | 277 -------------------------- 1 file changed, 277 deletions(-) delete mode 100644 src/librustc_mir/dataflow/graphviz.rs diff --git a/src/librustc_mir/dataflow/graphviz.rs b/src/librustc_mir/dataflow/graphviz.rs deleted file mode 100644 index e74d27bafb2d9..0000000000000 --- a/src/librustc_mir/dataflow/graphviz.rs +++ /dev/null @@ -1,277 +0,0 @@ -//! Hook into libgraphviz for rendering dataflow graphs for MIR. - -use rustc_hir::def_id::DefId; -use rustc_middle::mir::{BasicBlock, Body}; - -use std::fs; -use std::io; -use std::marker::PhantomData; -use std::path::Path; - -use crate::util::graphviz_safe_def_name; - -use super::DataflowBuilder; -use super::DebugFormatted; -use super::{BitDenotation, DataflowState}; - -pub trait MirWithFlowState<'tcx> { - type BD: BitDenotation<'tcx>; - fn def_id(&self) -> DefId; - fn body(&self) -> &Body<'tcx>; - fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>; -} - -impl<'a, 'tcx, BD> MirWithFlowState<'tcx> for DataflowBuilder<'a, 'tcx, BD> -where - BD: BitDenotation<'tcx>, -{ - type BD = BD; - fn def_id(&self) -> DefId { - self.def_id - } - fn body(&self) -> &Body<'tcx> { - self.flow_state.body() - } - fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { - &self.flow_state.flow_state - } -} - -struct Graph<'a, 'tcx, MWF, P> -where - MWF: MirWithFlowState<'tcx>, -{ - mbcx: &'a MWF, - phantom: PhantomData<&'tcx ()>, - render_idx: P, -} - -pub(crate) fn print_borrowck_graph_to<'a, 'tcx, BD, P>( - mbcx: &DataflowBuilder<'a, 'tcx, BD>, - path: &Path, - render_idx: P, -) -> io::Result<()> -where - BD: BitDenotation<'tcx>, - P: Fn(&BD, BD::Idx) -> DebugFormatted, -{ - let g = Graph { mbcx, phantom: PhantomData, render_idx }; - let mut v = Vec::new(); - dot::render(&g, &mut v)?; - debug!("print_borrowck_graph_to path: {} def_id: {:?}", path.display(), mbcx.def_id); - fs::write(path, v) -} - -pub type Node = BasicBlock; - -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub struct Edge { - source: BasicBlock, - index: usize, -} - -fn outgoing(body: &Body<'_>, bb: BasicBlock) -> Vec { - (0..body[bb].terminator().successors().count()) - .map(|index| Edge { source: bb, index }) - .collect() -} - -impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P> -where - MWF: MirWithFlowState<'tcx>, - P: Fn(&MWF::BD, >::Idx) -> DebugFormatted, -{ - type Node = Node; - type Edge = Edge; - fn graph_id(&self) -> dot::Id<'_> { - let name = graphviz_safe_def_name(self.mbcx.def_id()); - dot::Id::new(format!("graph_for_def_id_{}", name)).unwrap() - } - - fn node_id(&self, n: &Node) -> dot::Id<'_> { - dot::Id::new(format!("bb_{}", n.index())).unwrap() - } - - fn node_label(&self, n: &Node) -> dot::LabelText<'_> { - // Node label is something like this: - // +---------+----------------------------------+------------------+------------------+ - // | ENTRY | MIR | GEN | KILL | - // +---------+----------------------------------+------------------+------------------+ - // | | 0: StorageLive(_7) | bb3[2]: reserved | bb2[0]: reserved | - // | | 1: StorageLive(_8) | bb3[2]: active | bb2[0]: active | - // | | 2: _8 = &mut _1 | | bb4[2]: reserved | - // | | | | bb4[2]: active | - // | | | | bb9[0]: reserved | - // | | | | bb9[0]: active | - // | | | | bb10[0]: reserved| - // | | | | bb10[0]: active | - // | | | | bb11[0]: reserved| - // | | | | bb11[0]: active | - // +---------+----------------------------------+------------------+------------------+ - // | [00-00] | _7 = const Foo::twiddle(move _8) | [0c-00] | [f3-0f] | - // +---------+----------------------------------+------------------+------------------+ - let mut v = Vec::new(); - self.node_label_internal(n, &mut v, *n, self.mbcx.body()).unwrap(); - dot::LabelText::html(String::from_utf8(v).unwrap()) - } - - fn node_shape(&self, _n: &Node) -> Option> { - Some(dot::LabelText::label("none")) - } - - fn edge_label(&'a self, e: &Edge) -> dot::LabelText<'a> { - let term = self.mbcx.body()[e.source].terminator(); - let label = &term.kind.fmt_successor_labels()[e.index]; - dot::LabelText::label(label.clone()) - } -} - -impl<'a, 'tcx, MWF, P> Graph<'a, 'tcx, MWF, P> -where - MWF: MirWithFlowState<'tcx>, - P: Fn(&MWF::BD, >::Idx) -> DebugFormatted, -{ - /// Generate the node label - fn node_label_internal( - &self, - n: &Node, - w: &mut W, - block: BasicBlock, - body: &Body<'_>, - ) -> io::Result<()> { - // Header rows - const HDRS: [&str; 4] = ["ENTRY", "MIR", "BLOCK GENS", "BLOCK KILLS"]; - const HDR_FMT: &str = "bgcolor=\"grey\""; - write!(w, "")?; - for hdr in &HDRS { - write!(w, "", HDR_FMT, hdr)?; - } - write!(w, "")?; - - // Data row - self.node_label_verbose_row(n, w, block, body)?; - self.node_label_final_row(n, w, block, body)?; - write!(w, "
", HDRS.len())?; - write!(w, "{:?}", block.index())?; - write!(w, "
{}
")?; - - Ok(()) - } - - /// Builds the verbose row: full MIR data, and detailed gen/kill/entry sets. - fn node_label_verbose_row( - &self, - n: &Node, - w: &mut W, - block: BasicBlock, - body: &Body<'_>, - ) -> io::Result<()> { - let i = n.index(); - - macro_rules! dump_set_for { - ($set:ident, $interpret:ident) => { - write!(w, "")?; - - let flow = self.mbcx.flow_state(); - let entry_interp = - flow.$interpret(&flow.operator, flow.sets.$set(i), &self.render_idx); - for e in &entry_interp { - write!(w, "{:?}
", e)?; - } - write!(w, "")?; - }; - } - - write!(w, "")?; - // Entry - dump_set_for!(entry_set_for, interpret_set); - - // MIR statements - write!(w, "")?; - { - let data = &body[block]; - for (i, statement) in data.statements.iter().enumerate() { - write!( - w, - "{}
", - dot::escape_html(&format!("{:3}: {:?}", i, statement)) - )?; - } - } - write!(w, "")?; - - // Gen - dump_set_for!(gen_set_for, interpret_hybrid_set); - - // Kill - dump_set_for!(kill_set_for, interpret_hybrid_set); - - write!(w, "")?; - - Ok(()) - } - - /// Builds the summary row: terminator, gen/kill/entry bit sets. - fn node_label_final_row( - &self, - n: &Node, - w: &mut W, - block: BasicBlock, - body: &Body<'_>, - ) -> io::Result<()> { - let i = n.index(); - - let flow = self.mbcx.flow_state(); - - write!(w, "")?; - - // Entry - let set = flow.sets.entry_set_for(i); - write!(w, "{:?}", dot::escape_html(&set.to_string()))?; - - // Terminator - write!(w, "")?; - { - let data = &body[block]; - let mut terminator_head = String::new(); - data.terminator().kind.fmt_head(&mut terminator_head).unwrap(); - write!(w, "{}", dot::escape_html(&terminator_head))?; - } - write!(w, "")?; - - // Gen/Kill - let trans = flow.sets.trans_for(i); - write!(w, "{:?}", dot::escape_html(&format!("{:?}", trans.gen_set)))?; - write!(w, "{:?}", dot::escape_html(&format!("{:?}", trans.kill_set)))?; - - write!(w, "")?; - - Ok(()) - } -} - -impl<'a, 'tcx, MWF, P> dot::GraphWalk<'a> for Graph<'a, 'tcx, MWF, P> -where - MWF: MirWithFlowState<'tcx>, -{ - type Node = Node; - type Edge = Edge; - fn nodes(&self) -> dot::Nodes<'_, Node> { - self.mbcx.body().basic_blocks().indices().collect::>().into() - } - - fn edges(&self) -> dot::Edges<'_, Edge> { - let body = self.mbcx.body(); - - body.basic_blocks().indices().flat_map(|bb| outgoing(body, bb)).collect::>().into() - } - - fn source(&self, edge: &Edge) -> Node { - edge.source - } - - fn target(&self, edge: &Edge) -> Node { - let body = self.mbcx.body(); - *body[edge.source].terminator().successors().nth(edge.index).unwrap() - } -} From e9ce03648d293975e5b208b1b03b503270b80bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 27 Mar 2020 22:43:28 +0100 Subject: [PATCH 3/7] Make documentation examples use new integer assoc consts --- src/libcore/hint.rs | 2 +- src/libcore/num/f32.rs | 2 +- src/libcore/num/f64.rs | 2 +- src/libcore/num/mod.rs | 2 +- src/libcore/time.rs | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs index 698c97999c457..d406b3ce6ef6e 100644 --- a/src/libcore/hint.rs +++ b/src/libcore/hint.rs @@ -43,7 +43,7 @@ use crate::intrinsics; /// /// assert_eq!(div_1(7, 0), 7); /// assert_eq!(div_1(9, 1), 4); -/// assert_eq!(div_1(11, std::u32::MAX), 0); +/// assert_eq!(div_1(11, u32::MAX), 0); /// ``` #[inline] #[stable(feature = "unreachable", since = "1.27.0")] diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 09f1eab2d4b9d..4ab82add32b53 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -470,7 +470,7 @@ impl f32 { /// /// let value = -128.9_f32; /// let rounded = unsafe { value.to_int_unchecked::() }; - /// assert_eq!(rounded, std::i8::MIN); + /// assert_eq!(rounded, i8::MIN); /// ``` /// /// # Safety diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 65ef7ba9ac768..20818a9b750f4 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -484,7 +484,7 @@ impl f64 { /// /// let value = -128.9_f32; /// let rounded = unsafe { value.to_int_unchecked::() }; - /// assert_eq!(rounded, std::i8::MIN); + /// assert_eq!(rounded, i8::MIN); /// ``` /// /// # Safety diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c85064759ea03..7ba4004d8609c 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -174,7 +174,7 @@ NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize } /// let zero = Wrapping(0u32); /// let one = Wrapping(1u32); /// -/// assert_eq!(std::u32::MAX, (zero - one).0); +/// assert_eq!(u32::MAX, (zero - one).0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 2ece2150e6bed..924a64847a794 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -389,7 +389,7 @@ impl Duration { /// use std::time::Duration; /// /// assert_eq!(Duration::new(0, 0).checked_add(Duration::new(0, 1)), Some(Duration::new(0, 1))); - /// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(std::u64::MAX, 0)), None); + /// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None); /// ``` #[stable(feature = "duration_checked_ops", since = "1.16.0")] #[inline] @@ -460,7 +460,7 @@ impl Duration { /// use std::time::Duration; /// /// assert_eq!(Duration::new(0, 500_000_001).checked_mul(2), Some(Duration::new(1, 2))); - /// assert_eq!(Duration::new(std::u64::MAX - 1, 0).checked_mul(2), None); + /// assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None); /// ``` #[stable(feature = "duration_checked_ops", since = "1.16.0")] #[inline] From c0ec0a27b3ed532c0ce58a2ad2f4dcd3d939210a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 27 Mar 2020 22:15:02 +0100 Subject: [PATCH 4/7] Replace max/min_value() with MAX/MIN assoc consts --- src/liballoc/slice.rs | 2 +- src/liballoc/str.rs | 2 +- src/libcore/fmt/mod.rs | 2 +- src/libcore/intrinsics.rs | 12 ++++++------ src/libcore/iter/traits/iterator.rs | 2 +- src/libcore/ptr/const_ptr.rs | 4 ++-- src/libcore/ptr/mut_ptr.rs | 4 ++-- src/librustc_target/abi/mod.rs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index d8fc1faca3a39..2ce5bc8ed2f9d 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -432,7 +432,7 @@ impl [T] { /// /// ```should_panic /// // this will panic at runtime - /// b"0123456789abcdef".repeat(usize::max_value()); + /// b"0123456789abcdef".repeat(usize::MAX); /// ``` #[stable(feature = "repeat_generic_slice", since = "1.40.0")] pub fn repeat(&self, n: usize) -> Vec diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 843a2f1f8e9fc..70860c09a2c31 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -499,7 +499,7 @@ impl str { /// /// ```should_panic /// // this will panic at runtime - /// "0123456789abcdef".repeat(usize::max_value()); + /// "0123456789abcdef".repeat(usize::MAX); /// ``` #[stable(feature = "repeat_str", since = "1.16.0")] pub fn repeat(&self, n: usize) -> String { diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index fe728d42c76f7..95411b525d0db 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -852,7 +852,7 @@ pub trait LowerHex { /// } /// } /// -/// let l = Length(i32::max_value()); +/// let l = Length(i32::MAX); /// /// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF"); /// diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 7e9140faa6411..4a11fb393899f 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1739,11 +1739,11 @@ extern "rust-intrinsic" { pub fn mul_with_overflow(x: T, y: T) -> (T, bool); /// Performs an exact division, resulting in undefined behavior where - /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1` + /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1` pub fn exact_div(x: T, y: T) -> T; /// Performs an unchecked division, resulting in undefined behavior - /// where y = 0 or x = `T::min_value()` and y = -1 + /// where y = 0 or x = `T::MIN` and y = -1 /// /// The stabilized versions of this intrinsic are available on the integer /// primitives via the `checked_div` method. For example, @@ -1751,7 +1751,7 @@ extern "rust-intrinsic" { #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] pub fn unchecked_div(x: T, y: T) -> T; /// Returns the remainder of an unchecked division, resulting in - /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1 + /// undefined behavior where y = 0 or x = `T::MIN` and y = -1 /// /// The stabilized versions of this intrinsic are available on the integer /// primitives via the `checked_rem` method. For example, @@ -1777,17 +1777,17 @@ extern "rust-intrinsic" { pub fn unchecked_shr(x: T, y: T) -> T; /// Returns the result of an unchecked addition, resulting in - /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`. + /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`. #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] pub fn unchecked_add(x: T, y: T) -> T; /// Returns the result of an unchecked subtraction, resulting in - /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`. + /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`. #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] pub fn unchecked_sub(x: T, y: T) -> T; /// Returns the result of an unchecked multiplication, resulting in - /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`. + /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`. #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] pub fn unchecked_mul(x: T, y: T) -> T; diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index daa880e7cd53b..0c9318ab8e72d 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -198,7 +198,7 @@ pub trait Iterator { /// // and the maximum possible lower bound /// let iter = 0..; /// - /// assert_eq!((usize::max_value(), None), iter.size_hint()); + /// assert_eq!((usize::MAX, None), iter.size_hint()); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs index a540016854df3..52e224d2a026f 100644 --- a/src/libcore/ptr/const_ptr.rs +++ b/src/libcore/ptr/const_ptr.rs @@ -659,8 +659,8 @@ impl *const T { /// `align`. /// /// If it is not possible to align the pointer, the implementation returns - /// `usize::max_value()`. It is permissible for the implementation to *always* - /// return `usize::max_value()`. Only your algorithm's performance can depend + /// `usize::MAX`. It is permissible for the implementation to *always* + /// return `usize::MAX`. Only your algorithm's performance can depend /// on getting a usable offset here, not its correctness. /// /// The offset is expressed in number of `T` elements, and not bytes. The value returned can be diff --git a/src/libcore/ptr/mut_ptr.rs b/src/libcore/ptr/mut_ptr.rs index 01d830ca18602..9f85d781d698a 100644 --- a/src/libcore/ptr/mut_ptr.rs +++ b/src/libcore/ptr/mut_ptr.rs @@ -847,8 +847,8 @@ impl *mut T { /// `align`. /// /// If it is not possible to align the pointer, the implementation returns - /// `usize::max_value()`. It is permissible for the implementation to *always* - /// return `usize::max_value()`. Only your algorithm's performance can depend + /// `usize::MAX`. It is permissible for the implementation to *always* + /// return `usize::MAX`. Only your algorithm's performance can depend /// on getting a usable offset here, not its correctness. /// /// The offset is expressed in number of `T` elements, and not bytes. The value returned can be diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index f382ef984be24..4c25363a6575f 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -577,7 +577,7 @@ pub struct Scalar { pub value: Primitive, /// Inclusive wrap-around range of valid values, that is, if - /// start > end, it represents `start..=max_value()`, + /// start > end, it represents `start..=MAX`, /// followed by `0..=end`. /// /// That is, for an i8 primitive, a range of `254..=2` means following From c8312659403397c9fe4fcb2fd006268a7031d7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 27 Mar 2020 22:26:08 +0100 Subject: [PATCH 5/7] Replace float module consts with assoc consts in documentation --- src/libcore/cmp.rs | 2 +- src/libcore/iter/traits/iterator.rs | 6 +++--- src/libcore/ops/range.rs | 10 ++++------ src/libcore/slice/mod.rs | 2 +- src/libstd/f32.rs | 4 ++-- src/libstd/f64.rs | 4 ++-- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 604be7d5f68d0..8c542136a7fa6 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -817,7 +817,7 @@ pub trait PartialOrd: PartialEq { /// When comparison is impossible: /// /// ``` - /// let result = std::f64::NAN.partial_cmp(&1.0); + /// let result = f64::NAN.partial_cmp(&1.0); /// assert_eq!(result, None); /// ``` #[must_use] diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs index 0c9318ab8e72d..c8829817e190c 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -2920,7 +2920,7 @@ pub trait Iterator { /// assert_eq!([1.].iter().partial_cmp([1., 2.].iter()), Some(Ordering::Less)); /// assert_eq!([1., 2.].iter().partial_cmp([1.].iter()), Some(Ordering::Greater)); /// - /// assert_eq!([std::f64::NAN].iter().partial_cmp([1.].iter()), None); + /// assert_eq!([f64::NAN].iter().partial_cmp([1.].iter()), None); /// ``` #[stable(feature = "iter_order", since = "1.5.0")] fn partial_cmp(self, other: I) -> Option @@ -3170,7 +3170,7 @@ pub trait Iterator { /// assert!(![1, 3, 2, 4].iter().is_sorted()); /// assert!([0].iter().is_sorted()); /// assert!(std::iter::empty::().is_sorted()); - /// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted()); + /// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted()); /// ``` #[inline] #[unstable(feature = "is_sorted", reason = "new API", issue = "53485")] @@ -3197,7 +3197,7 @@ pub trait Iterator { /// assert!(![1, 3, 2, 4].iter().is_sorted_by(|a, b| a.partial_cmp(b))); /// assert!([0].iter().is_sorted_by(|a, b| a.partial_cmp(b))); /// assert!(std::iter::empty::().is_sorted_by(|a, b| a.partial_cmp(b))); - /// assert!(![0.0, 1.0, std::f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b))); + /// assert!(![0.0, 1.0, f32::NAN].iter().is_sorted_by(|a, b| a.partial_cmp(b))); /// ``` /// /// [`is_sorted`]: trait.Iterator.html#method.is_sorted diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index adee8cea442b4..946a765e18f3b 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -139,10 +139,9 @@ impl> Range { /// ``` /// #![feature(range_is_empty)] /// - /// use std::f32::NAN; /// assert!(!(3.0..5.0).is_empty()); - /// assert!( (3.0..NAN).is_empty()); - /// assert!( (NAN..5.0).is_empty()); + /// assert!( (3.0..f32::NAN).is_empty()); + /// assert!( (f32::NAN..5.0).is_empty()); /// ``` #[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")] pub fn is_empty(&self) -> bool { @@ -496,10 +495,9 @@ impl> RangeInclusive { /// ``` /// #![feature(range_is_empty)] /// - /// use std::f32::NAN; /// assert!(!(3.0..=5.0).is_empty()); - /// assert!( (3.0..=NAN).is_empty()); - /// assert!( (NAN..=5.0).is_empty()); + /// assert!( (3.0..=f32::NAN).is_empty()); + /// assert!( (f32::NAN..=5.0).is_empty()); /// ``` /// /// This method returns `true` after iteration has finished: diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 2140a7be9efe8..9be52e2dfb06b 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -2588,7 +2588,7 @@ impl [T] { /// assert!(![1, 3, 2, 4].is_sorted()); /// assert!([0].is_sorted()); /// assert!(empty.is_sorted()); - /// assert!(![0.0, 1.0, std::f32::NAN].is_sorted()); + /// assert!(![0.0, 1.0, f32::NAN].is_sorted()); /// ``` #[inline] #[unstable(feature = "is_sorted", reason = "new API", issue = "53485")] diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 20425aea8d517..ac8f305ae9127 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -284,7 +284,7 @@ impl f32 { /// assert_eq!(a.rem_euclid(-b), 3.0); /// assert_eq!((-a).rem_euclid(-b), 1.0); /// // limitation due to round-off error - /// assert!((-std::f32::EPSILON).rem_euclid(3.0) != 0.0); + /// assert!((-f32::EPSILON).rem_euclid(3.0) != 0.0); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[inline] @@ -962,7 +962,7 @@ impl f32 { /// assert!((-3.0f32).clamp(-2.0, 1.0) == -2.0); /// assert!((0.0f32).clamp(-2.0, 1.0) == 0.0); /// assert!((2.0f32).clamp(-2.0, 1.0) == 1.0); - /// assert!((std::f32::NAN).clamp(-2.0, 1.0).is_nan()); + /// assert!((f32::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index a1128a589a64a..798738e50a754 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -280,7 +280,7 @@ impl f64 { /// assert_eq!(a.rem_euclid(-b), 3.0); /// assert_eq!((-a).rem_euclid(-b), 1.0); /// // limitation due to round-off error - /// assert!((-std::f64::EPSILON).rem_euclid(3.0) != 0.0); + /// assert!((-f64::EPSILON).rem_euclid(3.0) != 0.0); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[inline] @@ -928,7 +928,7 @@ impl f64 { /// assert!((-3.0f64).clamp(-2.0, 1.0) == -2.0); /// assert!((0.0f64).clamp(-2.0, 1.0) == 0.0); /// assert!((2.0f64).clamp(-2.0, 1.0) == 1.0); - /// assert!((std::f64::NAN).clamp(-2.0, 1.0).is_nan()); + /// assert!((f64::NAN).clamp(-2.0, 1.0).is_nan()); /// ``` #[must_use = "method returns a new number and does not mutate the original value"] #[unstable(feature = "clamp", issue = "44095")] From 9db736059372e1031a6a894fe67140014954a696 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Apr 2020 13:41:34 +0200 Subject: [PATCH 6/7] Clean up E0502 explanation --- src/librustc_error_codes/error_codes/E0502.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0502.md b/src/librustc_error_codes/error_codes/E0502.md index f15c05d558d85..b90c59f580737 100644 --- a/src/librustc_error_codes/error_codes/E0502.md +++ b/src/librustc_error_codes/error_codes/E0502.md @@ -1,5 +1,4 @@ -This error indicates that you are trying to borrow a variable as mutable when it -has already been borrowed as immutable. +A variable already borrowed as immutable was borrowed as mutable. Erroneous code example: From 0ca2a5e52cb428a8381988e3551649ae07d4eb61 Mon Sep 17 00:00:00 2001 From: DutchGhost Date: Fri, 3 Apr 2020 18:28:01 +0200 Subject: [PATCH 7/7] Add test for #59023 --- .../impl_trait_as_trait_return_position.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/ui/traits/impl_trait_as_trait_return_position.rs diff --git a/src/test/ui/traits/impl_trait_as_trait_return_position.rs b/src/test/ui/traits/impl_trait_as_trait_return_position.rs new file mode 100644 index 0000000000000..c3325fd80ca0c --- /dev/null +++ b/src/test/ui/traits/impl_trait_as_trait_return_position.rs @@ -0,0 +1,17 @@ +// check-pass + +trait A { + type Foo; +} + +impl A for T { + type Foo = (); +} + +fn foo() -> impl std::borrow::Borrow<::Foo> { + () +} + +fn main() { + foo(); +}