Auto merge of #80867 - JohnTitor:rollup-tvqw555, r=JohnTitor

Rollup of 9 pull requests

Successful merges:

 - #79502 (Implement From<char> for u64 and u128.)
 - #79968 (Improve core::ptr::drop_in_place debuginfo)
 - #80774 (Fix safety comment)
 - #80801 (Use correct span for structured suggestion)
 - #80803 (Remove useless `fill_in` function)
 - #80820 (Support `download-ci-llvm` on NixOS)
 - #80825 (Remove under-used ImplPolarity enum)
 - #80850 (Allow #[rustc_builtin_macro = "name"])
 - #80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2021-01-10 08:01:12 +00:00
commit 34628e5b53
45 changed files with 298 additions and 170 deletions

View file

@ -413,7 +413,7 @@ class RustBuild(object):
lib_dir = "{}/lib".format(self.bin_root())
for lib in os.listdir(lib_dir):
if lib.endswith(".so"):
self.fix_bin_or_dylib("{}/{}".format(lib_dir, lib))
self.fix_bin_or_dylib(os.path.join(lib_dir, lib), rpath_libz=True)
with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(self.date)
@ -451,10 +451,15 @@ class RustBuild(object):
"{}/src/bootstrap/download-ci-llvm-stamp".format(top_level),
]).decode(sys.getdefaultencoding()).strip()
llvm_assertions = self.get_toml('assertions', 'llvm') == 'true'
llvm_root = self.llvm_root()
llvm_lib = os.path.join(llvm_root, "lib")
if self.program_out_of_date(self.llvm_stamp(), llvm_sha + str(llvm_assertions)):
self._download_ci_llvm(llvm_sha, llvm_assertions)
for binary in ["llvm-config", "FileCheck"]:
self.fix_bin_or_dylib("{}/bin/{}".format(self.llvm_root(), binary))
self.fix_bin_or_dylib(os.path.join(llvm_root, "bin", binary), rpath_libz=True)
for lib in os.listdir(llvm_lib):
if lib.endswith(".so"):
self.fix_bin_or_dylib(os.path.join(llvm_lib, lib), rpath_libz=True)
with output(self.llvm_stamp()) as llvm_stamp:
llvm_stamp.write(llvm_sha + str(llvm_assertions))
@ -501,7 +506,7 @@ class RustBuild(object):
match="rust-dev",
verbose=self.verbose)
def fix_bin_or_dylib(self, fname):
def fix_bin_or_dylib(self, fname, rpath_libz=False):
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
or the RPATH section, to fix the dynamic library search path
@ -571,20 +576,22 @@ class RustBuild(object):
self.nix_deps_dir = nix_deps_dir
patchelf = "{}/patchelf/bin/patchelf".format(nix_deps_dir)
patchelf_args = []
if fname.endswith(".so"):
# Dynamic library, patch RPATH to point to system dependencies.
if rpath_libz:
# Patch RPATH to add `zlib` dependency that stems from LLVM
dylib_deps = ["zlib"]
rpath_entries = [
# Relative default, all binary and dynamic libraries we ship
# appear to have this (even when `../lib` is redundant).
"$ORIGIN/../lib",
] + ["{}/{}/lib".format(nix_deps_dir, dep) for dep in dylib_deps]
patchelf_args = ["--set-rpath", ":".join(rpath_entries)]
else:
patchelf_args += ["--set-rpath", ":".join(rpath_entries)]
if not fname.endswith(".so"):
# Finally, set the corret .interp for binaries
bintools_dir = "{}/stdenv.cc.bintools".format(nix_deps_dir)
with open("{}/nix-support/dynamic-linker".format(bintools_dir)) as dynamic_linker:
patchelf_args = ["--set-interpreter", dynamic_linker.read().rstrip()]
patchelf_args += ["--set-interpreter", dynamic_linker.read().rstrip()]
try:
subprocess.check_output([patchelf] + patchelf_args + [fname])

View file

