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 #88920

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
efeb461
Make `UnsafeCell::get_mut` const
WaffleLapkin Sep 7, 2021
2c30162
Fill in the tracking issue for `#![feature(const_unsafecell_get_mut)]`
WaffleLapkin Sep 10, 2021
5dab3c5
feat(rustc_typeck): suggest removing bad parens in `(recv.method)()`
notriddle Sep 11, 2021
e5c2412
Add the corrections stuff to the 88803 test case
notriddle Sep 11, 2021
d98892b
Make sure the call span parens check only fires on the callee, not args
notriddle Sep 11, 2021
a0b83f5
Fix duplicate bounds for const_trait_impl
fee1-dead Sep 11, 2021
1b3fe75
Allow simd_shuffle to accept vectors of any length
calebzulawski Sep 11, 2021
6a2f500
Fix invalid background for jump-to-def links in source code pages
GuillaumeGomez Sep 12, 2021
40f2a3b
Move object safety suggestions to the end of the error
estebank Sep 12, 2021
3f0e695
Improve error message for missing trait in trait impl
FabianWolff Sep 12, 2021
cefa900
Reduce possibility of flaky tests
GuillaumeGomez Sep 12, 2021
8be729c
chore: convert to a multi-part suggestion
notriddle Sep 13, 2021
9e482c1
* Enable generate-link-to-def feature on a rustdoc GUI test
GuillaumeGomez Sep 12, 2021
84f1857
Rollup merge of #88722 - WaffleLapkin:unsafe_cell_const_get_mut, r=dt…
workingjubilee Sep 14, 2021
e660d13
Rollup merge of #88841 - notriddle:notriddle/method-parens, r=estebank
workingjubilee Sep 14, 2021
bc0ebfc
Rollup merge of #88851 - fee1-dead:dup-bound, r=oli-obk
workingjubilee Sep 14, 2021
d51a468
Rollup merge of #88855 - calebzulawski:feature/simd_shuffle, r=nagisa
workingjubilee Sep 14, 2021
2a65d56
Rollup merge of #88885 - GuillaumeGomez:fix-jump-def-background, r=ca…
workingjubilee Sep 14, 2021
1fa97b5
Rollup merge of #88892 - estebank:trait-objects, r=petrochenkov
workingjubilee Sep 14, 2021
b190806
Rollup merge of #88894 - FabianWolff:issue-88818, r=estebank
workingjubilee Sep 14, 2021
f453896
Rollup merge of #88896 - GuillaumeGomez:flakyness, r=camelid
workingjubilee Sep 14, 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
25 changes: 21 additions & 4 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,29 @@ fn generic_simd_intrinsic(
}

if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
let n: u64 = stripped.parse().unwrap_or_else(|_| {
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
});
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
// If there is no suffix, use the index array length.
let n: u64 = if stripped.is_empty() {
// Make sure this is actually an array, since typeck only checks the length-suffixed
// version of this intrinsic.
match args[2].layout.ty.kind() {
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
len.try_eval_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(|| {
span_bug!(span, "could not evaluate shuffle index array length")
})
}
_ => return_error!(
"simd_shuffle index must be an array of `u32`, got `{}`",
args[2].layout.ty
),
}
} else {
stripped.parse().unwrap_or_else(|_| {
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
})
};

require_simd!(ret_ty, "return");

