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 7 pull requests #81621

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4133,6 +4133,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
"rustc_trait_selection",
"rustc_typeck",
"tracing",
]
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let count = generics
.params
.iter()
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
.filter(|param| {
matches!(param.kind, ast::GenericParamKind::Lifetime { .. })
})
.count();
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl<'a> TraitDef<'a> {

let mut ty_params = params
.iter()
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type{..}))
.filter(|param| matches!(param.kind, ast::GenericParamKind::Type { .. }))
.peekable();

if ty_params.peek().is_some() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! forward_inner_docs {
($e:expr => $i:item) => {
#[doc = $e]
$i
}
};
}

/// In general, the `DiagnosticBuilder` uses deref to allow access to
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_errors/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ impl Annotation {
}

pub fn is_multiline(&self) -> bool {
matches!(self.annotation_type,
matches!(
self.annotation_type,
AnnotationType::Multiline(_)
| AnnotationType::MultilineStart(_)
| AnnotationType::MultilineLine(_)
| AnnotationType::MultilineEnd(_))
| AnnotationType::MultilineStart(_)
| AnnotationType::MultilineLine(_)
| AnnotationType::MultilineEnd(_)
)
}

pub fn len(&self) -> usize {
Expand Down Expand Up @@ -158,7 +160,10 @@ impl Annotation {

pub fn takes_space(&self) -> bool {
// Multiline annotations always have to keep vertical space.
matches!(self.annotation_type, AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_))
matches!(
self.annotation_type,
AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_)
)
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,10 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
**qpath,
QPath::LangItem(
LangItem::Range
| LangItem::RangeTo
| LangItem::RangeFrom
| LangItem::RangeFull
| LangItem::RangeToInclusive,
| LangItem::RangeTo
| LangItem::RangeFrom
| LangItem::RangeFull
| LangItem::RangeToInclusive,
_,
)
),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::infer::canonical::{
};
use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
use crate::infer::{InferCtxt, InferOk, InferResult, NLLRegionVariableOrigin};
use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
use crate::traits::query::{Fallible, NoSolution};
use crate::traits::TraitEngine;
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
Expand Down Expand Up @@ -644,7 +644,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
}

fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> {
let origin = NLLRegionVariableOrigin::Existential { from_forall };
let origin = NllRegionVariableOrigin::Existential { from_forall };
self.infcx.next_nll_region_var(origin)
}

Expand All @@ -654,7 +654,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {

fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
self.infcx.next_nll_region_var_in_universe(
NLLRegionVariableOrigin::Existential { from_forall: false },
NllRegionVariableOrigin::Existential { from_forall: false },
universe,
)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
format!(" for capture of `{}` by closure", var_name)
}
infer::NLL(..) => bug!("NLL variable found in lexical phase"),
infer::Nll(..) => bug!("NLL variable found in lexical phase"),
};

struct_span_err!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
[segment]
if segment
.res
.map(|res| matches!(res, Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _)))
.map(|res| {
matches!(
res,
Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _)
)
})
.unwrap_or(false) =>
{
self.types.push(path.span);
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ pub enum RegionVariableOrigin {

/// This origin is used for the inference variables that we create
/// during NLL region processing.
NLL(NLLRegionVariableOrigin),
Nll(NllRegionVariableOrigin),
}

#[derive(Copy, Clone, Debug)]
pub enum NLLRegionVariableOrigin {
pub enum NllRegionVariableOrigin {
/// During NLL region processing, we create variables for free
/// regions that we encounter in the function signature and
/// elsewhere. This origin indices we've got one of those.
Expand Down Expand Up @@ -1078,17 +1078,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}

/// Just a convenient wrapper of `next_region_var` for using during NLL.
pub fn next_nll_region_var(&self, origin: NLLRegionVariableOrigin) -> ty::Region<'tcx> {
self.next_region_var(RegionVariableOrigin::NLL(origin))
pub fn next_nll_region_var(&self, origin: NllRegionVariableOrigin) -> ty::Region<'tcx> {
self.next_region_var(RegionVariableOrigin::Nll(origin))
}

/// Just a convenient wrapper of `next_region_var` for using during NLL.
pub fn next_nll_region_var_in_universe(
&self,
origin: NLLRegionVariableOrigin,
origin: NllRegionVariableOrigin,
universe: ty::UniverseIndex,
) -> ty::Region<'tcx> {
self.next_region_var_in_universe(RegionVariableOrigin::NLL(origin), universe)
self.next_region_var_in_universe(RegionVariableOrigin::Nll(origin), universe)
}

pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
Expand Down Expand Up @@ -1770,7 +1770,7 @@ impl RegionVariableOrigin {
| LateBoundRegion(a, ..)
| UpvarRegion(_, a) => a,
BoundRegionInCoherence(_) => rustc_span::DUMMY_SP,
NLL(..) => bug!("NLL variable used with `span`"),
Nll(..) => bug!("NLL variable used with `span`"),
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ declare_lint! {

declare_lint_pass!(NonCamelCaseTypes => [NON_CAMEL_CASE_TYPES]);

/// Some unicode characters *have* case, are considered upper case or lower case, but they *can't*
/// be upper cased or lower cased. For the purposes of the lint suggestion, we care about being able
/// to change the char's case.
fn char_has_case(c: char) -> bool {
c.is_lowercase() || c.is_uppercase()
let mut l = c.to_lowercase();
let mut u = c.to_uppercase();
while let Some(l) = l.next() {
match u.next() {
Some(u) if l != u => return true,
_ => {}
}
}
u.next().is_some()
}

fn is_camel_case(name: &str) -> bool {
Expand Down Expand Up @@ -138,6 +149,8 @@ impl NonCamelCaseTypes {
to_camel_case(name),
Applicability::MaybeIncorrect,
);
} else {
err.span_label(ident.span, "should have an UpperCamelCase name");
}

err.emit();
Expand Down Expand Up @@ -299,6 +312,8 @@ impl NonSnakeCase {
} else {
err.help(&format!("convert the identifier to snake case: `{}`", sc));
}
} else {
err.span_label(ident.span, "should have a snake_case name");
}

err.emit();
Expand Down Expand Up @@ -477,6 +492,8 @@ impl NonUpperCaseGlobals {
uc,
Applicability::MaybeIncorrect,
);
} else {
err.span_label(ident.span, "should have an UPPER_CASE name");
}