@ -84,14 +84,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
new_generics
});
let polarity;
let negative_polarity;
let new_generics = match result {
AutoTraitResult::PositiveImpl(new_generics) => {
polarity = None;
negative_polarity = false;
new_generics
}
AutoTraitResult::NegativeImpl => {
polarity = Some(ImplPolarity::Negative);
negative_polarity = true;
// For negative impls, we use the generic params, but *not* the predicates,
// from the original type. Otherwise, the displayed impl appears to be a
@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
trait_: Some(trait_ref.clean(self.cx).get_trait_type().unwrap()),
for_: ty.clean(self.cx),
items: Vec::new(),
polarity,
negative_polarity,
synthetic: true,
blanket_impl: None,
}),

View file

@ -131,7 +131,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.in_definition_order()
.collect::<Vec<_>>()
.clean(self.cx),
polarity: None,
negative_polarity: false,
synthetic: false,
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
}),

View file

@ -438,7 +438,7 @@ crate fn build_impl(
trait_,
for_,
items: trait_items,
polarity: Some(polarity.clean(cx)),
negative_polarity: polarity.clean(cx),
synthetic: false,
blanket_impl: None,
}),
@ -451,60 +451,51 @@ crate fn build_impl(
fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>) -> clean::Module {
let mut items = Vec::new();
fill_in(cx, did, &mut items, visited);
return clean::Module { items, is_crate: false };
fn fill_in(
cx: &DocContext<'_>,
did: DefId,
items: &mut Vec<clean::Item>,
visited: &mut FxHashSet<DefId>,
) {
// If we're re-exporting a re-export it may actually re-export something in
// two namespaces, so the target may be listed twice. Make sure we only
// visit each node at most once.
for &item in cx.tcx.item_children(did).iter() {
if item.vis == ty::Visibility::Public {
if let Some(def_id) = item.res.mod_def_id() {
if did == def_id || !visited.insert(def_id) {
continue;
}
// If we're re-exporting a re-export it may actually re-export something in
// two namespaces, so the target may be listed twice. Make sure we only
// visit each node at most once.
for &item in cx.tcx.item_children(did).iter() {
if item.vis == ty::Visibility::Public {
if let Some(def_id) = item.res.mod_def_id() {
if did == def_id || !visited.insert(def_id) {
continue;
}
if let Res::PrimTy(p) = item.res {
// Primitive types can't be inlined so generate an import instead.
items.push(clean::Item {
name: None,
attrs: clean::Attributes::default(),
source: clean::Span::dummy(),
def_id: DefId::local(CRATE_DEF_INDEX),
visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
global: false,
res: item.res,
segments: vec![clean::PathSegment {
name: clean::PrimitiveType::from(p).as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Vec::new(),
bindings: Vec::new(),
},
}],
},
did: None,
}
if let Res::PrimTy(p) = item.res {
// Primitive types can't be inlined so generate an import instead.
items.push(clean::Item {
name: None,
attrs: clean::Attributes::default(),
source: clean::Span::dummy(),
def_id: DefId::local(CRATE_DEF_INDEX),
visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple(
item.ident.name,
clean::ImportSource {
path: clean::Path {
global: false,
res: item.res,
segments: vec![clean::PathSegment {
name: clean::PrimitiveType::from(p).as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Vec::new(),
bindings: Vec::new(),
},
}],
},
true,
)),
});
} else if let Some(i) =
try_inline(cx, did, item.res, item.ident.name, None, visited)
{
items.extend(i)
}
did: None,
},
true,
)),
});
} else if let Some(i) = try_inline(cx, did, item.res, item.ident.name, None, visited) {
items.extend(i)
}
}
}
clean::Module { items, is_crate: false }
}
crate fn print_inlined_const(cx: &DocContext<'_>, did: DefId) -> String {

View file

@ -2069,13 +2069,14 @@ impl Clean<Item> for hir::Variant<'_> {
}
}
impl Clean<ImplPolarity> for ty::ImplPolarity {
fn clean(&self, _: &DocContext<'_>) -> ImplPolarity {
impl Clean<bool> for ty::ImplPolarity {
/// Returns whether the impl has negative polarity.
fn clean(&self, _: &DocContext<'_>) -> bool {
match self {
&ty::ImplPolarity::Positive |
// FIXME: do we want to do something else here?
&ty::ImplPolarity::Reservation => ImplPolarity::Positive,
&ty::ImplPolarity::Negative => ImplPolarity::Negative,
&ty::ImplPolarity::Reservation => false,
&ty::ImplPolarity::Negative => true,
}
}
}
@ -2116,7 +2117,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
trait_,
for_,
items,
polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)),
negative_polarity: cx.tcx.impl_polarity(def_id).clean(cx),
synthetic: false,
blanket_impl: None,
});