let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
require!(
out_len == n,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0439.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

The length of the platform-intrinsic function `simd_shuffle` wasn't specified.

Erroneous code example:

```compile_fail,E0439
```ignore (no longer emitted)
#![feature(platform_intrinsics)]

extern "platform-intrinsic" {
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ pub fn report_object_safety_error(
messages.push(msg.clone());
}
}
if trait_span.is_some() {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
}
let has_multi_span = !multi_span.is_empty();
Expand All @@ -104,5 +100,11 @@ pub fn report_object_safety_error(
to be resolvable dynamically; for more information visit \
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);
if trait_span.is_some() {
for violation in reported_violations {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
err
}
15 changes: 14 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,20 @@ impl<'a> Parser<'a> {
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
{
let span = self.prev_token.span.between(self.token.span);
self.struct_span_err(span, "missing trait in a trait impl").emit();
self.struct_span_err(span, "missing trait in a trait impl")
.span_suggestion(
span,
"add a trait here",
" Trait ".into(),
Applicability::HasPlaceholders,
)
.span_suggestion(
span.to(self.token.span),
"for an inherent impl, drop this `for`",
"".into(),
Applicability::MaybeIncorrect,
)
.emit();
P(Ty {
kind: TyKind::Path(None, err_path(span)),
span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ symbols! {
simd_select_bitmask,
simd_shl,
simd_shr,
simd_shuffle,
simd_sub,
simd_trunc,
simd_xor,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,10 +1487,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) => false,

(ParamCandidate(other), ParamCandidate(victim)) => {
let value_same_except_bound_vars = other.value.skip_binder()
let same_except_bound_vars = other.value.skip_binder()
== victim.value.skip_binder()
&& other.constness == victim.constness
&& !other.value.skip_binder().has_escaping_bound_vars();
if value_same_except_bound_vars {
if same_except_bound_vars {
// See issue #84398. In short, we can generate multiple ParamCandidates which are
// the same except for unused bound vars. Just pick the one with the fewest bound vars
// or the current one if tied (they should both evaluate to the same answer). This is
Expand Down
23 changes: 22 additions & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr_t
);
err.span_label(field.span, "method, not a field");
if !self.expr_in_place(expr.hir_id) {
let expr_is_call =
if let hir::Node::Expr(hir::Expr { kind: ExprKind::Call(callee, _args), .. }) =
self.tcx.hir().get(self.tcx.hir().get_parent_node(expr.hir_id))
{
expr.hir_id == callee.hir_id
} else {
false
};
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);
err.multipart_suggestion(
"remove wrapping parentheses to call the method",
vec![
(expr.span.with_hi(after_open), String::new()),
(expr.span.with_lo(before_close), String::new()),
],
Applicability::MachineApplicable,
);
} else if !self.expr_in_place(expr.hir_id) {
self.suggest_method_call(
&mut err,
"use parentheses to call the method",
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! intrinsics that the compiler exposes.

use crate::errors::{
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
WrongNumberOfGenericArgumentsToIntrinsic,
};
use crate::require_same_types;
Expand Down Expand Up @@ -468,14 +468,17 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
| sym::simd_reduce_max
| sym::simd_reduce_min_nanless
| sym::simd_reduce_max_nanless => (2, vec![param(0)], param(1)),
sym::simd_shuffle => (3, vec![param(0), param(0), param(1)], param(2)),
name if name.as_str().starts_with("simd_shuffle") => {
match name.as_str()["simd_shuffle".len()..].parse() {
Ok(n) => {
let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)];
(2, params, param(1))
}
Err(_) => {
tcx.sess.emit_err(SimdShuffleMissingLength { span: it.span, name });
let msg =
format!("unrecognized platform-specific intrinsic function: `{}`", name);
tcx.sess.struct_span_err(it.span, &msg).emit();
return;
}
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ pub struct AssocTypeBindingNotAllowed {
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error = "E0439"]
pub struct SimdShuffleMissingLength {
#[message = "invalid `simd_shuffle`, needs length: `{name}`"]
pub span: Span,
pub name: Symbol,
}

#[derive(SessionDiagnostic)]
#[error = "E0436"]
pub struct FunctionalRecordUpdateOnNonStruct {
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,8 @@ impl<T: ?Sized> UnsafeCell<T> {
/// ```
#[inline(always)]
#[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
pub fn get_mut(&mut self) -> &mut T {
#[rustc_const_unstable(feature = "const_unsafecell_get_mut", issue = "88836")]
pub const fn get_mut(&mut self) -> &mut T {
&mut self.value
}

Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,11 @@ impl Step for RustdocGUI {
.env("RUSTDOC", builder.rustdoc(self.compiler))
.env("RUSTC", builder.rustc(self.compiler))
.current_dir(path);
// FIXME: implement a `// compile-flags` command or similar
// instead of hard-coding this test
if entry.file_name() == "link_to_definition" {
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
}
builder.run(&mut cargo);
}
}
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 @@ -217,7 +217,7 @@ a {
color: #c5c5c5;
}
body.source .example-wrap pre.rust a {
background: #c5c5c5;
background: #333;
}

.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow),
Expand Down
1 change: 1 addition & 0 deletions src/test/rustdoc-gui/code-sidebar-toggle.goml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
goto: file://|DOC_PATH|/test_docs/index.html
click: ".srclink"
wait-for: "#sidebar-toggle"
click: "#sidebar-toggle"
wait-for: 500
fail: true
Expand Down
23 changes: 23 additions & 0 deletions src/test/rustdoc-gui/jump-to-def-background.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// We check the background color on the jump to definition links in the source code page.
goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html

// Set the theme to dark.
local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:

assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(51, 51, 51)"}, ALL)

// Set the theme to ayu.
local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:

assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(51, 51, 51)"}, ALL)

// Set the theme to light.
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
// We reload the page so the local storage settings are being used.
reload:

assert-css: ("body.source .example-wrap pre.rust a", {"background-color": "rgb(238, 238, 238)"}, ALL)
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/link_to_definition/Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "link_to_definition"
version = "0.1.0"
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/link_to_definition/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "link_to_definition"
version = "0.1.0"
edition = "2018"

[lib]
path = "lib.rs"
6 changes: 6 additions & 0 deletions src/test/rustdoc-gui/src/link_to_definition/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub struct Bar {
pub a: String,
pub b: u32,
}

pub fn foo(_b: &Bar) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | impl dyn Trait {
| ^^^^^^^^^ `Trait` cannot be made into an object
|
= help: consider moving `N` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/associated-const-in-trait.rs:6:11
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | const N: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `N` to another trait

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-item/issue-48027.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ error[E0038]: the trait `Bar` cannot be made into an object
LL | impl dyn Bar {}
| ^^^^^^^ `Bar` cannot be made into an object
|
= help: consider moving `X` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-48027.rs:2:11
|
LL | trait Bar {
| --- this trait cannot be made into an object...
LL | const X: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `X` to another trait

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
= help: consider moving `eq` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:6:43
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| ------------- ^^^^ ...because method `eq` references the `Self` type in this parameter
| |
| this trait cannot be made into an object...
= help: consider moving `eq` to another trait

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | fn use_dyn(v: &dyn Foo) {
| ^^^^^^^ `Foo` cannot be made into an object
|
= help: consider moving `test` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-err-ret.rs:8:23
|
LL | trait Foo {
| --- this trait cannot be made into an object...
LL | fn test(&self) -> [u8; bar::<Self>()];
| ^^^^^^^^^^^^^^^^^^^ ...because method `test` references the `Self` type in its return type
= help: consider moving `test` to another trait

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0038.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | fn call_foo(x: Box<dyn Trait>) {
| ^^^^^^^^^ `Trait` cannot be made into an object
|
= help: consider moving `foo` to another trait
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/E0038.rs:2:22
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | fn foo(&self) -> Self;
| ^^^^ ...because method `foo` references the `Self` type in its return type
= help: consider moving `foo` to another trait

error: aborting due to previous error

Expand Down
8 changes: 0 additions & 8 deletions src/test/ui/error-codes/E0439.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/error-codes/E0439.stderr

This file was deleted.

Loading