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 8 pull requests #67949

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
097126e
Omit underscore constants from rustdoc
dtolnay Jan 4, 2020
e2305d0
rustdoc: HTML escape const values
ollie27 Jan 5, 2020
e6d95ce
Formatting an example for method Vec.retain
mgrachev Jan 6, 2020
24c6cd8
stabilise remove_item
Dylan-DPC Dec 30, 2019
0a739ce
remove usage of feature gate
Dylan-DPC Dec 30, 2019
99fda5c
Clean up E0178 explanation
GuillaumeGomez Jan 6, 2020
a7727c5
fire "non_camel_case_types" for associated types
euclio Jan 6, 2020
6bec8e9
stabilise it
Dylan-DPC Jan 6, 2020
d9a7db9
Add an unstable conversion from thread ID to u64
Mark-Simulacrum Dec 23, 2019
0113cac
Missing module std in example.
Stromberg90 Jan 6, 2020
a852941
Removed module usage.
Stromberg90 Jan 6, 2020
503d06b
oh the one that was left behind
Dylan-DPC Jan 6, 2020
839e74a
Rollup merge of #67566 - Mark-Simulacrum:thread-id-u64, r=alexcrichton
Dylan-DPC Jan 6, 2020
a7527b5
Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton
Dylan-DPC Jan 6, 2020
6698d98
Rollup merge of #67877 - dtolnay:const-_, r=nagisa
Dylan-DPC Jan 6, 2020
95a910f
Rollup merge of #67908 - ollie27:rustdoc_const_html_escape, r=Guillau…
Dylan-DPC Jan 6, 2020
068e8df
Rollup merge of #67929 - mgrachev:patch-1, r=jonas-schievink
Dylan-DPC Jan 6, 2020
d6b7b17
Rollup merge of #67934 - GuillaumeGomez:clean-up-e0178, r=Dylan-DPC
Dylan-DPC Jan 6, 2020
6492679
Rollup merge of #67936 - euclio:assoc-type-bad-style, r=Centril
Dylan-DPC Jan 6, 2020
f725e9f
Rollup merge of #67943 - Stromberg90:patch-1, r=jonas-schievink
Dylan-DPC Jan 6, 2020
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
1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![feature(associated_type_bounds)]
#![feature(binary_heap_into_iter_sorted)]
#![feature(binary_heap_drain_sorted)]
#![feature(vec_remove_item)]

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
Expand Down
5 changes: 2 additions & 3 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ impl<T> Vec<T> {
///
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.retain(|&x| x%2 == 0);
/// vec.retain(|&x| x % 2 == 0);
/// assert_eq!(vec, [2, 4]);
/// ```
///
Expand Down Expand Up @@ -1696,14 +1696,13 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// # #![feature(vec_remove_item)]
/// let mut vec = vec![1, 2, 3, 1];
///
/// vec.remove_item(&1);
///
/// assert_eq!(vec, vec![2, 3, 1]);
/// ```
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
#[stable(feature = "vec_remove_item", since = "1.42.0")]
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
where
T: PartialEq<V>,
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#![feature(thread_local)]
#![feature(trace_macros)]
#![feature(trusted_len)]
#![feature(vec_remove_item)]
#![feature(stmt_expr_attributes)]
#![feature(integer_atomics)]
#![feature(test)]
Expand Down
25 changes: 18 additions & 7 deletions src/librustc_error_codes/error_codes/E0178.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
In types, the `+` type operator has low precedence, so it is often necessary
to use parentheses.
The `+` type operator was used in an ambiguous context.

For example:
Erroneous code example:

```compile_fail,E0178
trait Foo {}

struct Bar<'a> {
w: &'a Foo + Copy, // error, use &'a (Foo + Copy)
x: &'a Foo + 'a, // error, use &'a (Foo + 'a)
y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
x: &'a Foo + 'a, // error!
y: &'a mut Foo + 'a, // error!
z: fn() -> Foo + 'a, // error!
}
```

In types, the `+` type operator has low precedence, so it is often necessary
to use parentheses:

```
trait Foo {}

struct Bar<'a> {
x: &'a (Foo + 'a), // ok!
y: &'a mut (Foo + 'a), // ok!
z: fn() -> (Foo + 'a), // ok!
}
```

Expand Down
6 changes: 6 additions & 0 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ impl EarlyLintPass for NonCamelCaseTypes {
}
}

fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
if let ast::AssocItemKind::TyAlias(..) = it.kind {
self.check_case(cx, "associated type", &it.ident);
}
}

fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
self.check_case(cx, "variant", &v.ident);
}
Expand Down
17 changes: 14 additions & 3 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_hir::def_id::DefId;
use rustc_target::spec::abi::Abi;

use crate::clean::{self, PrimitiveType};
use crate::html::escape::Escape;
use crate::html::item_type::ItemType;
use crate::html::render::{self, cache, CURRENT_DEPTH};

Expand Down Expand Up @@ -314,8 +315,14 @@ impl clean::Lifetime {
}

impl clean::Constant {
crate fn print(&self) -> &str {
&self.expr
crate fn print(&self) -> impl fmt::Display + '_ {
display_fn(move |f| {
if f.alternate() {
f.write_str(&self.expr)
} else {
write!(f, "{}", Escape(&self.expr))
}
})
}
}

Expand Down Expand Up @@ -689,7 +696,11 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) ->
clean::Array(ref t, ref n) => {
primitive_link(f, PrimitiveType::Array, "[")?;
fmt::Display::fmt(&t.print(), f)?;
primitive_link(f, PrimitiveType::Array, &format!("; {}]", n))
if f.alternate() {
primitive_link(f, PrimitiveType::Array, &format!("; {}]", n))
} else {
primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)))
}
}
clean::Never => primitive_link(f, PrimitiveType::Never, "!"),
clean::RawPointer(m, ref t) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,7 +2280,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons
);

