Skip to content

Commit 42ae1a7

Browse files
committed
Auto merge of rust-lang#118248 - compiler-errors:rollup-tye3vgj, r=compiler-errors
Rollup of 7 pull requests Successful merges: - rust-lang#118187 (Recompile LLVM when it changes in the git sources) - rust-lang#118210 (intercrate ambiguity causes: ignore candidates which don't apply) - rust-lang#118215 (Add common trait for crate definitions) - rust-lang#118238 (memcpy assumptions: update GCC link) - rust-lang#118243 (EvalCtxt::commit_if_ok don't inherit nested goals) - rust-lang#118245 (Add `Span` to `TraitBoundModifier`) - rust-lang#118246 (Remove a hack for effects) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4fd68eb + 592ee12 commit 42ae1a7

File tree

42 files changed

+485
-155
lines changed

Some content is hidden

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

42 files changed

+485
-155
lines changed

compiler/rustc_ast/src/ast.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub enum TraitBoundModifier {
301301
Maybe,
302302

303303
/// `~const Trait`
304-
MaybeConst,
304+
MaybeConst(Span),
305305

306306
/// `~const !Trait`
307307
//
@@ -317,8 +317,7 @@ pub enum TraitBoundModifier {
317317
impl TraitBoundModifier {
318318
pub fn to_constness(self) -> Const {
319319
match self {
320-
// FIXME(effects) span
321-
Self::MaybeConst => Const::Yes(DUMMY_SP),
320+
Self::MaybeConst(span) => Const::Yes(span),
322321
_ => Const::No,
323322
}
324323
}
@@ -3155,7 +3154,7 @@ mod size_asserts {
31553154
static_assert_size!(ForeignItem, 96);
31563155
static_assert_size!(ForeignItemKind, 24);
31573156
static_assert_size!(GenericArg, 24);
3158-
static_assert_size!(GenericBound, 56);
3157+
static_assert_size!(GenericBound, 64);
31593158
static_assert_size!(Generics, 40);
31603159
static_assert_size!(Impl, 136);
31613160
static_assert_size!(Item, 136);

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13691369
GenericBound::Trait(
13701370
ty,
13711371
modifier @ (TraitBoundModifier::None
1372-
| TraitBoundModifier::MaybeConst
1372+
| TraitBoundModifier::MaybeConst(_)
13731373
| TraitBoundModifier::Negative),
13741374
) => {
13751375
Some(this.lower_poly_trait_ref(ty, itctx, modifier.to_constness()))
@@ -2227,7 +2227,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22272227
fn lower_trait_bound_modifier(&mut self, f: TraitBoundModifier) -> hir::TraitBoundModifier {
22282228
match f {
22292229
TraitBoundModifier::None => hir::TraitBoundModifier::None,
2230-
TraitBoundModifier::MaybeConst => hir::TraitBoundModifier::MaybeConst,
2230+
TraitBoundModifier::MaybeConst(_) => hir::TraitBoundModifier::MaybeConst,
22312231

22322232
TraitBoundModifier::Negative => {
22332233
if self.tcx.features().negative_bounds {

compiler/rustc_ast_passes/src/ast_validation.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12031203
(BoundKind::TraitObject, TraitBoundModifier::Maybe) => {
12041204
self.err_handler().emit_err(errors::OptionalTraitObject { span: poly.span });
12051205
}
1206-
(_, TraitBoundModifier::MaybeConst)
1206+
(_, &TraitBoundModifier::MaybeConst(span))
12071207
if let Some(reason) = &self.disallow_tilde_const =>
12081208
{
12091209
let reason = match reason {
@@ -1224,8 +1224,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12241224
}
12251225
DisallowTildeConstContext::Item => errors::TildeConstReason::Item,
12261226
};
1227-
self.err_handler()
1228-
.emit_err(errors::TildeConstDisallowed { span: bound.span(), reason });
1227+
self.err_handler().emit_err(errors::TildeConstDisallowed { span, reason });
12291228
}
12301229
(_, TraitBoundModifier::MaybeConstMaybe) => {
12311230
self.err_handler().emit_err(errors::OptionalConstExclusive {

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ impl<'a> State<'a> {
15151515
TraitBoundModifier::Maybe => {
15161516
self.word("?");
15171517
}
1518-
TraitBoundModifier::MaybeConst => {
1518+
TraitBoundModifier::MaybeConst(_) => {
15191519
self.word_space("~const");
15201520
}
15211521
TraitBoundModifier::MaybeConstNegative => {

compiler/rustc_expand/src/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind,
44
use rustc_ast::{attr, token, util::literal};
55
use rustc_span::source_map::Spanned;
66
use rustc_span::symbol::{kw, sym, Ident, Symbol};
7-
use rustc_span::Span;
7+
use rustc_span::{Span, DUMMY_SP};
88
use thin_vec::{thin_vec, ThinVec};
99

1010
impl<'a> ExtCtxt<'a> {
@@ -135,7 +135,7 @@ impl<'a> ExtCtxt<'a> {
135135
ast::GenericBound::Trait(
136136
self.poly_trait_ref(path.span, path),
137137
if is_const {
138-
ast::TraitBoundModifier::MaybeConst
138+
ast::TraitBoundModifier::MaybeConst(DUMMY_SP)
139139
} else {
140140
ast::TraitBoundModifier::None
141141
},

compiler/rustc_hir_typeck/src/expr.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
526526
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
527527
};
528528

529-
if let ty::FnDef(did, callee_args) = *ty.kind() {
529+
if let ty::FnDef(did, _) = *ty.kind() {
530530
let fn_sig = ty.fn_sig(tcx);
531531

532-
// HACK: whenever we get a FnDef in a non-const context, enforce effects to get the
533-
// default `host = true` to avoid inference errors later.
534-
if tcx.hir().body_const_context(self.body_id).is_none() {
535-
self.enforce_context_effects(expr.hir_id, qpath.span(), did, callee_args);
536-
}
537532
if tcx.fn_sig(did).skip_binder().abi() == RustIntrinsic
538533
&& tcx.item_name(did) == sym::transmute
539534
{

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl BoundModifiers {
3737
(BoundPolarity::Positive, None) => TraitBoundModifier::None,
3838
(BoundPolarity::Negative(_), None) => TraitBoundModifier::Negative,
3939
(BoundPolarity::Maybe(_), None) => TraitBoundModifier::Maybe,
40-
(BoundPolarity::Positive, Some(_)) => TraitBoundModifier::MaybeConst,
40+
(BoundPolarity::Positive, Some(sp)) => TraitBoundModifier::MaybeConst(sp),
4141
(BoundPolarity::Negative(_), Some(_)) => TraitBoundModifier::MaybeConstNegative,
4242
(BoundPolarity::Maybe(_), Some(_)) => TraitBoundModifier::MaybeConstMaybe,
4343
}

compiler/rustc_smir/src/rustc_internal/internal.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use stable_mir::mir::alloc::AllocId;
1111
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
1212
use stable_mir::ty::{
1313
AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
14-
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, TraitRef,
15-
Ty, UintTy,
14+
ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IntTy, Region, RigidTy, Span,
15+
TraitRef, Ty, UintTy,
1616
};
1717
use stable_mir::{CrateItem, DefId};
1818

@@ -279,6 +279,14 @@ impl<'tcx> RustcInternal<'tcx> for AdtDef {
279279
}
280280
}
281281

282+
impl<'tcx> RustcInternal<'tcx> for Span {
283+
type T = rustc_span::Span;
284+
285+
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
286+
tables[*self]
287+
}
288+
}
289+
282290
impl<'tcx, T> RustcInternal<'tcx> for &T
283291
where
284292
T: RustcInternal<'tcx>,

compiler/rustc_smir/src/rustc_smir/mod.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::def::DefKind;
1414
use rustc_middle::mir;
1515
use rustc_middle::mir::interpret::{alloc_range, AllocId};
1616
use rustc_middle::mir::mono::MonoItem;
17+
use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
1718
use rustc_middle::ty::{self, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, Variance};
1819
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
1920
use rustc_target::abi::FieldIdx;
@@ -28,7 +29,7 @@ use stable_mir::ty::{
2829
EarlyParamRegion, FloatTy, FnDef, GenericArgs, GenericParamDef, IntTy, LineInfo, Movability,
2930
RigidTy, Span, TyKind, UintTy,
3031
};
31-
use stable_mir::{self, opaque, Context, CrateItem, Error, Filename, ItemKind};
32+
use stable_mir::{self, opaque, Context, Crate, CrateItem, Error, Filename, ItemKind, Symbol};
3233
use std::cell::RefCell;
3334
use tracing::debug;
3435

@@ -61,9 +62,18 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
6162
crates
6263
}
6364

64-
fn name_of_def_id(&self, def_id: stable_mir::DefId) -> String {
65+
fn def_name(&self, def_id: stable_mir::DefId, trimmed: bool) -> Symbol {
6566
let tables = self.0.borrow();
66-
tables.tcx.def_path_str(tables[def_id])
67+
if trimmed {
68+
with_forced_trimmed_paths!(tables.tcx.def_path_str(tables[def_id]))
69+
} else {
70+
with_no_trimmed_paths!(tables.tcx.def_path_str(tables[def_id]))
71+
}
72+
}
73+
74+
fn krate(&self, def_id: stable_mir::DefId) -> Crate {
75+
let tables = self.0.borrow();
76+
smir_crate(tables.tcx, tables[def_id].krate)
6777
}
6878

6979
fn span_to_string(&self, span: stable_mir::ty::Span) -> String {
@@ -240,12 +250,29 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
240250
tables.create_def_id(def_id)
241251
}
242252

243-
fn instance_mangled_name(&self, def: InstanceDef) -> String {
253+
fn instance_mangled_name(&self, instance: InstanceDef) -> Symbol {
244254
let tables = self.0.borrow_mut();
245-
let instance = tables.instances[def];
255+
let instance = tables.instances[instance];
246256
tables.tcx.symbol_name(instance).name.to_string()
247257
}
248258

259+
/// Retrieve the instance name for diagnostic messages.
260+
///
261+
/// This will return the specialized name, e.g., `Vec<char>::new`.
262+
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol {
263+
let tables = self.0.borrow_mut();
264+
let instance = tables.instances[def];
265+
if trimmed {
266+
with_forced_trimmed_paths!(
267+
tables.tcx.def_path_str_with_args(instance.def_id(), instance.args)
268+
)
269+
} else {
270+
with_no_trimmed_paths!(
271+
tables.tcx.def_path_str_with_args(instance.def_id(), instance.args)
272+
)
273+
}
274+
}
275+
249276
fn mono_instance(&self, item: stable_mir::CrateItem) -> stable_mir::mir::mono::Instance {
250277
let mut tables = self.0.borrow_mut();
251278
let def_id = tables[item.0];

compiler/rustc_trait_selection/src/solve/eval_ctxt/commit_if_ok.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::EvalCtxt;
1+
use super::{EvalCtxt, NestedGoals};
22
use crate::solve::inspect;
33
use rustc_middle::traits::query::NoSolution;
44

@@ -14,7 +14,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
1414
predefined_opaques_in_body: self.predefined_opaques_in_body,
1515
max_input_universe: self.max_input_universe,
1616
search_graph: self.search_graph,
17-
nested_goals: self.nested_goals.clone(),
17+
nested_goals: NestedGoals::new(),
1818
tainted: self.tainted,
1919
inspect: self.inspect.new_probe(),
2020
};
@@ -32,7 +32,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
3232
tainted,
3333
inspect,
3434
} = nested_ecx;
35-
self.nested_goals = nested_goals;
35+
self.nested_goals.extend(nested_goals);
3636
self.tainted = tainted;
3737
self.inspect.integrate_snapshot(inspect);
3838
} else {

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,19 @@ pub(super) struct NestedGoals<'tcx> {
108108
pub(super) goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
109109
}
110110

111-
impl NestedGoals<'_> {
111+
impl<'tcx> NestedGoals<'tcx> {
112112
pub(super) fn new() -> Self {
113113
Self { normalizes_to_hack_goal: None, goals: Vec::new() }
114114
}
115115

116116
pub(super) fn is_empty(&self) -> bool {
117117
self.normalizes_to_hack_goal.is_none() && self.goals.is_empty()
118118
}
119+
120+
pub(super) fn extend(&mut self, other: NestedGoals<'tcx>) {
121+
assert_eq!(other.normalizes_to_hack_goal, None);
122+
self.goals.extend(other.goals)
123+
}
119124
}
120125

121126
#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]

compiler/rustc_trait_selection/src/solve/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
334334
}
335335
}
336336

337-
// FIXME(@lcnr): If the normalization of the alias adds an inference constraint which
338-
// causes a previously added goal to fail, then we treat the alias as rigid.
339-
//
340-
// These feels like a potential issue, I should look into writing some tests here
341-
// and then probably changing `commit_if_ok` to not inherit the parent goals.
342337
match self.commit_if_ok(|this| {
343338
let normalized_ty = this.next_ty_infer();
344339
let normalizes_to_goal = Goal::new(

compiler/rustc_trait_selection/src/traits/coherence.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,10 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a> {
10501050
let mut ambiguity_cause = None;
10511051
for cand in goal.candidates() {
10521052
// FIXME: boiiii, using string comparisions here sure is scuffed.
1053-
if let inspect::ProbeKind::MiscCandidate { name: "coherence unknowable", result: _ } =
1054-
cand.kind()
1053+
if let inspect::ProbeKind::MiscCandidate {
1054+
name: "coherence unknowable",
1055+
result: Ok(_),
1056+
} = cand.kind()
10551057
{
10561058
let lazily_normalize_ty = |ty: Ty<'tcx>| {
10571059
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(infcx);

compiler/stable_mir/src/crate_def.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//! Module that define a common trait for things that represent a crate definition,
2+
//! such as, a function, a trait, an enum, and any other definitions.
3+
4+
use crate::ty::Span;
5+
use crate::{with, Crate, Symbol};
6+
7+
/// A unique identification number for each item accessible for the current compilation unit.
8+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
9+
pub struct DefId(pub(crate) usize);
10+
11+
/// A trait for retrieving information about a particular definition.
12+
///
13+
/// Implementors must provide the implementation of `def_id` which will be used to retrieve
14+
/// information about a crate's definition.
15+
pub trait CrateDef {
16+
/// Retrieve the unique identifier for the current definition.
17+
fn def_id(&self) -> DefId;
18+
19+
/// Return the fully qualified name of the current definition.
20+
fn name(&self) -> Symbol {
21+
let def_id = self.def_id();
22+
with(|cx| cx.def_name(def_id, false))
23+
}
24+
25+
/// Return a trimmed name of this definition.
26+
///
27+
/// This can be used to print more user friendly diagnostic messages.
28+
///
29+
/// If a symbol name can only be imported from one place for a type, and as
30+
/// long as it was not glob-imported anywhere in the current crate, we trim its
31+
/// path and print only the name.
32+
///
33+
/// For example, this function may shorten `std::vec::Vec` to just `Vec`,
34+
/// as long as there is no other `Vec` importable anywhere.
35+
fn trimmed_name(&self) -> Symbol {
36+
let def_id = self.def_id();
37+
with(|cx| cx.def_name(def_id, true))
38+
}
39+
40+
/// Return information about the crate where this definition is declared.
41+
///
42+
/// This will return the crate number and its name.
43+
fn krate(&self) -> Crate {
44+
let def_id = self.def_id();
45+
with(|cx| cx.krate(def_id))
46+
}
47+
48+
/// Return the span of this definition.
49+
fn span(&self) -> Span {
50+
let def_id = self.def_id();
51+
with(|cx| cx.span_of_an_item(def_id))
52+
}
53+
}
54+
55+
macro_rules! crate_def {
56+
( $(#[$attr:meta])*
57+
$vis:vis $name:ident $(;)?
58+
) => {
59+
$(#[$attr])*
60+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
61+
$vis struct $name(pub DefId);
62+
63+
impl CrateDef for $name {
64+
fn def_id(&self) -> DefId {
65+
self.0
66+
}
67+
}
68+
};
69+
}

0 commit comments

Comments
 (0)