Skip to content

Commit 63f70b3

Browse files
committed
Auto merge of #123991 - fmease:rollup-96xcgnm, r=fmease
Rollup of 7 pull requests Successful merges: - #123016 (Remove `TypeVariableOriginKind` and `ConstVariableOriginKind`) - #123462 (Cleanup: Rename `ModSep` to `PathSep`) - #123603 (Don't even parse an intrinsic unless the feature gate is enabled) - #123926 (Fix pretty HIR for anon consts in diagnostics) - #123973 (crashes: readme: add reminder to add Fixes #abcde to prs to automatically close issues.) - #123984 (sanitizers: Add rustc_sanitizers to triagebot.toml) - #123989 (Just use `type_dependent_def_id` to figure out what the method is for an expr) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ccfcd95 + daa2ebc commit 63f70b3

File tree

83 files changed

+401
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+401
-628
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4278,6 +4278,7 @@ dependencies = [
42784278
"rustc_fluent_macro",
42794279
"rustc_graphviz",
42804280
"rustc_hir",
4281+
"rustc_hir_pretty",
42814282
"rustc_index",
42824283
"rustc_macros",
42834284
"rustc_query_system",

compiler/rustc_ast/src/attr/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ impl MetaItem {
308308
// FIXME: Share code with `parse_path`.
309309
let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() {
310310
Some(&TokenTree::Token(
311-
Token { kind: ref kind @ (token::Ident(..) | token::ModSep), span },
311+
Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span },
312312
_,
313313
)) => 'arm: {
314314
let mut segments = if let &token::Ident(name, _) = kind {
315-
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. }, _)) =
315+
if let Some(TokenTree::Token(Token { kind: token::PathSep, .. }, _)) =
316316
tokens.peek()
317317
{
318318
tokens.next();
@@ -331,7 +331,7 @@ impl MetaItem {
331331
} else {
332332
return None;
333333
}
334-
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. }, _)) =
334+
if let Some(TokenTree::Token(Token { kind: token::PathSep, .. }, _)) =
335335
tokens.peek()
336336
{
337337
tokens.next();

compiler/rustc_ast/src/token.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub enum TokenKind {
290290
/// `:`
291291
Colon,
292292
/// `::`
293-
ModSep,
293+
PathSep,
294294
/// `->`
295295
RArrow,
296296
/// `<-`
@@ -393,7 +393,7 @@ impl TokenKind {
393393
BinOpEq(Shr) => (Gt, Ge),
394394
DotDot => (Dot, Dot),
395395
DotDotDot => (Dot, DotDot),
396-
ModSep => (Colon, Colon),
396+
PathSep => (Colon, Colon),
397397
RArrow => (BinOp(Minus), Gt),
398398
LArrow => (Lt, BinOp(Minus)),
399399
FatArrow => (Eq, Gt),
@@ -454,7 +454,9 @@ impl Token {
454454
match self.kind {
455455
Eq | Lt | Le | EqEq | Ne | Ge | Gt | AndAnd | OrOr | Not | Tilde | BinOp(_)
456456
| BinOpEq(_) | At | Dot | DotDot | DotDotDot | DotDotEq | Comma | Semi | Colon
457-
| ModSep | RArrow | LArrow | FatArrow | Pound | Dollar | Question | SingleQuote => true,
457+
| PathSep | RArrow | LArrow | FatArrow | Pound | Dollar | Question | SingleQuote => {
458+
true
459+
}
458460

459461
OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | Ident(..)
460462
| Lifetime(..) | Interpolated(..) | Eof => false,
@@ -481,7 +483,7 @@ impl Token {
481483
// DotDotDot is no longer supported, but we need some way to display the error
482484
DotDot | DotDotDot | DotDotEq | // range notation
483485
Lt | BinOp(Shl) | // associated path
484-
ModSep | // global path
486+
PathSep | // global path
485487
Lifetime(..) | // labeled loop
486488
Pound => true, // expression attributes
487489
Interpolated(ref nt) => matches!(&nt.0, NtLiteral(..) |
@@ -507,7 +509,7 @@ impl Token {
507509
// DotDotDot is no longer supported
508510
| DotDot | DotDotDot | DotDotEq // ranges
509511
| Lt | BinOp(Shl) // associated path
510-
| ModSep => true, // global path
512+
| PathSep => true, // global path
511513
Interpolated(ref nt) => matches!(&nt.0, NtLiteral(..) |
512514
NtPat(..) |
513515
NtBlock(..) |
@@ -530,7 +532,7 @@ impl Token {
530532
Question | // maybe bound in trait object
531533
Lifetime(..) | // lifetime bound in trait object
532534
Lt | BinOp(Shl) | // associated path
533-
ModSep => true, // global path
535+
PathSep => true, // global path
534536
Interpolated(ref nt) => matches!(&nt.0, NtTy(..) | NtPath(..)),
535537
// For anonymous structs or unions, which only appear in specific positions
536538
// (type of struct fields or union fields), we don't consider them as regular types
@@ -708,7 +710,7 @@ impl Token {
708710
}
709711

710712
pub fn is_path_start(&self) -> bool {
711-
self == &ModSep
713+
self == &PathSep
712714
|| self.is_qpath_start()
713715
|| self.is_whole_path()
714716
|| self.is_path_segment_keyword()
@@ -821,7 +823,7 @@ impl Token {
821823
_ => return None,
822824
},
823825
Colon => match joint.kind {
824-
Colon => ModSep,
826+
Colon => PathSep,
825827
_ => return None,
826828
},
827829
SingleQuote => match joint.kind {
@@ -830,7 +832,7 @@ impl Token {
830832
},
831833

832834
Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq(..) | At | DotDotDot
833-
| DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar
835+
| DotDotEq | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar
834836
| Question | OpenDelim(..) | CloseDelim(..) | Literal(..) | Ident(..)
835837
| Lifetime(..) | Interpolated(..) | DocComment(..) | Eof => return None,
836838
};

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
893893
token::Comma => ",".into(),
894894
token::Semi => ";".into(),
895895
token::Colon => ":".into(),
896-
token::ModSep => "::".into(),
896+
token::PathSep => "::".into(),
897897
token::RArrow => "->".into(),
898898
token::LArrow => "<-".into(),
899899
token::FatArrow => "=>".into(),

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -1752,32 +1752,31 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17521752
let tcx = self.infcx.tcx;
17531753
let hir = tcx.hir();
17541754
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
1755-
struct FindUselessClone<'hir> {
1756-
tcx: TyCtxt<'hir>,
1757-
def_id: DefId,
1758-
pub clones: Vec<&'hir hir::Expr<'hir>>,
1755+
1756+
struct FindUselessClone<'tcx> {
1757+
tcx: TyCtxt<'tcx>,
1758+
typeck_results: &'tcx ty::TypeckResults<'tcx>,
1759+
pub clones: Vec<&'tcx hir::Expr<'tcx>>,
17591760
}
1760-
impl<'hir> FindUselessClone<'hir> {
1761-
pub fn new(tcx: TyCtxt<'hir>, def_id: DefId) -> Self {
1762-
Self { tcx, def_id, clones: vec![] }
1761+
impl<'tcx> FindUselessClone<'tcx> {
1762+
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
1763+
Self { tcx, typeck_results: tcx.typeck(def_id), clones: vec![] }
17631764
}
17641765
}
1765-
1766-
impl<'v> Visitor<'v> for FindUselessClone<'v> {
1767-
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
1768-
if let hir::ExprKind::MethodCall(segment, _rcvr, args, _span) = ex.kind
1769-
&& segment.ident.name == sym::clone
1770-
&& args.len() == 0
1771-
&& let Some(def_id) = self.def_id.as_local()
1772-
&& let Some(method) = self.tcx.lookup_method_for_diagnostic((def_id, ex.hir_id))
1773-
&& Some(self.tcx.parent(method)) == self.tcx.lang_items().clone_trait()
1766+
impl<'tcx> Visitor<'tcx> for FindUselessClone<'tcx> {
1767+
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
1768+
if let hir::ExprKind::MethodCall(..) = ex.kind
1769+
&& let Some(method_def_id) =
1770+
self.typeck_results.type_dependent_def_id(ex.hir_id)
1771+
&& self.tcx.lang_items().clone_trait() == Some(self.tcx.parent(method_def_id))
17741772
{
17751773
self.clones.push(ex);
17761774
}
17771775
hir::intravisit::walk_expr(self, ex);
17781776
}
17791777
}
1780-
let mut expr_finder = FindUselessClone::new(tcx, self.mir_def_id().into());
1778+
1779+
let mut expr_finder = FindUselessClone::new(tcx, self.mir_def_id());
17811780

17821781
let body = hir.body(body_id).value;
17831782
expr_finder.visit_expr(body);

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::{self, RegionVid, Ty};
2626
use rustc_middle::ty::{Region, TyCtxt};
2727
use rustc_span::symbol::{kw, Ident};
2828
use rustc_span::Span;
29-
use rustc_trait_selection::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
29+
use rustc_trait_selection::infer::type_variable::TypeVariableOrigin;
3030
use rustc_trait_selection::infer::InferCtxtExt;
3131
use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
3232

@@ -1104,10 +1104,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11041104
);
11051105
let closure_kind = args.as_closure().kind();
11061106
let closure_kind_ty = Ty::from_closure_kind(tcx, closure_kind);
1107-
let tupled_upvars_ty = self.infcx.next_ty_var(TypeVariableOrigin {
1108-
kind: TypeVariableOriginKind::ClosureSynthetic,
1109-
span: closure_expr.span,
1110-
});
1107+
let tupled_upvars_ty = self
1108+
.infcx
1109+
.next_ty_var(TypeVariableOrigin { param_def_id: None, span: closure_expr.span });
11111110
let closure_args = ty::ClosureArgs::new(
11121111
tcx,
11131112
ty::ClosureArgsParts {
@@ -1131,17 +1130,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11311130
};
11321131
// The found `Self` type of the method call.
11331132
let Some(possible_rcvr_ty) = tables.node_type_opt(rcvr.hir_id) else { return };
1134-
1135-
// The `MethodCall` expression is `Res::Err`, so we search for the method on the `rcvr_ty`.
1136-
let Some(method) = tcx.lookup_method_for_diagnostic((self.mir_def_id(), expr.hir_id))
1137-
else {
1138-
return;
1139-
};
1133+
let Some(method_def_id) = tables.type_dependent_def_id(expr.hir_id) else { return };
11401134

11411135
// Get the type for the parameter corresponding to the argument the closure with the
11421136
// lifetime error we had.
11431137
let Some(input) = tcx
1144-
.fn_sig(method)
1138+
.fn_sig(method_def_id)
11451139
.instantiate_identity()
11461140
.inputs()
11471141
.skip_binder()
@@ -1156,7 +1150,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11561150
let ty::Param(closure_param) = input.kind() else { return };
11571151

11581152
// Get the arguments for the found method, only specifying that `Self` is the receiver type.
1159-
let args = GenericArgs::for_item(tcx, method, |param, _| {
1153+
let args = GenericArgs::for_item(tcx, method_def_id, |param, _| {
11601154
if param.index == 0 {
11611155
possible_rcvr_ty.into()
11621156
} else if param.index == closure_param.index {
@@ -1166,7 +1160,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
11661160
}
11671161
});
11681162

1169-
let preds = tcx.predicates_of(method).instantiate(tcx, args);
1163+
let preds = tcx.predicates_of(method_def_id).instantiate(tcx, args);
11701164

11711165
let ocx = ObligationCtxt::new(&self.infcx);
11721166
ocx.register_obligations(preds.iter().map(|(pred, span)| {

compiler/rustc_borrowck/src/type_check/input_output.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::assert_matches::assert_matches;
1111

1212
use itertools::Itertools;
1313
use rustc_hir as hir;
14-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
14+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1515
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
1616
use rustc_middle::mir::*;
1717
use rustc_middle::ty::{self, Ty};
@@ -75,10 +75,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7575
);
7676

7777
let next_ty_var = || {
78-
self.infcx.next_ty_var(TypeVariableOrigin {
79-
span: body.span,
80-
kind: TypeVariableOriginKind::MiscVariable,
81-
})
78+
self.infcx.next_ty_var(TypeVariableOrigin { span: body.span, param_def_id: None })
8279
};
8380
let output_ty = Ty::new_coroutine(
8481
self.tcx(),

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::{IndexSlice, IndexVec};
1616
use rustc_infer::infer::canonical::QueryRegionConstraints;
1717
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1818
use rustc_infer::infer::region_constraints::RegionConstraintData;
19-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
19+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
2020
use rustc_infer::infer::{
2121
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
2222
};
@@ -2425,7 +2425,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24252425
ty::RawPtr(_, _) | ty::FnPtr(_) => {
24262426
let ty_right = right.ty(body, tcx);
24272427
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
2428-
kind: TypeVariableOriginKind::MiscVariable,
2428+
param_def_id: None,
24292429
span: body.source_info(location).span,
24302430
});
24312431
self.sub_types(

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_errors::ErrorGuaranteed;
3-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
3+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
44
use rustc_infer::infer::NllRegionVariableOrigin;
55
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
66
use rustc_infer::traits::{Obligation, PredicateObligations};
@@ -129,10 +129,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
129129
// the opaque.
130130
let mut enable_subtyping = |ty, opaque_is_expected| {
131131
let ty_vid = infcx.next_ty_var_id_in_universe(
132-
TypeVariableOrigin {
133-
kind: TypeVariableOriginKind::MiscVariable,
134-
span: self.span(),
135-
},
132+
TypeVariableOrigin { param_def_id: None, span: self.span() },
136133
ty::UniverseIndex::ROOT,
137134
);
138135

compiler/rustc_driver_impl/src/pretty.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ struct AstNoAnn;
2424

2525
impl pprust_ast::PpAnn for AstNoAnn {}
2626

27-
struct HirNoAnn<'tcx> {
28-
tcx: TyCtxt<'tcx>,
29-
}
30-
31-
impl<'tcx> pprust_hir::PpAnn for HirNoAnn<'tcx> {
32-
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
33-
pprust_hir::PpAnn::nested(
34-
&(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>),
35-
state,
36-
nested,
37-
)
38-
}
39-
}
40-
4127
struct AstIdentifiedAnn;
4228

4329
impl pprust_ast::PpAnn for AstIdentifiedAnn {
@@ -300,10 +286,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
300286
)
301287
};
302288
match s {
303-
PpHirMode::Normal => {
304-
let annotation = HirNoAnn { tcx };
305-
f(&annotation)
306-
}
289+
PpHirMode::Normal => f(&tcx),
307290
PpHirMode::Identified => {
308291
let annotation = HirIdentifiedAnn { tcx };
309292
f(&annotation)

compiler/rustc_expand/src/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
208208
Comma => op(","),
209209
Semi => op(";"),
210210
Colon => op(":"),
211-
ModSep => op("::"),
211+
PathSep => op("::"),
212212
RArrow => op("->"),
213213
LArrow => op("<-"),
214214
FatArrow => op("=>"),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::intravisit;
1010
use rustc_hir::{GenericParamKind, ImplItemKind};
1111
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
12-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
12+
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1313
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
1414
use rustc_infer::traits::{util, FulfillmentError};
1515
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -800,10 +800,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
800800
bug!("FIXME(RPITIT): error here");
801801
}
802802
// Replace with infer var
803-
let infer_ty = self.ocx.infcx.next_ty_var(TypeVariableOrigin {
804-
span: self.span,
805-
kind: TypeVariableOriginKind::MiscVariable,
806-
});
803+
let infer_ty = self
804+
.ocx
805+
.infcx
806+
.next_ty_var(TypeVariableOrigin { span: self.span, param_def_id: None });
807807
self.types.insert(proj.def_id, (infer_ty, proj.args));
808808
// Recurse into bounds
809809
for (pred, pred_span) in self

compiler/rustc_hir_analysis/src/check/errs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn maybe_expr_static_mut(tcx: TyCtxt<'_>, expr: hir::Expr<'_>) {
1212
let hir_id = expr.hir_id;
1313
if let hir::ExprKind::AddrOf(borrow_kind, m, expr) = expr.kind
1414
&& matches!(borrow_kind, hir::BorrowKind::Ref)
15-
&& let Some(var) = is_path_static_mut(*expr)
15+
&& let Some(var) = path_if_static_mut(tcx, expr)
1616
{
1717
handle_static_mut_ref(tcx, span, var, span.edition().at_least_rust_2024(), m, hir_id);
1818
}
@@ -24,7 +24,7 @@ pub fn maybe_stmt_static_mut(tcx: TyCtxt<'_>, stmt: hir::Stmt<'_>) {
2424
&& let hir::PatKind::Binding(ba, _, _, _) = loc.pat.kind
2525
&& let hir::ByRef::Yes(rmutbl) = ba.0
2626
&& let Some(init) = loc.init
27-
&& let Some(var) = is_path_static_mut(*init)
27+
&& let Some(var) = path_if_static_mut(tcx, init)
2828
{
2929
handle_static_mut_ref(
3030
tcx,
@@ -37,13 +37,13 @@ pub fn maybe_stmt_static_mut(tcx: TyCtxt<'_>, stmt: hir::Stmt<'_>) {
3737
}
3838
}
3939

40-
fn is_path_static_mut(expr: hir::Expr<'_>) -> Option<String> {
40+
fn path_if_static_mut(tcx: TyCtxt<'_>, expr: &hir::Expr<'_>) -> Option<String> {
4141
if let hir::ExprKind::Path(qpath) = expr.kind
4242
&& let hir::QPath::Resolved(_, path) = qpath
4343
&& let hir::def::Res::Def(def_kind, _) = path.res
4444
&& let hir::def::DefKind::Static { mutability: Mutability::Mut, nested: false } = def_kind
4545
{
46-
return Some(qpath_to_string(&qpath));
46+
return Some(qpath_to_string(&tcx, &qpath));
4747
}
4848
None
4949
}

0 commit comments

Comments
 (0)