Skip to content

Commit

Permalink
Auto merge of rust-lang#105644 - matthiaskrgr:rollup-qc6hlzq, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104864 (Account for item-local in inner scope for E0425)
 - rust-lang#105332 (Point out the type of associated types in every method call of iterator chains)
 - rust-lang#105620 (Remove unnecessary uses of `clone`)
 - rust-lang#105625 (minor code cleanups)
 - rust-lang#105629 (rustdoc: stop treating everything in a trait item as a method)
 - rust-lang#105636 (Add check for local-storage value when changing "display line numbers" settings)
 - rust-lang#105639 (rustdoc: remove `type="text/css" from stylesheet links)
 - rust-lang#105640 (Adjust miri to still be optional)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 13, 2022
2 parents ed97493 + 5af0447 commit b96d9e0
Show file tree
Hide file tree
Showing 60 changed files with 865 additions and 244 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,9 @@ impl Integer {
pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
let dl = cx.data_layout();

for candidate in [I8, I16, I32, I64, I128] {
if wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() {
return Some(candidate);
}
}
None
[I8, I16, I32, I64, I128].into_iter().find(|&candidate| {
wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes()
})
}

/// Find the largest integer with the given alignment or less.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Lit {
if let NtExpr(expr) | NtLiteral(expr) = &**nt
&& let ast::ExprKind::Lit(token_lit) = expr.kind =>
{
Some(token_lit.clone())
Some(token_lit)
}
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn check_incompatible_features(sess: &Session) {
{
let spans = vec![f1_span, f2_span];
sess.struct_span_err(
spans.clone(),
spans,
&format!(
"features `{}` and `{}` are incompatible, using them at the same time \
is not allowed",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider cloning the value if the performance cost is acceptable",
".clone()".to_string(),
".clone()",
Applicability::MachineApplicable,
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn expand(
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
} else {
ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "alloc_error_handler must be a function");
return vec![orig_item.clone()];
return vec![orig_item];
};

// Generate a bunch of new items using the AllocFnFactory
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/concat_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn expand_concat_bytes(
}
}
if !missing_literals.is_empty() {
let mut err = cx.struct_span_err(missing_literals.clone(), "expected a byte literal");
let mut err = cx.struct_span_err(missing_literals, "expected a byte literal");
err.note("only byte literals (like `b\"foo\"`, `b's'`, and `[3, 4, 5]`) can be passed to `concat_bytes!()`");
err.emit();
return base::MacEager::expr(DummyResult::raw_expr(sp, true));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub(crate) fn run_thin(
}

pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
let name = module.name.clone();
let name = module.name;
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true);
(name, buffer)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/base_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const MAX_BASE: usize = 64;
pub const ALPHANUMERIC_ONLY: usize = 62;
pub const CASE_INSENSITIVE: usize = 36;

const BASE_64: &[u8; MAX_BASE as usize] =
const BASE_64: &[u8; MAX_BASE] =
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";

#[inline]
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ impl Diagnostic {
self.set_span(after);
for span_label in before.span_labels() {
if let Some(label) = span_label.label {
self.span.push_span_label(after, label);
if span_label.is_primary {
self.span.push_span_label(after, label);
} else {
self.span.push_span_label(span_label.span, label);
}
}
}
self
Expand Down Expand Up @@ -802,7 +806,7 @@ impl Diagnostic {
debug_assert!(
!(suggestions
.iter()
.flat_map(|suggs| suggs)
.flatten()
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
"Span must not be empty and have no suggestion"
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ impl EmitterWriter {
// see how it *looks* with
// very *weird* formats
// see?
for &(ref text, ref style) in msg.iter() {
for (text, style) in msg.iter() {
let text = self.translate_message(text, args);
let lines = text.split('\n').collect::<Vec<_>>();
if lines.len() > 1 {
Expand Down Expand Up @@ -1370,7 +1370,7 @@ impl EmitterWriter {
buffer.append(0, ": ", header_style);
label_width += 2;
}
for &(ref text, _) in msg.iter() {
for (text, _) in msg.iter() {
let text = self.translate_message(text, args);
// Account for newlines to align output to its label.
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,7 @@ impl<'hir> Generics<'hir> {
}

pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'hir>> {
for param in self.params {
if name == param.name.ident().name {
return Some(param);
}
}
None
self.params.iter().find(|&param| name == param.name.ident().name)
}

pub fn spans(&self) -> MultiSpan {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<T: Idx> BitSet<T> {
self.words[start_word_index] |= !(start_mask - 1);
// And all trailing bits (i.e. from 0..=end) in the end word,
// including the end.
self.words[end_word_index] |= end_mask | end_mask - 1;
self.words[end_word_index] |= end_mask | (end_mask - 1);
} else {
self.words[start_word_index] |= end_mask | (end_mask - start_mask);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub fn suggest_new_region_bound(
Applicability::MaybeIncorrect,
);
}
if let Some((param_span, param_ty)) = param.clone() {
if let Some((param_span, ref param_ty)) = param {
err.span_suggestion_verbose(
param_span,
add_static_bound,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lexer/src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,13 @@ fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError
})?;
}
Some(c) => {
let digit =
let digit: u32 =
c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
n_digits += 1;
if n_digits > 6 {
// Stop updating value since we're sure that it's incorrect already.
continue;
}
let digit = digit as u32;
value = value * 16 + digit;
}
};
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
/// FIXME #4948: Reuse ribs to avoid allocation.
ribs: PerNS<Vec<Rib<'a>>>,

/// Previous poped `rib`, only used for diagnostic.
last_block_rib: Option<Rib<'a>>,

/// The current set of local scopes, for labels.
label_ribs: Vec<Rib<'a, NodeId>>,

Expand Down Expand Up @@ -873,6 +876,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
// Ignore errors in function bodies if this is rustdoc
// Be sure not to set this until the function signature has been resolved.
let previous_state = replace(&mut this.in_func_body, true);
// We only care block in the same function
this.last_block_rib = None;
// Resolve the function body, potentially inside the body of an async closure
this.with_lifetime_rib(
LifetimeRibKind::Elided(LifetimeRes::Infer),
Expand Down Expand Up @@ -1168,6 +1173,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
type_ns: vec![Rib::new(start_rib_kind)],
macro_ns: vec![Rib::new(start_rib_kind)],
},
last_block_rib: None,
label_ribs: Vec::new(),
lifetime_ribs: Vec::new(),
lifetime_elision_candidates: None,
Expand Down Expand Up @@ -3769,7 +3775,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.ribs[ValueNS].pop();
self.label_ribs.pop();
}
self.ribs[ValueNS].pop();
self.last_block_rib = self.ribs[ValueNS].pop();
if anonymous_module.is_some() {
self.ribs[TypeNS].pop();
}
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,22 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
return (true, candidates);
}
}

// Try to find in last block rib
if let Some(rib) = &self.last_block_rib && let RibKind::NormalRibKind = rib.kind {
for (ident, &res) in &rib.bindings {
if let Res::Local(_) = res && path.len() == 1 &&
ident.span.eq_ctxt(path[0].ident.span) &&
ident.name == path[0].ident.name {
err.span_help(
ident.span,
&format!("the binding `{}` is available in a different scope in the same function", path_str),
);
return (true, candidates);
}
}
}

return (false, candidates);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ impl FilePathMapping {
// NOTE: We are iterating over the mapping entries from last to first
// because entries specified later on the command line should
// take precedence.
for &(ref from, ref to) in mapping.iter().rev() {
for (from, to) in mapping.iter().rev() {
debug!("Trying to apply {from:?} => {to:?}");

if let Ok(rest) = path.strip_prefix(from) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use crate::infer::InferCtxt;

use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::{self, Ty, TyCtxt};

pub struct CollectAllMismatches<'a, 'tcx> {
pub infcx: &'a InferCtxt<'tcx>,
pub param_env: ty::ParamEnv<'tcx>,
pub errors: Vec<TypeError<'tcx>>,
}

impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
fn tag(&self) -> &'static str {
"CollectAllMismatches"
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}
fn intercrate(&self) -> bool {
false
}
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
}
fn a_is_expected(&self) -> bool {
true
} // irrelevant
fn mark_ambiguous(&mut self) {
bug!()
}
fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
_: ty::Variance,
_: ty::VarianceDiagInfo<'tcx>,
a: T,
b: T,
) -> RelateResult<'tcx, T> {
self.relate(a, b)
}
fn regions(
&mut self,
a: ty::Region<'tcx>,
_b: ty::Region<'tcx>,
) -> RelateResult<'tcx, ty::Region<'tcx>> {
Ok(a)
}
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
if a == b || matches!(a.kind(), ty::Infer(_)) || matches!(b.kind(), ty::Infer(_)) {
return Ok(a);
}
relate::super_relate_tys(self, a, b).or_else(|e| {
self.errors.push(e);
Ok(a)
})
}
fn consts(
&mut self,
a: ty::Const<'tcx>,
b: ty::Const<'tcx>,
) -> RelateResult<'tcx, ty::Const<'tcx>> {
if a == b {
return Ok(a);
}
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
}
fn binders<T: Relate<'tcx>>(
&mut self,
a: ty::Binder<'tcx, T>,
b: ty::Binder<'tcx, T>,
) -> RelateResult<'tcx, ty::Binder<'tcx, T>> {
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod ambiguity;
pub mod method_chain;
pub mod on_unimplemented;
pub mod suggestions;

Expand Down Expand Up @@ -536,7 +537,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|err| {
self.note_obligation_cause_code(
err,
&predicate,
predicate,
obligation.param_env,
obligation.cause.code(),
&mut vec![],
Expand Down Expand Up @@ -1587,7 +1588,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
{
self.note_obligation_cause_code(
&mut diag,
&error.obligation.predicate,
error.obligation.predicate,
error.obligation.param_env,
code,
&mut vec![],
Expand Down Expand Up @@ -2602,7 +2603,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
self.note_obligation_cause_code(
err,
&obligation.predicate,
obligation.predicate,
obligation.param_env,
obligation.cause.code(),
&mut vec![],
Expand Down
Loading

0 comments on commit b96d9e0

Please sign in to comment.