err.emit();
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ impl<'hir> Map<'hir> {
self.find(self.get_parent_node(id)),
Some(
Node::Item(_)
| Node::TraitItem(_)
| Node::ImplItem(_)
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
| Node::TraitItem(_)
| Node::ImplItem(_)
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
)
)
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,7 @@ impl<'tcx> LocalDecl<'tcx> {
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})
| BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
}) | BindingForm::ImplicitSelf(ImplicitSelfKind::Imm),
)))
)
}
Expand All @@ -980,8 +979,7 @@ impl<'tcx> LocalDecl<'tcx> {
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
})
| BindingForm::ImplicitSelf(_),
}) | BindingForm::ImplicitSelf(_),
)))
)
}
Expand Down
18 changes: 11 additions & 7 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ impl<'tcx> TyS<'tcx> {
pub fn is_primitive_ty(&self) -> bool {
matches!(
self.kind(),
Bool | Char | Str | Int(_) | Uint(_) | Float(_)
| Infer(
InferTy::IntVar(_)
| InferTy::FloatVar(_)
| InferTy::FreshIntTy(_)
| InferTy::FreshFloatTy(_)
)
Bool | Char
| Str
| Int(_)
| Uint(_)
| Float(_)
| Infer(
InferTy::IntVar(_)
| InferTy::FloatVar(_)
| InferTy::FreshIntTy(_)
| InferTy::FreshFloatTy(_)
)
)
}

Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,14 @@ impl<T> Trait<T> for X {
let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name);

// We don't want to suggest calling an assoc fn in a scope where that isn't feasible.
let callable_scope = matches!(body_owner, Some(
let callable_scope = matches!(
body_owner,
Some(
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. })
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
));
| hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }),
)
);
let impl_comparison = matches!(
cause_code,
ObligationCauseCode::CompareImplMethodObligation { .. }
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,14 @@ impl<'tcx> TyS<'tcx> {
pub fn is_scalar(&self) -> bool {
matches!(
self.kind(),
Bool | Char | Int(_) | Float(_) | Uint(_) | FnDef(..) | FnPtr(_) | RawPtr(_)
| Infer(IntVar(_) | FloatVar(_))
Bool | Char
| Int(_)
| Float(_)
| Uint(_)
| FnDef(..)
| FnPtr(_)
| RawPtr(_)
| Infer(IntVar(_) | FloatVar(_))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::VecDeque;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_index::vec::IndexVec;
use rustc_infer::infer::NLLRegionVariableOrigin;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{
Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue,
Statement, StatementKind, TerminatorKind,
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let (category, from_closure, span) = self.regioncx.best_blame_constraint(
&self.body,
borrow_region,
NLLRegionVariableOrigin::FreeRegion,
NllRegionVariableOrigin::FreeRegion,
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_infer::infer::{
error_reporting::nice_region_error::NiceRegionError,
error_reporting::unexpected_hidden_region_diagnostic, NLLRegionVariableOrigin,
error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin,
};
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
use rustc_middle::ty::subst::Subst;
Expand Down Expand Up @@ -75,13 +75,13 @@ crate enum RegionErrorKind<'tcx> {
/// The region element that erroneously must be outlived by `longer_fr`.
error_element: RegionElement,
/// The origin of the placeholder region.
fr_origin: NLLRegionVariableOrigin,
fr_origin: NllRegionVariableOrigin,
},

/// Any other lifetime error.
RegionError {
/// The origin of the region.
fr_origin: NLLRegionVariableOrigin,
fr_origin: NllRegionVariableOrigin,
/// The region that should outlive `shorter_fr`.
longer_fr: RegionVid,
/// The region that should be shorter, but we can't prove it.
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
pub(in crate::borrow_check) fn report_region_error(
&mut self,
fr: RegionVid,
fr_origin: NLLRegionVariableOrigin,
fr_origin: NllRegionVariableOrigin,
outlived_fr: RegionVid,
outlives_suggestion: &mut OutlivesSuggestionBuilder,
) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use super::{OutlivesConstraint, RegionInferenceContext};
use crate::borrow_check::type_check::Locations;
use rustc_infer::infer::NLLRegionVariableOrigin;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::ty::TyCtxt;
use std::io::{self, Write};

Expand All @@ -20,7 +20,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
writeln!(out, "| Free Region Mapping")?;

for region in self.regions() {
if let NLLRegionVariableOrigin::FreeRegion = self.definitions[region].origin {
if let NllRegionVariableOrigin::FreeRegion = self.definitions[region].origin {
let classification = self.universal_regions.region_classification(region).unwrap();
let outlived_by = self.universal_region_relations.regions_outlived_by(region);
writeln!(
Expand Down
Loading