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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
df89b63
Only assert for unstable expectation ids after conversion (RFC 2383)
xFrednet Mar 28, 2022
ee33544
Move lint expectation checking into a separate query (RFC 2383)
xFrednet Mar 28, 2022
63a7a53
Test `expect` attribute for tool lints, rustc edition (RFC 2383)
xFrednet Mar 31, 2022
36c1ab0
Test `expect` attribute for tool lints, clippy edition (RFC 2383)
xFrednet Mar 31, 2022
6a6d895
Support `#[expect]` attributes for rustdoc lints (RFC 2383)
xFrednet Mar 31, 2022
c26742d
Fixed typo in docs
xFrednet Apr 5, 2022
c81734f
bump libc version for uclibc fixes
skrap May 2, 2022
3d43be3
Add unused_macro_rules lint definition
est31 Apr 16, 2022
6c8a2d4
rustdoc: when running a function-signature search, tweak the tab bar
notriddle Apr 30, 2022
345a580
Use STARTS_WITH, since it's more specific
notriddle May 1, 2022
21a1213
rustdoc: change the "In Function Signatures" to context-sensitive
notriddle May 2, 2022
8b2147b
rustdoc: fix keyboard shortcuts and console log on search page
notriddle May 2, 2022
75790fa
rustdoc: add test case assertions for ArrowDown highlight first result
notriddle May 3, 2022
4c183cd
rustdoc: fix JS error when rendering parse error
notriddle May 3, 2022
0bd2232
Implement the unused_macro_rules lint
est31 Apr 17, 2022
5646e9a
Allow unused rules in some places in the compiler, library and tools
est31 Apr 17, 2022
d76a939
Add tests
est31 Apr 17, 2022
3989f02
Allow unused rules in the testsuite where the lint triggers
est31 Apr 17, 2022
30309db
Put the 2229 migration errors in alphabetical order
scottmcm May 4, 2022
20010d7
rustdoc: ensure HTML/JS side implementors don't have dups
notriddle May 6, 2022
903aebe
Fix test case checking for where the JS goes
notriddle May 6, 2022
3dac70f
typeck: port "unconstrained opaque type" diag
davidtwco May 4, 2022
859079f
macros: allow `Vec` fields in diagnostic derive
davidtwco May 6, 2022
3f413d2
sess: add `create_{err,warning}`
davidtwco May 6, 2022
af47257
typeck: port "explicit generic args w/ impl trait"
davidtwco May 6, 2022
8ff0189
turn `append_place_to_string` from recursion into iteration
SparrowLii May 6, 2022
bd31ba0
make Size and Align debug-printing a bit more compact
RalfJung Apr 30, 2022
22cc6c3
don't debug-print ConstValue in MIR pretty-printer
RalfJung May 6, 2022
d455752
bless mir-opt
RalfJung May 6, 2022
279dee5
Fix reexports missing from the search index
GuillaumeGomez May 5, 2022
fb2f97a
Add GUI test for search reexports
GuillaumeGomez May 5, 2022
bd11e22
Add missing newline
notriddle May 6, 2022
08e74e4
Rollup merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
GuillaumeGomez May 6, 2022
914f947
Rollup merge of #96150 - est31:unused_macro_rules, r=petrochenkov
GuillaumeGomez May 6, 2022
33424a4
Rollup merge of #96581 - RalfJung:debug-size-align, r=oli-obk
GuillaumeGomez May 6, 2022
659875f
Rollup merge of #96590 - notriddle:notriddle/tab-bar-fn-search, r=Gui…
GuillaumeGomez May 6, 2022
6983a7d
Rollup merge of #96656 - skrap:master, r=JohnTitor
GuillaumeGomez May 6, 2022
a2c8bb3
Rollup merge of #96733 - SparrowLii:place_to_string, r=davidtwco
GuillaumeGomez May 6, 2022
49d39b6
Rollup merge of #96748 - GuillaumeGomez:reexports-in-search, r=notriddle
GuillaumeGomez May 6, 2022
4e132e2
Rollup merge of #96752 - scottmcm:error-sorting, r=compiler-errors
GuillaumeGomez May 6, 2022
9090bb3
Rollup merge of #96754 - notriddle:notriddle/impl-dups, r=GuillaumeGomez
GuillaumeGomez May 6, 2022
7ea92fc
Rollup merge of #96760 - davidtwco:diagnostic-translation-vec, r=oli-obk
GuillaumeGomez May 6, 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
210 changes: 78 additions & 132 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Borrow checker diagnostics.

use itertools::Itertools;
use rustc_const_eval::util::{call_kind, CallDesugaringKind};
use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir;
Expand Down Expand Up @@ -161,158 +162,103 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}

