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 10 pull requests #104270

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6630c14
Implement the `+whole-archive` modifier for `wasm-ld`
alexcrichton Sep 24, 2022
fb9d98c
Improve diagnostic when passing arg to closure and missing borrow.
Akida31 Oct 8, 2022
4992e8c
Fix stderr of tests which have improved diagnostics
Akida31 Oct 8, 2022
e8cd512
Remove `hint` from help message
Akida31 Oct 9, 2022
23c99a4
move changes to an extra function
Akida31 Oct 11, 2022
121b431
change error message
Akida31 Oct 11, 2022
0f5409b
remove manual `fn_decl` extraction
Akida31 Oct 11, 2022
449a440
test attr: point at return type if Termination bound unsatisfied
fmease Oct 23, 2022
c0447b4
fix #103435, unused lint won't produce invalid code
chenyukang Oct 24, 2022
a46af18
fix parentheses surrounding spacing issue in parser
chenyukang Oct 24, 2022
32a2f0d
suggest calling the method of the same name when method not found
chenyukang Oct 25, 2022
2716449
add testcase for suggest self
chenyukang Oct 25, 2022
4b5cff5
Fix broken link in error code E0706 docs
PeteDevoy Nov 3, 2022
8e0cac1
rustdoc: refactor `notable_traits_decl` to just act on the type directly
notriddle Nov 7, 2022
303653e
rustdoc: use javascript to layout notable traits popups
notriddle Nov 7, 2022
a45151e
rustdoc: fix font color inheritance from body, and test
notriddle Nov 8, 2022
0e0bcd9
prevent uninitialized access in black_box for zero-sized-types
krasimirgg Nov 4, 2022
06a77af
Add retry flag to remote-test-server
Ayush1325 Nov 8, 2022
53e8b49
rustdoc: sort output to make it deterministic
notriddle Nov 9, 2022
50bb7a4
Tweak span for `#[must_use]`
estebank Aug 16, 2022
243496e
Consider `#[must_use]` annotation on `async fn` as also affecting the…
estebank Aug 16, 2022
8bd8484
review comments
estebank Aug 17, 2022
f57713b
Fix tests after rebase
estebank Nov 11, 2022
37c5efa
Rollup merge of #100633 - estebank:must_use_async_fn_return, r=tmandry
Manishearth Nov 11, 2022
c6251c9
Rollup merge of #102215 - alexcrichton:wasm-link-whole-archive, r=est…
Manishearth Nov 11, 2022
82cb9ee
Rollup merge of #102813 - Akida31:issue-64915/simpler_diagnostic_when…
Manishearth Nov 11, 2022
8048504
Rollup merge of #103445 - fmease:fix-50291, r=estebank
Manishearth Nov 11, 2022
6c35e1a
Rollup merge of #103468 - chenyukang:yukang/fix-103435-extra-parenthe…
Manishearth Nov 11, 2022
be70abe
Rollup merge of #103531 - chenyukang:yukang/fix-103474, r=estebank
Manishearth Nov 11, 2022
7658f0e
Rollup merge of #103924 - PeteDevoy:patch-1, r=estebank
Manishearth Nov 11, 2022
55f07c7
Rollup merge of #104110 - krasimirgg:msan-16, r=nagisa
Manishearth Nov 11, 2022
206928c
Rollup merge of #104129 - notriddle:notriddle/102576-js-notable-trait…
Manishearth Nov 11, 2022
fe41af6
Rollup merge of #104146 - Ayush1325:remote-test-server, r=jyn514
Manishearth Nov 11, 2022
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
18 changes: 12 additions & 6 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn expand_test_or_bench(
};

