Skip to content

Commit

Permalink
Auto merge of rust-lang#87347 - GuillaumeGomez:rollup-ke92xxc, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 9 pull requests

Successful merges:

 - rust-lang#87187 (Fix NixOS detection)
 - rust-lang#87206 (avoid temporary vectors/reuse iterators)
 - rust-lang#87230 (Fix docblock <table> overflow)
 - rust-lang#87273 (Recognize bounds on impls as const bounds)
 - rust-lang#87279 (Add comments explaining the unix command-line argument support.)
 - rust-lang#87301 (Fix typo in compile.rs)
 - rust-lang#87311 (Get back the more precise suggestion spans of old regionck)
 - rust-lang#87321 (Add long explanation for E0722)
 - rust-lang#87342 (Add long explanation for E0757)

Failed merges:

 - rust-lang#87270 (Don't display <table> in item summary)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 21, 2021
2 parents cf932aa + 3a8bc0d commit 05f2326
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 61 deletions.
10 changes: 3 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ impl Path {
) -> ast::Path {
let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
let lt = mk_lifetimes(cx, span, &self.lifetime);
let tys: Vec<P<ast::Ty>> =
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
let params = lt
.into_iter()
.map(GenericArg::Lifetime)
.chain(tys.into_iter().map(GenericArg::Type))
.collect();
let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
let params =
lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();

match self.kind {
PathKind::Global => cx.path_all(span, true, idents, params),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ E0716: include_str!("./error_codes/E0716.md"),
E0718: include_str!("./error_codes/E0718.md"),
E0719: include_str!("./error_codes/E0719.md"),
E0720: include_str!("./error_codes/E0720.md"),
E0722: include_str!("./error_codes/E0722.md"),
E0724: include_str!("./error_codes/E0724.md"),
E0725: include_str!("./error_codes/E0725.md"),
E0727: include_str!("./error_codes/E0727.md"),
Expand Down Expand Up @@ -449,6 +450,7 @@ E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0756: include_str!("./error_codes/E0756.md"),
E0757: include_str!("./error_codes/E0757.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
Expand Down Expand Up @@ -634,10 +636,8 @@ E0783: include_str!("./error_codes/E0783.md"),
E0711, // a feature has been declared with conflicting stability attributes
E0717, // rustc_promotable without stability attribute
// E0721, // `await` keyword
E0722, // Malformed `#[optimize]` attribute
// E0723, unstable feature in `const` context
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
}
31 changes: 31 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0722.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
The `optimize` attribute was malformed.

Erroneous code example:

```compile_fail,E0722
#![feature(optimize_attribute)]
#[optimize(something)] // error: invalid argument
pub fn something() {}
```

The `#[optimize]` attribute should be used as follows:

- `#[optimize(size)]` -- instructs the optimization pipeline to generate code
that's smaller rather than faster

- `#[optimize(speed)]` -- instructs the optimization pipeline to generate code
that's faster rather than smaller

For example:

```
#![feature(optimize_attribute)]
#[optimize(size)]
pub fn something() {}
```

See [RFC 2412] for more details.

[RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html
33 changes: 33 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0757.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
A function was given both the `ffi_const` and `ffi_pure` attributes.

Erroneous code example:

```compile_fail,E0757
#![feature(ffi_const, ffi_pure)]
extern "C" {
#[ffi_const]
#[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]`
pub fn square(num: i32) -> i32;
}
```

As `ffi_const` provides stronger guarantees than `ffi_pure`, remove the
`ffi_pure` attribute:

```
#![feature(ffi_const)]
extern "C" {
#[ffi_const]
pub fn square(num: i32) -> i32;
}
```

You can get more information about `const` and `pure` in the [GCC documentation
on Common Function Attributes]. The unstable Rust Book has more information
about [`ffi_const`] and [`ffi_pure`].

[GCC documentation on Common Function Attributes]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
[`ffi_const`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
[`ffi_pure`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-pure.html
21 changes: 21 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,27 @@ impl<'hir> Node<'hir> {
Node::Crate(_) | Node::Visibility(_) => None,
}
}

/// Returns `Constness::Const` when this node is a const fn/impl.
pub fn constness(&self) -> Constness {
match self {
Node::Item(Item {
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::TraitItem(TraitItem {
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::ImplItem(ImplItem {
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
..
})
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,

_ => Constness::NotConst,
}
}
}

// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let new_lt = generics
.as_ref()
.and_then(|(parent_g, g)| {
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
let mut lts_names = g
.params
.iter()
Expand All @@ -2146,7 +2146,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
}
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
possible.find(|candidate| !lts.contains(&candidate.as_str()))
})
.unwrap_or("'lt".to_string());
let add_lt_sugg = generics
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, RegionVid, Ty};
use rustc_span::symbol::{kw, sym};
use rustc_span::Span;
use rustc_span::{BytePos, Span};

use crate::util::borrowck_errors;

Expand Down Expand Up @@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} else {
"'_".to_string()
};
let suggestion = if snippet.ends_with(';') {
let span = if snippet.ends_with(';') {
// `type X = impl Trait;`
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
span.with_hi(span.hi() - BytePos(1))
} else {
format!("{} + {}", snippet, suggestable_fr_name)
span
};
let suggestion = format!(" + {}", suggestable_fr_name);
let span = span.shrink_to_hi();
diag.span_suggestion(
span,
&format!(
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,19 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
permitted = true;
}
}
let mut const_impls = true;
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
if const_impls {
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
const_impls = false;
if !permitted {
// if trait's impls are all const, permit the call.
let mut const_impls = true;
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
if const_impls {
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
const_impls = false;
}
}
});
if const_impls {
permitted = true;
}
});
if const_impls {
permitted = true;
}
}

Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_hir::def_id::DefId;
use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
use rustc_middle::hir::map::blocks::FnLikeNode;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
Expand Down Expand Up @@ -175,13 +174,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
}

fn default_constness_for_trait_bounds(&self) -> hir::Constness {
// FIXME: refactor this into a method
let node = self.tcx.hir().get(self.body_id);
if let Some(fn_like) = FnLikeNode::from_node(node) {
fn_like.constness()
} else {
hir::Constness::NotConst
}
self.tcx.hir().get(self.body_id).constness()
}

fn get_type_parameter_bounds(
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::weak_lang_items;
use rustc_hir::{GenericParamKind, HirId, Node};
use rustc_middle::hir::map::blocks::FnLikeNode;
use rustc_middle::hir::map::Map;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::mono::Linkage;
Expand Down Expand Up @@ -358,11 +357,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
}

fn default_constness_for_trait_bounds(&self) -> hir::Constness {
if let Some(fn_like) = FnLikeNode::from_node(self.node()) {
fn_like.constness()
} else {
hir::Constness::NotConst
}
self.node().constness()
}

fn get_type_parameter_bounds(
Expand Down
18 changes: 16 additions & 2 deletions library/std/src/sys/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ mod imp {
use crate::ptr;
use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering};

// The system-provided argc and argv, which we store in static memory
// here so that we can defer the work of parsing them until its actually
// needed.
//
// Note that we never mutate argv/argc, the argv array, or the argv
// strings, which allows the code in this file to be very simple.
static ARGC: AtomicIsize = AtomicIsize::new(0);
static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut());

unsafe fn really_init(argc: isize, argv: *const *const u8) {
// These don't need to be ordered with each other or other stores,
// because they only hold the unmodified system-provide argv/argc.
ARGC.store(argc, Ordering::Relaxed);
ARGV.store(argv as *mut _, Ordering::Relaxed);
}
Expand Down Expand Up @@ -122,8 +130,14 @@ mod imp {

fn clone() -> Vec<OsString> {
unsafe {
// Load ARGC and ARGV without a lock. If the store to either ARGV or
// ARGC isn't visible yet, we'll return an empty argument list.
// Load ARGC and ARGV, which hold the unmodified system-provided
// argc/argv, so we can read the pointed-to memory without atomics
// or synchronization.
//
// If either ARGC or ARGV is still zero or null, then either there
// really are no arguments, or someone is asking for `args()`
// before initialization has completed, and we return an empty
// list.
let argv = ARGV.load(Ordering::Relaxed);
let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) };
(0..argc)
Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,13 @@ def fix_bin_or_dylib(self, fname):
if ostype != "Linux":
return

if not os.path.exists("/etc/NIXOS"):
# Use `/etc/os-release` instead of `/etc/NIXOS`.
# The latter one does not exist on NixOS when using tmpfs as root.
try:
with open("/etc/os-release", "r") as f:
if not any(line.strip() == "ID=nixos" for line in f):
return
except FileNotFoundError:
return
if os.path.exists("/lib"):
return
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! library.
//!
//! This module contains some of the real meat in the rustbuild build system
//! which is where Cargo is used to compiler the standard library, libtest, and
//! which is where Cargo is used to compile the standard library, libtest, and
//! compiler. This module is also responsible for assembling the sysroot as it
//! goes along from the output of the previous stage.
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ nav.sub {
.docblock table {
margin: .5em 0;
width: calc(100% - 2px);
border: 1px dashed;
overflow-x: auto;
display: block;
}

.docblock table td {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pre, .rustdoc.source .example-wrap {
border-bottom-color: #5c6773;
}

.docblock table, .docblock table td, .docblock table th {
.docblock table td, .docblock table th {
border-color: #5c6773;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap {
border-bottom-color: #DDD;
}

.docblock table, .docblock table td, .docblock table th {
.docblock table td, .docblock table th {
border-color: #ddd;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap {
border-bottom-color: #ddd;
}

.docblock table, .docblock table td, .docblock table th {
.docblock table td, .docblock table th {
border-color: #ddd;
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc-gui/docblock-table-overflow.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This test ensures that the type declaration content overflow is handled inside the <pre> directly.
goto: file://|DOC_PATH|/lib2/long_table/struct.Foo.html
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// Logically, the ".docblock" and the "<p>" should have the same scroll width.
compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["scrollWidth"])
assert-property: (".top-doc .docblock", {"scrollWidth": "816"})
// However, since there is overflow in the <table>, its scroll width is bigger.
assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"})
9 changes: 9 additions & 0 deletions src/test/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ pub mod long_trait {
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut<Target = u32>
+ From<u128> + Send + Sync + AsRef<str> + 'static {}
}

pub mod long_table {
/// | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two |
/// | ----------- | ----------- | ----------- | ----------- |
/// | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two |
///
/// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq
pub struct Foo;
}
7 changes: 0 additions & 7 deletions src/test/rustdoc-gui/src/lib2/src/lib.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ LL | #[optimize(banana)]

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors have detailed explanations: E0658, E0722.
For more information about an error, try `rustc --explain E0658`.
1 change: 1 addition & 0 deletions src/test/ui/ffi_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | #[ffi_pure]

error: aborting due to previous error

For more information about this error, try `rustc --explain E0757`.
Loading

0 comments on commit 05f2326

Please sign in to comment.