if c.value.is_some() || c.is_literal {
write!(w, " = {expr};", expr = c.expr);
write!(w, " = {expr};", expr = Escape(&c.expr));
} else {
write!(w, ";");
}
Expand All @@ -2293,7 +2293,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons
if value_lowercase != expr_lowercase
&& value_lowercase.trim_end_matches("i32") != expr_lowercase
{
write!(w, " // {value}", value = value);
write!(w, " // {value}", value = Escape(value));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#![feature(nll)]
#![feature(set_stdio)]
#![feature(test)]
#![feature(vec_remove_item)]
#![feature(ptr_offset_from)]
#![feature(crate_visibility_modifier)]
#![feature(const_fn)]
Expand Down
26 changes: 15 additions & 11 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Node;
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::sym;
use rustc_span::symbol::{kw, sym};
use rustc_span::{self, Span};
use syntax::ast;

Expand Down Expand Up @@ -514,16 +514,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.statics.push(s);
}
hir::ItemKind::Const(type_, expr) => {
let s = Constant {
type_,
expr,
id: item.hir_id,
name: ident.name,
attrs: &item.attrs,
whence: item.span,
vis: &item.vis,
};
om.constants.push(s);
// Underscore constants do not correspond to a nameable item and
// so are never useful in documentation.
if ident.name != kw::Underscore {
let s = Constant {
type_,
expr,
id: item.hir_id,
name: ident.name,
attrs: &item.attrs,
whence: item.span,
vis: &item.vis,
};
om.constants.push(s);
}
}
hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
let items = item_ids.iter().map(|ti| self.cx.tcx.hir().trait_item(ti.id)).collect();
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ pub struct TcpStream(net_imp::TcpStream);
/// # Examples
///
/// ```no_run
/// # use std::io;
/// use std::net::{TcpListener, TcpStream};
///
/// fn handle_client(stream: TcpStream) {
/// // ...
/// }
///
/// fn main() -> io::Result<()> {
/// fn main() -> std::io::Result<()> {
/// let listener = TcpListener::bind("127.0.0.1:80")?;
///
/// // accept connections and process them serially
Expand Down
13 changes: 13 additions & 0 deletions src/libstd/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,19 @@ impl ThreadId {
ThreadId(NonZeroU64::new(id).unwrap())
}
}

/// This returns a numeric identifier for the thread identified by this
/// `ThreadId`.
///
/// As noted in the documentation for the type itself, it is essentially an
/// opaque ID, but is guaranteed to be unique for each thread. The returned
/// value is entirely opaque -- only equality testing is stable. Note that
/// it is not guaranteed which values new threads will return, and this may
/// change across Rust versions.
#[unstable(feature = "thread_id_value", issue = "67939")]
pub fn as_u64(&self) -> u64 {
self.0.get()
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc/const-generics/const-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ impl <T> VSet<T, {Order::Unsorted}> {
Self { inner: Vec::new() }
}
}

pub struct Escape<const S: &'static str>;

// @has foo/struct.Escape.html '//h3[@id="impl"]/code' 'impl Escape<{ r#"<script>alert("Escape");</script>"# }>'
impl Escape<{ r#"<script>alert("Escape");</script>"# }> {
pub fn f() {}
}
7 changes: 7 additions & 0 deletions src/test/rustdoc/const-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-flags: --document-private-items

// @!has const_underscore/constant._.html
const _: () = {
#[no_mangle]
extern "C" fn implementation_detail() {}
};
3 changes: 3 additions & 0 deletions src/test/rustdoc/show-const-contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ macro_rules! int_module {

// @has show_const_contents/constant.MIN.html '= i16::min_value(); // -32_768i16'
int_module!(i16);

// @has show_const_contents/constant.ESCAPE.html //pre '= r#"<script>alert("ESCAPE");</script>"#;'
pub const ESCAPE: &str = r#"<script>alert("ESCAPE");</script>"#;
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-17732.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// check-pass
#![allow(dead_code)]
#![allow(non_camel_case_types)]
// pretty-expanded FIXME #23616

trait Person {
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issues/issue-35600.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// run-pass
#![allow(non_camel_case_types)]
#![allow(unused_variables)]

trait Foo {
type bar;
fn bar();
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/lint/lint-non-camel-case-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum Foo5 {
}

trait foo6 { //~ ERROR trait `foo6` should have an upper camel case name
type foo7; //~ ERROR associated type `foo7` should have an upper camel case name
fn dummy(&self) { }
}

Expand Down
10 changes: 8 additions & 2 deletions src/test/ui/lint/lint-non-camel-case-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ error: trait `foo6` should have an upper camel case name
LL | trait foo6 {
| ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo6`

error: associated type `foo7` should have an upper camel case name
--> $DIR/lint-non-camel-case-types.rs:26:10
|
LL | type foo7;
| ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo7`

error: type parameter `ty` should have an upper camel case name
--> $DIR/lint-non-camel-case-types.rs:29:6
--> $DIR/lint-non-camel-case-types.rs:30:6
|
LL | fn f<ty>(_: ty) {}
| ^^ help: convert the identifier to upper camel case: `Ty`

error: aborting due to 8 previous errors
error: aborting due to 9 previous errors

1 change: 0 additions & 1 deletion src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![crate_name = "compiletest"]
#![feature(test)]
#![feature(vec_remove_item)]
#![deny(warnings)]

extern crate test;
Expand Down