// Note: non-associated fn items are already handled by `expand_test_or_bench`
if !matches!(item.kind, ast::ItemKind::Fn(_)) {
let ast::ItemKind::Fn(fn_) = &item.kind else {
let diag = &cx.sess.parse_sess.span_diagnostic;
let msg = "the `#[test]` attribute may only be used on a non-associated function";
let mut err = match item.kind {
Expand All @@ -130,7 +130,7 @@ pub fn expand_test_or_bench(
.emit();

return vec![Annotatable::Item(item)];
}
};

// has_*_signature will report any errors in the type so compilation
// will fail. We shouldn't try to expand in this case because the errors
Expand All @@ -141,12 +141,14 @@ pub fn expand_test_or_bench(
return vec![Annotatable::Item(item)];
}

let (sp, attr_sp) = (cx.with_def_site_ctxt(item.span), cx.with_def_site_ctxt(attr_sp));
let sp = cx.with_def_site_ctxt(item.span);
let ret_ty_sp = cx.with_def_site_ctxt(fn_.sig.decl.output.span());
let attr_sp = cx.with_def_site_ctxt(attr_sp);

let test_id = Ident::new(sym::test, attr_sp);

// creates test::$name
let test_path = |name| cx.path(sp, vec![test_id, Ident::from_str_and_span(name, sp)]);
let test_path = |name| cx.path(ret_ty_sp, vec![test_id, Ident::from_str_and_span(name, sp)]);

// creates test::ShouldPanic::$name
let should_panic_path = |name| {
Expand Down Expand Up @@ -192,7 +194,7 @@ pub fn expand_test_or_bench(
vec![
// super::$test_fn(b)
cx.expr_call(
sp,
ret_ty_sp,
cx.expr_path(cx.path(sp, vec![item.ident])),
vec![cx.expr_ident(sp, b)],
),
Expand All @@ -216,7 +218,11 @@ pub fn expand_test_or_bench(
cx.expr_path(test_path("assert_test_result")),
vec![
// $test_fn()
cx.expr_call(sp, cx.expr_path(cx.path(sp, vec![item.ident])), vec![]), // )
cx.expr_call(
ret_ty_sp,
cx.expr_path(cx.path(sp, vec![item.ident])),
vec![],
), // )
],
), // }
), // )
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,26 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {

sym::black_box => {
args[0].val.store(self, result);

let result_val_span = [result.llval];
// We need to "use" the argument in some way LLVM can't introspect, and on
// targets that support it we can typically leverage inline assembly to do
// this. LLVM's interpretation of inline assembly is that it's, well, a black
// box. This isn't the greatest implementation since it probably deoptimizes
// more than we want, but it's so far good enough.
//
// For zero-sized types, the location pointed to by the result may be
// uninitialized. Do not "use" the result in this case; instead just clobber
// the memory.
let (constraint, inputs): (&str, &[_]) = if result.layout.is_zst() {
("~{memory}", &[])
} else {
("r,~{memory}", &result_val_span)
};
crate::asm::inline_asm_call(
self,
"",
"r,~{memory}",
&[result.llval],
constraint,
inputs,
self.type_void(),
true,
false,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,11 +1260,11 @@ impl<'a> Linker for WasmLd<'a> {
}

fn link_whole_staticlib(&mut self, lib: &str, _verbatim: bool, _search_path: &[PathBuf]) {
self.cmd.arg("-l").arg(lib);
self.cmd.arg("--whole-archive").arg("-l").arg(lib).arg("--no-whole-archive");
}

fn link_whole_rlib(&mut self, lib: &Path) {
self.cmd.arg(lib);
self.cmd.arg("--whole-archive").arg(lib).arg("--no-whole-archive");
}

fn gc_sections(&mut self, _keep_metadata: bool) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0706.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ You might be interested in visiting the [async book] for further information.
[`async-trait` crate]: https://crates.io/crates/async-trait
[async-is-hard]: https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
[Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265
[async book]: https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html
[async book]: https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html
72 changes: 52 additions & 20 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_infer::traits::util::elaborate_predicates_with_span;
use rustc_middle::ty::adjustment;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::{self, DefIdTree, Ty};
use rustc_span::symbol::Symbol;
use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, Span};
Expand Down Expand Up @@ -87,17 +87,33 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);

impl<'tcx> LateLintPass<'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
let expr = match s.kind {
hir::StmtKind::Semi(ref expr) => &**expr,
_ => return,
};
let hir::StmtKind::Semi(expr) = s.kind else { return; };

if let hir::ExprKind::Ret(..) = expr.kind {
return;
}

if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
&& let ty = cx.typeck_results().expr_ty(&await_expr)
&& let ty::Opaque(future_def_id, _) = ty.kind()
&& cx.tcx.ty_is_opaque_future(ty)
// FIXME: This also includes non-async fns that return `impl Future`.
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
&& check_must_use_def(
cx,
async_fn_def_id,
expr.span,
"output of future returned by ",
"",
)
{
// We have a bare `foo().await;` on an opaque type from an async function that was
// annotated with `#[must_use]`.
return;
}

let ty = cx.typeck_results().expr_ty(&expr);
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1);
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, expr.span, "", "", 1);

let mut fn_warned = false;
let mut op_warned = false;
Expand All @@ -119,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
_ => None,
};
if let Some(def_id) = maybe_def_id {
fn_warned = check_must_use_def(cx, def_id, s.span, "return value of ", "");
fn_warned = check_must_use_def(cx, def_id, expr.span, "return value of ", "");
} else if type_permits_lack_of_use {
// We don't warn about unused unit or uninhabited types.
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
Expand Down Expand Up @@ -565,10 +581,24 @@ trait UnusedDelimLint {
lint.set_arg("delim", Self::DELIM_STR);
lint.set_arg("item", msg);
if let Some((lo, hi)) = spans {
let replacement = vec![
(lo, if keep_space.0 { " ".into() } else { "".into() }),
(hi, if keep_space.1 { " ".into() } else { "".into() }),
];
let sm = cx.sess().source_map();
let lo_replace =
if keep_space.0 &&
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(" ") {
" ".to_string()
} else {
"".to_string()
};

let hi_replace =
if keep_space.1 &&
let Ok(snip) = sm.span_to_next_source(hi) && !snip.starts_with(" ") {
" ".to_string()
} else {
"".to_string()
};

let replacement = vec![(lo, lo_replace), (hi, hi_replace)];
lint.multipart_suggestion(
fluent::suggestion,
replacement,
Expand Down Expand Up @@ -765,6 +795,7 @@ impl UnusedParens {
value: &ast::Pat,
avoid_or: bool,
avoid_mut: bool,
keep_space: (bool, bool),
) {
use ast::{BindingAnnotation, PatKind};

Expand All @@ -789,7 +820,7 @@ impl UnusedParens {
} else {
None
};
self.emit_unused_delims(cx, value.span, spans, "pattern", (false, false));
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space);
}
}
}
Expand All @@ -798,7 +829,7 @@ impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
match e.kind {
ExprKind::Let(ref pat, _, _) | ExprKind::ForLoop(ref pat, ..) => {
self.check_unused_parens_pat(cx, pat, false, false);
self.check_unused_parens_pat(cx, pat, false, false, (true, true));
}
// We ignore parens in cases like `if (((let Some(0) = Some(1))))` because we already
// handle a hard error for them during AST lowering in `lower_expr_mut`, but we still
Expand Down Expand Up @@ -842,40 +873,41 @@ impl EarlyLintPass for UnusedParens {

fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &ast::Pat) {
use ast::{Mutability, PatKind::*};
let keep_space = (false, false);
match &p.kind {
// Do not lint on `(..)` as that will result in the other arms being useless.
Paren(_)
// The other cases do not contain sub-patterns.
| Wild | Rest | Lit(..) | MacCall(..) | Range(..) | Ident(.., None) | Path(..) => {},
// These are list-like patterns; parens can always be removed.
TupleStruct(_, _, ps) | Tuple(ps) | Slice(ps) | Or(ps) => for p in ps {
self.check_unused_parens_pat(cx, p, false, false);
self.check_unused_parens_pat(cx, p, false, false, keep_space);
},
Struct(_, _, fps, _) => for f in fps {
self.check_unused_parens_pat(cx, &f.pat, false, false);
self.check_unused_parens_pat(cx, &f.pat, false, false, keep_space);
},
// Avoid linting on `i @ (p0 | .. | pn)` and `box (p0 | .. | pn)`, #64106.
Ident(.., Some(p)) | Box(p) => self.check_unused_parens_pat(cx, p, true, false),
Ident(.., Some(p)) | Box(p) => self.check_unused_parens_pat(cx, p, true, false, keep_space),
// Avoid linting on `&(mut x)` as `&mut x` has a different meaning, #55342.
// Also avoid linting on `& mut? (p0 | .. | pn)`, #64106.
Ref(p, m) => self.check_unused_parens_pat(cx, p, true, *m == Mutability::Not),
Ref(p, m) => self.check_unused_parens_pat(cx, p, true, *m == Mutability::Not, keep_space),
}
}

fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
if let StmtKind::Local(ref local) = s.kind {
self.check_unused_parens_pat(cx, &local.pat, true, false);
self.check_unused_parens_pat(cx, &local.pat, true, false, (false, false));
}

<Self as UnusedDelimLint>::check_stmt(self, cx, s)
}

fn check_param(&mut self, cx: &EarlyContext<'_>, param: &ast::Param) {
self.check_unused_parens_pat(cx, &param.pat, true, false);
self.check_unused_parens_pat(cx, &param.pat, true, false, (false, false));
}

fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
self.check_unused_parens_pat(cx, &arm.pat, false, false);
self.check_unused_parens_pat(cx, &arm.pat, false, false, (false, false));
}

fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,12 @@ pub(crate) struct ParenthesesInForHead {
#[derive(Subdiagnostic)]
#[multipart_suggestion(suggestion, applicability = "machine-applicable")]
pub(crate) struct ParenthesesInForHeadSugg {
#[suggestion_part(code = "")]
#[suggestion_part(code = "{left_snippet}")]
pub left: Span,
#[suggestion_part(code = "")]
pub left_snippet: String,
#[suggestion_part(code = "{right_snippet}")]
pub right: Span,
pub right_snippet: String,
}

#[derive(Diagnostic)]
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,15 +1653,29 @@ impl<'a> Parser<'a> {
(token::CloseDelim(Delimiter::Parenthesis), Some(begin_par_sp)) => {
self.bump();

let sm = self.sess.source_map();
let left = begin_par_sp;
let right = self.prev_token.span;
let left_snippet = if let Ok(snip) = sm.span_to_prev_source(left) &&
!snip.ends_with(" ") {
" ".to_string()
} else {
"".to_string()
};

let right_snippet = if let Ok(snip) = sm.span_to_next_source(right) &&
!snip.starts_with(" ") {
" ".to_string()
} else {
"".to_string()
};

self.sess.emit_err(ParenthesesInForHead {
span: vec![begin_par_sp, self.prev_token.span],
span: vec![left, right],
// With e.g. `for (x) in y)` this would replace `(x) in y)`
// with `x) in y)` which is syntactically invalid.
// However, this is prevented before we get here.
sugg: ParenthesesInForHeadSugg {
left: begin_par_sp,
right: self.prev_token.span,
},
sugg: ParenthesesInForHeadSugg { left, right, left_snippet, right_snippet },
});

// Unwrap `(pat)` into `pat` to avoid the `unused_parens` lint.
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl CheckAttrVisitor<'_> {
sym::collapse_debuginfo => self.check_collapse_debuginfo(attr, span, target),
sym::const_trait => self.check_const_trait(attr, span, target),
sym::must_not_suspend => self.check_must_not_suspend(&attr, span, target),
sym::must_use => self.check_must_use(hir_id, &attr, span, target),
sym::must_use => self.check_must_use(hir_id, &attr, target),
sym::rustc_pass_by_value => self.check_pass_by_value(&attr, span, target),
sym::rustc_allow_incoherent_impl => {
self.check_allow_incoherent_impl(&attr, span, target)
Expand Down Expand Up @@ -1163,17 +1163,7 @@ impl CheckAttrVisitor<'_> {
}

/// Warns against some misuses of `#[must_use]`
fn check_must_use(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
let node = self.tcx.hir().get(hir_id);
if let Some(kind) = node.fn_kind() && let rustc_hir::IsAsync::Async = kind.asyncness() {
self.tcx.emit_spanned_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::MustUseAsync { span }
);
}

fn check_must_use(&self, hir_id: HirId, attr: &Attribute, target: Target) -> bool {
if !matches!(
target,
Target::Fn
Expand Down
Loading