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 9 pull requests #87347

Merged
merged 26 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8462a37
avoid temporary vectors
matthiaskrgr Jul 16, 2021
31484c0
Fix <table> overflow in doc blocks
GuillaumeGomez Jul 17, 2021
b0f8776
Remove unused file
GuillaumeGomez Jul 17, 2021
3f1a120
Add GUI test for <table> overflow
GuillaumeGomez Jul 17, 2021
d05a286
Iterate through impls only when permitted
fee1-dead Jul 19, 2021
4b82bbe
Recognize bounds on impls as const bounds
fee1-dead Jul 19, 2021
2a56a68
Add comments explaining the unix command-line argument support.
sunfishcode Jul 19, 2021
64f4e34
Fix typo in compile.rs
Jul 20, 2021
b3594f0
Get back the more precise suggestion spans of old regionck
oli-obk Jul 20, 2021
919a8a5
Fix NixOS detection
oxalica Jul 16, 2021
320d049
Add long explanation for E0722
midgleyc Jul 20, 2021
e09d782
add working code example
midgleyc Jul 21, 2021
adc5de6
docs: remove spurious main functions
midgleyc Jul 21, 2021
b24d491
docs: add newline before example
midgleyc Jul 21, 2021
27ffc37
Add long explanation for E0757
midgleyc Jul 21, 2021
3e981e2
docs: add additional links for ffi_pure / ffi_const
midgleyc Jul 21, 2021
8b75fec
docs: normalise wording in line with docs
midgleyc Jul 21, 2021
2861265
Rollup merge of #87187 - oxalica:fix-nixos-detect, r=nagisa
GuillaumeGomez Jul 21, 2021
358b2cc
Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco
GuillaumeGomez Jul 21, 2021
e6380a6
Rollup merge of #87230 - GuillaumeGomez:docblock-table-overflow, r=no…
GuillaumeGomez Jul 21, 2021
1008ace
Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obk
GuillaumeGomez Jul 21, 2021
eb54ddd
Rollup merge of #87279 - sunfishcode:document-unix-argv, r=RalfJung
GuillaumeGomez Jul 21, 2021
c6aaadc
Rollup merge of #87301 - chinmaydd:chinmaydd-patch-1-1, r=jyn514
GuillaumeGomez Jul 21, 2021
fc10326
Rollup merge of #87311 - oli-obk:nll_suggestion_span, r=estebank
GuillaumeGomez Jul 21, 2021
23ecb8b
Rollup merge of #87321 - midgleyc:add-E0722-long, r=GuillaumeGomez
GuillaumeGomez Jul 21, 2021
3a8bc0d
Rollup merge of #87342 - midgleyc:add-E0757-long, r=GuillaumeGomez
GuillaumeGomez Jul 21, 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
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