/// End-user visible description of `place` if one can be found.
/// If the place is a temporary for instance, None will be returned.
/// If the place is a temporary for instance, `None` will be returned.
pub(super) fn describe_place(&self, place_ref: PlaceRef<'tcx>) -> Option<String> {
self.describe_place_with_options(place_ref, IncludingDowncast(false))
}

/// End-user visible description of `place` if one can be found. If the
/// place is a temporary for instance, None will be returned.
/// `IncludingDowncast` parameter makes the function return `Err` if `ProjectionElem` is
/// End-user visible description of `place` if one can be found. If the place is a temporary
/// for instance, `None` will be returned.
/// `IncludingDowncast` parameter makes the function return `None` if `ProjectionElem` is
/// `Downcast` and `IncludingDowncast` is true
pub(super) fn describe_place_with_options(
&self,
place: PlaceRef<'tcx>,
including_downcast: IncludingDowncast,
) -> Option<String> {
let local = place.local;
let mut autoderef_index = None;
let mut buf = String::new();
match self.append_place_to_string(place, &mut buf, false, &including_downcast) {
Ok(()) => Some(buf),
Err(()) => None,
}
}

/// Appends end-user visible description of `place` to `buf`.
fn append_place_to_string(
&self,
place: PlaceRef<'tcx>,
buf: &mut String,
mut autoderef: bool,
including_downcast: &IncludingDowncast,
) -> Result<(), ()> {
match place {
PlaceRef { local, projection: [] } => {
self.append_local_to_string(local, buf)?;
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[local].is_ref_for_guard() =>
{
self.append_place_to_string(
PlaceRef { local, projection: &[] },
buf,
autoderef,
&including_downcast,
)?;
}
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[local].is_ref_to_static() =>
{
let local_info = &self.body.local_decls[local].local_info;
if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {
buf.push_str(self.infcx.tcx.item_name(def_id).as_str());
} else {
unreachable!();
}
}
PlaceRef { local, projection: [proj_base @ .., elem] } => {
match elem {
ProjectionElem::Deref => {
let upvar_field_projection = self.is_upvar_field_projection(place);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
let name = self.upvars[var_index].place.to_string(self.infcx.tcx);
if self.upvars[var_index].by_ref {
buf.push_str(&name);
} else {
buf.push('*');
buf.push_str(&name);
}
} else {
if autoderef {
// FIXME turn this recursion into iteration
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
} else {
buf.push('*');
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
}
let mut ok = self.append_local_to_string(local, &mut buf);

for (index, elem) in place.projection.into_iter().enumerate() {
match elem {
ProjectionElem::Deref => {
if index == 0 {
if self.body.local_decls[local].is_ref_for_guard() {
continue;
}
}
ProjectionElem::Downcast(..) => {
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
if including_downcast.0 {
return Err(());
if let Some(box LocalInfo::StaticRef { def_id, .. }) =
&self.body.local_decls[local].local_info
{
buf.push_str(self.infcx.tcx.item_name(*def_id).as_str());
ok = Ok(());
continue;
}
}
ProjectionElem::Field(field, _ty) => {
autoderef = true;

// FIXME(project-rfc_2229#36): print capture precisely here.
let upvar_field_projection = self.is_upvar_field_projection(place);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
let name = self.upvars[var_index].place.to_string(self.infcx.tcx);
buf.push_str(&name);
} else {
let field_name = self
.describe_field(PlaceRef { local, projection: proj_base }, *field);
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
buf.push('.');
buf.push_str(&field_name);
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
local,
projection: place.projection.split_at(index + 1).0,
}) {
let var_index = field.index();
buf = self.upvars[var_index].place.to_string(self.infcx.tcx);
ok = Ok(());
if !self.upvars[var_index].by_ref {
buf.insert(0, '*');
}
}
ProjectionElem::Index(index) => {
autoderef = true;

self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
buf.push('[');
if self.append_local_to_string(*index, buf).is_err() {
buf.push('_');
} else {
if autoderef_index.is_none() {
autoderef_index =
match place.projection.into_iter().rev().find_position(|elem| {
!matches!(
elem,
ProjectionElem::Deref | ProjectionElem::Downcast(..)
)
}) {
Some((index, _)) => Some(place.projection.len() - index),
None => Some(0),
};
}
if index >= autoderef_index.unwrap() {
buf.insert(0, '*');
}
buf.push(']');
}
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
autoderef = true;
// Since it isn't possible to borrow an element on a particular index and
// then use another while the borrow is held, don't output indices details
// to avoid confusing the end-user
self.append_place_to_string(
PlaceRef { local, projection: proj_base },
buf,
autoderef,
&including_downcast,
)?;
buf.push_str("[..]");
}
ProjectionElem::Downcast(..) if including_downcast.0 => return None,
ProjectionElem::Downcast(..) => (),
ProjectionElem::Field(field, _ty) => {
// FIXME(project-rfc_2229#36): print capture precisely here.
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
local,
projection: place.projection.split_at(index + 1).0,
}) {
buf = self.upvars[field.index()].place.to_string(self.infcx.tcx);
ok = Ok(());
} else {
let field_name = self.describe_field(
PlaceRef { local, projection: place.projection.split_at(index).0 },
*field,
);
buf.push('.');
buf.push_str(&field_name);
}
};
}
ProjectionElem::Index(index) => {
buf.push('[');
if self.append_local_to_string(*index, &mut buf).is_err() {
buf.push('_');
}
buf.push(']');
}
ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
// Since it isn't possible to borrow an element on a particular index and
// then use another while the borrow is held, don't output indices details
// to avoid confusing the end-user
buf.push_str("[..]");
}
}
}

Ok(())
ok.ok().map(|_| buf)
}

/// Appends end-user visible description of the `local` place to `buf`. If `local` doesn't have
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
span: Span,
) -> Result<&'ll Value, ()> {
// macros for error handling:
#[cfg_attr(not(bootstrap), allow(unused_macro_rules))]
macro_rules! emit_error {
($msg: tt) => {
emit_error!($msg, )
Expand Down Expand Up @@ -1144,6 +1145,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
span: Span,
args: &[OperandRef<'tcx, &'ll Value>],
) -> Result<&'ll Value, ()> {
#[cfg_attr(not(bootstrap), allow(unused_macro_rules))]
macro_rules! emit_error {
($msg: tt) => {
emit_error!($msg, )
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ typeck-add-return-type-missing-here = a return type might be missing here
typeck-expected-default-return-type = expected `()` because of default return type

typeck-expected-return-type = expected `{$expected}` because of return type

typeck-unconstrained-opaque-type = unconstrained opaque type
.note = `{$name}` must be used in combination with a concrete type within the same module

typeck-explicit-generic-args-with-impl-trait =
cannot provide explicit generic arguments when `impl Trait` is used in argument position
.label = explicit generic argument not allowed
.note = see issue #83701 <https://github.com/rust-lang/rust/issues/83701> for more information

typeck-explicit-generic-args-with-impl-trait-feature =
add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable
23 changes: 17 additions & 6 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ struct HandlerInner {

future_breakage_diagnostics: Vec<Diagnostic>,

/// The [`unstable_expect_diagnostics`] should be empty when this struct is
/// dropped. However, it can have values if the compilation is stopped early
/// or is only partially executed. To avoid ICEs, like in rust#94953 we only
/// check if [`unstable_expect_diagnostics`] is empty, if the expectation ids
/// have been converted.
check_unstable_expect_diagnostics: bool,

/// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of
/// the lint level. [`LintExpectationId`]s created early during the compilation
/// (before `HirId`s have been defined) are not stable and can therefore not be
Expand Down Expand Up @@ -497,10 +504,12 @@ impl Drop for HandlerInner {
);
}

assert!(
self.unstable_expect_diagnostics.is_empty(),
"all diagnostics with unstable expectations should have been converted",
);
if self.check_unstable_expect_diagnostics {
assert!(
self.unstable_expect_diagnostics.is_empty(),
"all diagnostics with unstable expectations should have been converted",
);
}
}
}

Expand Down Expand Up @@ -574,6 +583,7 @@ impl Handler {
emitted_diagnostics: Default::default(),
stashed_diagnostics: Default::default(),
future_breakage_diagnostics: Vec::new(),
check_unstable_expect_diagnostics: false,
unstable_expect_diagnostics: Vec::new(),
fulfilled_expectations: Default::default(),
}),
Expand Down Expand Up @@ -988,12 +998,13 @@ impl Handler {
&self,
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
) {
let diags = std::mem::take(&mut self.inner.borrow_mut().unstable_expect_diagnostics);
let mut inner = self.inner.borrow_mut();
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);
inner.check_unstable_expect_diagnostics = true;
if diags.is_empty() {
return;
}

let mut inner = self.inner.borrow_mut();
for mut diag in diags.into_iter() {
diag.update_unstable_expectation_id(unstable_to_stable);

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ pub trait ResolverExpand {
force: bool,
) -> Result<Lrc<SyntaxExtension>, Indeterminate>;

fn record_macro_rule_usage(&mut self, mac_id: NodeId, rule_index: usize);

fn check_unused_macros(&mut self);

// Resolver interfaces for specific built-in macros.
Expand Down
Loading