View file

@ -175,9 +175,11 @@ impl Item {
}
crate fn is_crate(&self) -> bool {
matches!(*self.kind,
matches!(
*self.kind,
StrippedItem(box ModuleItem(Module { is_crate: true, .. }))
| ModuleItem(Module { is_crate: true, .. }))
| ModuleItem(Module { is_crate: true, .. })
)
}
crate fn is_mod(&self) -> bool {
self.type_() == ItemType::Module
@ -1226,6 +1228,7 @@ crate enum Type {
BareFunction(Box<BareFunctionDecl>),
Tuple(Vec<Type>),
Slice(Box<Type>),
/// The `String` field is about the size or the constant representing the array's length.
Array(Box<Type>, String),
Never,
RawPointer(Mutability, Box<Type>),
@ -1857,12 +1860,6 @@ crate struct Constant {
crate is_literal: bool,
}
#[derive(Clone, PartialEq, Debug)]
crate enum ImplPolarity {
Positive,
Negative,
}
#[derive(Clone, Debug)]
crate struct Impl {
crate unsafety: hir::Unsafety,
@ -1871,7 +1868,7 @@ crate struct Impl {
crate trait_: Option<Type>,
crate for_: Type,
crate items: Vec<Item>,
crate polarity: Option<ImplPolarity>,
crate negative_polarity: bool,
crate synthetic: bool,
crate blanket_impl: Option<Type>,
}

View file

@ -870,7 +870,7 @@ impl clean::Impl {
}
if let Some(ref ty) = self.trait_ {
if self.polarity == Some(clean::ImplPolarity::Negative) {
if self.negative_polarity {
write!(f, "!")?;
}

View file

@ -4327,16 +4327,15 @@ fn sidebar_assoc_items(cx: &Context<'_>, it: &clean::Item) -> String {
let mut ret = impls
.iter()
.filter_map(|i| {
let is_negative_impl = is_negative_impl(i.inner_impl());
if let Some(ref i) = i.inner_impl().trait_ {
.filter_map(|it| {
if let Some(ref i) = it.inner_impl().trait_ {
let i_display = format!("{:#}", i.print());
let out = Escape(&i_display);
let encoded = small_url_encode(&format!("{:#}", i.print()));
let generated = format!(
"<a href=\"#impl-{}\">{}{}</a>",
encoded,
if is_negative_impl { "!" } else { "" },
if it.inner_impl().negative_polarity { "!" } else { "" },
out
);
if links.insert(generated.clone()) { Some(generated) } else { None }
@ -4503,10 +4502,6 @@ fn extract_for_impl_name(item: &clean::Item) -> Option<(String, String)> {
}
}
fn is_negative_impl(i: &clean::Impl) -> bool {
i.polarity == Some(clean::ImplPolarity::Negative)
}
fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
let mut sidebar = String::new();

View file

@ -422,7 +422,7 @@ impl From<clean::Impl> for Impl {
trait_,
for_,
items,
polarity,
negative_polarity,
synthetic,
blanket_impl,
} = impl_;
@ -436,7 +436,7 @@ impl From<clean::Impl> for Impl {
trait_: trait_.map(Into::into),
for_: for_.into(),
items: ids(items),
negative: polarity == Some(clean::ImplPolarity::Negative),
negative: negative_polarity,
synthetic,
blanket_impl: blanket_impl.map(Into::into),
}

View file

@ -70,7 +70,10 @@ impl Events {
}
fn is_comment(&self) -> bool {
matches!(self, Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_))
matches!(
self,
Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_)
)
}
}

View file

@ -0,0 +1,6 @@
// run-rustfix
fn main () {
#[allow(non_upper_case_globals)]
const foo: usize = 42;
let _: [u8; foo]; //~ ERROR E0435
}

View file

@ -1,4 +1,6 @@
// run-rustfix
fn main () {
let foo = 42u32;
#[allow(non_upper_case_globals)]
let foo: usize = 42;
let _: [u8; foo]; //~ ERROR E0435
}

View file

@ -1,8 +1,8 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/E0435.rs:3:17
--> $DIR/E0435.rs:5:17
|
LL | let foo = 42u32;
| --- help: consider using `const` instead of `let`
LL | let foo: usize = 42;
| ------- help: consider using `const` instead of `let`: `const foo`
LL | let _: [u8; foo];
| ^^^ non-constant value

View file

@ -2,33 +2,33 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/bindings.rs:5:29
|
LL | const foo: impl Clone = x;
| --- ^ non-constant value
| |
| help: consider using `let` instead of `const`
| --------- ^ non-constant value
| |
| help: consider using `let` instead of `const`: `let foo`
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/bindings.rs:11:33
|
LL | const foo: impl Clone = x;
| --- ^ non-constant value
| |
| help: consider using `let` instead of `const`
| --------- ^ non-constant value
| |
| help: consider using `let` instead of `const`: `let foo`
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/bindings.rs:18:33
|
LL | const foo: impl Clone = x;
| --- ^ non-constant value
| |
| help: consider using `let` instead of `const`
| --------- ^ non-constant value
| |
| help: consider using `let` instead of `const`: `let foo`
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/bindings.rs:25:33
|
LL | const foo: impl Clone = x;
| --- ^ non-constant value
| |
| help: consider using `let` instead of `const`
| --------- ^ non-constant value
| |
| help: consider using `let` instead of `const`: `let foo`
warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/bindings.rs:1:12

View file

@ -0,0 +1,7 @@
// run-rustfix
fn main() {
let foo = 42u32;
#[allow(unused_variables, non_snake_case)]
let FOO : u32 = foo;
//~^ ERROR attempt to use a non-constant value in a constant
}

View file

@ -1,5 +1,7 @@
// run-rustfix
fn main() {
let foo = 42u32;
#[allow(unused_variables, non_snake_case)]
const FOO : u32 = foo;
//~^ ERROR attempt to use a non-constant value in a constant
}

View file

@ -1,10 +1,10 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-27433.rs:3:23
--> $DIR/issue-27433.rs:5:23
|
LL | const FOO : u32 = foo;
| --- ^^^ non-constant value
| |
| help: consider using `let` instead of `const`
| --------- ^^^ non-constant value
| |
| help: consider using `let` instead of `const`: `let FOO`
error: aborting due to previous error

View file

@ -0,0 +1,9 @@
// run-rustfix
fn main() {
let foo = 100;
let y: isize = foo + 1;
//~^ ERROR attempt to use a non-constant value in a constant
println!("{}", y);
}

View file

@ -1,3 +1,4 @@
// run-rustfix
fn main() {
let foo = 100;

View file

@ -1,10 +1,10 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3521-2.rs:4:23
--> $DIR/issue-3521-2.rs:5:23
|
LL | static y: isize = foo + 1;
| - ^^^ non-constant value
| |
| help: consider using `let` instead of `static`
| -------- ^^^ non-constant value
| |
| help: consider using `let` instead of `static`: `let y`
error: aborting due to previous error

View file

@ -0,0 +1,13 @@
// run-rustfix
fn main() {
#[allow(non_upper_case_globals)]
const foo: isize = 100;
#[derive(Debug)]
enum Stuff {
Bar = foo
//~^ ERROR attempt to use a non-constant value in a constant
}
println!("{:?}", Stuff::Bar);
}

View file

@ -1,5 +1,7 @@
// run-rustfix
fn main() {
let foo = 100;
#[allow(non_upper_case_globals)]
let foo: isize = 100;
#[derive(Debug)]
enum Stuff {

View file

@ -1,8 +1,8 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3521.rs:6:15
--> $DIR/issue-3521.rs:8:15
|
LL | let foo = 100;
| --- help: consider using `const` instead of `let`
LL | let foo: isize = 100;
| ------- help: consider using `const` instead of `let`: `const foo`
...
LL | Bar = foo
| ^^^ non-constant value

View file

@ -0,0 +1,8 @@
// run-rustfix
#![allow(unused_variables, dead_code)]
fn f(x:isize) {
let child: isize = x + 1;
//~^ ERROR attempt to use a non-constant value in a constant
}
fn main() {}

View file

@ -1,3 +1,5 @@
// run-rustfix
#![allow(unused_variables, dead_code)]
fn f(x:isize) {
static child: isize = x + 1;
//~^ ERROR attempt to use a non-constant value in a constant

View file

@ -1,10 +1,10 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3668-2.rs:2:27
--> $DIR/issue-3668-2.rs:4:27
|
LL | static child: isize = x + 1;
| ----- ^ non-constant value
| |
| help: consider using `let` instead of `static`
| ------------ ^ non-constant value
| |
| help: consider using `let` instead of `static`: `let child`
error: aborting due to previous error

View file

@ -2,9 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3668.rs:8:34
|
LL | static childVal: Box<P> = self.child.get();
| -------- ^^^^ non-constant value
| |
| help: consider using `let` instead of `static`
| --------------- ^^^^ non-constant value
| |
| help: consider using `let` instead of `static`: `let childVal`
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-42060.rs:3:23
|
LL | let thing = ();
| ----- help: consider using `const` instead of `let`
| --------- help: consider using `const` instead of `let`: `const thing`
LL | let other: typeof(thing) = thing;
| ^^^^^ non-constant value
@ -10,7 +10,7 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-42060.rs:9:13
|
LL | let q = 1;
| - help: consider using `const` instead of `let`
| ----- help: consider using `const` instead of `let`: `const q`
LL | <typeof(q)>::N
| ^ non-constant value

View file

@ -0,0 +1,11 @@
// run-rustfix
#![allow(dead_code, non_upper_case_globals)]
fn main() {
const n: usize = 0;
struct Foo;
impl Foo {
const N: usize = n;
//~^ ERROR attempt to use a non-constant value
}
}

View file

@ -1,5 +1,7 @@
// run-rustfix
#![allow(dead_code, non_upper_case_globals)]
fn main() {
let n = 0;
let n: usize = 0;
struct Foo;
impl Foo {

View file

@ -1,8 +1,8 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-44239.rs:6:26
--> $DIR/issue-44239.rs:8:26
|
LL | let n = 0;
| - help: consider using `const` instead of `let`
LL | let n: usize = 0;
| ----- help: consider using `const` instead of `let`: `const n`
...
LL | const N: usize = n;
| ^ non-constant value

View file

@ -2,9 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/non-constant-expr-for-arr-len.rs:5:22
|
LL | fn bar(n: usize) {
| - help: consider using `const` instead of `let`
| - this would need to be a `const`
LL | let _x = [0; n];
| ^ non-constant value
| ^
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/repeat_count.rs:5:17
|
LL | let n = 1;
| - help: consider using `const` instead of `let`
| ----- help: consider using `const` instead of `let`: `const n`
LL | let a = [0; n];
| ^ non-constant value

View file

@ -2,9 +2,9 @@ error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-dependent-def-issue-49241.rs:3:22
|
LL | const l: usize = v.count();
| - ^ non-constant value
| |
| help: consider using `let` instead of `const`
| ------- ^ non-constant value
| |
| help: consider using `let` instead of `const`: `let l`
error: aborting due to previous error